:root {
  --bg: #efe8da;
  --panel: #fbf7ef;
  --ink: #2b2620;
  --muted: #7a6f60;
  --line: #d8ccb6;
  --accent: #2f6f4f;
  --accent-ink: #fff;
  --table: #c9b48d;
  --legal: rgba(47, 111, 79, .22);
  --legal-stroke: #2f6f4f;
  --field: #8cbf5f;
  --city: #d9b27a;
  --city-stroke: #9a7140;
  --road: #f4efe2;
  --road-edge: #6d6252;
  --monastery: #b8653b;
  --flash: #ffd34d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1b17;
    --panel: #29251f;
    --ink: #efe6d6;
    --muted: #a99c87;
    --line: #463e33;
    --accent: #5aa57d;
    --accent-ink: #0f1a14;
    --table: #3a3228;
    --legal: rgba(90, 165, 125, .25);
    --legal-stroke: #7fd0a3;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1b17;
  --panel: #29251f;
  --ink: #efe6d6;
  --muted: #a99c87;
  --line: #463e33;
  --accent: #5aa57d;
  --accent-ink: #0f1a14;
  --table: #3a3228;
  --legal: rgba(90, 165, 125, .25);
  --legal-stroke: #7fd0a3;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 18px; margin: 0 0 8px; }
h2 { font-size: 13px; margin: 0 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
button, select, input, .file-button {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type="number"] { width: 90px; }
.file-button input { display: none; }
label { display: inline-flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 6px; }
.small { font-size: 12px; color: var(--muted); }

.layout { display: flex; height: 100vh; }
.board-wrap { position: relative; flex: 1; min-width: 0; background: var(--table); overflow: hidden; }
.board { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.board.dragging { cursor: grabbing; }
.board-hint { position: absolute; left: 12px; top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; font-size: 13px; }
.board-hint:empty { display: none; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 34px; height: 34px; padding: 0; font-size: 18px; }

.side { width: 360px; flex: none; overflow-y: auto; padding: 14px; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 14px; }
.hand { display: flex; gap: 12px; align-items: center; }
.hand-tile { width: 96px; height: 96px; flex: none; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--table); }
.hand-tile svg { display: block; }
.turn-label { font-weight: 600; }

.players { display: grid; gap: 8px; }
.player { display: grid; grid-template-columns: 14px 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.player.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--legal); }
.player .dot { width: 14px; height: 14px; border-radius: 50%; }
.player .name { font-weight: 600; }
.player .score { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.player .meeples { grid-column: 2 / 4; display: flex; gap: 3px; }
.player .meeples i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.player .meeples i.used { opacity: .2; }
.player .projected { font-size: 15px; font-weight: 600; color: var(--muted); }

.remaining-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--rt-size, 56px), 1fr)); gap: 4px; }
.remaining-grid .rt { position: relative; }
.remaining-grid .rt.none { opacity: .25; }
.remaining-grid .rt b { position: absolute; right: 1px; bottom: 1px; background: var(--panel); border-radius: 4px; padding: 0 3px; font-size: calc(var(--rt-size, 56px) * .22 + 2px); }
.remaining-grid svg { width: 100%; height: auto; display: block; border-radius: 3px; }

.final table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.final td, .final th { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.final th:first-child, .final td:first-child { text-align: left; }
.log ol { margin: 0; padding-left: 26px; max-height: 260px; overflow-y: auto; font-size: 12px; }
.log li { margin: 2px 0; }

/* board */
.field { fill: var(--field); }
.city { fill: var(--city); stroke: var(--city-stroke); stroke-width: 1.2; stroke-linejoin: round; }
.road { fill: none; stroke: var(--road); stroke-width: 9; stroke-linecap: butt; filter: drop-shadow(0 0 1px var(--road-edge)); }
.crossing { fill: var(--road-edge); }
.monastery { fill: var(--monastery); }
.monastery-roof { fill: #7d3b20; }
.shield { fill: #2d5aa8; stroke: #fff; stroke-width: 1.2; }
.tile-frame { fill: none; stroke: rgba(0, 0, 0, .25); stroke-width: 1; }
.legal-cell { fill: var(--legal); stroke: var(--legal-stroke); stroke-width: 2; stroke-dasharray: 6 4; cursor: pointer; }
.legal-cell:hover { fill: rgba(47, 111, 79, .4); }
.preview { opacity: .9; }
.preview-frame { fill: none; stroke: var(--flash); stroke-width: 4; }
.spot-option { fill: rgba(255, 255, 255, .55); stroke: #222; stroke-width: 1.5; cursor: pointer; }
.spot-option.chosen { fill: var(--flash); }
.board-button { cursor: pointer; }
.board-button circle { fill: #fff; stroke: #2b2b2b; stroke-width: 2; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); }
.board-button text { font: bold 22px system-ui, sans-serif; text-anchor: middle; fill: #2b2b2b; pointer-events: none; }
.board-button.confirm circle { fill: #2e7d4f; stroke: #1d5134; }
.board-button.confirm text { fill: #fff; }
.board-button:hover circle { filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .55)); }
.last-move { fill: none; stroke-width: 4; opacity: .75; pointer-events: none; }
.last-move.newest { stroke-width: 5; opacity: 1; }
.flash { fill: var(--flash); opacity: 0; animation: flash 1.6s ease-out; pointer-events: none; }
@keyframes flash { 0% { opacity: .75; } 100% { opacity: 0; } }
.meeple circle:first-child { stroke: #fff; stroke-width: 2; }

@media (max-width: 800px) {
  .layout { flex-direction: column; height: auto; }
  .board-wrap { height: 60vh; flex: none; }
  .side { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
}

.remaining h2 { display: flex; justify-content: space-between; align-items: center; }
.hide-used-toggle { white-space: nowrap; display: flex; gap: 4px; align-items: center; font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; cursor: pointer; }
.remaining-grid.hide-used .rt.none { display: none; }
.remaining-tools { display: flex; gap: 10px; align-items: center; }
#tile-size { width: 80px; }
.fit-count { font: 700 26px system-ui, sans-serif; text-anchor: middle; fill: rgba(0, 0, 0, .55); pointer-events: none; }
.fit-count.warn { fill: #c25e00; }
.fit-count.dead { fill: #b3261e; }
.fit-dead { fill: rgba(179, 38, 30, .18); stroke: #b3261e; stroke-width: 2; pointer-events: none; }

.replay .rp-pos { min-width: 110px; text-align: center; align-self: center; }
.replay .rp-slider { width: 100%; margin: 6px 0; }
.analysis h3 { font-size: 13px; margin: 10px 0 4px; }
.analysis table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.analysis td, .analysis th { padding: 2px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.analysis td:nth-child(2), .analysis th:nth-child(2), .analysis .explain td:first-child, .analysis .explain th:first-child { text-align: left; }
.analysis tr.played td { font-weight: 700; background: var(--legal); }
.cand-mark circle { fill: #fff; stroke: #2b2b2b; stroke-width: 2; }
.cand-mark.best circle { fill: var(--flash); }
.cand-mark text { font: 700 16px system-ui, sans-serif; text-anchor: middle; fill: #2b2b2b; }
.cand-mark { pointer-events: none; }
#rp-move { width: 56px; padding: 3px 4px; text-align: right; }

.site-only { display: none; }
body.site .site-only { display: flex; }
.account-row { flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 6px; font-size: 13px; }
.account-row input { width: 130px; }
.comment-box { width: 100%; margin-top: 8px; }
.comment-box textarea { width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; resize: vertical; }
.games-dialog { max-width: min(900px, 96vw); width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
.games-dialog table { width: 100%; border-collapse: collapse; font-size: 13px; }
.games-dialog td, .games-dialog th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.games-dialog tr[data-i] { cursor: pointer; }
.games-dialog tr[data-i]:hover { background: var(--legal); }
@media (max-width: 800px) {
  .games-dialog td:nth-child(4), .games-dialog th:nth-child(4) { display: none; }
}

[hidden] { display: none !important; }

/* Site, not logged in: only the title and the login button. */
body.needs-login .board-wrap,
body.needs-login .side > :not(.setup),
body.needs-login .setup > :not(h1):not(.account-row),
body.needs-login .account-row > :not(#account) { display: none !important; }
body.needs-login .layout { justify-content: center; align-items: center; }
body.needs-login .side { width: auto; border: 0; background: transparent; text-align: center; }
body.needs-login #account { font-size: 16px; }
