:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #d9d6cf;
  --accent: #b5532a;
  --accent-soft: #f3dfd4;
  --ok: #2f7d32;
  --warn: #a05a00;
  --board-bg: #2b2a28;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a19;
    --panel: #262523;
    --text: #ecebe8;
    --muted: #a3a19c;
    --line: #3d3b38;
    --accent: #e0784a;
    --accent-soft: #4a2f22;
    --ok: #7bc47f;
    --warn: #e5a34a;
    --board-bg: #121110;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
h1 { font-size: 1.2rem; margin: 0; letter-spacing: 0.04em; }
h3 { font-size: 0.95rem; margin: 18px 0 4px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.85rem; margin: 0 0 8px; }
.github-link {
  margin-left: auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background-color 0.15s;
}
.github-link:hover {
  color: var(--text);
  background-color: var(--line);
}


main { display: grid; gap: 12px; padding: 0 16px 24px; }
@media (min-width: 960px) {
  main { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  #panel { position: sticky; top: 12px; }
}

#board-pane { background: var(--board-bg); border-radius: 12px; padding: 8px; }
#board { width: 100%; height: auto; max-height: calc(100vh - 90px); display: block; touch-action: manipulation; }
.board-tools { display: flex; justify-content: flex-end; color: #ddd; font-size: 0.85rem; padding: 4px 4px 0; }

#panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px 16px; }
#tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: -4px -4px 8px; overflow-x: auto; scrollbar-width: none; }
#tabs button { border: 0; background: none; padding: 8px 10px; white-space: nowrap; font: inherit; color: var(--muted); border-bottom: 3px solid transparent; }
#tabs button[aria-selected='true'] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

button, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; min-height: 36px;
}
button:hover { border-color: var(--accent); }
button.on { background: var(--accent-soft); border-color: var(--accent); }
button.danger { color: var(--accent); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; min-height: 36px; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.seg button:last-child { border-radius: 0 8px 8px 0; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tile { display: flex; gap: 4px; }
.tile select { flex: 1; }
.flip { padding: 4px 10px; }

.structs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.struct { display: flex; align-items: center; gap: 8px; text-align: left; font-size: 0.85rem; }
.struct .where { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.status { font-size: 0.9rem; margin: 14px 0 8px; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.error { color: var(--accent); min-height: 1em; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); width: min(560px, 92vw); }
dialog textarea { width: 100%; font-family: ui-monospace, monospace; font-size: 0.8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 8px 14px; border-radius: 8px; opacity: 0;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* Board */
.hex { cursor: pointer; }
.hex-bg { stroke: rgba(0, 0, 0, 0.35); stroke-width: 1; }
.hex:hover .hex-bg { filter: brightness(1.12); }
.glyph { font-size: 9px; fill: rgba(0, 0, 0, 0.35); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.territory { fill: none; stroke-width: 2.5; pointer-events: none; }
.territory.bear { stroke: #111; stroke-dasharray: 5 3; }
.territory.cougar { stroke: #d62828; }
.structure { stroke: #111; stroke-width: 1.5; }
.structure.black { stroke: #f2f2f2; }
.disc { stroke: rgba(0, 0, 0, 0.6); stroke-width: 1; }
.cube { stroke: #fff; stroke-width: 2; }
.coord { font-size: 7px; fill: rgba(0, 0, 0, 0.6); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.ring { fill: none; stroke-width: 3; pointer-events: none; }
.ring.select { stroke: #fff; stroke-dasharray: 4 3; }
.badge { stroke: #fff; stroke-width: 1; }
.badge-text { font-size: 13px; font-weight: 700; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.ruled-out { fill: url(#ruled-out-hatch); fill-opacity: 0.18; pointer-events: none; }
.ring.viable {
  stroke: var(--viable-color, #ff007a);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 2.5px rgba(0, 0, 0, 0.9));
}
.ring.dim { stroke: none; }

/* Me / Play panels */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.4); flex: none; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 0.9rem; }
button:disabled { opacity: 0.45; cursor: default; border-color: var(--line); }
#clue { width: 100%; }
.hidden-clue:not(:focus) { filter: blur(5px); }
.locs, .clues { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.locs li { display: grid; grid-template-columns: 3.2em 1fr 3em; gap: 8px; align-items: center; padding: 2px 0; }
.locs li span:last-child, .clues li span:last-child { text-align: right; color: var(--muted); }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #9b8bb8; border-radius: 4px; }
.clues li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0 2px 20px; }
details { margin: 4px 0; }
details summary { cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 4px 0; }

/* Advice panel */
.rec { border: 2px solid var(--accent); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.rec-action { font-size: 1.15rem; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rec .muted { font-size: 0.85rem; }
.answer { align-items: center; margin-top: 8px; }
table.advice { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.advice th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px; }
table.advice td { padding: 4px; border-bottom: 1px solid var(--line); }
table.advice td .dot { margin-right: 4px; vertical-align: -1px; }
table.advice button { min-height: 28px; padding: 2px 10px; }
.settings { margin-top: 16px; }
.slider { display: block; font-size: 0.85rem; margin: 8px 0; }
.slider input { width: 100%; }
.ring.best { stroke: #fff; stroke-width: 3.5; }
.ring.ask { stroke: #60a5fa; stroke-width: 2.5; }
.ring.search { stroke: #4ade80; stroke-width: 2.5; stroke-dasharray: 4 2; }
.ring.cube-spot { stroke: #f8fafc; stroke-width: 2.5; stroke-dasharray: 2 2; }
.badge.best { fill: #b5532a; } .badge.ask { fill: #2563eb; }
.badge.search { fill: #15803d; } .badge.cube-spot { fill: #475569; }

/* vs AI panel */
.log { font-size: 0.85rem; list-style: none; padding-left: 0; margin: 4px 0 12px; }
.log li { padding: 2px 0; }
.log li:first-child { font-weight: 600; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.rec .seg { margin: 6px 0; }
.ring.select { stroke: #fff; stroke-dasharray: 4 3; stroke-width: 2.5; }

footer { text-align: center; font-size: 0.8rem; color: var(--muted); padding: 0 16px 24px; }
footer a { color: inherit; }
.disclaimer { max-width: 640px; margin: 6px auto 0; line-height: 1.4; }
.tile-label {
  font-size: 40px; font-weight: 800; fill: #fff; stroke: #111; stroke-width: 5px;
  paint-order: stroke; stroke-linejoin: round; text-anchor: middle; dominant-baseline: central;
  pointer-events: none;
}
.tile-label.beside { font-size: 30px; }
.tile-border { stroke: #000; stroke-width: 4; stroke-linecap: round; pointer-events: none; }

/* Drag and drop in setup */
.setup-mode .hex.has-structure, .struct { touch-action: none; }
.setup-mode .hex.has-structure { cursor: grab; }
.hex.drop-target .hex-bg { stroke: #fff; stroke-width: 3; filter: brightness(1.25); }
.drag-ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 10; margin: -16px 0 0 -16px; }
.drag-ghost .structure-icon { display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); }
.structure-icon { flex: none; overflow: visible; }

/* Hex references: coordinates in panels that spotlight their hex */
.hexref {
  font-variant-numeric: tabular-nums; border-bottom: 1.5px dotted currentColor;
  cursor: help; border-radius: 3px; padding: 0 1px;
}
.hexref:hover, .hexref:focus { background: var(--accent-soft); outline: none; }
#board.spotlit .hex:not(.spot), .board-peek svg.spotlit .hex:not(.spot) { opacity: 0.3; transition: opacity 0.12s; }
.spot-ring { pointer-events: none; }
.spot-outer { fill: none; stroke: #000; stroke-width: 9; }
.spot-inner { fill: none; stroke: #fff; stroke-width: 5; animation: spot-pulse 0.9s ease-in-out infinite; }
@keyframes spot-pulse { 50% { stroke: #ffd400; stroke-width: 7; } }
@media (prefers-reduced-motion: reduce) { .spot-inner { animation: none; } }
.board-peek {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 20;
  width: min(94vw, 460px); background: var(--board-bg); border-radius: 10px; padding: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); pointer-events: none;
}
.board-peek svg { width: 100%; height: auto; display: block; }
