/* 色はすべて :root の変数。JS 側の色は src/config.js の colors */
:root {
  --bg: #cfe6f7;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.95);
  --ink: #1b2a3a;
  --ink-soft: #4a5b6e;
  --accent: #e8452c;
  --accent-ink: #ffffff;
  --good: #2fb344;
  --bad: #d62828;
  --star: #f5a700;
  --meter-bg: rgba(27, 42, 58, 0.18);
  --meter-fill: #2a6fd6;
  --meter-lean: #e8452c;
  --shade: rgba(14, 28, 46, 0.55);
  --speed-line: rgba(255, 255, 255, 0.4);
  --shade-strong: rgba(14, 28, 46, 0.78);
  --text-shadow: rgba(255, 255, 255, 0.9);
  --focus: #2a6fd6;
  --font: "Yu Gothic UI", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); font-family: var(--font); color: var(--ink); }
#app { position: fixed; inset: 0; }
#app canvas { display: block; width: 100%; height: 100%; }

.hud { position: absolute; inset: 0; pointer-events: none; user-select: none; }
.hud > * { position: absolute; }
.hud:not(.live) .speed, .hud:not(.live) .progress, .hud:not(.live) .meters, .hud:not(.live) .level-tag { display: none; }
.panel {
  background: var(--panel); border-radius: 14px; padding: 8px 16px;
  box-shadow: 0 2px 10px rgba(14, 28, 46, 0.18);
}

.speed { left: 18px; top: 16px; display: flex; align-items: baseline; gap: 6px; }
.speed b { font-size: 46px; line-height: 1; font-variant-numeric: tabular-nums; min-width: 2.1ch; text-align: right; }
.speed span { font-size: 18px; color: var(--ink-soft); }
.mode-note { font-size: 14px; color: var(--accent); font-weight: 700; margin-left: 6px; }

.progress { left: 50%; top: 16px; transform: translateX(-50%); width: min(44vw, 520px); text-align: center; }
.progress .row { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; }
.progress .stars { color: var(--star); font-size: 24px; }
.bar { height: 10px; border-radius: 6px; background: var(--meter-bg); overflow: hidden; margin-top: 6px; position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--meter-fill); width: 0; }
.bar.lean > i { background: var(--meter-lean); }
.bar.lean::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: 0.5; }

.meters { left: 18px; bottom: 18px; width: 230px; display: grid; gap: 4px; }
.meters label { font-size: 14px; color: var(--ink-soft); display: block; }

.level-tag { right: 18px; top: 16px; font-size: 15px; font-weight: 700; color: var(--ink-soft); }
.pose-wipe {
  display: none; right: 18px; top: 44px; width: 220px; height: 280px; border: 3px solid var(--panel-strong);
  border-radius: 14px; overflow: hidden; color: var(--ink); font-size: 14px; font-weight: 700;
}
.pose-wipe.show { display: block; }
.pose-wipe-band { position: absolute; right: 0; bottom: 0; left: 0; padding: 5px 9px; background: var(--panel); display: flex; justify-content: space-between; }

.toast {
  left: 50%; top: 26%; transform: translate(-50%, -50%); font-size: 46px; font-weight: 900;
  color: var(--ink); text-shadow: 0 0 10px var(--text-shadow), 0 0 4px var(--text-shadow);
  opacity: 0; transition: opacity 0.18s; white-space: nowrap;
}
.toast.show { opacity: 1; }
.toast.good { color: var(--good); }
.toast.bad { color: var(--bad); }

.stopcount {
  left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: 190px; font-weight: 900; line-height: 1;
  color: var(--bad); text-shadow: 0 0 18px var(--text-shadow), 0 0 6px var(--text-shadow); opacity: 0;
}
.stopcount.show { opacity: 1; }
.stopcount.go { color: var(--good); }

.overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column;
  gap: 14px; background: var(--shade); color: var(--accent-ink); text-align: center; padding: 24px;
}
.overlay.show { display: flex; }
.overlay h1 { font-size: clamp(40px, 8vw, 78px); margin: 0; letter-spacing: 0.06em; text-shadow: 0 3px 16px rgba(0, 0, 0, 0.4); }
.overlay h2 { font-size: clamp(30px, 5vw, 52px); margin: 0; }
.overlay p { margin: 0; font-size: clamp(16px, 2.2vw, 22px); }
.overlay .hint { font-size: 18px; opacity: 0.92; }
.overlay.light { background: var(--shade); }
.count-big { font-size: 150px; font-weight: 900; line-height: 1; text-shadow: 0 4px 22px rgba(0, 0, 0, 0.5); }

.menu { display: grid; gap: 10px; min-width: min(420px, 90vw); }
.menu .item {
  background: var(--panel-strong); color: var(--ink); border-radius: 12px; padding: 12px 18px; font-size: 22px;
  font-weight: 700; display: flex; justify-content: space-between; gap: 18px; pointer-events: auto; cursor: pointer;
  border: 3px solid transparent;
}
.menu .item.sel { border-color: var(--focus); background: var(--accent-ink); }
.menu .item .val { color: var(--accent); }
/* せっていの10行が iPad 横（768px）でも収まるよう、背の低い画面では詰める */
@media (max-height: 860px) {
  .overlay { gap: 8px; padding-top: 12px; padding-bottom: 12px; }
  .overlay h2 { font-size: clamp(26px, 4vw, 40px); }
  .menu { gap: 6px; }
  .menu .item { padding: 7px 16px; font-size: 19px; }
}

/* タイトル・せってい: 左に文字、右に人物が見えるよう左寄せ＋左から濃い帯 */
.overlay.side {
  align-items: flex-start; text-align: left; padding-left: 7vw; padding-right: 45vw;
  background: linear-gradient(90deg, var(--shade-strong) 0%, var(--shade-strong) 40%, transparent 78%);
}
.overlay.side .btns { justify-content: flex-start; }

.help {
  background: var(--panel); color: var(--ink); border-radius: 14px; padding: 10px 20px; font-size: 18px;
  text-align: left; display: grid; grid-template-columns: max-content 1fr; column-gap: 18px; row-gap: 4px;
}
.help div { display: contents; }
.help kbd { font-weight: 800; color: var(--accent); white-space: nowrap; }

.result-card { background: var(--panel-strong); color: var(--ink); border-radius: 18px; padding: 18px 34px; display: grid; gap: 6px; font-size: 24px; min-width: min(420px, 90vw); }
.result-card .big { font-size: 54px; font-weight: 900; color: var(--accent); }
.result-card .stars-line { font-size: 44px; color: var(--star); letter-spacing: 0.1em; }
.star-off { opacity: 0.45; }
.star-pop { display: inline-block; opacity: 0; animation: starPop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) forwards; }
@keyframes starPop { 0% { opacity: 0; transform: scale(0.1) rotate(-60deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
.progress .stars.pop { display: inline-block; animation: countPop 0.45s ease-out; }
@keyframes countPop { 0% { transform: scale(1); } 35% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* スピード線: 画面の端だけ、中心へ向かう細い線 */
.speedlines {
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 50% 52%, transparent 0deg 5deg, var(--speed-line) 5.4deg 5.9deg, transparent 6.3deg 11deg);
  -webkit-mask-image: radial-gradient(ellipse at 50% 52%, transparent 52%, #000 92%);
  mask-image: radial-gradient(ellipse at 50% 52%, transparent 52%, #000 92%);
}
.result-card .new { color: var(--good); font-weight: 800; }

.btn {
  pointer-events: auto; border: 0; border-radius: 14px; padding: 12px 22px; font: inherit; font-size: 20px; font-weight: 800;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
.btn.sub { background: var(--panel-strong); color: var(--ink); }
.btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.touch { right: 14px; bottom: 14px; display: none; gap: 10px; pointer-events: none; }
.touch.on { display: flex; }
.touch .pad {
  pointer-events: auto; width: 72px; height: 72px; border-radius: 18px; background: var(--panel); color: var(--ink);
  border: 3px solid var(--ink-soft); font-size: 28px; font-weight: 900; display: flex; flex-direction: column;
  align-items: center; justify-content: center; touch-action: none; user-select: none;
}
.touch .pad small { font-size: 11px; font-weight: 700; }
.touch .pad.down { background: var(--accent); color: var(--accent-ink); }
.touch .pause-pad { position: fixed; top: 14px; right: 14px; display: none; font-size: 15px; }
.touch.playing .pause-pad { display: flex; }

.webgl-error {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 16px; padding: 24px;
  text-align: center; background: var(--shade); color: var(--accent-ink); font-size: 20px;
}

.debug-tag { left: 50%; bottom: 8px; transform: translateX(-50%); font-size: 12px; color: var(--ink-soft); }

@media (max-width: 720px) {
  .progress { width: 46vw; padding: 6px 10px; }
  .speed b { font-size: 34px; }
  .meters { width: 170px; bottom: 100px; }
  .toast { font-size: 32px; }
  .stopcount { font-size: 120px; }
  .pose-wipe { width: 150px; height: 190px; }
}
@media (hover: none) and (pointer: coarse) { .touch { display: flex; } }
