:root {
  --bg: #f4f1ea; --panel: #fffdf8; --ink: #1d2128; --muted: #6b7280; --line: #e3ddd0;
  --accent: #1f6f5c; --accent-ink: #ffffff; --warn: #b4531f; --bad: #b42318;
  --wood: #d9b26a; --wood-dark: #c49a4f; --grid: #3b2f1d;
  --radius: 10px; --shadow: 0 1px 2px rgba(30, 24, 12, .06), 0 4px 16px rgba(30, 24, 12, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b; --panel: #1d2026; --ink: #e8e6e1; --muted: #9aa1ab; --line: #2c3038;
    --accent: #3fa98f; --accent-ink: #0d1412; --warn: #e08a52; --bad: #f0645a;
    --wood: #c9a160; --wood-dark: #b08a4c; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 10; }
header.top .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
header.top .brand svg { width: 28px; height: 28px; }
header.top nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer; font: inherit; color: var(--ink); }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
h1 { font-size: 22px; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 780px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 18px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input[type=text], input[type=number] { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: 100%; }
.seg button { flex: 1; font: inherit; border: 0; padding: 8px 6px; background: var(--bg); color: var(--ink); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form { display: grid; gap: 12px; }
.error { color: var(--bad); font-size: 13px; min-height: 1.2em; }
table.games { width: 100%; border-collapse: collapse; font-size: 14px; }
table.games td, table.games th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.games th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.games td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.wrap { overflow-x: auto; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; margin-right: 5px; }
.dot.b { background: radial-gradient(circle at 35% 35%, #555, #000 70%); }
.dot.w { background: radial-gradient(circle at 35% 35%, #fff, #d8d8d8 75%); border: 1px solid #aaa; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.pill.live { color: var(--accent); border-color: var(--accent); }
footer.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 24px 0 0; }

/* game page */
.game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: 20px; align-items: start; }
@media (max-width: 860px) { .game { grid-template-columns: minmax(0, 1fr); } }
.boardwrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; }
.boardwrap svg { display: block; width: 100%; height: auto; max-width: 760px; margin: 0 auto; touch-action: manipulation; user-select: none; }
.player { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.player.turn { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.player .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.player .meta { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.status { font-size: 14px; min-height: 1.5em; }
.status.warn { color: var(--warn); }
.result { font-size: 20px; font-weight: 700; }
.moves { font-family: var(--mono); font-size: 12px; color: var(--muted); max-height: 160px; overflow-y: auto; line-height: 1.7; }
.confirm { display: none; gap: 8px; align-items: center; font-size: 13px; }
.confirm.show { display: flex; }
.hint { font-size: 13px; color: var(--muted); }

.clock { display: block; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; line-height: 1.2; }
.clock .byo { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.clock.low { color: var(--bad); }
.clock.idle { color: var(--muted); font-weight: 500; }

/* chat */
.chatlog { max-height: 240px; min-height: 60px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; font-size: 14px; overscroll-behavior: contain; }
.chatlog .line { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; }
.chatlog .who { font-weight: 600; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatlog .line.me .who { color: var(--accent); }
.chatlog time { color: var(--muted); font-size: 11px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.chatlog .text { grid-column: 1 / -1; white-space: pre-wrap; overflow-wrap: anywhere; }
.chatform { display: flex; gap: 8px; }
.chatform input { flex: 1; min-width: 0; }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: var(--accent-ink); }

/* lobby: phone = one column (new game, chat, lists); tablet = new game and chat on the left of the lists;
   wide desktop = three columns with the chat on the right, sticky and as tall as the window */
main.wide { max-width: 1100px; }
.lobby { display: grid; gap: 18px; align-items: start; grid-template-columns: minmax(0, 1fr); grid-template-areas: "new" "chat" "lists"; }
#newcard { grid-area: new; } #chatcard { grid-area: chat; } #lists { grid-area: lists; }
@media (min-width: 781px) {
  .lobby { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "new lists" "chat lists"; }
}
@media (min-width: 1280px) {
  main.wide { max-width: 1480px; }
  .lobby { grid-template-columns: minmax(0, 340px) minmax(0, 1fr) minmax(0, 340px); grid-template-rows: auto; grid-template-areas: "new lists chat"; }
  #chatcard { position: sticky; top: 76px; }
  #chatcard .chatlog { max-height: none; height: calc(100vh - 360px); min-height: 240px; }
}

/* move navigation under the board */
.navbar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 0 2px; }
.navbar .btn { min-width: 46px; padding: 6px 10px; font-size: 15px; line-height: 1.2; }
.navpos { min-width: 130px; text-align: center; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.moves .mv { white-space: nowrap; border-radius: 4px; padding: 0 2px; }
.moves .mv.nav { cursor: pointer; }
.moves .mv.nav:hover { color: var(--ink); background: var(--bg); }
.moves .mv.cur { color: var(--accent-ink); background: var(--accent); }
