:root {
  --bg: #f5f3ee; --surface: #fffefa; --surface-soft: #f7f6f1; --hover: #efeee8;
  --border: #e4e1d8; --text: #232b26; --muted: #707970; --accent: #286c50;
  --accent-hover: #205b43; --danger: #ad514a; --board-bg: #eeede6;
  --grid-line: rgba(39, 54, 43, .055); --frontier-line: rgba(39, 54, 43, .14);
  --log-ai-color: #765e56; --log-player-color: #286c50; --accent-contrast: #fff;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
:root[data-theme='dark'] {
  --bg: #191e1b; --surface: #242b26; --surface-soft: #2b332d; --hover: #354037;
  --border: #3b473e; --text: #f0f2ec; --muted: #a6b2a8; --accent: #76c49b;
  --accent-hover: #91d3ae; --danger: #ec9188; --board-bg: #171e19;
  --grid-line: rgba(240, 246, 237, .055); --frontier-line: rgba(240, 246, 237, .16);
  --log-ai-color: #d4b1a7; --log-player-color: #91d3ae; --accent-contrast: #15251c; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) {
    --bg: #191e1b; --surface: #242b26; --surface-soft: #2b332d; --hover: #354037;
    --border: #3b473e; --text: #f0f2ec; --muted: #a6b2a8; --accent: #76c49b;
    --accent-hover: #91d3ae; --danger: #ec9188; --board-bg: #171e19;
    --grid-line: rgba(240, 246, 237, .055); --frontier-line: rgba(240, 246, 237, .16);
    --log-ai-color: #d4b1a7; --log-player-color: #91d3ae; --accent-contrast: #15251c; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button { font: inherit; }
button:focus-visible, summary:focus-visible, .hand-tile-wrapper:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 520px; }
#topbar { display: flex; align-items: center; gap: clamp(16px, 2.5vw, 40px); flex: none; min-height: 76px; padding: 12px clamp(16px, 2vw, 32px); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 1.65rem; line-height: 1; }
.brand h1 { margin: 0; font-size: 1.06rem; font-weight: 760; letter-spacing: -.035em; }
.brand h1 span { color: var(--muted); font-weight: 500; }
#scoreboard { display: flex; align-items: center; gap: 20px; }
.score-chip { display: flex; align-items: baseline; gap: 9px; font-variant-numeric: tabular-nums; }
.score-chip .label { color: var(--muted); font-size: .77rem; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; }
.score-chip span:last-child { font-size: 1.65rem; line-height: 1; font-weight: 730; letter-spacing: -.055em; }
.score-chip.you span:last-child { color: var(--accent); }
.score-divider { width: 1px; height: 25px; background: var(--border); }
.header-meta { display: flex; align-items: center; gap: 18px; margin-left: auto; white-space: nowrap; }
#turn-indicator { display: flex; align-items: center; gap: 8px; font-size: .86rem; font-weight: 650; }
#turn-indicator::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
#turn-indicator.ai-turn::before { background: #c18c58; }
#turn-indicator.game-over::before { background: var(--muted); }
.bag-count { display: flex; align-items: baseline; gap: 6px; color: var(--muted); font-size: .78rem; }
.bag-count strong { color: var(--text); font-size: .94rem; font-variant-numeric: tabular-nums; }
#theme-toggle { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 1rem; }
#layout { flex: 1; display: flex; min-height: 0; }
#board-section { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#board-container { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: grab; background: var(--board-bg); }
#board-canvas { display: block; width: 100%; height: 100%; }
#zoom-controls { position: absolute; top: 18px; right: 18px; display: grid; grid-template-columns: repeat(2, 36px); gap: 5px; padding: 5px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); box-shadow: 0 5px 18px rgba(25, 35, 25, .1); }
#zoom-controls button { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; font-size: 1.15rem; }
#zoom-controls button:hover { background: var(--hover); }
#board-message { position: absolute; bottom: 18px; left: 50%; width: max-content; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 10px 15px; border-radius: 10px; background: #983c35; color: #fff; font-size: .87rem; line-height: 1.4; box-shadow: 0 8px 24px rgba(0,0,0,.14); display: none; }
#board-message.visible { display: block; }
#board-message.info { background: #245b45; }
#hand-tray { flex: none; display: flex; flex-direction: column; gap: 12px; padding: 15px clamp(18px, 2.3vw, 34px) 18px; background: var(--surface); border-top: 1px solid var(--border); }
.tray-heading { display: flex; align-items: baseline; gap: 15px; }
.tray-heading h2, .panel h2 { margin: 0; font-size: .88rem; font-weight: 740; letter-spacing: -.01em; }
.tray-heading span, .panel-heading span { color: var(--muted); font-size: .78rem; }
#hand-tiles { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-height: 60px; }
.hand-tile-wrapper { flex: none; width: 56px; height: 56px; cursor: pointer; border-radius: 10px; transition: transform .12s ease, box-shadow .12s ease; }
.hand-tile-wrapper:hover { transform: translateY(-4px); }
.hand-tile-wrapper.selected { outline: 3px solid var(--accent); outline-offset: 1px; transform: translateY(-5px); }
.hand-tile-wrapper.swap-selected { outline: 3px solid var(--danger); outline-offset: 1px; transform: translateY(-5px); }
#hand-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
button { min-height: 38px; padding: 8px 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: .84rem; font-weight: 600; cursor: pointer; transition: background .12s ease, border-color .12s ease; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .43; cursor: not-allowed; }
#commit-move { min-width: 126px; background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
#commit-move:hover:not(:disabled) { background: var(--accent-hover); }
#commit-move:disabled { opacity: .55; }
#pass-turn { color: var(--muted); }
#sidebar { width: clamp(264px, 21vw, 316px); flex: none; display: flex; flex-direction: column; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); }
.panel { padding: 22px 20px; border-bottom: 1px solid var(--border); }
.panel-heading { display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px; }
#ask-coach { width: 100%; min-height: 42px; border-color: var(--accent); color: var(--accent); background: transparent; }
#ask-coach:hover:not(:disabled) { background: var(--surface-soft); }
#coach-suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
#coach-suggestions:empty { display: none; }
#coach-suggestions > p { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.5; }
.suggestion { padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-soft); font-size: .83rem; line-height: 1.5; cursor: pointer; }
.suggestion:hover { border-color: var(--accent); }
.suggestion .rank { color: var(--accent); font-weight: 750; }
.suggestion .score { float: right; font-weight: 750; font-variant-numeric: tabular-nums; }
.suggestion p { margin: 5px 0 0; }
#log-panel summary { cursor: pointer; font-size: .85rem; font-weight: 700; list-style-position: outside; }
#log-panel summary::marker { color: var(--muted); }
#game-log { display: flex; flex-direction: column; gap: 0; max-height: 260px; overflow-y: auto; margin: 16px 0 0; padding: 0; list-style: none; font-size: .79rem; line-height: 1.45; }
#game-log li { padding: 9px 0; border-top: 1px solid var(--border); }
#game-log li.ai-entry { color: var(--log-ai-color); }
#game-log li.player-entry { color: var(--log-player-color); }
#game-log li.log-clickable { cursor: pointer; }
#game-log li.log-clickable:hover { background: var(--hover); }
#new-game-panel { margin-top: auto; border-bottom: 0; }
#new-game { width: 100%; }
@media (max-width: 900px) {
  #topbar { gap: 18px; }
  #sidebar { width: 245px; }
  .panel { padding: 18px 15px; }
  .tray-heading span { display: none; }
}
@media (max-width: 700px) {
  #app { min-height: 0; height: auto; }
  #topbar { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; padding: 12px 16px; }
  .brand { grid-column: 1; }
  #theme-toggle { grid-column: 2; grid-row: 1; }
  #scoreboard { grid-column: 1; grid-row: 2; gap: 13px; }
  .score-chip { gap: 6px; }
  .score-chip span:last-child { font-size: 1.4rem; }
  .header-meta { grid-column: 2; grid-row: 2; gap: 11px; margin-left: 0; }
  #turn-indicator { font-size: .77rem; }
  .bag-count { font-size: .74rem; }
  #layout { display: flex; flex-direction: column; }
  #board-section { flex: none; }
  #board-container { flex: none; height: clamp(330px, 52dvh, 600px); }
  #hand-tray { padding: 14px 16px 18px; }
  #sidebar { width: 100%; overflow: visible; border-left: 0; border-top: 1px solid var(--border); }
  #new-game-panel { margin-top: 0; }
}
@media (max-width: 430px) {
  .brand h1 { font-size: .98rem; }
  .header-meta { gap: 7px; }
  #turn-indicator { max-width: 108px; white-space: normal; line-height: 1.2; }
  #turn-indicator::before { flex: none; }
  .bag-count { gap: 3px; }
  #hand-actions button { flex: 1 1 calc(50% - 4px); }
  #commit-move { min-width: 0; }
  #zoom-controls { top: 10px; right: 10px; }
}

/* Chroma Table visual adaptation */
:root{--bg:#f6f0e7;--surface:#fffaf2;--accent:#246d64;--border:#ddd3c1;--grid-line:rgba(71,65,44,.10);--frontier-line:rgba(48,83,65,.36)}.brand h1{font:600 24px Georgia,serif;letter-spacing:-.8px}.brand h1 span{color:#246d64}#sidebar{width:300px}.rules-panel{font-size:12px;line-height:1.65;color:var(--muted)}.rules-panel h2{font:26px Georgia,serif;color:var(--text)}.rules-panel a{color:var(--accent)}.rules-panel .eyebrow{font-size:9px;letter-spacing:1.7px;color:var(--accent)}.suggestion{text-align:left}.rules-panel summary{cursor:pointer;font-weight:700;color:var(--text)}.rules-panel details{margin-top:18px}#new-game-panel{margin-top:auto}.hand-tile-wrapper[role=button]:focus-visible{outline:3px solid #d69729;outline-offset:3px}@media(max-width:750px){#sidebar{width:100%}.brand h1{font-size:20px}.rules-panel{font-size:11px}}
