/* guki.si: dark, quiet, mobile-first. Layout budget per docs/design.md (360x740 reference). */
:root {
  --bg: #121417;
  --panel: #191c20;
  --line: #262a30;
  --text: #e7e4de;
  --muted: #8f949b;
  --accent: #d6b46a;
  --warn: #e5a54b;
  --sq-light: #a4aa9f;
  --sq-dark: #6d766e;
  --header-h: 40px;
  --row-h: 28px;
  --sync-h: 48px;
  /* Board shrinks first: whatever height is left after header, 16:9 embed, 2 player rows, sync. */
  --board: min(100vw, max(220px, calc(100svh - var(--header-h) - 56.25vw - 2 * var(--row-h) - var(--sync-h))));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Noto Sans", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button { font: inherit; }

/* Header */
.top {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.01em; }
.sep { color: var(--muted); }
.unofficial { color: var(--muted); font-size: 13px; }

/* Page: one column on mobile */
.page { display: flex; flex-direction: column; }

/* Stream: always 16:9, never shrinks */
.stream {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  flex: none;
  background: #000;
  overflow: hidden;
}
.stream iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.stream-failed {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #0b0c0e;
  color: var(--muted);
  text-align: center;
  padding: 16px;
}
.stream-failed p { margin: 0; color: var(--text); }
.stream-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: #3a4048; }

/* Live column: players, board, sync */
.col-live { display: flex; flex-direction: column; align-items: center; }
.player, .board-wrap, .sync { width: var(--board); }
.player {
  height: var(--row-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  color: var(--muted);
}
.player .turn { width: 1em; font-size: 10px; text-align: center; }
.player .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .clock {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 600;
  font-size: 15px;
  padding: 1px 8px;
  border-radius: 4px;
}
.player.active { color: var(--text); }
.player.active .turn { color: var(--accent); }
.player.active .clock { background: #2a2f36; color: #fff; }

.board-wrap { aspect-ratio: 1; flex: none; }
.board-svg { display: block; width: 100%; height: 100%; }
.sq.l { fill: var(--sq-light); }
.sq.d { fill: var(--sq-dark); }
.hl { fill: rgba(226, 204, 120, 0.38); }
.chk { fill: url(#chk-grad); }
.coord { font-size: 18px; font-weight: 600; font-family: inherit; pointer-events: none; }
.coord.on-l { fill: #4f5650; }
.coord.on-d { fill: #c4c9be; }
.pc {
  font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", "DejaVu Sans", "Apple Symbols", sans-serif;
  font-size: 80px;
  text-anchor: middle;
  dominant-baseline: central;
  paint-order: stroke;
  pointer-events: none;
}
.pc.w { fill: #f4f1ea; stroke: #1b1c1e; stroke-width: 4px; }
.pc.b { fill: #18191b; stroke: #d9d4c8; stroke-width: 2px; }

.sync {
  height: var(--sync-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  border-top: 1px solid var(--line);
}
.sync { gap: 6px; }
.sync .grow { flex: 1; }
.sync .chip { background: var(--panel); color: var(--text); font-variant-numeric: tabular-nums; }
.icon {
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.icon:hover { color: var(--text); background: var(--panel); }
.btn.sm { min-height: 32px; padding: 0 9px; font-size: 13px; font-variant-numeric: tabular-nums; }
.btn.warn { color: var(--warn); border-color: #4a3a22; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; }
.player .score { font-weight: 700; color: var(--accent); }

/* Cold-start strip: takes the board's place until the user picks */
.align {
  width: var(--board);
  min-height: calc(var(--board) + 2 * var(--row-h) + var(--sync-h));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 12px;
}
.align p { margin: 0; }
.align-q { font-size: 16px; line-height: 1.5; }
.align-note { color: var(--muted); font-size: 13px; }
.align-moves { display: flex; flex-wrap: wrap; gap: 8px; }
.mv-pick { font-variant-numeric: tabular-nums; font-weight: 600; }
.align .btn.link { padding: 0; }
.align-manual { display: flex; align-items: center; gap: 8px; }
.align-manual input {
  width: 5em;
  height: 36px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

/* "Live ⚠" confirm sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 10; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
}
.sheet p { margin: 0 0 16px; font-size: 15px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }

.chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 13px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.live, .sync .chip.live { background: #24302a; color: #9fd3a8; }
.chip.warn, .sync .chip.warn { background: #3a2c17; color: var(--warn); padding: 0 8px; }
.moves .result { margin: 6px 0 0; font-weight: 700; color: var(--accent); }

/* Below the fold: "What happened?" first */
.notes { padding: 12px 12px 0; }
.notes h2 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.notes-list { list-style: none; margin: 0; padding: 0; }
.notes-list li { display: grid; grid-template-columns: 4.8em 1fr; gap: 8px; padding: 3px 0; }
.notes-list .lbl { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
.notes-list li.auto .txt { color: var(--muted); }
.notes-empty { margin: 0; color: var(--muted); font-size: 13px; }
.col-extra { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.moves summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
.move-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  column-gap: 12px;
}
.move-list li { display: grid; grid-template-columns: 2.6em 1fr 1fr; padding: 2px 0; }
.move-list .no { color: var(--muted); }
.mv.cur { color: var(--bg); background: var(--accent); border-radius: 3px; padding: 0 4px; justify-self: start; }

.health p { margin: 2px 0; color: var(--muted); font-size: 13px; }
.health .warn { color: var(--warn); }
.health .disclaimer { margin-top: 10px; font-size: 12px; opacity: 0.8; }

/* Desktop: stream left (~60%), live column right; same tree. */
@media (min-width: 960px) {
  .page {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(340px, 2fr);
    grid-template-areas:
      "stream live"
      "notes  live"
      "notes  extra";
    grid-template-rows: auto auto 1fr;
    gap: 0 20px;
    padding: 16px 20px;
    max-width: 1600px;
    margin: 0 auto;
  }
  .col-stream { grid-area: stream; }
  .col-live { grid-area: live; --board: min(100%, calc(100svh - var(--header-h) - 32px - 2 * var(--row-h) - var(--sync-h) - 110px)); }
  .col-extra { grid-area: extra; padding: 8px 0 0; }
  .notes { grid-area: notes; padding: 14px 0 0; font-size: 15px; }
  .stream { border-radius: 8px; }
  .move-list { max-height: 30vh; overflow-y: auto; grid-template-columns: 1fr; }
  /* One move pair per row: keep White and Black next to each other, not at opposite edges. */
  .move-list li { grid-template-columns: 2.6em 6em 6em; }
}
