:root {
  --bg: #120a1e; --panel: rgba(26, 14, 40, 0.92); --panel2: rgba(48, 26, 70, 0.92); --line: rgba(200, 180, 255, 0.16);
  --ink: #f6f0ff; --muted: #c4b6dc; --ecto: #7cff6b; --candle: #ff9a3c; --pink: #ff5fa2; --red: #ff4d6d; --on-ecto: #08200a;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom); --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#touch { position: fixed; inset: 0; z-index: 5; display: none; touch-action: none; -webkit-touch-callout: none; }
body.playing #touch { display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: default; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; background: rgba(255, 255, 255, 0.05); }
body.touch .key-only, body:not(.touch) .touch-only { display: none; }
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg); z-index: 50; }
#loading b { font-size: 34px; letter-spacing: 6px; font-weight: 900; color: var(--ecto); }
#loading span { color: var(--muted); }

/* ------------------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
.h-pause { position: absolute; top: max(8px, var(--sat)); left: max(8px, var(--sal)); pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; z-index: 9; }
.h-song { position: absolute; top: max(8px, var(--sat)); left: calc(max(8px, var(--sal)) + 50px); max-width: 38vw; }
.h-song b { display: block; font-size: 13px; color: var(--candle); text-transform: uppercase; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-song span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-prog { height: 4px; background: rgba(255, 255, 255, 0.12); border-radius: 4px; margin-top: 4px; width: min(180px, 34vw); overflow: hidden; }
.h-prog u { display: block; height: 100%; width: 0; background: var(--candle); }
.h-score { position: absolute; top: max(8px, var(--sat)); right: max(10px, var(--sar)); text-align: right; }
.h-score b { font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6); }
.h-mult { display: inline-block; margin-left: 6px; font-weight: 900; font-size: 14px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); vertical-align: 4px; transition: transform 0.15s; }
.h-mult.m2 { background: var(--candle); color: #2a1200; } .h-mult.m3 { background: var(--pink); color: #2a0012; } .h-mult.m4 { background: var(--ecto); color: var(--on-ecto); transform: scale(1.1); }
.h-spirit { position: absolute; top: calc(max(8px, var(--sat)) + 36px); right: max(10px, var(--sar)); display: flex; align-items: center; gap: 6px; }
.h-spirit i { font-style: normal; font-size: 15px; }
.h-spirit .bar { width: min(150px, 30vw); height: 10px; border-radius: 6px; background: rgba(0, 0, 0, 0.5); border: 1px solid var(--line); overflow: hidden; }
.h-spirit u { display: block; height: 100%; width: 60%; background: var(--ecto); transition: width 0.15s, background 0.3s; }
.h-candy { position: absolute; top: calc(max(8px, var(--sat)) + 58px); right: max(10px, var(--sar)); font-weight: 900; font-size: 14px; }
.h-candy i { font-style: normal; margin-right: 4px; }
.coach { position: absolute; z-index: 2; left: 50%; transform: translateX(-50%); top: 38%; max-width: min(360px, 88vw); background: var(--panel); border: 1px solid var(--ecto); border-radius: 14px; padding: 10px 14px; text-align: center; font-weight: 800; font-size: 15px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); animation: pop 0.25s; }
.count { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: 72px; font-weight: 900; color: var(--ecto); text-shadow: 0 0 30px rgba(124, 255, 107, 0.6); }
@keyframes pop { from { transform: translateX(-50%) scale(0.85); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* ------------------------------------------------------------ screens */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; inset: 0; display: none; pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal));
  background: radial-gradient(ellipse at 50% 40%, rgba(18, 10, 30, 0.45), rgba(18, 10, 30, 0.9)); }
.screen.active { display: flex; }
.screen > * { margin: auto; }
#title.screen { background: linear-gradient(90deg, rgba(18, 10, 30, 0.94) 0%, rgba(18, 10, 30, 0.6) 48%, rgba(18, 10, 30, 0.08) 100%); gap: 24px; align-items: center; }
.t-main { max-width: 480px; width: 100%; margin: auto auto auto clamp(0px, 5vw, 80px); }
.kicker { color: var(--candle); letter-spacing: 1.5px; text-transform: uppercase; font-size: 12.5px; font-weight: 800; margin: 0; }
.logo { margin: 6px 0 10px; font-size: clamp(50px, 9vw, 96px); line-height: 0.86; font-weight: 900; letter-spacing: 2px; color: #f4f0ff;
  text-shadow: 0 0 24px rgba(180, 200, 255, 0.45), 0 4px 0 #3a2060; }
.logo span { color: var(--ecto); text-shadow: 0 0 26px rgba(124, 255, 107, 0.55), 0 4px 0 #1e4a1a; }
.lead { color: #e8def8; font-size: 15.5px; line-height: 1.5; margin: 0 0 16px; }
.challenge:empty { display: none; }
.challenge { background: rgba(124, 255, 107, 0.1); border: 1px solid rgba(124, 255, 107, 0.45); padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu .row { display: flex; gap: 8px; } .menu .row button { flex: 1; }
.menu button, .buttons button { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-size: 17px; font-weight: 800; text-align: left; transition: transform 0.1s, border-color 0.15s; }
.menu button:hover, .buttons button:hover { border-color: var(--ecto); }
.menu button:active, .buttons button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(90deg, #7cff6b, #3fd9a0) !important; color: var(--on-ecto) !important; border-color: transparent !important; }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--muted); }
.disclaimer { color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.45; } .disclaimer a { color: var(--muted); }
.t-side { width: 320px; max-width: 100%; margin: auto clamp(0px, 4vw, 60px) auto auto; display: flex; flex-direction: column; gap: 10px; }
.t-side > div:empty { display: none; }
.gg-board { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }

.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 20px; width: 100%; max-width: 760px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.sheet.wide { max-width: 980px; } .sheet.narrow { max-width: 400px; }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sheet h2 { margin: 0; font-size: 26px; font-weight: 900; }
.sheet h4 { margin: 14px 0 8px; font-size: 12.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--candle); }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 6px 0 0; }

/* map */
.diffs { display: flex; gap: 6px; margin-bottom: 12px; }
.diffs button { flex: 1; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-weight: 900; font-size: 15px; }
.diffs button.on { background: var(--ecto); color: var(--on-ecto); border-color: var(--ecto); }
.diffs button small { display: block; font-weight: 700; font-size: 11px; opacity: 0.8; }
.rooms { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.room { position: relative; text-align: left; border-radius: 14px; padding: 12px; min-height: 172px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px;
  background: linear-gradient(170deg, color-mix(in srgb, var(--c) 30%, #120a1e), #120a1e 80%); overflow: hidden; }
.room:not(:disabled):hover { border-color: var(--c); transform: translateY(-2px); }
.room .rn { font-size: 11px; font-weight: 900; letter-spacing: 1.3px; text-transform: uppercase; color: var(--c); }
.room b { font-size: 17px; line-height: 1.15; }
.room .inst { font-size: 13px; color: var(--muted); }
.room .bests { margin-top: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.room .bests span { font-size: 11.5px; font-weight: 900; padding: 2px 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); }
.room .bests span.g-S { background: var(--ecto); color: var(--on-ecto); } .room .bests span.g-A { background: var(--candle); color: #2a1200; }
.room:disabled { opacity: 1; }
.room:disabled > :not(.lock) { opacity: 0.32; filter: grayscale(0.6); }
.room .lock { margin-top: auto; display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 12.5px; color: var(--muted); line-height: 1.25; }
.room .lock i { font-style: normal; font-size: 18px; }
.room .ico { font-size: 26px; }
.wardrobe { margin-top: 14px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.wardrobe > span { font-size: 13px; color: var(--muted); margin-right: 4px; }
.wardrobe button { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font-weight: 800; font-size: 13px; }
.wardrobe button.on { border-color: var(--ecto); background: rgba(124, 255, 107, 0.14); }

/* results */
.res-top { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.grade { width: 108px; height: 108px; border-radius: 26px; display: flex; align-items: center; justify-content: center; font-size: 72px; font-weight: 900; background: var(--panel2); border: 2px solid var(--line); }
.grade.g-S { background: var(--ecto); color: var(--on-ecto); box-shadow: 0 0 40px rgba(124, 255, 107, 0.45); } .grade.g-A { background: var(--candle); color: #2a1200; } .grade.g-F { background: var(--red); color: #2a0010; }
.res-top h2 { margin: 0; font-size: 30px; font-weight: 900; } .res-top p { margin: 2px 0; color: var(--muted); }
.stars { color: var(--candle); font-size: 26px; letter-spacing: 3px; }
.near { color: var(--candle); font-size: 14px; margin: 4px 0 0; opacity: 0.9; }
.res-score { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; }
.res-score small { font-size: 13px; color: var(--ecto); margin-left: 8px; vertical-align: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stats div { background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 9px 10px; }
.stats small { display: block; color: var(--muted); font-size: 11.5px; } .stats b { font-size: 19px; }
.unlock { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(124, 255, 107, 0.1); border: 1px solid rgba(124, 255, 107, 0.4); font-weight: 800; }
.e-board:empty { display: none; } .e-board { margin: 12px 0 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.buttons button { flex: 1 1 140px; text-align: center; }

/* calibration and settings */
.cal-pad { height: 170px; border-radius: 16px; border: 2px dashed var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; touch-action: manipulation; user-select: none; -webkit-user-select: none; margin: 10px 0; }
.cal-dot { width: 54px; height: 54px; border-radius: 50%; background: var(--ecto); opacity: 0.25; transition: opacity 0.05s, transform 0.05s; }
.cal-dot.on { opacity: 1; transform: scale(1.15); }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.srow b { font-size: 15px; } .srow input[type=range] { flex: 1; max-width: 170px; accent-color: var(--ecto); } .srow span { min-width: 54px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; font-weight: 800; font-size: 13.5px; }
.chip.on { background: var(--ecto); color: var(--on-ecto); border-color: var(--ecto); }
.help { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.help h4 { margin-top: 4px; } .help p { font-size: 14.5px; line-height: 1.5; color: #e8def8; margin: 0 0 10px; }

/* ------------------------------------------------------------ phones */
@media (max-width: 860px) {
  .rooms { grid-template-columns: repeat(2, 1fr); } .rooms .room:last-child { grid-column: span 2; min-height: 120px; }
  .help { grid-template-columns: 1fr; gap: 4px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (orientation: landscape) and (max-height: 500px) {
  #title.screen { padding-top: max(10px, var(--sat)); padding-bottom: max(10px, var(--sab)); gap: 14px; }
  .logo { font-size: 46px; margin: 2px 0 6px; } .lead { font-size: 13.5px; margin-bottom: 10px; line-height: 1.4; }
  .menu button { padding: 8px 14px; font-size: 15px; } .menu { gap: 6px; } .disclaimer { margin-top: 8px; font-size: 11px; }
  .t-side { width: 270px; } .t-side .gg-board { max-height: 64vh; overflow: auto; }
  .rooms { grid-template-columns: repeat(5, 1fr); gap: 6px; } .rooms .room:last-child { grid-column: auto; }
  .room { min-height: 128px; padding: 8px; } .room b { font-size: 14px; } .room .ico { font-size: 20px; } .room .inst { font-size: 11.5px; }
  .sheet { padding: 12px 14px 14px; } .sheet h2 { font-size: 21px; } .sheet header { margin-bottom: 6px; }
  .diffs button { padding: 5px; font-size: 13.5px; } .diffs button small { display: none; } .diffs { margin-bottom: 8px; }
  .wardrobe { margin-top: 8px; } .wardrobe button { padding: 4px 10px; }
  .res-top { gap: 12px; } .grade { width: 76px; height: 76px; font-size: 50px; border-radius: 18px; } .res-top h2 { font-size: 22px; } .res-score { font-size: 28px; }
  .stats { grid-template-columns: repeat(4, 1fr); margin-top: 8px; } .stats div { padding: 5px 8px; } .stats b { font-size: 16px; }
  .buttons { margin-top: 8px; } .buttons button { padding: 8px 12px; font-size: 15px; }
  .help { grid-template-columns: repeat(3, 1fr); } .help p { font-size: 12.5px; }
  .cal-pad { height: 110px; }
  .res-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 12px; align-items: start; }
  .res-grid .stats { grid-template-columns: repeat(2, 1fr); margin-top: 0; gap: 5px; }
  .res-top { grid-template-columns: auto 1fr; } .res-top h2 { font-size: 18px; } .stars { font-size: 18px; } .res-score { font-size: 24px; }
  .unlock { margin-top: 8px; padding: 6px 10px; font-size: 13px; }
  .coach { left: max(10px, var(--sal)); transform: none; top: auto; bottom: 14%; max-width: 28vw; font-size: 12.5px; padding: 8px 10px; animation: none; }
  .h-score b { font-size: 20px; } .h-spirit { top: calc(max(6px, var(--sat)) + 30px); } .h-candy { top: calc(max(6px, var(--sat)) + 50px); }
}
@media (max-width: 640px) and (orientation: portrait) {
  #title.screen { flex-direction: column; align-items: stretch; background: linear-gradient(180deg, rgba(18, 10, 30, 0.35) 0%, rgba(18, 10, 30, 0.92) 42%); }
  .t-main { margin: 34vh 0 0; } .t-side { width: 100%; margin: 0; }
  .logo { font-size: 58px; }
  .sheet { padding: 14px; } .rooms .room { min-height: 140px; }
  .res-top { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .h-song { max-width: 40vw; } .h-spirit .bar { width: 26vw; }
}
@media (max-width: 380px) { .stats { grid-template-columns: repeat(2, 1fr); } .menu .row { flex-direction: column; } }
@media (orientation: landscape) and (min-height: 501px) { .coach { left: max(16px, var(--sal)); transform: none; top: auto; bottom: 18%; max-width: min(300px, 26vw); animation: none; } }
@media (min-width: 1600px) and (min-height: 900px) { #hud { zoom: 1.3; } }
