/* ====================================================================
   Hansa Teutonica — styl: drewno + pergamin, mobile-first
   ==================================================================== */
:root {
  --wood-1: #2a1a10;
  --wood-2: #3d2616;
  --wood-3: #5a3820;
  --parch: #f6ebcc;
  --parch-2: #ead8a8;
  --ink: #2f1d0e;
  --ink-soft: #6b4e30;
  --accent: #8f2a22;
  --accent-2: #b8402f;
  --gold: #d9a441;
  --ok: #2f7d3a;
  --radius: 12px;
  --shadow: 0 6px 18px rgba(20, 8, 0, .35);
  --font-body: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --font-head: "Cinzel", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, rgba(255, 200, 120, .12), transparent 60%),
    repeating-linear-gradient(92deg, rgba(0,0,0,.06) 0 3px, transparent 3px 11px),
    linear-gradient(180deg, var(--wood-2), var(--wood-1));
  background-attachment: fixed;
}
.sprite-sheet { position: absolute; width: 0; height: 0; overflow: hidden; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-head); margin: 0 0 .5em; letter-spacing: .02em; }
h2 { font-size: 1.15rem; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.ico { width: 22px; height: 22px; flex: none; }
.ico.used { opacity: .35; filter: grayscale(1); }

.parchment, .panel {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.5), transparent 60%),
    linear-gradient(180deg, var(--parch), var(--parch-2));
  border: 1px solid #b89a62;
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 30px rgba(140, 95, 40, .18);
}

/* ---------------- górny pasek ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #5c1e16, #3a120c);
  color: #f3dc9c;
  border-bottom: 2px solid #1d0a06;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.brand { display: flex; align-items: center; gap: 8px; color: #f3dc9c; text-decoration: none;
  font-family: var(--font-head); font-weight: 700; white-space: nowrap; }
.brand-ico { width: 28px; height: 28px; }
.topbar-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.userbox { display: flex; align-items: center; gap: 8px; margin: 0; }
.username { font-weight: 700; max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { background: none; border: 1px solid rgba(243, 220, 156, .5); color: #f3dc9c; border-radius: 8px;
  padding: 4px 10px; font: inherit; cursor: pointer; }
body.offline .topbar::after { content: "⟳ łączenie…"; font-size: .8rem; color: #ffb4a0; }

/* ---------------- przyciski ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid rgba(0,0,0,.35);
  font: 600 .98rem var(--font-body); text-decoration: none; cursor: pointer;
  color: #fff; background: #6b4e30;
  box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.25);
  transition: transform .06s, filter .15s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:hover { filter: brightness(1.08); }
.btn[disabled] { opacity: .55; }
.btn-primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.btn-action { background: linear-gradient(180deg, #4a6e8a, #2f4c63); }
.btn-token { background: linear-gradient(180deg, #557c8f, #33586b); }
.btn-secondary { background: linear-gradient(180deg, #f3e3bb, #dcc48c); color: var(--ink); border-color: #a88a52; }
.btn-danger { background: linear-gradient(180deg, #7a2a2a, #511818); }
.btn-big { min-height: 52px; font-size: 1.05rem; padding: 10px 22px; }
.btn .ico { width: 24px; height: 24px; color: currentColor; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

input[type=text], select {
  font: inherit; font-size: 16px; padding: 10px 12px; min-height: 44px;
  border: 1px solid #a88a52; border-radius: 10px; background: #fffaf0; color: var(--ink);
}
.error-msg { background: #f9d6cf; border: 1px solid #c0503e; color: #6d160c; border-radius: 8px;
  padding: 8px 10px; margin: 0 0 10px; font-weight: 600; }
.chip { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid rgba(0,0,0,.6);
  vertical-align: -2px; }
.you { background: var(--gold); color: var(--ink); border-radius: 6px; padding: 0 6px; font-size: .75rem; font-weight: 700; }

/* ---------------- logowanie ---------------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); padding: 26px 22px; text-align: center; }
.login-card h1 { font-size: 1.9rem; color: var(--accent); margin-top: 6px; }
.login-art { width: 160px; height: 106px; }
.lead { margin: .2em 0 1.2em; }
.login-form { display: grid; gap: 10px; text-align: left; }
.login-form label { font-weight: 700; }

/* ---------------- lobby ---------------- */
.lobby { max-width: 980px; margin: 0 auto; padding: 14px; display: grid; gap: 16px; }
.lobby > .parchment { padding: 16px; }
.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row-form input[type=text] { flex: 1 1 220px; }
.select-label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.tables { display: grid; gap: 12px; }
.tables > h2 { color: #f3dc9c; margin: 4px 0 0; }
.tables > p.muted { color: #e7d2a0; }
.table-card { padding: 14px 16px; display: grid; gap: 8px; }
.table-card.mine { outline: 3px solid var(--gold); }
.table-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.table-main h3 { margin: 0; font-size: 1.1rem; }
.table-main h3 a { color: var(--ink); text-decoration: none; }
.badge { font-size: .78rem; font-weight: 700; border-radius: 999px; padding: 2px 10px; background: #ddd; }
.badge.wait { background: #f2d58a; }
.badge.live { background: #9fd59b; }
.badge.done { background: #c9c3b6; }
.seat-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0; margin: 0; }
.seat-list li { display: flex; align-items: center; gap: 6px; }
.about p { margin: 0; }
.tutorial-cta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
.tutorial-cta p { margin: 0; }
.bot-badge { font-size: .72rem; font-weight: 700; background: #33586b; color: #e9f2f6; border-radius: 999px; padding: 1px 8px;
  white-space: nowrap; }
.seat-remove-form { margin: 0 0 0 auto; }
.seat-remove { width: 36px; height: 36px; border-radius: 50%; border: 1px solid #a88a52;
  background: #fffaf0; color: var(--accent); font-weight: 700; cursor: pointer; }
.check-label { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; }
.check-label input { width: 20px; height: 20px; accent-color: var(--accent); }
.table-admin { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.confirm-dialog { border: 1px solid #b89a62; border-radius: var(--radius); padding: 18px; max-width: min(440px, 92vw);
  background: linear-gradient(180deg, var(--parch), var(--parch-2)); color: var(--ink); box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(20, 8, 0, .6); }
.confirm-dialog h2 { color: var(--accent); }
.confirm-dialog label { display: grid; gap: 8px; margin-top: 8px; }
.confirm-word { font-family: var(--font-head); color: var(--accent); letter-spacing: .05em; }
.add-bot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.add-bot label { font-weight: 700; }

/* ---------------- poczekalnia ---------------- */
.waiting { max-width: 640px; margin: 18px auto; padding: 20px; }
.share { display: flex; gap: 8px; }
.share-url { flex: 1; min-width: 0; }
.seats { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; }
.seats li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: rgba(255,255,255,.45); border: 1px solid #d3bb86; }
.seats li.me { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(217,164,65,.4); }
.seats .empty-seat { color: var(--ink-soft); font-style: italic; justify-content: center; border-style: dashed; }
ht-piece { display: inline-flex; width: 22px; height: 22px; }
ht-piece svg { width: 100%; height: 100%; }
ht-token { display: inline-flex; width: 30px; height: 30px; }
ht-token svg { width: 100%; height: 100%; }

/* ---------------- gra: pasek stanu ---------------- */
.status-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 12px; background: rgba(20, 10, 4, .55); color: #f6e7c1;
  border-bottom: 1px solid rgba(0,0,0,.4);
}
.status-bar .prompt { flex: 1 1 200px; font-weight: 500; }
.status-bar.over { background: linear-gradient(90deg, #6b4a12, #3a2508); }
.turn-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 700;
  background: rgba(255,255,255,.1); border-radius: 999px; padding: 3px 10px; }
.turn-chip .acts { background: var(--gold); color: var(--ink); border-radius: 999px; padding: 0 7px; font-size: .8rem; }
.stack { display: inline-flex; align-items: center; gap: 4px; }
.my-turn .status-bar { background: linear-gradient(90deg, #7b2219, #3a120c); }

/* ---------------- układ ---------------- */
.layout { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 10px; padding-bottom: 12px; }
.board-col { min-width: 0; }
.side { display: grid; gap: 12px; align-content: start; min-width: 0; }
.panel { padding: 12px; }

/* ---------------- plansza ---------------- */
ht-zoom {
  position: relative; display: block; overflow: hidden;
  aspect-ratio: 1280 / 900; width: 100%;
  border-radius: 10px; box-shadow: var(--shadow);
  background: #7a2e20;
  touch-action: pan-y;
  user-select: none; -webkit-user-select: none;
}
ht-zoom.zoomed { touch-action: none; cursor: grab; }
.zoom-stage { transform-origin: 0 0; width: 100%; height: 100%; will-change: transform; }
ht-board { display: block; width: 100%; height: 100%; }
.board-svg { display: block; width: 100%; height: 100%; }
.zoom-ctl { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 2; }
.zoom-ctl button {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(0,0,0,.4);
  background: rgba(246, 235, 204, .92); color: var(--ink); font: 700 1.25rem var(--font-body); cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}

/* elementy SVG planszy */
.board-svg .tgt { cursor: pointer; }
.board-svg .tgt .hit { fill: transparent; }
.board-svg .tgt .ring { fill: rgba(255, 236, 140, .35); stroke: #ffde59; stroke-width: 3.5;
  animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.board-svg .tgt-opp .ring { fill: rgba(255, 90, 70, .25); stroke: #ff5a46; }
.board-svg .tgt-own .ring { fill: rgba(120, 220, 255, .2); stroke: #4fd2ff; }
.board-svg .tgt-held .ring { fill: rgba(120, 255, 140, .3); stroke: #43e06a; stroke-width: 4.5; }
.board-svg .tgt-route { fill: none; stroke-width: 30; stroke-linecap: round; stroke-opacity: .55;
  animation: glow 1.4s ease-in-out infinite; }
.board-svg .tgt-establish { stroke: #ffd23f; }
.board-svg .tgt-token { stroke: #6fd3ff; }
.board-svg .tgt-swap circle { fill: #ffde59; stroke: #3b2412; stroke-width: 2; }
.board-svg .tgt-swap text { font: 700 16px var(--font-body); fill: #3b2412; pointer-events: none; }
.board-svg .tgt-face circle { fill: rgba(255, 222, 89, .55); stroke: #3b2412; stroke-width: 2.5;
  animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.board-svg .pending .ring, .board-svg .pending circle { animation: none; fill: rgba(255,255,255,.7); }
.board-svg .pc .halo { fill: none; stroke: #43e06a; stroke-width: 4; }
.board-svg .province { fill: rgba(255, 240, 160, .28); stroke: #b8402f; stroke-width: 3; stroke-dasharray: 9 6;
  pointer-events: none; }
.board-svg .border-line { stroke: #8f2a22; stroke-width: 3; stroke-dasharray: 2 7; stroke-linecap: round; opacity: .8; }
.board-svg .ctrl { stroke: rgba(0,0,0,.6); stroke-width: 1; }
ht-board.busy { cursor: progress; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes glow { 0%, 100% { stroke-opacity: .35; } 50% { stroke-opacity: .7; } }

/* ---------------- panel akcji ---------------- */
.actions-panel .panel-prompt { margin: 0 0 8px; font-weight: 700; }
.actions-panel:not(.active) .buttons:empty { display: none; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.buttons .btn { flex: 1 1 auto; }
.kind-picker.hidden { display: none; }
.kind-picker { display: flex; gap: 8px; margin-bottom: 10px; }
.kind-picker label { flex: 1; }
.kind-picker input { position: absolute; opacity: 0; pointer-events: none; }
.kind-picker span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  border: 2px solid #a88a52; border-radius: 10px; background: #fffaf0; font-weight: 700; cursor: pointer; }
.kind-picker input:checked + span { border-color: var(--accent); background: #ffe7b0; box-shadow: 0 0 0 2px rgba(143,42,34,.25); }

/* ---------------- sekretarzyki ---------------- */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
ht-desk {
  display: block; padding: 8px 10px; border-radius: var(--radius);
  background: linear-gradient(180deg, #f6ebcc, #e3cd98);
  border: 1px solid #b89a62; box-shadow: var(--shadow);
}
ht-desk.active { outline: 3px solid var(--gold); }
ht-desk.me { background: linear-gradient(180deg, #fff3d6, #ecd7a3); }
.desk-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.desk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.desk-head .score { font-family: var(--font-head); font-weight: 700; background: var(--accent); color: #f6e7c1;
  border-radius: 999px; padding: 1px 10px; }
.startp { font-size: .75rem; font-weight: 700; color: var(--ink-soft); border: 1px solid var(--ink-soft); border-radius: 6px; padding: 0 4px; }
.desk-body { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 8px; align-items: start; }
.desk-svg { width: 100%; height: auto; display: block; }
.desk-svg .desk-wood { fill: #6a4426; }
.desk-svg .cell { stroke: #2b1a0c; stroke-width: 1; }
.desk-svg .cell.cur { stroke: #ffd23f; stroke-width: 3; }
.desk-svg .cell-t { font: 700 13px var(--font-body); fill: #3b2412; }
.desk-svg .cell-t.inv { fill: #f6e7c1; }
.desk-svg .max-t { font: 700 11px var(--font-body); fill: #ffd23f; }
.desk-side { display: grid; gap: 4px; font-size: .92rem; }
.stock { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.stock .lbl { width: 52px; font-weight: 700; color: var(--ink-soft); font-size: .8rem; text-transform: uppercase; }
.stock b { margin-right: 6px; }
.tokens { display: flex; flex-wrap: wrap; gap: 3px; min-height: 30px; align-items: center; }

/* ---------------- dziennik, pomoc, wyniki ---------------- */
.log summary, .help summary { cursor: pointer; font-family: var(--font-head); font-weight: 700; }
.log ol { margin: 8px 0 0; padding-left: 0; list-style: none; max-height: 220px; overflow: auto; font-size: .92rem; }
.log li { padding: 3px 0; border-bottom: 1px dotted #c8ad78; }
.help-body { font-size: .95rem; }
.help-body ol { padding-left: 1.2em; }
.final h2 { color: var(--accent); }
.table-scroll { overflow-x: auto; }
.score-table { border-collapse: collapse; width: 100%; font-size: .95rem; }
.score-table th, .score-table td { padding: 6px 6px; text-align: center; border-bottom: 1px solid #c8ad78; white-space: nowrap; }
.score-table td:first-child, .score-table th:first-child { text-align: left; }
.score-table tr.winner { background: rgba(217, 164, 65, .35); font-weight: 700; }

/* ---------------- samouczek ---------------- */
.tut-progress { display: flex; align-items: center; gap: 12px; padding: 8px 12px; color: #f6e7c1;
  background: rgba(20, 10, 4, .55); }
.tut-count { font-weight: 700; white-space: nowrap; }
.tut-dots { list-style: none; display: flex; flex-wrap: wrap; gap: 5px; padding: 0; margin: 0; }
.tut-dots button { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #f3dc9c; background: transparent;
  padding: 0; cursor: pointer; }
.tut-dots .past button { background: #b8a26a; border-color: #b8a26a; }
.tut-dots .cur button { background: var(--gold); transform: scale(1.25); }
.tut-card { padding: 16px 18px; }
.tut-card h1 { font-size: 1.35rem; color: var(--accent); }
.tut-body { font-size: 1.02rem; line-height: 1.45; }
.tut-body p { margin: 0 0 .6em; }
.tut-body ul, .tut-body ol { margin: 0 0 .6em; padding-left: 1.2em; }
.tut-body li { margin: .25em 0; }
.tut-body .ico { width: 22px; height: 22px; vertical-align: -5px; }
.tut-task { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #fff4cf; border: 2px solid var(--gold); }
.tut-task p { margin: 2px 0 0; }
.tut-task.ok { background: #ddf3d8; border-color: var(--ok); }
.tut-task-ico { font-size: 1.4rem; font-weight: 700; color: var(--accent); line-height: 1; }
.tut-task.ok .tut-task-ico { color: var(--ok); }
.tut-finish { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; align-items: center; }
.tut-nav { display: flex; gap: 8px; margin-top: 10px; }
.tut-nav .btn { flex: 1; }
.tut-nav .btn[title] { flex: 0 0 52px; }
.tut-panel .buttons:empty { display: none; }
.tut-panel-task { margin: 0 0 6px; font-size: .95rem; }
.tut-panel-task.ok { color: var(--ok); }
.tut-panel .panel-prompt { font-size: .85rem; font-weight: 500; color: var(--ink-soft); }
.tutorial-page .log ol { max-height: 120px; }
.lesson-done .tut-nav .btn-primary { animation: nudge 1.2s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(4px); } }
@media (min-width: 900px) {
  .tut-layout { grid-template-columns: minmax(0, 1fr) 400px; grid-template-areas: "board card" "board side"; }
  .tut-layout .tut-card { grid-area: card; }
  .tut-layout .board-col { grid-area: board; }
  .tut-layout .side { grid-area: side; }
  .tut-panel { position: fixed; right: 14px; bottom: 14px; width: 400px; z-index: 20; }
  .tutorial-page .tut-layout { padding-bottom: 220px; }
}

/* ---------------- telefon: panel akcji przyklejony do dołu ---------------- */
@media (max-width: 899px) {
  .topbar .brand span { display: none; }
  .game-page .layout { padding: 6px; gap: 8px; padding-bottom: calc(40vh + 12px); }
  .game-page .actions-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    border-radius: 16px 16px 0 0; max-height: 40vh; overflow-y: auto;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 24px rgba(0,0,0,.45);
  }
  .game-page .actions-panel:not(.active) { max-height: 22vh; }
  .game-page .actions-panel .panel-prompt { font-size: .95rem; }
  .status-bar .prompt { display: none; }
  .buttons .btn { flex: 1 1 calc(50% - 8px); font-size: .92rem; padding: 6px 8px; }
  .players { grid-template-columns: 1fr; }
  .zoom-ctl { right: 6px; bottom: 6px; gap: 4px; }
  .zoom-ctl button { width: 32px; height: 32px; font-size: 1.05rem; opacity: .85; }
}

/* ---------------- desktop: plansza + panel boczny ---------------- */
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; padding: 14px; gap: 14px; }
  .board-col { position: sticky; top: 64px; }
  ht-zoom { max-height: calc(100vh - 120px); width: auto; max-width: 100%; margin: 0 auto; }
  .players { grid-template-columns: 1fr; }
  .status-bar .prompt { display: inline; }
}
@media (min-width: 1500px) {
  .layout { grid-template-columns: minmax(0, 1fr) 460px; }
}
