/* Platforma gier — wspólny wygląd: ciemny, „przemysłowy" motyw z mosiężnymi akcentami. */
:root {
  --bg: #121419;
  --bg-2: #181b22;
  --panel: #1d2129;
  --panel-2: #252a34;
  --line: #343a46;
  --text: #ece6da;
  --muted: #a39b8b;
  --brass: #d1a54a;
  --brass-2: #f0cf7e;
  --brass-dark: #8c6a26;
  --paper: #f4ecd9;
  --paper-2: #e9dcc0;
  --ink: #2a2117;
  --danger: #d2563f;
  --ok: #6fae6a;
  --focus: #79b8ff;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .25);
  --font: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: "Cinzel", Georgia, "Times New Roman", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.45 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(209, 165, 74, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(80, 120, 160, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
a { color: var(--brass-2); }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .02em; margin: 0 0 .6em; line-height: 1.2; }
h1 { font-size: clamp(1.5rem, 3.5vw, 2.2rem); }
h2 { font-size: 1.15rem; }
code { background: var(--panel-2); padding: .1em .35em; border-radius: 4px; }
small { font-size: .82em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .9rem; margin: .8em 0 0; }
.inline { display: inline; margin: 0; }
.sprite-host { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 1.15em; height: 1.15em; vertical-align: -.2em; fill: currentColor; }

/* ---------- Pasek górny ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(24, 27, 34, .97), rgba(18, 20, 25, .94));
  border-bottom: 1px solid #2a2f39;
  box-shadow: 0 2px 0 rgba(209, 165, 74, .18);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 1.1rem; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--brass-2); }
.topnav { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.navlink { color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: 8px; font-weight: 600; font-size: .95rem; }
.navlink:hover { background: var(--panel-2); }
.linkbtn { background: none; border: 0; cursor: pointer; font: inherit; }
.who { color: var(--brass-2); font-weight: 700; padding: 0 6px; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); flex: none; }
body.offline .conn { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

.main { padding: 18px max(14px, env(safe-area-inset-right)) 40px max(14px, env(safe-area-inset-left)); max-width: 1500px; margin: 0 auto; }
.narrow { max-width: 560px; }
.flash { background: rgba(209, 86, 63, .14); border: 1px solid rgba(209, 86, 63, .5); color: #ffd7cf; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }

/* ---------- Karty, formularze, przyciski ---------- */
.card {
  background: linear-gradient(180deg, var(--panel), #1a1e25);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-accent { border-color: rgba(209, 165, 74, .55); box-shadow: var(--shadow), inset 0 1px 0 rgba(240, 207, 126, .15); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .92rem; }
.field > span { color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text);
  background: #12151a; border: 1px solid #3a4150; border-radius: 9px;
  padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; cursor: pointer; }
.check input { min-height: 0; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brass); }
.check small { display: block; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  font: 700 .98rem/1.1 var(--font); letter-spacing: .01em;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer; text-decoration: none;
  touch-action: manipulation; user-select: none; transition: transform .06s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { color: #23180a; background: linear-gradient(180deg, var(--brass-2), var(--brass)); border-color: #b08a35; box-shadow: 0 2px 0 var(--brass-dark), 0 6px 16px rgba(209, 165, 74, .25); }
.btn-primary:hover:not([disabled]) { filter: brightness(1.06); }
.btn-secondary { color: var(--text); background: var(--panel-2); border-color: #444c5b; }
.btn-secondary:hover:not([disabled]) { background: #2d333f; }
.btn-ghost { color: var(--text); background: transparent; border-color: #3d4452; }
.btn-ghost:hover:not([disabled]) { background: var(--panel-2); }
.btn-danger { color: #fff; background: linear-gradient(180deg, #df6a52, #b9442f); border-color: #9c3826; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: 12px 22px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.button-row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.error-msg { background: rgba(209, 86, 63, .15); border: 1px solid rgba(209, 86, 63, .55); color: #ffd3c9; padding: 10px 14px; border-radius: 10px; margin: 8px 0; font-weight: 600; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.badge-open { background: rgba(111, 174, 106, .18); color: #a9e3a4; border: 1px solid rgba(111, 174, 106, .45); }
.badge-play { background: rgba(209, 165, 74, .16); color: var(--brass-2); border: 1px solid rgba(209, 165, 74, .5); }
.badge-over { background: rgba(160, 160, 170, .14); color: #c9c9d2; border: 1px solid rgba(160, 160, 170, .35); }

/* ---------- Logowanie ---------- */
.login-hero { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.login-card { width: min(460px, 100%); text-align: center; padding: 28px 24px; }
.login-art svg { width: 96px; height: 96px; filter: drop-shadow(0 6px 18px rgba(209, 165, 74, .35)); }
.login-card h1 { color: var(--brass-2); margin-top: .3em; }
.lead { color: var(--muted); margin: 0 0 18px; }
.login-card .stack { text-align: left; }

/* ---------- Lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 22px; align-items: start; }
.lobby-side { position: sticky; top: 72px; }
.section-title { font-size: 1rem; color: var(--brass-2); text-transform: uppercase; letter-spacing: .12em; margin: 6px 0 12px; display: flex; align-items: center; gap: 10px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(209, 165, 74, .5), transparent); }
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; margin-bottom: 26px; }
.empty { margin: 0 0 26px; }
.table-card {
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
  background: linear-gradient(180deg, #20252e, #1b1f27); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); text-decoration: none; transition: transform .12s, border-color .12s, box-shadow .12s;
}
.table-card:hover { transform: translateY(-2px); border-color: rgba(209, 165, 74, .6); box-shadow: var(--shadow); }
.table-card.my-turn { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass), 0 8px 24px rgba(209, 165, 74, .2); }
.tc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tc-name { font-size: 1.02rem; overflow-wrap: anywhere; }
.tc-seats { display: flex; flex-wrap: wrap; gap: 6px; }
.tc-foot { font-size: .88rem; }
.turn-flag { color: #23180a; background: var(--brass-2); padding: 3px 10px; border-radius: 99px; font-weight: 800; animation: pulse 1.6s ease-in-out infinite; display: inline-block; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(240, 207, 126, .0), 0 0 14px rgba(240, 207, 126, .55); } }
.seat-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; padding: 3px 9px 3px 4px; border-radius: 99px; background: #262b35; border: 1px solid #353c49; max-width: 13em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-chip i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .3), 0 0 0 1px rgba(0, 0, 0, .4); flex: none; }
.seat-chip.empty { color: var(--muted); border-style: dashed; background: transparent; }
.seat-chip.empty i { background: transparent; border: 1px dashed var(--muted); }

/* ---------- Poczekalnia ---------- */
.room-wrap { display: grid; place-items: start center; }
.room-card { width: min(640px, 100%); }
.room-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; }
.seats { list-style: none; padding: 0; margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.seat { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; background: #161a20; border: 1px solid #2c323d; }
.seat-disc { width: 26px; height: 26px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .28), inset 0 2px 0 rgba(255, 255, 255, .25), 0 0 0 2px rgba(0, 0, 0, .35); flex: none; }
.seat-free .seat-disc { background: transparent; border: 2px dashed color-mix(in srgb, var(--c) 70%, transparent); box-shadow: none; }
.seat-name { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.room-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 6px 0 4px; }
.share { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
g-copy { display: flex; gap: 8px; }
g-copy input { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); }
.danger-zone { margin-top: 18px; display: flex; justify-content: flex-end; }

/* ---------- Okno potwierdzenia ---------- */
.confirm-dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 22px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
.confirm-word { color: var(--brass-2); }

/* ---------- Zoom ---------- */
g-zoom { position: relative; display: block; overflow: hidden; touch-action: pan-y; border-radius: var(--radius); }
g-zoom.zoomed { touch-action: none; cursor: grab; }
.zoom-stage { transform-origin: 0 0; will-change: transform; }
.zoom-ctl { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.zoom-ctl button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid #5a4a2a; background: rgba(22, 24, 29, .85); color: var(--brass-2); font: 700 1.25rem/1 var(--font); cursor: pointer; touch-action: manipulation; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
g-board.busy { cursor: progress; }

/* ---------- Administracja ---------- */
.admin h1 { color: var(--brass-2); }
.narrow-card { max-width: 420px; }
.admin-stats { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 110px; }
.stat b { display: block; font-size: 1.4rem; color: var(--brass-2); }
.stat span { color: var(--muted); font-size: .85rem; }
.cleanup { display: flex; flex-direction: column; gap: 10px; }
.cleanup .num { width: 80px; }
.cleanup .confirm-in { width: 180px; }
.admin-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.admin-tools h2 { margin: 0; margin-right: auto; }
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.grid td.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.grid input[type=checkbox] { min-height: 0; width: 20px; height: 20px; accent-color: var(--brass); }
.adminlog { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0; background: #2a1d17; border: 1px solid var(--danger); color: #ffd7cf; padding: 10px 16px; border-radius: 10px; z-index: 100; transition: .25s; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .lobby { grid-template-columns: 1fr; }
  .lobby-side { position: static; }
  .lobby:has(.tables.mine) .lobby-main { order: -1; }
  .brand-name { font-size: 1rem; }
  .who { display: none; }
}
@media (max-width: 420px) {
  .navlink { padding: 8px 6px; font-size: .9rem; }
  .row2 { grid-template-columns: 1fr; }
}

/* ---------- Nagłówek strony gry: stan gry i menu stołu w jednym pasku ---------- */
.tb-slot { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.tb-table { position: relative; flex: none; }
.tb-table summary { list-style: none; cursor: pointer; min-height: 34px; display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 9px; border: 1px solid #3d4452; color: var(--text); font-weight: 700; font-size: .88rem; white-space: nowrap; }
.tb-table summary::-webkit-details-marker { display: none; }
.tb-table[open] summary { border-color: var(--brass); }
.tb-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; width: min(360px, calc(100vw - 24px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.tb-name { font-family: var(--display); color: var(--brass-2); }
.tb-status { flex: 0 .15 auto; min-width: 0; }
.tb-turn { flex: 1 1 160px; min-width: 0; }
.topbar.has-game { gap: 10px; padding-top: 6px; padding-bottom: 6px; }
.topbar.has-game .brand-mark { width: 30px; height: 30px; }
@media (max-width: 1500px) { .topbar.has-game .brand-name { display: none; } }
@media (max-width: 900px) {
  .topbar.has-game { flex-wrap: wrap; position: relative; }
  .topbar.has-game .tb-slot { order: 3; flex-basis: 100%; }
  .topbar.has-game { row-gap: 4px; }
  .tb-label { display: none; }
  .topbar.has-game .tb-table { position: static; }
  .topbar.has-game .tb-menu { right: 12px; top: calc(100% + 4px); }
}

/* ---------- Panel analizy SI (podpowiedzi i myślenie botów) ---------- */
.tb-ai { flex: none; display: inline-flex; gap: 4px; }
.tb-ai button {
  width: 36px; height: 34px; display: inline-grid; place-items: center; cursor: pointer;
  border-radius: 9px; border: 1px solid #3d4452; background: transparent; color: var(--brass-2);
}
.tb-ai button:hover, .tb-ai button.on { border-color: var(--brass); background: rgba(209, 165, 74, .14); }
.tb-ai svg, .an-tab svg, .an-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

g-analysis { position: fixed; z-index: 60; top: 52px; right: 0; bottom: 0; width: min(1240px, 100vw); display: block; pointer-events: none; }
g-analysis[hidden] { display: none; }
.an-panel {
  pointer-events: auto; height: 100%; display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1b1f27, #15181e); border-left: 1px solid #3a3326;
  box-shadow: -18px 0 40px rgba(0, 0, 0, .45); animation: an-in .22s ease-out;
}
@keyframes an-in { from { transform: translateX(28px); opacity: 0; } }
.an-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.an-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid #2c3039; }
.an-tabs { display: flex; gap: 4px; flex: 1; min-width: 0; }
.an-tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 9px; cursor: pointer;
  font: 700 .92rem var(--font); color: var(--muted); background: transparent; border: 1px solid transparent; white-space: nowrap;
}
.an-tab:hover { color: var(--text); background: var(--panel-2); }
.an-tab.sel { color: var(--brass-2); border-color: rgba(209, 165, 74, .5); background: rgba(209, 165, 74, .12); }
.an-x { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.an-x:hover { color: var(--text); background: var(--panel-2); }
.an-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.an-side { border-right: 1px solid #2c3039; padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.an-detail { overflow: auto; padding: 14px 16px 24px; min-width: 0; }
.an-sub { margin: 4px 0 0; font: 700 .78rem var(--font); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.an-sub small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.an-why { margin: 0; font-size: .86rem; color: var(--muted); }
.an-hint { display: flex; flex-direction: column; gap: 8px; }
.an-hint .btn .busy-lbl { display: none; }
.an-hint.htmx-request .btn .lbl { display: none; }
.an-hint.htmx-request .btn .busy-lbl { display: inline; }
.an-seats { display: flex; flex-wrap: wrap; gap: 6px; }
.an-seat {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid #3d4452; background: var(--panel); color: var(--text); font: 600 .86rem var(--font);
}
.an-seat i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(0, 0, 0, .4); }
.an-seat small { color: var(--muted); }
.an-seat.sel { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--panel)); }
.an-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.an-item {
  width: 100%; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px;
  padding: 7px 9px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); font: .86rem/1.3 var(--font);
}
.an-item:hover { background: var(--panel-2); }
.an-item.sel { border-color: rgba(209, 165, 74, .55); background: rgba(209, 165, 74, .1); }
.an-item small { color: var(--muted); font-size: .76rem; }
.an-empty { color: var(--muted); font-size: .86rem; padding: 6px 2px; }
.an-note { padding: 14px 16px; border-radius: 10px; border: 1px dashed #4a4334; color: var(--muted); background: rgba(255, 255, 255, .02); }
.an-intro { max-width: 640px; }
.an-intro h3 { color: var(--brass-2); }
@media (max-width: 900px) {
  g-analysis { top: 0; width: 100vw; }
  .an-main { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .an-side { border-right: 0; border-bottom: 1px solid #2c3039; max-height: 32vh; }
  .an-tab { padding: 8px 10px; }
}
