:root {
  --bg: #070912;
  --bg-2: #0c0f1e;
  --ink: #eef0f8;
  --muted: #878ca6;
  --gold: #f5c454;
  --gold-deep: #d99a2b;
  --line: rgba(255, 255, 255, 0.08);
  --panel: rgba(255, 255, 255, 0.035);
  --ivory-top: #f6f3ec;
  --ivory-bot: #d8d3c4;
  --ebony-top: #23262f;
  --ebony-bot: #0c0d13;
  --display: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, sans-serif;
  --mono: 'Space Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none; /* no long-press callout menu on iOS */
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% -10%, #191d3a 0%, rgba(25, 29, 58, 0) 55%),
    radial-gradient(90% 70% at 85% 110%, #1a1330 0%, rgba(26, 19, 48, 0) 60%),
    var(--bg);
  touch-action: manipulation;
  user-select: none;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 600;
}

/* ============================ MENU ============================ */
#menu {
  padding: clamp(1.4rem, 4vw, 3rem);
  gap: 1.6rem;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}
.brand-mark {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 46px;
}
.brand-mark span {
  width: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  animation: eq 1.6s ease-in-out infinite;
}
.brand-mark span:nth-child(1) { height: 40%; animation-delay: 0s; }
.brand-mark span:nth-child(2) { height: 90%; animation-delay: 0.2s; }
.brand-mark span:nth-child(3) { height: 60%; animation-delay: 0.4s; }
.brand-mark span:nth-child(4) { height: 100%; animation-delay: 0.6s; }
@keyframes eq {
  0%, 100% { transform: scaleY(0.5); opacity: 0.7; }
  50% { transform: scaleY(1); opacity: 1; }
}
.brand-text h1 {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  font-optical-sizing: auto;
}
.brand-text .eyebrow {
  margin-bottom: 0.35rem;
}

.menu-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.4rem;
  min-height: 0;
}
@media (min-width: 820px) {
  .menu-body {
    grid-template-columns: 1.1fr 0.9fr;
  }
}

.col-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}
.col-head h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.35rem;
}

.song-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.song-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.12s;
}
.song-item:hover {
  border-color: rgba(245, 196, 84, 0.4);
  background: rgba(245, 196, 84, 0.05);
}
.song-item.selected {
  border-color: var(--gold);
  background: rgba(245, 196, 84, 0.09);
}
.song-swatch {
  width: 8px;
  align-self: stretch;
  border-radius: 6px;
  flex: none;
}
.song-meta h3 {
  font-size: 1.02rem;
  font-weight: 600;
}
.song-meta p {
  font-size: 0.82rem;
  color: var(--muted);
}
.difficulty {
  margin-left: auto;
  display: flex;
  gap: 3px;
  align-items: center;
}
.pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
}
.pip.on {
  background: var(--gold);
}

/* Detail card */
.detail-col {
  min-height: 0;
}
.song-detail {
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.empty-hint {
  margin: auto;
  color: var(--muted);
  font-style: italic;
}
.detail-title {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.02em;
}
.detail-sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}
.detail-facts {
  display: flex;
  gap: 1.4rem;
  padding: 0.8rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.detail-facts div span {
  display: block;
}
.fact-label {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}
.fact-val {
  font-family: var(--mono);
  font-size: 1.1rem;
  margin-top: 0.2rem;
}
.mode-label {
  font-size: 0.8rem;
  color: var(--muted);
}
.mode-grid {
  display: grid;
  gap: 0.6rem;
  margin-top: auto;
}
.mode-btn {
  text-align: left;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.mode-btn:hover {
  border-color: var(--gold);
  transform: translateX(3px);
}
.mode-btn strong {
  display: block;
  font-size: 1rem;
}
.mode-btn small {
  color: var(--muted);
}
.mode-btn .arrow {
  float: right;
  color: var(--gold);
  font-size: 1.2rem;
}

.footnote {
  color: var(--muted);
  font-size: 0.8rem;
  max-width: 60ch;
}

.ghost-btn,
.primary-btn {
  font-family: inherit;
  cursor: pointer;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 1.1rem;
  transition: transform 0.12s, filter 0.15s, background 0.15s;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.ghost-btn:hover {
  border-color: var(--gold);
}
.primary-btn {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  border: none;
  color: #241a05;
}
.primary-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

/* ============================ GAME ============================ */
.hud {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem clamp(0.7rem, 2vw, 1.2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 18, 0.6);
  backdrop-filter: blur(8px);
}
.hud-btn {
  font-family: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 9px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}
.hud-btn:hover {
  border-color: var(--gold);
}
.hud-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#hudSong {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-mode {
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}
.hud-stats {
  margin-left: auto;
  display: flex;
  gap: clamp(0.8rem, 3vw, 2rem);
}
.stat {
  text-align: right;
}
.stat-label {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-val {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
}

.progress-track {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  box-shadow: 0 0 10px rgba(245, 196, 84, 0.7);
  transition: width 0.1s linear;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.highway-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
#highway {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.judgement {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(1.8rem, 6vw, 3rem);
  letter-spacing: -0.01em;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}
.judgement.show {
  animation: pop 0.6s ease-out;
}
@keyframes pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  30% { opacity: 1; transform: translateX(-50%) scale(1.05); }
  100% { opacity: 0; transform: translateX(-50%) scale(1) translateY(-18px); }
}

/* --------------------------- KEYBOARD --------------------------- */
.keyboard {
  position: relative;
  height: clamp(150px, 30vh, 260px);
  flex: none;
  background: linear-gradient(180deg, #05060c, #010103);
  border-top: 2px solid rgba(245, 196, 84, 0.25);
  box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.6);
}
.key {
  position: absolute;
  top: 0;
  cursor: pointer;
  touch-action: none;
}
.key.white {
  height: 100%;
  background: linear-gradient(180deg, var(--ivory-top), var(--ivory-bot));
  border: 1px solid #b7b2a3;
  border-radius: 0 0 7px 7px;
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, 0.12), inset 0 2px 0 rgba(255, 255, 255, 0.7);
  z-index: 1;
}
.key.black {
  height: 62%;
  background: linear-gradient(180deg, var(--ebony-top), var(--ebony-bot));
  border: 1px solid #000;
  border-radius: 0 0 6px 6px;
  box-shadow: inset 0 -6px 8px rgba(0, 0, 0, 0.6), 0 4px 6px rgba(0, 0, 0, 0.5);
  z-index: 2;
}
.key .label {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: #9a9585;
  pointer-events: none;
}
.key.lit {
  background: linear-gradient(180deg,
    hsl(var(--hue) 90% 72%), hsl(var(--hue) 85% 55%));
  box-shadow: 0 0 22px hsl(var(--hue) 90% 60% / 0.75);
}
.key.black.lit {
  background: linear-gradient(180deg,
    hsl(var(--hue) 80% 55%), hsl(var(--hue) 85% 38%));
}
.key.pressed {
  transform: translateY(2px) scaleY(0.985);
  filter: brightness(1.12);
}
.key.target {
  animation: target-pulse 0.9s ease-in-out infinite;
}
@keyframes target-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 hsl(var(--hue) 90% 60% / 0.6), inset 0 0 0 2px hsl(var(--hue) 90% 60%);
  }
  50% {
    box-shadow: 0 0 26px 4px hsl(var(--hue) 90% 60% / 0.9), inset 0 0 0 2px hsl(var(--hue) 90% 70%);
  }
}

/* Pause overlay */
.pause-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(7, 9, 18, 0.82);
  backdrop-filter: blur(4px);
  z-index: 5;
}
.pause-overlay p {
  font-family: var(--display);
  font-weight: 900;
  font-size: 2.4rem;
}
.hidden {
  display: none !important;
}

/* ========================== OVERLAYS ========================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  background: rgba(4, 5, 12, 0.72);
  backdrop-filter: blur(6px);
}
.results-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2rem;
  background: linear-gradient(180deg, #12152a, #0a0c18);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.results-card h2 {
  font-family: var(--display);
  font-weight: 900;
  font-size: 2rem;
  margin: 0.3rem 0 0.8rem;
}
.stars {
  font-size: 2rem;
  letter-spacing: 0.3rem;
  color: var(--gold);
  margin-bottom: 1.2rem;
  min-height: 2.4rem;
}
.stars .off {
  color: rgba(255, 255, 255, 0.14);
}
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.6rem;
}
.result-grid > div {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 0.8rem;
}
.big {
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 700;
  display: block;
  margin-top: 0.2rem;
}
.result-actions {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
}

.import-copy {
  color: var(--muted);
  margin: 0.6rem 0 1.2rem;
  font-size: 0.92rem;
  line-height: 1.5;
}
.import-copy code,
code {
  font-family: var(--mono);
  color: var(--gold);
}
.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 1rem;
  transition: border-color 0.15s, background 0.15s;
}
.file-drop:hover,
.file-drop.drag {
  border-color: var(--gold);
  background: rgba(245, 196, 84, 0.06);
}
.import-error {
  color: #ff8080;
  font-size: 0.85rem;
  min-height: 1.2rem;
  margin: 0.6rem 0;
}

/* Rotate hint */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg);
  text-align: center;
  padding: 2rem;
}
.rotate-icon {
  font-size: 3rem;
  color: var(--gold);
  animation: spin 3s ease-in-out infinite;
}
@keyframes spin {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(90deg); }
}
/* Show only on short, portrait phone screens while in-game. */
@media (max-height: 480px) and (orientation: portrait) {
  body.in-game .rotate-hint {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
