:root {
  --bg: #02030a;
  --text: #eef0ff;
  --muted: #8f96c8;
  --cyan: #4fe3ff;
  --pink: #ff4f8b;
  --gold: #ffd84a;
  --panel: rgba(8, 12, 32, 0.78);
  --line: rgba(79, 227, 255, 0.35);
  --pad-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --display: "Orbitron", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: system-ui, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

/* 3D表示。スマホのプレイ中は十字ボタンの分だけ上に詰める */
#stage { position: fixed; left: 0; top: 0; width: 100%; height: calc(100% - var(--pad-h)); display: block; }
body[data-device="touch"][data-screen="play"],
body[data-device="touch"][data-screen="pause"] { --pad-h: min(22vh, 170px); }

.screen { position: fixed; left: 0; right: 0; top: 0; bottom: var(--pad-h); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.screen.dim { background: rgba(2, 3, 10, 0.6); backdrop-filter: blur(4px); }

/* 操作の案内は、最後に使った機器のものだけ出す */
.kbd-only, .pad-only, .touch-only { display: none; }
body[data-device="key"] .kbd-only,
body[data-device="pad"] .pad-only,
body[data-device="touch"] .touch-only { display: inline; }

/* ---- タイトル ---- */
.logo {
  font-family: var(--display); font-weight: 800; font-size: clamp(26px, 12vw, 110px); letter-spacing: 0.02em; white-space: nowrap; line-height: 1;
  color: #fff; text-shadow: 0 0 18px var(--cyan), 0 0 42px rgba(79, 227, 255, 0.6);
}
.logo span { color: var(--pink); text-shadow: 0 0 18px var(--pink), 0 0 42px rgba(255, 79, 139, 0.6); }
.press { margin-top: 12vh; font-family: var(--display); font-size: clamp(18px, 5vw, 28px); letter-spacing: 0.3em; color: var(--gold); text-shadow: 0 0 12px rgba(255, 216, 74, 0.7); }
.blink { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.how { margin-top: 10px; font-size: 13px; color: var(--muted); }
#title { cursor: pointer; }

/* ---- 共通のメニュー ---- */
.menu { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 6px; min-height: 52px; padding: 0 10px;
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 10px;
  transition: transform 0.08s, border-color 0.08s, background 0.08s;
}
.item .k { flex: 0 0 34%; color: var(--muted); font-size: 14px; }
.item .k.wide { flex: 1; text-align: center; color: var(--text); font-size: 17px; font-weight: 700; letter-spacing: 0.08em; }
.item .v { flex: 1; text-align: center; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .arrow { width: 44px; height: 44px; border-radius: 8px; color: var(--cyan); font-size: 16px; }
.item .arrow:active { background: rgba(79, 227, 255, 0.2); }
.item.action { cursor: pointer; justify-content: center; }
.item.primary .k.wide { font-family: var(--display); color: var(--gold); letter-spacing: 0.25em; font-size: 20px; }
.item.focus {
  border-color: var(--cyan); background: rgba(20, 50, 90, 0.85);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(79, 227, 255, 0.35); transform: scale(1.02);
}
.item.focus .k { color: #fff; }

/* ---- 曲選び（スクロールしない。上：筒の枠／下：選択肢） ---- */
#select {
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: 100%;
  align-items: stretch; justify-content: stretch; gap: 0; padding: 0;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.sel-head { text-align: center; padding: 10px 56px 0; }
.bar-title { font-family: var(--display); font-size: clamp(14px, 2.6vh, 20px); letter-spacing: 0.2em; color: var(--cyan); text-shadow: 0 0 10px rgba(79, 227, 255, 0.6); }
.song-no { margin-top: 2px; font-family: var(--display); font-size: clamp(11px, 1.7vh, 14px); letter-spacing: 0.12em; color: var(--muted); font-variant-numeric: tabular-nums; }
.song-name { margin-top: 4px; font-size: clamp(16px, 3vh, 24px); font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 2px 8px #000; }
.sel-stage { position: relative; min-height: 0; }
/* スマホ縦持ちは筒が上下にはみ出すので、文字の後ろを暗くして読めるようにする */
.sel-head { position: relative; z-index: 1; padding-bottom: 8px; background: linear-gradient(180deg, rgba(5, 6, 13, 0.92) 70%, rgba(5, 6, 13, 0)); }
@media (orientation: portrait) {
  .sel-panel { position: relative; z-index: 1; padding-top: 14px; background: linear-gradient(0deg, rgba(5, 6, 13, 0.94) 88%, rgba(5, 6, 13, 0)); width: 100%; }
}
body[data-device="touch"] .sel-touch-hint { display: block; margin-top: 2px; font-size: clamp(11px, 1.6vh, 13px); color: var(--muted); }
.sel-stage.focus { box-shadow: inset 0 0 0 2px rgba(79, 227, 255, 0.5); border-radius: 12px; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 1;
  width: clamp(40px, 7vh, 56px); height: clamp(56px, 11vh, 84px); border-radius: 12px;
  font-size: 20px; color: var(--cyan); background: rgba(8, 12, 32, 0.7); border: 1px solid var(--line);
}
.nav:active { background: rgba(79, 227, 255, 0.3); }
/* 左右ボタンは、下の選択ボタン群（幅560px・内側12px）の端と同じ縦の線にそろえる */
.nav.prev { left: max(8px, calc((100% - 560px) / 2 + 12px)); } .nav.next { right: max(8px, calc((100% - 560px) / 2 + 12px)); }

.sel-panel {
  width: min(560px, 100%); justify-self: center; padding: 6px 12px 10px;
  display: flex; flex-direction: column; gap: clamp(4px, 0.9vh, 8px);
}
.row { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 12px; border: 1px solid transparent; }
.row.focus { border-color: var(--cyan); background: rgba(20, 50, 90, 0.5); box-shadow: 0 0 14px rgba(79, 227, 255, 0.25); }
.row .k { flex: 0 0 5.2em; font-size: clamp(11px, 1.7vh, 14px); color: var(--muted); }
.chips { flex: 1; display: flex; gap: 6px; align-items: center; min-width: 0; }
.chip {
  flex: 1; min-width: 0; height: clamp(34px, 5.6vh, 48px); border-radius: 10px;
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: clamp(12px, 1.9vh, 16px); font-weight: 700; white-space: nowrap; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.chip small { font-size: 0.68em; font-weight: 400; color: var(--muted); }
.chip.on { background: linear-gradient(180deg, rgba(79, 227, 255, 0.35), rgba(20, 60, 120, 0.9)); border-color: var(--cyan); color: #fff; box-shadow: 0 0 10px rgba(79, 227, 255, 0.4); }
.chip.on small { color: #d8f6ff; }
.chip-value { flex: 1.2; text-align: center; font-weight: 700; font-size: clamp(13px, 2vh, 17px); font-variant-numeric: tabular-nums; }
.add-row .chip.add { flex: 0 0 auto; padding: 0 14px; }
.add-note { flex: 1; min-width: 0; margin: 0; font-size: clamp(10px, 1.5vh, 12px); line-height: 1.35; color: var(--muted); }
/* キー・パッドで選んでいるボタン（割り当ての行など） */
.chip.sel { outline: 3px solid #fff; outline-offset: 2px; background: rgba(79, 227, 255, 0.28); box-shadow: 0 0 14px rgba(255, 255, 255, 0.45); }
.row-help { margin: 2px 0 0; text-align: center; font-size: clamp(11px, 1.7vh, 14px); color: #cfe9ff; }
.row-help b { display: inline-block; padding: 0 6px; margin: 0 2px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel); color: #fff; }
.row-help.wait { color: var(--gold); }
body[data-device="touch"] .row-help { display: none; }
.note { margin: 0; min-height: 1.2em; text-align: center; font-size: 12px; color: var(--muted); }

/* キー・パッドでは、設定（選択肢）は X で開いたときだけ出す。スマホは常に全部出す */
.sel-hint { display: none; grid-column: 1 / -1; text-align: center; padding: 10px 12px 18px; font-size: clamp(13px, 2.2vh, 17px); color: var(--muted); letter-spacing: 0.06em; }
.sel-hint b { display: inline-block; min-width: 1.8em; padding: 2px 8px; margin: 0 4px; border-radius: 6px; border: 1px solid var(--line); color: #fff; background: var(--panel); }
body:not([data-device="touch"]) #select:not(.open) .sel-panel { display: none; }
body:not([data-device="touch"]) #select:not(.open) .sel-hint { display: block; }
body:not([data-device="touch"]) #select:not(.open) { grid-template-columns: 100%; grid-template-rows: auto minmax(0, 1fr) auto; }

/* 背の低い横長画面（スマホ横持ちなど）は、筒を左・選択肢を右に並べる */
@media (orientation: landscape) and (max-height: 560px) {
  #select { grid-template-columns: minmax(0, 1fr) min(430px, 52vw); grid-template-rows: auto minmax(0, 1fr); }
  .sel-head { grid-column: 1; grid-row: 1; }
  .sel-stage { grid-column: 1; grid-row: 2; }
  .sel-panel { grid-column: 2; grid-row: 1 / 3; align-self: stretch; justify-content: center; position: relative; z-index: 1; background: linear-gradient(90deg, rgba(5, 6, 13, 0), rgba(5, 6, 13, 0.94) 14px); }
  .chip { height: clamp(30px, 9vh, 44px); }
  .nav.prev { left: 8px; } .nav.next { right: 8px; }
}

/* ---- 読み込み中 ---- */
.spinner { width: 64px; height: 64px; border-radius: 50%; border: 4px solid rgba(79, 227, 255, 0.2); border-top-color: var(--cyan); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 18px; font-family: var(--display); letter-spacing: 0.35em; color: var(--cyan); }

/* ---- プレイ中 ---- */
#hud { pointer-events: none; justify-content: flex-start; padding: 0; }
.progress { width: 100%; height: 4px; background: rgba(255, 255, 255, 0.08); }
#progressBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--pink)); box-shadow: 0 0 8px var(--cyan); }
.hud-top { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.hud-song { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-score { text-align: right; font-family: var(--display); line-height: 1; }
.hud-score small { display: block; font-size: 9px; letter-spacing: 0.3em; color: var(--muted); }
.life { display: flex; align-items: center; gap: 8px; width: min(420px, calc(100% - 24px)); margin: 0 auto; }
.life small { font-family: var(--display); font-size: 10px; letter-spacing: 0.25em; color: var(--muted); }
.life-bar { flex: 1; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); overflow: hidden; }
#lifeBar { height: 100%; width: 100%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); transition: width 0.2s ease-out, background-color 0.4s; }
#lifeBar.mid { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
#lifeBar.low { background: #ff6b6b; box-shadow: 0 0 8px #ff6b6b; }
/* ゲームオーバー: 画面をゆっくり暗く赤くし、文字を浮かび上がらせる（点滅はしない） */
#stage { transition: filter 1.4s ease-out; }
body.failing #stage { filter: saturate(0.35) brightness(0.55) sepia(0.4) hue-rotate(-40deg); }
#gameover {
  position: absolute; left: 0; right: 0; top: 42%; transform: translateY(-50%); text-align: center; opacity: 0; pointer-events: none;
  font-family: var(--display); font-weight: 800; font-size: clamp(36px, 10vw, 72px); letter-spacing: 0.12em; color: #ff6b6b; text-shadow: 0 0 24px rgba(255, 107, 107, 0.8);
}
body.failing #gameover { animation: gameover 2.8s ease-out forwards; }
@keyframes gameover { 0% { opacity: 0; transform: translateY(-50%) scale(1.3); letter-spacing: 0.4em; } 30% { opacity: 1; transform: translateY(-50%) scale(1); letter-spacing: 0.12em; } 85% { opacity: 1; } 100% { opacity: 0; } }
.hud-score span { font-size: 22px; font-variant-numeric: tabular-nums; text-shadow: 0 0 10px rgba(79, 227, 255, 0.6); }
.icon-btn { pointer-events: auto; width: 40px; height: 40px; border-radius: 10px; background: rgba(8, 12, 32, 0.6); border: 1px solid rgba(255,255,255,0.15); color: #fff; font-size: 14px; }
#ready { position: absolute; left: 0; right: 0; top: 42%; text-align: center; font-family: var(--display); font-size: 34px; letter-spacing: 0.3em; color: #fff; text-shadow: 0 0 16px var(--cyan); }
#judge {
  position: absolute; left: 0; right: 0; top: 76%; transform: translateY(-50%); text-align: center;
  font-family: var(--display); font-size: clamp(26px, 7vw, 40px); font-weight: 800; letter-spacing: 0.08em; text-shadow: 0 0 16px currentColor; opacity: 0;
}
#judge.pop { animation: pop 0.6s ease-out; }
@keyframes pop { 0% { opacity: 1; transform: translateY(-50%) scale(1.12); } 30% { opacity: 1; transform: translateY(-50%) scale(1); } 100% { opacity: 0; transform: translateY(-70%) scale(1); } }
#combo { position: absolute; left: 0; right: 0; top: calc(76% + 26px); text-align: center; font-family: var(--display); font-size: 15px; font-weight: 800; color: #fff; letter-spacing: 0.1em; }

/* ---- 一時停止・結果 ---- */
.dialog { width: min(420px, 100%); padding: 22px 18px; background: rgba(8, 12, 32, 0.92); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 0 40px rgba(79, 227, 255, 0.15); max-height: 100%; overflow-y: auto; }
.dialog-title { text-align: center; margin-bottom: 14px; font-family: var(--display); font-size: 22px; letter-spacing: 0.35em; color: var(--cyan); }
.rank { text-align: center; font-family: var(--display); font-weight: 800; font-size: 88px; line-height: 1; color: var(--gold); text-shadow: 0 0 24px rgba(255, 216, 74, 0.8); }
.final-score { text-align: center; margin: 6px 0 14px; font-family: var(--display); font-size: 30px; font-variant-numeric: tabular-nums; }
.stats { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 15px; }
.stats td { padding: 3px 2px; }
.stats td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.stats .p { color: var(--gold); } .stats .g { color: var(--cyan); } .stats .o { color: #9dff8a; } .stats .m { color: #ff6b6b; }

/* ---- 画面下のスライダー ---- */
#slider {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--pad-h);
  padding: 12px 10px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, rgba(2,3,10,0.2), rgba(10, 14, 36, 0.95) 20%);
  border-top: 1px solid var(--line);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#slider .track { position: relative; height: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
#slider i { border-radius: 14px; background: linear-gradient(180deg, rgba(var(--lc), 0.22), rgba(20, 30, 70, 0.85)); border: 1px solid rgba(var(--lc), 0.45); }
#slider .k0, .chip.key.k0 { --lc: 255, 107, 213; }
#slider .k1, .chip.key.k1 { --lc: 255, 216, 74; }
#slider .k2, #slider .k4, .chip.key.k2, .chip.key.k4 { --lc: 79, 227, 255; }
#slider .k3, .chip.key.k3 { --lc: 157, 255, 138; }
#slider i.off { opacity: 0.25; } /* その曲で使わないボタン */
#slider .track b {
  position: absolute; top: 0; bottom: 0; width: 18%; transform: translateX(-50%); border-radius: 16px; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.55), rgba(79, 227, 255, 0.15) 70%); box-shadow: 0 0 24px rgba(79, 227, 255, 0.7);
}
.chip.key:not(.reset) { border-color: rgba(var(--lc), 0.55); }

.corner { position: fixed; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 5; }
body[data-screen="play"] .corner, body[data-screen="pause"] .corner { display: none; }
/* 曲選びでは右下が START なので、右上へ */
body[data-screen="select"] .corner { bottom: auto; top: calc(10px + env(safe-area-inset-top)); }
/* 横持ちの低い画面の曲選びでは、右上が選択肢なので左下へ */
@media (orientation: landscape) and (max-height: 560px) {
  body[data-screen="select"] .corner { top: auto; right: auto; left: 12px; bottom: calc(10px + var(--safe-b)); }
}
