/* Key Cascade — styles
   Layout note: .stage is a size container so overlay chrome scales against the
   playfield, not the viewport. Its height comes from the app grid, never from
   its contents (container-type: size implies contain: size). */

:root {
  --bg:        #080a15;
  --bg-2:      #0e1226;
  --panel:     #141936;
  --panel-2:   #1b2145;
  --line:      #2a3160;
  --text:      #e8ebff;
  --muted:     #9aa2d0;
  --accent:    #7c6cff;
  --accent-2:  #3fd0ff;
  --good:      #58e08a;
  --warn:      #ffc75a;
  --bad:       #ff6b8a;
  --radius:    14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -15%, #1d2350 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 55%);
  color: var(--text);
  font: 400 15px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 10px clamp(10px, 2vw, 22px) max(10px, env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 26px);
  min-height: 46px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(124, 108, 255, .55);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 6px 5px;
  background:
    linear-gradient(90deg,
      #0b0d1a 0 2px, transparent 2px 5px,
      #0b0d1a 5px 7px, transparent 7px 10px,
      #0b0d1a 10px 12px, transparent 12px);
  opacity: .8;
}

.brand-text {
  font-weight: 700;
  letter-spacing: .04em;
  font-size: 15px;
  white-space: nowrap;
}

.hud {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, auto)) 1fr;
  grid-template-areas: "score combo acc bar" "score combo acc song";
  align-items: center;
  gap: 2px clamp(12px, 2.4vw, 30px);
  min-width: 0;
}
.hud .stat:nth-of-type(1) { grid-area: score; }
.hud .stat:nth-of-type(2) { grid-area: combo; }
.hud .stat:nth-of-type(3) { grid-area: acc; }
.hud .progress           { grid-area: bar; align-self: end; }
.hud .now-playing        { grid-area: song; align-self: start; }

.stat { display: flex; align-items: baseline; gap: 7px; }
.stat-label {
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(15px, 2.2vw, 20px);
}
.stat-mult {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  opacity: 0;
  transition: opacity .15s;
}
.stat-mult.on { opacity: 1; }

.progress {
  height: 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .09);
  overflow: hidden;
  min-width: 60px;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .12s linear;
}

.now-playing {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.controls { display: flex; gap: 6px; flex: 0 0 auto; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); border-color: #3b4488; }
.icon-btn:active { transform: translateY(1px); }
.icon-btn[aria-pressed="true"] { color: var(--muted); }

/* ------------------------------------------------------------------ stage */

.stage {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0d1c;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .04);
  container-type: size;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(8px, 3cqh, 26px);
  background: rgba(6, 8, 18, .78);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  z-index: 2;
}

.panel {
  width: min(680px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2cqh, 16px);
  padding: clamp(14px, 3.4cqh, 26px) clamp(16px, 3cqw, 30px);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}
.panel.narrow { width: min(360px, 100%); text-align: center; }

.panel h2 {
  margin: 0;
  font-size: clamp(17px, 4cqh, 24px);
  letter-spacing: .01em;
}

.songlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  overflow: auto;
  max-height: 52cqh;
  min-height: 0;
}

.song {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
  width: 100%;
  text-align: left;
  padding: clamp(7px, 1.6cqh, 12px) 14px;
  color: var(--text);
  font: inherit;
  background: rgba(255, 255, 255, .04);
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  transition: background .13s, border-color .13s;
}
.song:hover { background: rgba(255, 255, 255, .09); }
.song[aria-selected="true"] {
  background: rgba(124, 108, 255, .22);
  border-color: var(--accent);
}
.song-main { min-width: 0; }
.song-title { display: block; font-weight: 600; font-size: clamp(13px, 2.4cqh, 15px); }
.song-sub { display: block; font-size: 11px; color: var(--muted); }
.song-meta { display: grid; justify-items: end; gap: 2px; }
.song-best {
  font-size: 11px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.song-best:empty { display: none; }
.stars { letter-spacing: 2px; font-size: 11px; color: var(--warn); white-space: nowrap; }

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}
.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.opt select,
.opt input[type="range"] {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  accent-color: var(--accent);
}
.opt input[type="range"] { width: 110px; padding: 0; }

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.btn {
  flex: 1 1 auto;
  padding: clamp(9px, 2cqh, 13px) 18px;
  font: 600 14px/1 inherit;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: background .14s, transform .08s, box-shadow .14s;
}
.btn:hover { background: rgba(255, 255, 255, .15); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #5b7cff);
  border-color: transparent;
  box-shadow: 0 8px 26px rgba(124, 108, 255, .38);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, .07); }

.panel-note { margin: 0; font-size: 11.5px; color: var(--muted); }

.results-head { display: flex; align-items: center; gap: 18px; }
.grade {
  width: clamp(58px, 13cqh, 84px);
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-size: clamp(30px, 8cqh, 46px);
  font-weight: 800;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #08091a;
  box-shadow: 0 10px 34px rgba(63, 208, 255, .3);
}
.grade[data-grade="D"], .grade[data-grade="F"] {
  background: linear-gradient(135deg, #6b7099, #444a72);
  color: #e8ebff;
  box-shadow: none;
}
.results-meta { min-width: 0; }
.res-song { font-size: 13px; color: var(--muted); }
.res-score { font-size: clamp(24px, 6cqh, 34px); font-weight: 800; font-variant-numeric: tabular-nums; }
.res-best { font-size: 12px; color: var(--warn); font-weight: 600; }

.breakdown {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 7px;
}
.breakdown li {
  padding: 8px 10px;
  background: rgba(255, 255, 255, .05);
  border-radius: 10px;
  text-align: center;
}
.breakdown .bk-label { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.breakdown .bk-value { display: block; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ hints */

.hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
}
.hint-sep { opacity: .5; }
kbd {
  display: inline-block;
  min-width: 17px;
  padding: 1px 4px;
  margin: 0 1px;
  font: 600 10px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-align: center;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

.rotate-hint { display: none; }

/* ------------------------------------------------------------ small/phone */

@media (max-width: 760px) {
  /* Give the HUD a row of its own rather than squeezing it between the brand
     and the buttons. Phone landscape is wider than this, so the playfield
     keeps the single-row bar where it matters. */
  .topbar { flex-wrap: wrap; row-gap: 8px; column-gap: 10px; }
  .brand { order: 1; }
  .controls { order: 2; margin-left: auto; }
  .hud {
    order: 3;
    flex: 1 0 100%;
    grid-template-areas: "score combo acc bar";
    gap: 0 14px;
  }
  .hud .now-playing { display: none; }
  .hud .progress { align-self: center; }
  .brand-text { display: none; }
  .hints { display: none; }
}

@media (max-width: 430px) {
  .stat-label { font-size: 9px; letter-spacing: .06em; }
  .stat-value { font-size: 15px; }
}

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-hint {
    display: block;
    position: absolute;
    left: 50%;
    top: 10px;
    transform: translateX(-50%);
    margin: 0;
    padding: 5px 12px;
    font-size: 11px;
    color: var(--muted);
    background: rgba(8, 10, 21, .8);
    border: 1px solid var(--line);
    border-radius: 999px;
    pointer-events: none;
    z-index: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}

[hidden] { display: none !important; }
