/*
 * 素振りスピード計測 — 見た目の決まりごと
 * ・ほぼ黒の下地に、速度＝ライム／本数＝シアンの2色だけを載せる
 * ・数値は極太・特大。イベント会場で遠くから読める大きさにする
 * ・角丸は 6px で統一（丸すぎると計測機器に見えない）
 */
:root {
  color-scheme: dark;
  --bg: #050708;
  --surface: #0b1012;
  --surface-2: #101719;
  --ink: #f5f8f7;
  --muted: #85918d;
  --line: rgba(255, 255, 255, 0.11);
  --speed: #c7ff4f; /* 速度・主操作 */
  --count: #4cddff; /* 本数・参加者 */
  --warn: #ffba4a;
  --danger: #ff647c;
  --r: 6px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, system-ui, sans-serif;
  background:
    radial-gradient(circle at 16% 5%, rgba(199, 255, 79, 0.07), transparent 28%),
    radial-gradient(circle at 90% 12%, rgba(76, 221, 255, 0.09), transparent 26%),
    var(--bg);
}

button, input { font: inherit; }
h1, h2, h3 { margin: 0; }

button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.045);
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, background-color .15s, transform .15s;
}
button:hover:not(:disabled) {
  border-color: rgba(199, 255, 79, .48);
  background: rgba(199, 255, 79, .08);
  transform: translateY(-1px);
}
button:disabled { cursor: not-allowed; color: rgba(245, 248, 247, .34); }

button.primary {
  border-color: rgba(199, 255, 79, .7);
  color: #101600;
  background: var(--speed);
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(199, 255, 79, .13);
}
button.primary:hover:not(:disabled) { filter: brightness(1.06); background: var(--speed); }
button.wide { width: 100%; }

/* ---- 全体レイアウト ---- */
.app { width: min(1920px, 100%); min-height: 100vh; margin: 0 auto; padding: 14px; }

.topbar {
  min-height: 68px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 0 4px 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 7px; height: 44px;
  background: linear-gradient(180deg, var(--speed), var(--count));
  box-shadow: 0 0 24px rgba(199, 255, 79, .35);
}
.brand p, .board-head p { margin: 0 0 3px; color: var(--muted); font-size: 11px; font-weight: 800; }
h1 { font-size: clamp(23px, 3vw, 38px); line-height: 1; font-weight: 900; }
h2 { font-size: 20px; font-weight: 900; }
h3 { font-size: 14px; font-weight: 900; }

.status-strip { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.chip {
  min-height: 26px; display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px; padding: 0 9px;
  color: var(--muted); background: rgba(255, 255, 255, .035);
  font-size: 11px; font-weight: 800; white-space: nowrap;
}
.chip.ok { border-color: rgba(199, 255, 79, .3); color: var(--speed); }
.chip.info { border-color: rgba(76, 221, 255, .3); color: var(--count); }
.chip.warn { border-color: rgba(255, 186, 74, .3); color: var(--warn); }
.chip.ng { border-color: rgba(255, 100, 124, .3); color: var(--danger); }

.layout {
  min-height: calc(100vh - 96px);
  display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 27vw);
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

/* ---- 左：カメラ ---- */
.vision { min-width: 0; display: flex; flex-direction: column; gap: 10px; }

/* 枠の大きさは app.js がカメラの縦横比に合わせて決める。
   映像を切り落とさず、カメラが写している範囲をすべて見せる */
.stage {
  position: relative; overflow: hidden; margin: 0 auto;
  width: 100%; aspect-ratio: 16 / 9;
  border: 1px solid rgba(199, 255, 79, .25); border-radius: var(--r);
  background: #020405;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .035), 0 24px 80px rgba(0, 0, 0, .52);
}
#camera, #view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#camera { object-fit: contain; background: #020405; }
#view { background: transparent; } /* 映像の上に軌跡だけを描く */
.stage.picking #view { cursor: crosshair; }

.scanline {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(199, 255, 79, .045) 1px, transparent 1px);
  background-size: 100% 20px, 48px 100%;
  mix-blend-mode: screen;
}
.corner { position: absolute; width: 48px; height: 48px; border-color: rgba(199, 255, 79, .72); pointer-events: none; }
.tl { top: 14px; left: 14px; border-top: 2px solid; border-left: 2px solid; }
.tr { top: 14px; right: 14px; border-top: 2px solid; border-right: 2px solid; }
.bl { bottom: 14px; left: 14px; border-bottom: 2px solid; border-left: 2px solid; }
.br { right: 14px; bottom: 14px; border-right: 2px solid; border-bottom: 2px solid; }

.stage-hint {
  position: absolute; inset: 0; margin: 0; display: flex;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  color: var(--muted); font-size: 18px; font-weight: 800; pointer-events: none;
}
.stage-hint.error { color: var(--danger); }
.stage-hint[hidden] { display: none; }

.stage-status {
  position: absolute; left: 16px; bottom: 16px;
  min-height: 34px; display: inline-flex; align-items: center; gap: 8px; padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, .16); border-radius: var(--r);
  background: rgba(3, 6, 7, .72); backdrop-filter: blur(14px);
  font-size: 13px; font-weight: 800;
}
.stage-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.stage-status i.live { background: var(--speed); box-shadow: 0 0 12px rgba(199, 255, 79, .7); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.toolbar { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; }

.telemetry { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.telemetry > div {
  min-height: 64px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: linear-gradient(180deg, rgba(255, 255, 255, .055), rgba(255, 255, 255, .025));
}
.telemetry span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }
.telemetry strong { font-size: 17px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* ---- 右：スコア ---- */
.board {
  min-width: 0; max-height: calc(100vh - 96px); overflow-y: auto;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--r);
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), transparent 24%), var(--surface);
}
.board-head { min-height: 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.name-panel {
  margin-bottom: 10px; padding: 11px;
  border: 1px solid rgba(76, 221, 255, .22); border-radius: var(--r);
  background: rgba(76, 221, 255, .055);
}
.name-panel label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 900; }
.name-panel input {
  width: 100%; min-height: 52px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: rgba(0, 0, 0, .4); color: var(--ink); font-size: 18px; font-weight: 800;
}

.score {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 15px; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r);
}
.score + .score { margin-top: 9px; }
.score > span { color: var(--muted); font-size: 13px; font-weight: 900; }
.score > div { display: flex; align-items: baseline; justify-content: flex-end; gap: 7px; }
.score strong { line-height: .82; font-weight: 900; font-variant-numeric: tabular-nums; }
.score small { color: var(--muted); font-size: 15px; font-weight: 800; }

.score.count { min-height: 118px; border-color: rgba(76, 221, 255, .25);
  background: linear-gradient(135deg, rgba(76, 221, 255, .13), transparent 58%), var(--surface-2); }
.score.count strong { color: var(--count); font-size: clamp(52px, 5.5vw, 88px); text-shadow: 0 0 32px rgba(76, 221, 255, .16); }

.score.now { min-height: 118px; }
.score.now strong { color: var(--ink); font-size: clamp(52px, 5.5vw, 88px); }

.score.best { min-height: 152px; border-color: rgba(199, 255, 79, .27);
  background: linear-gradient(135deg, rgba(199, 255, 79, .14), transparent 58%), var(--surface-2); }
.score.best strong { color: var(--speed); font-size: clamp(64px, 7vw, 112px); text-shadow: 0 0 32px rgba(199, 255, 79, .18); }

/* 記録が更新された瞬間だけ軽く光らせる（中央ポップアップはしない） */
.score.best.hit { animation: hit .6s ease-out; }
@keyframes hit {
  0% { box-shadow: 0 0 0 0 rgba(199, 255, 79, .5); }
  100% { box-shadow: 0 0 0 18px rgba(199, 255, 79, 0); }
}

.panel { margin-top: 10px; padding: 11px; border: 1px solid var(--line); border-radius: var(--r); background: rgba(255, 255, 255, .025); }
.panel-head { min-height: 28px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.history, .saved { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.history li, .saved li {
  min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px; color: var(--muted); background: rgba(255, 255, 255, .035);
  border-left: 3px solid var(--speed); font-size: 13px;
}
.history li.empty, .saved li.empty { border-left-color: var(--line); justify-content: flex-start; }
.history strong, .saved strong { color: var(--ink); font-weight: 900; font-variant-numeric: tabular-nums; }
.saved li { border-left-color: var(--count); flex-wrap: wrap; }
.saved .meta { min-width: 0; flex: 1; }
.saved .meta p { margin: 0; }
.saved .acts { display: flex; gap: 6px; }
.saved .acts button { min-height: 40px; padding: 0 10px; font-size: 12px; }

.swatches { display: flex; gap: 8px; }
.swatch { flex: 1; min-height: 52px; border: 2px solid rgba(255, 255, 255, .2); border-radius: var(--r); background: var(--c); }
.swatch:hover { background: var(--c); filter: brightness(1.08); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, .25); }

.field { margin-top: 9px; display: grid; grid-template-columns: 1fr auto; gap: 7px; color: var(--muted); font-size: 12px; }
.field span { color: var(--ink); font-weight: 800; }
.field input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--speed); }
.field.row { align-items: center; }
.field input[type="number"] {
  min-height: 52px; width: 110px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: rgba(0, 0, 0, .4); color: var(--ink); font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.note { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.select {
  width: 100%; min-height: 52px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: rgba(0, 0, 0, .4); color: var(--ink); font-weight: 800;
}
#fps.low { color: var(--warn); }
.select.narrow { width: auto; min-width: 170px; }

/* ---- お知らせ ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  margin: 0; padding: 12px 20px; z-index: 20;
  border: 1px solid rgba(199, 255, 79, .4); border-radius: var(--r);
  background: rgba(8, 14, 10, .95); color: var(--speed);
  font-weight: 900; box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
}
.toast[hidden] { display: none; }
.toast.ng { border-color: rgba(255, 100, 124, .5); color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .stage-status i.live, .score.best.hit { animation: none; }
}

/* ---- 2点マーカー方式で足した部品 ---- */
.sub {
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .02em;
}
.telemetry.compact { grid-template-columns: 1fr; margin-bottom: 10px; }
details { margin-top: 10px; }
details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  padding: 6px 0;
}
details[open] > summary { margin-bottom: 4px; }
