/* Piano Master — Premium mobile rhythm game UI */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --neon-cyan: #00f0ff;
  --neon-magenta: #ff00aa;
  --neon-gold: #ffd700;
  --neon-blue: #4488ff;
  --glass: rgba(12, 16, 32, 0.72);
  --glass-border: rgba(255, 255, 255, 0.12);
  --lane-0: #ff3366;
  --lane-1: #00e5ff;
  --lane-2: #a855f7;
  --lane-3: #facc15;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  position: fixed;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #030508;
  color: #f0f4ff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: relative;
  background:
    radial-gradient(ellipse 80% 50% at 50% 100%, rgba(0, 240, 255, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 20% 20%, rgba(168, 85, 247, 0.1) 0%, transparent 50%),
    linear-gradient(180deg, #050810 0%, #0a0e1a 40%, #060810 100%);
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  position: absolute;
  inset: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

.screen-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* ─── Menu screens ─── */
.logo {
  font-size: clamp(2.2rem, 9vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, var(--neon-cyan) 40%, var(--neon-magenta) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 24px rgba(0, 240, 255, 0.4));
  margin-bottom: 6px;
}

.subtitle {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.95rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  margin-bottom: 36px;
}

h2 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 20px;
  background: linear-gradient(90deg, #fff, var(--neon-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.form-group {
  width: 100%;
  max-width: 400px;
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.form-group input {
  width: 100%;
  padding: 16px 18px;
  font-size: 1.1rem;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 24px rgba(0, 0, 0, 0.4);
}

.form-group input:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.25);
}

.sound-hint {
  color: var(--neon-gold);
  font-size: 0.85rem;
  margin-bottom: 20px;
  text-align: center;
}

.sound-hint.unlocked { color: #4ade80; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 52px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  width: 100%;
  max-width: 400px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #6366f1, #a855f7, #ec4899);
  color: #fff;
  box-shadow: 0 4px 24px rgba(168, 85, 247, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-sound {
  width: 100%;
  max-width: 400px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.35);
}

.btn-secondary {
  width: 100%;
  max-width: 400px;
  margin-bottom: 10px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  color: rgba(255, 255, 255, 0.75);
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  color: #fff;
  font-size: 0.8rem;
  padding: 10px 18px;
  min-height: 40px;
  border-radius: 10px;
}

.btn-large { min-height: 56px; font-size: 1.05rem; }
.btn-small { min-width: auto; }

/* Duration card */
.duration-picker {
  width: 100%;
  max-width: 400px;
  margin-bottom: 24px;
  padding: 20px;
  border-radius: 18px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.duration-label {
  display: block;
  text-align: center;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 14px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.duration-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.duration-btn {
  padding: 14px 6px;
  font-size: 1rem;
  font-weight: 800;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  touch-action: manipulation;
  min-height: 52px;
  transition: all 0.2s ease;
}

.duration-btn.active {
  border-color: var(--neon-cyan);
  background: linear-gradient(180deg, rgba(0, 240, 255, 0.2), rgba(0, 240, 255, 0.05));
  color: #fff;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.35), inset 0 0 12px rgba(0, 240, 255, 0.1);
}

.player-label {
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 20px;
  font-size: 0.88rem;
}

.song-list {
  list-style: none;
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
}

.song-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  margin-bottom: 12px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
  min-height: 76px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.12s;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.song-item:active {
  transform: scale(0.98);
  border-color: var(--neon-magenta);
  box-shadow: 0 0 24px rgba(255, 0, 170, 0.25);
}

.song-item-info h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.song-item-info p {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.45);
}

.song-item-arrow {
  font-size: 1.5rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px var(--neon-cyan);
}

/* ─── Game HUD ─── */
.game-top-bar {
  flex-shrink: 0;
  padding: 10px 16px 8px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(5, 8, 16, 0.95) 0%, transparent 100%);
  z-index: 10;
}

.game-song-header {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-progress-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.game-progress-fill {
  height: 100%;
  width: 100%;
  transform-origin: left;
  background: linear-gradient(90deg, var(--neon-magenta), var(--neon-cyan), var(--neon-gold));
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.6);
  transition: transform 0.08s linear;
}

.game-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
}

.hud-stat.right { align-items: flex-end; text-align: right; }

.hud-label {
  font-size: 0.62rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 2px;
}

.hud-score-wrap {
  position: relative;
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.hud-value.combo-display {
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(180deg, #fff 30%, var(--neon-gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 16px rgba(255, 215, 0, 0.5));
  transition: transform 0.15s ease;
}

.hud-value.combo-display.pulse {
  animation: combo-pulse 0.2s ease-out;
}

@keyframes combo-pulse {
  0% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.hud-value.accuracy-display {
  color: var(--neon-cyan);
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.5);
}

.floating-scores {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 7;
}

.float-score {
  position: absolute;
  font-weight: 800;
  font-size: 1.1rem;
  pointer-events: none;
  animation: float-up 0.7s ease-out forwards;
  text-shadow: 0 0 10px currentColor;
}

.float-score.perfect { color: var(--neon-gold); }
.float-score.great { color: var(--neon-blue); }
.float-score.good { color: #fff; }

@keyframes float-up {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-48px) scale(1.1); }
}

/* ─── Game playfield ─── */
.game-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #04060c;
}

.game-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 48px, rgba(0, 240, 255, 0.02) 48px, rgba(0, 240, 255, 0.02) 49px),
    repeating-linear-gradient(90deg, transparent, transparent 48px, rgba(255, 0, 170, 0.015) 48px, rgba(255, 0, 170, 0.015) 49px);
  pointer-events: none;
  z-index: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 1;
}

.lane-glows {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  pointer-events: none;
  z-index: 2;
}

.lane-glow {
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  animation: lane-breathe 3s ease-in-out infinite;
}

.lane-glow[data-lane="0"] { animation-delay: 0s; --lane-color: var(--lane-0); }
.lane-glow[data-lane="1"] { animation-delay: 0.4s; --lane-color: var(--lane-1); }
.lane-glow[data-lane="2"] { animation-delay: 0.8s; --lane-color: var(--lane-2); }
.lane-glow[data-lane="3"] { animation-delay: 1.2s; --lane-color: var(--lane-3); }

@keyframes lane-breathe {
  0%, 100% { box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.02); }
  50% { box-shadow: inset 0 0 40px color-mix(in srgb, var(--lane-color) 12%, transparent); }
}

.effective-zone {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--zone-top, 50%);
  height: var(--zone-height, 50%);
  background: linear-gradient(180deg,
    rgba(34, 197, 94, 0.03) 0%,
    rgba(34, 197, 94, 0.1) 40%,
    rgba(34, 197, 94, 0.06) 100%);
  border-top: 1px solid rgba(74, 222, 128, 0.2);
  pointer-events: none;
  z-index: 2;
}

.effective-zone-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(0.6rem, 2.5vw, 0.72rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: rgba(74, 222, 128, 0.45);
  white-space: nowrap;
  pointer-events: none;
}

.judgment-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  z-index: 4;
  pointer-events: none;
}

.judgment-line {
  height: 8px;
  margin: 0 4%;
  border-radius: 4px;
  background: linear-gradient(90deg,
    transparent,
    #ff4466 10%,
    #ff6688 50%,
    #ff4466 90%,
    transparent);
  box-shadow:
    0 0 20px rgba(255, 68, 102, 0.9),
    0 0 40px rgba(255, 68, 102, 0.4),
    0 0 60px rgba(255, 68, 102, 0.2);
  animation: line-pulse 1.5s ease-in-out infinite;
}

@keyframes line-pulse {
  0%, 100% { opacity: 0.9; filter: brightness(1); }
  50% { opacity: 1; filter: brightness(1.2); }
}

.lane-touches {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 5;
}

.lane-touch {
  touch-action: none;
}

.lane-touch.flash {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 40px rgba(255, 255, 255, 0.15);
}

.judgment-text {
  position: absolute;
  left: 50%;
  bottom: 26%;
  transform: translateX(-50%);
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
}

.judgment-text.show {
  opacity: 1;
  animation: judgment-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.judgment-text.perfect {
  color: var(--neon-gold);
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.9), 0 0 60px rgba(255, 215, 0, 0.4);
}
.judgment-text.great {
  color: var(--neon-blue);
  text-shadow: 0 0 24px rgba(68, 136, 255, 0.8);
}
.judgment-text.good {
  color: #fff;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
}
.judgment-text.miss {
  color: #ff4466;
  text-shadow: 0 0 20px rgba(255, 68, 102, 0.7);
}

@keyframes judgment-pop {
  0% { transform: translateX(-50%) scale(0.3); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.15); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

.screen-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
}

.screen-flash.active.perfect {
  background: radial-gradient(circle at 50% 80%, rgba(255, 215, 0, 0.45), transparent 70%);
  animation: flash-fade 0.3s ease-out;
}
.screen-flash.active.great {
  background: radial-gradient(circle at 50% 80%, rgba(68, 136, 255, 0.35), transparent 70%);
  animation: flash-fade 0.25s ease-out;
}
.screen-flash.active.good {
  background: rgba(255, 255, 255, 0.12);
  animation: flash-fade 0.2s ease-out;
}
.screen-flash.active.miss {
  background: rgba(255, 34, 68, 0.2);
  animation: flash-fade 0.35s ease-out;
}

@keyframes flash-fade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* Perfect segment */
.segment-popup {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  text-align: center;
  pointer-events: none;
  animation: segment-pop 1.2s ease-out forwards;
}

.segment-popup.hidden { display: none; }

.segment-title {
  display: block;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--neon-gold);
  text-shadow:
    0 0 20px rgba(255, 215, 0, 0.9),
    0 0 40px rgba(255, 215, 0, 0.5),
    0 0 80px rgba(255, 100, 0, 0.3);
}

.segment-bonus {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: #4ade80;
  margin-top: 8px;
  animation: bonus-pop 0.6s ease-out 0.2s both;
}

@keyframes segment-pop {
  0% { transform: translateX(-50%) scale(0.2); opacity: 0; }
  25% { transform: translateX(-50%) scale(1.15); opacity: 1; }
  75% { transform: translateX(-50%) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 0; }
}

@keyframes bonus-pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.segment-confetti, .fireworks-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  overflow: hidden;
}

.firework-burst {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: firework-fly 1s ease-out forwards;
}

@keyframes firework-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--fx), var(--fy)) scale(0); opacity: 0; }
}

.confetti-piece {
  position: absolute;
  border-radius: 2px;
  animation: confetti-fall 1.8s ease-in forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(180px) rotate(720deg); opacity: 0; }
}

.game-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(5, 8, 16, 0.95) 0%, transparent 100%);
  flex-shrink: 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.4);
  z-index: 10;
}

#game-duration-label {
  color: var(--neon-cyan);
  font-weight: 700;
}

/* Result & leaderboard */
.result-card {
  width: 100%;
  max-width: 400px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.92rem;
}

.result-row:last-child { border-bottom: none; }

.result-row .highlight {
  color: var(--neon-gold);
  font-weight: 800;
  font-size: 1.3rem;
  text-shadow: 0 0 16px rgba(255, 215, 0, 0.4);
}

.celebration { width: 100%; max-width: 400px; margin-bottom: 20px; }
.celebration.hidden { display: none; }

.celebration-banner {
  background: linear-gradient(135deg, var(--neon-gold), #f97316);
  color: #0a0a0f;
  font-weight: 900;
  font-size: 1.2rem;
  letter-spacing: 0.06em;
  text-align: center;
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
  animation: celebration-bounce 0.6s ease infinite alternate;
}

@keyframes celebration-bounce {
  from { transform: scale(1); }
  to { transform: scale(1.02); }
}

.leaderboard-table-wrap {
  width: 100%;
  max-width: 480px;
  overflow-x: auto;
  margin-bottom: 20px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  background: var(--glass);
  border-radius: 14px;
  overflow: hidden;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 12px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard-table th {
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.3);
}

.leaderboard-table .rank-1 { color: var(--neon-gold); font-weight: 800; }
.leaderboard-table .rank-2 { color: #c0d0e0; font-weight: 700; }
.leaderboard-table .rank-3 { color: #cd7f32; font-weight: 700; }

.empty-msg { color: rgba(255, 255, 255, 0.4); margin-bottom: 20px; text-align: center; }
.empty-msg.hidden { display: none; }

@media (min-width: 768px) {
  .song-item:hover {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 28px rgba(0, 240, 255, 0.2);
  }
}
