:root {
  --bg: #0b0f0c;
  --panel: rgba(18, 24, 20, 0.92);
  --panel-solid: #141a16;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f5f2;
  --muted: #9aa69d;
  --accent: #3ddc84;
  --good: #3ddc84;
  --caution: #ffc233;
  --bad: #ff5a4f;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; }
#video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#overlay { pointer-events: none; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 6px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.spacer { flex: 1; }
.pill { padding: 4px 10px; border-radius: 99px; background: var(--panel); font-size: 13px; white-space: nowrap; }
.pill.subtle { color: var(--muted); }
.pill[data-state="address"] { background: var(--accent); color: #002a12; font-weight: 700; }
.pill[data-state="swing"] { background: var(--caution); color: #2a1f00; font-weight: 700; }
.icon-btn { border: 0; background: var(--panel); border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; }

.hint, .toast {
  position: absolute; left: 50%; transform: translateX(-50%); padding: 8px 14px; border-radius: 99px;
  background: var(--panel); font-size: 14px; white-space: nowrap;
}
.hint { top: 45%; }
.toast { top: calc(env(safe-area-inset-top) + 56px); color: var(--muted); }

.start {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px 16px; text-align: center; background: radial-gradient(circle at 50% 30%, #173322, var(--bg) 70%);
}
.start h1 { margin: 0; font-size: 30px; letter-spacing: .04em; }
.lead { margin: 0; color: var(--muted); line-height: 1.7; }
.guide { text-align: left; margin: 8px 0 12px; padding-left: 1.4em; line-height: 1.9; font-size: 14px; }
.primary, .secondary {
  width: min(320px, 100%); padding: 14px; border-radius: var(--radius); border: 0; font-size: 16px; font-weight: 700; cursor: pointer;
}
.primary { background: var(--accent); color: #002a12; }
.secondary { background: transparent; border: 1px solid var(--line); display: block; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }
.loading { color: var(--muted); }
.error { color: var(--bad); max-width: 360px; }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 78vh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0; padding: 6px 16px calc(env(safe-area-inset-bottom) + 14px);
  backdrop-filter: blur(8px);
}
.sheet-handle { display: block; margin: 0 auto 6px; width: 44px; height: 5px; border-radius: 99px; background: var(--line); border: 0; padding: 0; cursor: pointer; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; }
.muted { color: var(--muted); font-size: 13px; }
.tempo span { font-size: 30px; font-weight: 800; }
.tempo small { margin-left: 8px; color: var(--muted); }
.tempo[data-status="good"] span { color: var(--good); }
.tempo[data-status="caution"] span { color: var(--caution); }
.tempo[data-status="bad"] span { color: var(--bad); }
.ai-comment { margin: 6px 0 8px; line-height: 1.7; font-size: 15px; }
.ai-comment.pending { color: var(--muted); }

.metrics { list-style: none; margin: 0; padding: 0; }
.metrics li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.metrics .label { font-size: 14px; }
.metrics .detail { display: block; color: var(--muted); font-size: 12px; }
.metrics .value { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; font-weight: 700; }
.badge.good { background: var(--good); color: #002a12; }
.badge.caution { background: var(--caution); color: #2a1f00; }
.badge.bad { background: var(--bad); color: #fff; }
.metrics .tip { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin-top: -2px; }

.replay { margin-top: 10px; }
#replayCanvas { width: 100%; max-height: 50vh; object-fit: contain; background: #000; border-radius: 10px; display: block; }
.replay-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.replay-controls button { flex: 1 1 auto; border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 8px 6px; font-size: 13px; cursor: pointer; }
.replay-controls [data-play] { background: var(--accent); color: #002a12; border: 0; font-weight: 700; }

dialog {
  width: min(420px, calc(100% - 32px)); background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
dialog select, dialog input[type="password"] { padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; padding: 0; margin: 8px 0 0; }
dialog menu button { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; width: auto; font-size: 14px; }
dialog menu .primary { border: 0; }
.history { list-style: none; padding: 0; margin: 0; max-height: 50vh; overflow-y: auto; font-size: 13px; }
.history li { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.history .worst { color: var(--muted); text-align: right; }
