:root {
  --bg: #0e1116; --panel: #161a21; --surface: #1b2029; --ink: #e8ebf0; --muted: #9aa3b2;
  --line: #2a303b; --p1: #e0a53a; --p2: #3366e0; --accent: #4fd1b3; --accent-ink: #06231c;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
.app { display: grid; grid-template-columns: 1fr 340px; height: 100vh; height: 100svh; }

.stage { position: relative; overflow: hidden; }
#scene { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#scene:active { cursor: grabbing; }

.overlay-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(14,17,22,0.85), transparent); pointer-events: none; flex-wrap: wrap;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.s { background: var(--p1); } .dot.n { background: var(--p2); }
.scoreline { font-family: var(--mono); font-size: 0.86rem; color: var(--muted); }
.scoreline .s { color: #ffcf7a; } .scoreline .n { color: #8fb0ff; } .scoreline b { color: var(--ink); }
.turn { font-family: var(--mono); font-size: 0.9rem; padding: 5px 12px; border-radius: 999px; background: var(--surface); }
.turn.p1 { color: #ffcf7a; box-shadow: inset 0 0 0 1px rgba(224,165,58,0.5); }
.turn.p2 { color: #8fb0ff; box-shadow: inset 0 0 0 1px rgba(51,102,224,0.5); }

.overlay-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 18px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(14,17,22,0.85), transparent); pointer-events: none;
}
.hint { font-size: 0.86rem; color: var(--muted); }
.cam-btn {
  position: absolute; right: 14px; bottom: 54px; font: inherit; font-size: 0.8rem;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 11px; cursor: pointer; min-height: 40px;
}
.cam-btn:hover { border-color: var(--accent); }

.panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  overflow-y: auto; padding: 14px; gap: 12px; }
.pnl { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.pnl.grow { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
.pnl h2 { margin: 0 0 8px; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button {
  font: inherit; font-size: 0.85rem; padding: 9px 8px; min-height: 44px; cursor: pointer;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line); border-radius: 8px;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-color: var(--accent); }

.row { display: flex; gap: 6px; margin-bottom: 10px; }
.row button {
  flex: 1; font: inherit; font-size: 0.82rem; padding: 9px 6px; min-height: 44px; cursor: pointer;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.row button:hover:not(:disabled) { border-color: var(--accent); }
.row button:disabled { opacity: 0.4; cursor: default; }
.row .primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; border-color: var(--accent); }
.row .primary[aria-pressed="true"] { background: #e0a53a; border-color: #e0a53a; color: #241704; }

.ctl { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem; color: var(--muted); margin: 8px 0; }
.ctl input[type=range] { flex: 1; }
.ctl select { font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px; min-height: 36px; }
.meta { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

.pnl h2 .tag { float: right; font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.02em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 999px; background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); }
.tag.sky-day { color: #ffd27a; border-color: rgba(224,165,58,0.5); }
.tag.sky-twilight { color: #ffb08a; border-color: rgba(224,120,70,0.5); }
.tag.sky-dusk { color: #b79bff; border-color: rgba(140,110,230,0.5); }
.tag.sky-night { color: #8fb0ff; border-color: rgba(51,102,224,0.5); }
.ctl-val { font-family: var(--mono); color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--muted); margin: 8px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.candidates { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.cand-head { font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.cand {
  display: grid; grid-template-columns: 22px 1fr 60px 46px; align-items: center; gap: 8px;
  width: 100%; text-align: left; font: inherit; font-size: 0.82rem; cursor: pointer; min-height: 40px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
}
.cand:hover { border-color: var(--accent); background: #10161c; }
.cand.top { border-color: rgba(224,165,58,0.55); }
.cand-rank { font-family: var(--mono); color: var(--muted); text-align: center; }
.cand.top .cand-rank { color: #e0a53a; }
.cand-move { font-family: var(--mono); }
.cand-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.cand-bar span { display: block; height: 100%; background: var(--accent); }
.cand-score { font-family: var(--mono); font-size: 0.76rem; color: var(--muted); text-align: right; }
.muted { color: var(--muted); font-size: 0.82rem; }

.result { background: rgba(79,209,179,0.12); border: 1px solid rgba(79,209,179,0.4); color: #9ff0dd;
  border-radius: 10px; padding: 10px 12px; font-size: 0.85rem; margin: 0; }
.foot { font-size: 0.72rem; color: var(--muted); line-height: 1.5; margin: 0; }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 52vh 1fr; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}
