:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1d1f1c;
  --muted: #6b6f68;
  --line: #e2ddd2;
  --accent: #2f5d46;
  --accent-ink: #ffffff;
  --light-sq: #ebe3d1;
  --dark-sq: #9b7b5a;
  --hl: rgba(214, 178, 52, 0.55);
  --top: #1f2a24;
  --top-ink: #f4f1ea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141714;
    --surface: #1e221e;
    --ink: #ece9e1;
    --muted: #9aa096;
    --line: #2f352f;
    --accent: #6fae8b;
    --accent-ink: #0f1410;
    --light-sq: #c9bfa8;
    --dark-sq: #7d6248;
    --top: #0e110e;
  }
}
* { box-sizing: border-box; }
html { background: var(--top); }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; }

/* Native-style press feedback instead of hover */
.chip, .games li button, .controls button, .strip .mv, .icon-btn {
  transition: transform .08s ease, background-color .08s ease, opacity .08s ease;
}
.chip:active, .games li button:active, .controls button:active { transform: scale(.97); }
.icon-btn:active { opacity: .5; }

.top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--top); color: var(--top-ink);
}
.top h1 { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; font-size: 30px; line-height: 1; padding: 0 8px 0 0; color: var(--top-ink); }
.titles { flex: 1; min-width: 0; }
.subtitle { margin: 1px 0 0; font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-result {
  flex: none; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums; background: rgba(255,255,255,.12); color: var(--top-ink);
}

main { background: var(--bg); }
main > section { max-width: 560px; margin: 0 auto; padding: 12px 16px 8px; }

/* Game screen: one fixed screen, nothing scrolls except the move strip sideways */
#game-view { height: 100%; display: flex; flex-direction: column; padding: 4px 12px 0; }
/* Board area takes the spare height; names stay attached above and below the board */
.board-wrap {
  flex: 1; min-height: 0; container-type: size;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.board-wrap > * { width: min(100cqw, calc(100cqh - 72px)); flex: none; }

.filters { display: grid; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 7px 14px; font-size: 14px;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.search-row { display: flex; gap: 8px; }
.search-row input, .search-row select {
  font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
}
.search-row input { flex: 1; min-width: 0; }
.search-row select { flex: none; max-width: 42%; }
main, .filters, .search-row { min-width: 0; }
.chips { max-width: 100%; }

.count { color: var(--muted); font-size: 13px; margin: 14px 2px 6px; }
.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.games li button {
  width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  display: grid; gap: 3px;
}
.games .names { font-weight: 600; }
.games .names .vs { color: var(--muted); font-weight: 400; }
.games .sub { color: var(--muted); font-size: 13px; }
.games .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.result { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.board {
  display: grid; grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  touch-action: pan-y; user-select: none;
}
.sq { position: relative; }
.sq.l { background: var(--light-sq); }
.sq.d { background: var(--dark-sq); }
.sq.hl::before { content: ""; position: absolute; inset: 0; background: var(--hl); }
.sq piece { position: absolute; inset: 0; background-size: 100%; background-repeat: no-repeat; }
.sq .coord { position: absolute; font-size: 10px; font-weight: 600; opacity: .75; pointer-events: none; }
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.l .coord { color: var(--dark-sq); }
.sq.d .coord { color: var(--light-sq); }

.players { flex: none; height: 36px; display: flex; align-items: center; justify-content: space-between; padding: 0 2px; font-size: 14px; }
.players .pl { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
.pl .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl .side { color: var(--muted); font-weight: 400; font-size: 12px; flex: none; }
.pl .crown { flex: none; width: 18px; height: 18px; fill: #d4a017; stroke: #9a7410; stroke-width: 1; stroke-linejoin: round; }

/* Move strip: one swipeable row, current move kept in view */
.strip {
  flex: none; position: relative; display: flex; align-items: center; gap: 2px;
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none;
  white-space: nowrap; padding: 6px 2px; margin: 2px 0 4px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; touch-action: pan-x;
}
.strip::-webkit-scrollbar { display: none; }
.strip .num { flex: none; color: var(--muted); font-size: 14px; padding: 0 2px 0 8px; }
.strip .num:first-child { padding-left: 2px; }
.strip .mv { flex: none; background: none; border: 0; padding: 6px 8px; border-radius: 7px; font-size: 15px; font-weight: 600; }
.strip .mv.cur { background: var(--accent); color: var(--accent-ink); }
.strip .res { flex: none; color: var(--muted); font-weight: 700; padding: 0 12px 0 10px; }

/* Control bar pinned to the bottom, clear of the home indicator */
.controls {
  flex: none; display: grid; grid-template-columns: 1fr 1.5fr 1.5fr 1fr 1fr; gap: 8px;
  padding: 4px 0 calc(env(safe-area-inset-bottom) + 10px);
}
.controls button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 0; font-size: 18px;
}
.controls button:active { background: var(--line); }

.foot { text-align: center; color: var(--muted); font-size: 11px; padding: 16px 0 calc(env(safe-area-inset-bottom) + 12px); }
