/* ==========================================================================
   KidPiano · 星空五线谱小钢琴 (V1 Mobile Portrait + iPad Responsive)
   Flat 2D Starry Glow Aesthetic · Touch-Optimized for Young Children
   ========================================================================== */

:root {
  --bg-deep: #0b1120;
  --bg-mid: #131d36;
  --card-bg: rgba(255, 255, 255, 0.045);
  --card-border: rgba(148, 163, 184, 0.2);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --gold: #fbbf24;
  --cyan: #22d3ee;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 18%, #1d2b4e 0%, #10192f 52%, #090e1c 100%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  touch-action: manipulation;
}

#bgStarsCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* Main responsive vertical container */
.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 820px;
  height: 100vh;
  margin: 0 auto;
  overflow: hidden;
  padding-top: calc(10px + var(--safe-top));
  padding-bottom: calc(10px + var(--safe-bottom));
  padding-left: calc(10px + var(--safe-left));
  padding-right: calc(10px + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@supports (height: 100dvh) {
  .app-shell {
    height: 100dvh;
  }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  padding: 2px 2px;
}

.pill-btn,
.icon-pill-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.pill-btn:active,
.icon-pill-btn:active {
  transform: scale(0.95);
}

.song-picker-btn {
  padding: 7px 11px;
  font-size: 13.5px;
  min-width: 0;
  flex-shrink: 1;
  background: rgba(30, 41, 72, 0.85);
}

.song-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.music-icon {
  color: var(--gold);
  font-size: 15px;
  flex-shrink: 0;
}

.chevron {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.icon-pill-btn {
  padding: 7px 9px;
  font-size: 12.5px;
  color: #cbd5e1;
  gap: 4px;
}

.icon-pill-btn.is-on {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.55);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.22);
}

.icon-pill-btn.is-playing {
  background: rgba(251, 191, 36, 0.22);
  border-color: rgba(251, 191, 36, 0.65);
  color: #fef08a;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.28);
}

.btn-label {
  font-size: 11.5px;
}

/* Narrow phone compact labels */
@media (max-width: 360px) {
  .btn-label {
    display: none;
  }
  .icon-pill-btn {
    padding: 7px 9px;
  }
}

/* ---------- Progress Strip ---------- */
.progress-strip {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  padding: 0 4px;
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.phrase-badge {
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.07);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  flex-shrink: 0;
}

.feedback-banner {
  color: #93c5fd;
  font-weight: 700;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.18s ease, text-shadow 0.18s ease;
}

.feedback-banner.lit {
  color: #fef08a;
  text-shadow: 0 0 12px rgba(250, 204, 21, 0.75);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff5e6c, #fbbf24, #4ad991, #22d3ee, #a78bfa);
  transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.55);
}

/* ---------- 2D Staff Stage ---------- */
.staff-stage {
  flex: 1.08;
  min-height: 175px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  position: relative;
}

.staff-card {
  position: relative;
  width: 100%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(15, 23, 42, 0.42) 100%);
  border: 1.5px solid var(--card-border);
  border-radius: 24px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09), 0 14px 36px rgba(0, 0, 0, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px 6px;
}

.staff-svg-host {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.staff-svg-host.phrase-fade {
  opacity: 0;
  transform: translateX(18px);
}

.staff-svg-host svg {
  width: 100%;
  height: 100%;
  max-height: 290px;
  display: block;
}

.particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* Animated target ring pulse inside SVG */
@keyframes targetPulse {
  0%, 100% {
    opacity: 0.92;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.12);
  }
}

.svg-target-ring {
  transform-box: fill-box;
  transform-origin: center;
  animation: targetPulse 1.5s ease-in-out infinite;
}

@keyframes hitPop {
  0% {
    transform: scale(0.86);
  }
  45% {
    transform: scale(1.22);
  }
  100% {
    transform: scale(1);
  }
}

.svg-note-just-hit {
  transform-box: fill-box;
  transform-origin: center;
  animation: hitPop 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Visual Light Beam & Octave Bar ---------- */
.bridge-zone {
  position: relative;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.light-beam {
  position: absolute;
  bottom: -24px;
  height: 120px;
  width: 54px;
  border-radius: 30px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) scaleY(0.65);
  transform-origin: bottom center;
  filter: blur(11px);
  transition: opacity 0.24s ease, transform 0.22s ease;
  z-index: 1;
}

.light-beam.active {
  opacity: 0.9;
  transform: translateX(-50%) scaleY(1.05);
}

.octave-bar {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.24);
  padding: 5px 12px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.octave-minimap {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 5px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
}

.mm-seg {
  width: 14px;
  height: 9px;
  border-radius: 2.5px;
  background: rgba(255, 255, 255, 0.16);
}

.mm-seg.active {
  width: 24px;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.85);
}

.octave-text {
  font-size: 12px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: 0.2px;
}

.mini-reset-btn {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.mini-reset-btn:active {
  transform: scale(0.94);
}

/* ---------- Piano Keyboard Stage ---------- */
.keyboard-stage {
  flex: 1.05;
  min-height: 205px;
  max-height: 360px;
  width: 100%;
  display: flex;
  align-items: stretch;
  padding: 2px 2px 4px 2px;
  touch-action: none;
}

.piano-keyboard {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.white-keys-layer {
  display: flex;
  gap: 4px;
  width: 100%;
  height: 100%;
}

.white-key {
  flex: 1;
  height: 100%;
  position: relative;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 18%, #eef2f7 100%);
  border: 1.5px solid rgba(15, 23, 42, 0.18);
  border-radius: 7px 7px 14px 14px;
  box-shadow: 0 6px 0 #b8c4d4, 0 10px 18px rgba(0, 0, 0, 0.32);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 14px;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.08s ease, background 0.1s ease;
  touch-action: none;
}

.white-key .key-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.white-key .key-anchor {
  font-size: 11px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.3px;
}

.white-key .chroma-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  transition: opacity 0.2s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.rainbow-off .white-key .chroma-dot {
  opacity: 0;
  transform: scale(0.4);
}

/* Guided breathing hint on target white key */
@keyframes keyBreathe {
  0%, 100% {
    box-shadow: inset 0 0 0 3px var(--hint-color, #fbbf24), 0 6px 0 #b8c4d4, 0 0 16px var(--hint-glow, rgba(251, 191, 36, 0.45));
  }
  50% {
    box-shadow: inset 0 0 0 4.5px var(--hint-color, #fbbf24), 0 6px 0 #b8c4d4, 0 0 26px var(--hint-glow, rgba(251, 191, 36, 0.78));
  }
}

.white-key.is-guided {
  animation: keyBreathe 1.4s ease-in-out infinite;
}

.white-key.is-guided::before {
  content: "";
  position: absolute;
  bottom: 44px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--hint-color, #fbbf24);
  opacity: 0.25;
  pointer-events: none;
}

/* Active pressed & glowing key */
.white-key.is-pressed {
  transform: translateY(5px);
  background: linear-gradient(180deg, #ffffff 0%, var(--press-soft, rgba(34, 211, 238, 0.28)) 40%, var(--press-color, #22d3ee) 100%);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.15), 0 1px 0 #94a3b8, 0 0 26px var(--press-glow, rgba(34, 211, 238, 0.82));
  animation: none;
}

.white-key.is-pressed .chroma-dot {
  transform: scale(1.25);
  box-shadow: 0 0 12px var(--press-color, #22d3ee);
}

.white-key.is-wrong {
  transform: translateY(4px);
  background: linear-gradient(180deg, #f8fafc 0%, #e2e8f0 100%);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.18), 0 2px 0 #94a3b8;
}

/* Black keys overlay */
.black-keys-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 57%;
  pointer-events: none;
}

.black-key {
  position: absolute;
  top: 0;
  height: 100%;
  background: linear-gradient(180deg, #334155 0%, #1e293b 62%, #0f172a 100%);
  border: 1px solid #475569;
  border-top: none;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.5), inset 0 -4px 4px rgba(255, 255, 255, 0.08);
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.08s ease;
  touch-action: none;
}

.black-key.is-pressed {
  transform: translateY(3px);
  background: linear-gradient(180deg, #475569 0%, #334155 100%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

/* ---------- iPad / Tablet Spacious Refinements ---------- */
@media (min-width: 720px) {
  .app-shell {
    padding: 18px 24px 20px 24px;
    gap: 12px;
  }

  .song-picker-btn {
    padding: 10px 18px;
    font-size: 16px;
  }

  .icon-pill-btn {
    padding: 9px 14px;
    font-size: 14px;
  }

  .btn-label {
    font-size: 13.5px;
  }

  .progress-meta {
    font-size: 14px;
  }

  .staff-card {
    border-radius: 30px;
    padding: 14px 18px;
  }

  .white-keys-layer {
    gap: 6px;
  }

  .white-key {
    border-radius: 8px 8px 18px 18px;
    padding-bottom: 18px;
  }

  .white-key .chroma-dot {
    width: 18px;
    height: 18px;
  }

  .white-key .key-anchor {
    font-size: 13px;
  }
}

/* ---------- Modals (Song Picker & Celebration) ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 10, 22, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, #17233f 0%, #0f172a 100%);
  border: 1.5px solid rgba(148, 163, 184, 0.25);
  border-radius: 26px;
  padding: 22px 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 800;
}

.modal-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.close-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  font-size: 15px;
  cursor: pointer;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.song-item {
  width: 100%;
  text-align: left;
  border: 1.5px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 13px 15px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.song-item:active {
  transform: scale(0.98);
}

.song-item.active {
  border-color: rgba(34, 211, 238, 0.7);
  background: rgba(34, 211, 238, 0.12);
}

.song-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.song-emoji {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.song-item-name {
  font-size: 15.5px;
  font-weight: 800;
  margin-bottom: 3px;
}

.song-item-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.song-item-stars {
  font-size: 15px;
  color: #fbbf24;
  letter-spacing: 2px;
  flex-shrink: 0;
}

/* Win celebration modal */
.win-card {
  text-align: center;
  padding: 28px 22px;
}

.win-stars {
  font-size: 42px;
  color: #fbbf24;
  text-shadow: 0 0 24px rgba(251, 191, 36, 0.85);
  margin-bottom: 12px;
  letter-spacing: 6px;
}

.win-title {
  font-size: 21px;
  font-weight: 800;
  margin-bottom: 8px;
}

.win-sub {
  font-size: 14px;
  color: #cbd5e1;
  margin-bottom: 22px;
}

.win-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.win-btn {
  flex: 1;
  padding: 13px 16px;
  border-radius: 16px;
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.win-btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
}

.win-btn.primary {
  background: linear-gradient(135deg, #22d3ee, #38bdf8);
  color: #082f49;
  box-shadow: 0 8px 20px rgba(34, 211, 238, 0.35);
}
