:root {
  --bg: #0b0d17;
  --bg2: #141829;
  --lane-a: #10131f;
  --lane-b: #0d1019;
  --line: rgba(255,255,255,0.08);
  --tile: #1b1f33;
  --tile-edge: #2b3150;
  --accent: #4f8cff;
  --accent2: #7c5cff;
  --hold: #ff5c8a;
  --hold2: #ffb35c;
  --good: #ffd34f;
  --perfect: #4fffa8;
  --miss: #ff5b5b;
  --text: #eef1ff;
  --muted: #8a90b0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

/* ---- Portrait game frame: keep a phone-like column even on desktop ---- */
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* =================== HOME =================== */
#screen-home {
  background: radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg));
  overflow-y: auto;
}
.home-inner {
  max-width: 480px; margin: 0 auto; min-height: 100%;
  padding: max(6vh, 32px) 24px 40px;
  display: flex; flex-direction: column; align-items: center;
}
.logo {
  font-size: clamp(40px, 12vw, 68px); font-weight: 900; letter-spacing: 2px;
  margin: 12px 0 4px; line-height: 0.95; text-align: center;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo span { color: var(--hold); -webkit-text-fill-color: var(--hold); display: block; }
.tagline { color: var(--muted); margin: 0 0 28px; text-align: center; }

.song-list { list-style: none; padding: 0; margin: 0; width: 100%; display: grid; gap: 12px; }
.song-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, var(--bg2), #10131f);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; cursor: pointer; transition: transform .1s, border-color .2s;
}
.song-card:active { transform: scale(0.98); }
.song-card:hover { border-color: var(--accent); }
.song-card .art {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, var(--accent2), var(--hold));
  display: grid; place-items: center; font-size: 22px;
}
.song-card .meta { flex: 1; min-width: 0; }
.song-card .title { font-weight: 700; font-size: 17px; }
.song-card .sub { color: var(--muted); font-size: 13px; }
.song-card .go { color: var(--accent); font-weight: 800; font-size: 20px; }

.home-actions { margin-top: 28px; width: 100%; display: flex; justify-content: center; }

.btn {
  appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 700;
  color: #fff; background: linear-gradient(120deg, var(--accent), var(--accent2));
  padding: 14px 26px; border-radius: 14px; font-size: 16px; transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(0.97); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn[disabled], .btn-ghost[disabled] { opacity: .45; cursor: not-allowed; }

/* =================== PLAY =================== */
#screen-play { background: #000; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: max(14px, env(safe-area-inset-top)) 18px 10px;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 5;
}
.hud-score { font-size: 34px; font-weight: 900; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.hud-combo { font-size: 15px; color: var(--accent); font-weight: 800; height: 18px; }
.btn-icon {
  pointer-events: auto; appearance: none; border: none; cursor: pointer;
  background: rgba(255,255,255,0.08); color: #fff; width: 44px; height: 44px;
  border-radius: 12px; font-size: 14px; letter-spacing: -2px;
}

.judgement {
  position: absolute; top: 40%; left: 0; right: 0; text-align: center;
  font-size: 30px; font-weight: 900; pointer-events: none; opacity: 0; z-index: 4;
  text-shadow: 0 2px 12px rgba(0,0,0,.7);
}
.judgement.show { animation: pop .45s ease-out; }
@keyframes pop { 0%{opacity:0; transform: translateY(10px) scale(.8);} 25%{opacity:1; transform: translateY(0) scale(1.1);} 100%{opacity:0; transform: translateY(-6px) scale(1);} }

/* =================== OVERLAYS =================== */
.overlay {
  position: absolute; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(5,6,12,0.78); backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
#countdown { background: rgba(5,6,12,0.5); }
#countdown span { font-size: 120px; font-weight: 900; color: #fff; text-shadow: 0 4px 30px rgba(0,0,0,.8); }
.panel { text-align: center; display: grid; gap: 14px; padding: 30px; }
.panel h2 { margin: 0 0 8px; font-size: 30px; }

/* upload modal */
.upload-panel { width: min(92vw, 380px); max-height: 92vh; overflow-y: auto; gap: 10px; }
.upload-hint { color: var(--muted); font-size: 14px; margin: 0 0 4px; }
.upload-filename { color: var(--accent); font-size: 13px; min-height: 16px; word-break: break-all; }
.upload-status { color: var(--muted); font-size: 14px; min-height: 18px; }
.field {
  appearance: none; width: 100%; box-sizing: border-box;
  background: #0d1019; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 14px; font: inherit; font-size: 16px;
}
.field:focus { outline: none; border-color: var(--accent); }
select.field { cursor: pointer; }

/* =================== RESULTS =================== */
#screen-results {
  background: radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg));
  overflow-y: auto;
}
.results-inner { max-width: 480px; margin: 0 auto; padding: max(8vh,48px) 28px; text-align: center; }
.results-inner h2 { font-size: 30px; margin: 0 0 10px; }
.stars { font-size: 44px; letter-spacing: 6px; margin: 6px 0 24px; }
.results-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0 0 28px; text-align: left;
}
.results-grid > div {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  display: flex; flex-direction: column;
}
.rlabel { color: var(--muted); font-size: 13px; }
.rval { font-size: 24px; font-weight: 800; }
.results-actions { display: grid; gap: 12px; }
