:root {
  color-scheme: dark;
  --bg: #0e0f13;
  --surface: #16181f;
  --surface-2: #1d2029;
  --border: #2a2e3a;
  --border-strong: #3a3f4e;
  --text: #e8e9ee;
  --muted: #9aa0b0;
  --accent: #ff5c6c;
  --accent-2: #ff8a5c;
  --accent-soft: rgba(255,92,108,.14);
  --focus-ring: rgba(255,92,108,.18);
  --ok: #3ddc84;
  --ok-text: #9ff0c4;
  --warn: #ffb547;
  --warn-text: #ffd79a;
  --off: #6b7180;
  --error: #ff6b6b;
  --danger-text: #ffb3b3;
  --hover: rgba(255,255,255,.04);
  --tip-bg: #0b0c10;
  --shadow: 0 6px 18px rgba(0,0,0,.35);
  --glow-1: rgba(255,92,108,.12);
  --glow-2: rgba(255,138,92,.08);
  --radius: 14px;
}
/* Motyw jasny: wybrany recznie albo "auto" przy jasnym systemie */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --border: #dde1ea;
  --border-strong: #c3c9d6;
  --text: #171923;
  --muted: #5a6273;
  --accent: #d83a4b;
  --accent-2: #e2602f;
  --accent-soft: rgba(216,58,75,.10);
  --focus-ring: rgba(216,58,75,.20);
  --ok: #17924f;
  --ok-text: #0f7a40;
  --warn: #c77a00;
  --warn-text: #8f5800;
  --off: #8a90a0;
  --error: #c62f3c;
  --danger-text: #b3202e;
  --hover: rgba(0,0,0,.04);
  --tip-bg: #ffffff;
  --shadow: 0 6px 18px rgba(20,24,40,.12);
  --glow-1: rgba(216,58,75,.08);
  --glow-2: rgba(226,96,47,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, var(--glow-1), transparent 60%),
              radial-gradient(900px 500px at -10% 10%, var(--glow-2), transparent 60%),
              var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  min-height: 100vh;
}
a { color: inherit; }
code {
  font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
}
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* ---------- Naglowek i zakladki ---------- */
header { padding: 18px 0 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: .2px; text-decoration: none; }
.logo .heart { color: var(--accent); font-size: 22px; }
.account { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.account .who { color: var(--muted); }

.tabs {
  display: flex; gap: 4px; margin-top: 18px; border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 9px 16px; border-radius: 999px; text-decoration: none; font: inherit; font-weight: 600; font-size: 14px;
  color: var(--text); border: 1px solid var(--border); background: var(--surface-2); transition: transform .15s, border-color .15s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn.big { padding: 11px 20px; font-size: 15px; }
.btn[disabled] { opacity: .6; cursor: wait; transform: none; }

/* ---------- Tresc ---------- */
.hero { padding: 48px 0 28px; }
.hero h1 { font-size: clamp(32px, 6vw, 54px); line-height: 1.1; margin: 0 0 16px; letter-spacing: -.5px; }
.hero h1 strong, .hero h1 span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); font-size: 18px; max-width: 640px; margin: 0 0 26px; }
.hero .actions { display: flex; gap: 12px; flex-wrap: wrap; }
.hero p:last-child { margin-bottom: 0; }
.hero:empty { min-height: 230px; }
.hero code { font-size: .9em; }
.preview .hero { padding: 4px 0 10px; }
.preview .hero h1 { font-size: 28px; }
.preview .hero p { font-size: 15px; margin-bottom: 14px; }
.preview .home-more section { padding: 12px 0 0; }
.preview .home-more h2 { font-size: 18px; }

.page-head { padding: 40px 0 8px; }
.page-head h1 { font-size: clamp(28px, 5vw, 40px); margin: 0 0 8px; }
.page-head p { color: var(--muted); margin: 0; max-width: 680px; }

section { padding: 24px 0; }
h2 { font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; }
.updated { color: var(--muted); font-size: 13px; font-weight: 400; margin-left: auto; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.card h3 { margin: 0; font-size: 18px; display: flex; gap: 10px; align-items: center; }
.card p { margin: 0; color: var(--muted); }
.notice { color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 18px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.info { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ---------- Kafelki serwerow ---------- */
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.game { color: var(--muted); font-size: 13px; }
.badge {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.online .dot { background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.stats { display: grid; grid-template-columns: 1fr 1.7fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.stat .value { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desc { color: var(--muted); margin: 0; font-size: 15px; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { font-size: 13px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.tag.active { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.join { font-size: 14px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 12px; margin: 0; }

/* ---------- Poradniki / zasady ---------- */
details.guide {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 20px; margin-bottom: 12px;
}
details.guide summary {
  cursor: pointer; list-style: none; padding: 16px 0; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; gap: 10px;
}
details.guide summary::-webkit-details-marker { display: none; }
details.guide summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 22px; font-weight: 400; }
details.guide[open] summary::after { content: "−"; }
details.guide .body { padding: 0 0 18px; color: var(--muted); }
details.guide .body p { margin: 0 0 10px; }
table.cmds { width: 100%; border-collapse: collapse; font-size: 15px; }
table.cmds td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
table.cmds td:first-child { white-space: nowrap; width: 1%; padding-right: 16px; }
ol.rules { counter-reset: r; list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
ol.rules li {
  counter-increment: r; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px 16px 60px; position: relative; color: var(--muted);
}
ol.rules li strong { color: var(--text); display: block; margin-bottom: 2px; }
ol.rules li::before {
  content: counter(r); position: absolute; left: 18px; top: 16px; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

/* ---------- Zarzadzanie serwerami ---------- */
.badge.warn .dot { background: var(--warn); }
.badge.unknown .dot { background: var(--error); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.danger { border-color: color-mix(in srgb, var(--error) 45%, transparent); color: var(--danger-text); }
.btn.danger:hover { border-color: var(--error); }
.btn.on { border-color: var(--accent); background: var(--accent-soft); cursor: default; transform: none; }
.mini-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: -6px; }
.job { font-size: 14px; border-radius: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); }
.job.running { border-color: var(--warn); }
.job.done { border-color: var(--ok); }
.job.error { border-color: var(--error); color: var(--danger-text); }
.job .who { color: var(--muted); font-size: 12px; display: block; }

/* ---------- Strefa v4: gracze, formularze, wykresy, konto ---------- */
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.player-list li { display: flex; justify-content: space-between; gap: 12px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.player-list .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list .pmeta { color: var(--muted); font-size: 13px; white-space: nowrap; }

.inline-form { display: flex; gap: 8px; }
.inline-form input, .inline-form select, .row-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; outline: none;
}
.inline-form input:focus, .inline-form select:focus, .row-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.stack { display: flex; flex-direction: column; gap: 2px; }
.stack .btn { align-self: flex-start; }
.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.row-form .field { margin: 0; flex: 1 1 180px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); padding-bottom: 10px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.narrow { max-width: 460px; }
.form-ok { color: var(--ok); font-size: 14px; min-height: 22px; margin: 0 0 10px; }
.warn-text { color: var(--warn-text) !important; font-size: 14px; }

.chart-title { font-size: 13px; color: var(--muted); margin: 6px 0 -6px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--hover); }
.chart-tip {
  position: absolute; top: 0; transform: translateX(-50%); pointer-events: none;
  background: var(--tip-bg); border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px;
  font-size: 13px; white-space: nowrap; color: var(--text); box-shadow: var(--shadow);
}
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details.table-view[open] summary { margin-bottom: 10px; }

.qr { width: 180px; height: 180px; border-radius: 10px; background: #fff; padding: 6px; image-rendering: pixelated; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.codes code { text-align: center; padding: 6px; font-size: 15px; }

/* ---------- Panel admina ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.users { width: 100%; border-collapse: collapse; font-size: 15px; }
table.users th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.users td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.users tr:last-child td { border-bottom: 0; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.pill.accent { border-color: var(--accent); background: var(--accent-soft); }
.pill.ok { border-color: color-mix(in srgb, var(--ok) 50%, transparent); color: var(--ok-text); }
.pill.warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); color: var(--warn-text); }
.pill.muted { color: var(--muted); }
.btn.small-btn { padding: 5px 10px; font-size: 13px; }
.temp { margin-top: 6px; padding: 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--ok); }
.temp p { margin: 0 0 8px; color: var(--text); }
.big-code { font-size: 16px; padding: 3px 8px; }

/* ---------- Logowanie ---------- */
.login-box { max-width: 420px; margin: 56px auto 40px; }
.login-box h1 { font-size: 28px; margin: 0 0 6px; }
.login-box .sub { color: var(--muted); margin: 0 0 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 600; }
.field input, .field textarea, .field select {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 13px; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.form-error { color: var(--error); font-size: 14px; min-height: 22px; margin: 0 0 10px; }
.login-box .btn { width: 100%; justify-content: center; }
.small { font-size: 13px; color: var(--muted); }

footer { padding: 40px 0 50px; color: var(--muted); font-size: 14px; }
footer .wrap { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; border-top: 1px solid var(--border); padding-top: 20px; }

/* ==========================================================================
   v5: motyw, ogloszenia, tresci z edytora, sesje, dziennik, zaproszenia
   ========================================================================== */
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 16px; padding: 0;
}
.icon-btn:hover { border-color: var(--border-strong); }

/* Ogloszenia */
.news { display: grid; gap: 14px; }
.post { gap: 10px; }
.post-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.post-head h3 { margin: 0; font-size: 18px; }
.post-meta { color: var(--muted); font-size: 13px; }
.post-flags { display: inline-flex; gap: 6px; }
.post.pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.post .md { color: var(--muted); }
.more-row { display: flex; justify-content: center; }
.more-row.spaced { margin-top: 14px; }

/* Tresc z edytora (bezpieczny markdown) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h2 { font-size: 20px; margin: 22px 0 10px; }
.md h3 { font-size: 17px; margin: 18px 0 8px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 0 0 10px; padding: 8px 14px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.md pre { margin: 0 0 10px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.md pre code { border: 0; padding: 0; background: none; white-space: pre; }
.md a { color: var(--accent); }
.md strong { color: var(--text); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md .table-scroll { overflow-x: auto; margin: 0 0 10px; }
.md table { width: 100%; border-collapse: collapse; font-size: 15px; }
.md th { text-align: left; color: var(--text); font-size: 13px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.md td { padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.md td:first-child { white-space: nowrap; width: 1%; padding-right: 16px; }
.page-intro { color: var(--muted); max-width: 680px; margin: -4px 0 8px; }
.page-intro p { margin: 0 0 8px; }
.page-meta { color: var(--muted); font-size: 13px; margin-top: 18px; }
.info .card .md { color: var(--muted); }
.info .card .md a[href^="http"] { color: var(--text); }

/* Podzakladki admina */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.subtabs a { text-decoration: none; font-size: 14px; font-weight: 600; color: var(--muted); padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.subtabs a:hover { color: var(--text); }
.subtabs a.active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

/* Formularze v5 */
.field textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.field textarea.code { font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 380px; }
.field select { cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.editor .preview { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-height: 120px; max-height: 640px; overflow: auto; }
.editor .preview .info { grid-template-columns: 1fr; }
.preview-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; font-weight: 600; }
details.help { font-size: 14px; color: var(--muted); }
details.help summary { cursor: pointer; }
details.help table { border-collapse: collapse; margin-top: 8px; }
details.help td { padding: 4px 14px 4px 0; vertical-align: top; }
.save-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.save-row .form-error, .save-row .form-ok { margin: 0; min-height: 0; }

/* Zalogowane urzadzenia, historia */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.list .main { min-width: 0; flex: 1; }
.list li > .pill, .list li > .btn, .list li > .btn-row { flex-shrink: 0; }
.list .sub { display: flex; flex-wrap: wrap; column-gap: 6px; }
.list .sub span { white-space: nowrap; }
.list .sub span + span::before { content: "· "; }
.info .card.wide { grid-column: 1 / -1; }
.list .title { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 13px; }
.list li.current { outline: 1px solid color-mix(in srgb, var(--ok) 55%, transparent); }
.list li.bad .title { color: var(--danger-text); }

/* Dziennik */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; flex: 0 1 220px; }
table.users td.nowrap { white-space: nowrap; }
.ev-detail { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* Zaproszenia */
.invite-link { display: flex; gap: 8px; }
.invite-link input { flex: 1; min-width: 0; font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }

@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
  .field textarea.code { min-height: 280px; }
}
@media (max-width: 560px) {
  .icon-btn { width: 34px; height: 34px; }
  .invite-link { flex-wrap: wrap; }
}
@media (forced-colors: active) { .btn.primary { border: 1px solid ButtonText; } }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; grid-auto-flow: dense; }
  .stats .stat.wide { grid-column: 1 / -1; }
  .account .who { display: none; }
  .tabs a { padding: 10px 10px; font-size: 14px; }
  .tabs a .long { display: none; }
  table.cmds td:first-child { white-space: normal; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input, .inline-form select { flex: 1 1 150px; }
  .inline-form .btn { flex: 1 0 auto; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
