*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FFF7EC;
  --text: #3D2C2E;
  --text-muted: #8B7E80;
  --card: #ffffff;
  --accent-red: #FF6B6B;
  --accent-teal: #4ECDC4;
  --accent-yellow: #FFD93D;
  --accent-purple: #6C5CE7;
  --accent-orange: #FF9F43;
  --accent-green: #2ECC71;
  --shadow-sm: 0 4px 12px rgba(61, 44, 46, 0.08);
  --shadow-md: 0 8px 28px rgba(61, 44, 46, 0.12);
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.22; z-index: 0; animation: blobFloat 14s ease-in-out infinite alternate; pointer-events: none; }
.blob-1 { width: 380px; height: 380px; background: var(--accent-purple); top: -140px; left: -80px; }
.blob-2 { width: 340px; height: 340px; background: var(--accent-red); bottom: -100px; right: -60px; animation-delay: -5s; }
.blob-3 { width: 280px; height: 280px; background: var(--accent-teal); top: 35%; left: 55%; animation-delay: -9s; }
@keyframes blobFloat { 0% { transform: translate(0,0) scale(1); } 100% { transform: translate(24px,-32px) scale(1.06); } }

.top-bar { position: relative; z-index: 10; padding: 12px 20px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.95rem;
  color: var(--text-muted); text-decoration: none;
  padding: 8px 14px; border-radius: 14px;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(8px);
  transition: background 0.2s, color 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.9); color: var(--text); }

.game-wrapper {
  position: relative; z-index: 1; flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 32px;
  max-width: 660px; margin: 0 auto; width: 100%;
}

.game-header { text-align: center; margin-bottom: 14px; animation: fadeDown 0.5s ease both; }
.game-header h1 {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-red));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.emoji-bounce { display: inline-block; -webkit-text-fill-color: initial; animation: emojiBounce 2s ease-in-out infinite; }
@keyframes emojiBounce { 0%,100%{transform:translateY(0) rotate(0)} 25%{transform:translateY(-6px) rotate(-8deg)} 75%{transform:translateY(-3px) rotate(6deg)} }
.subtitle { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
@keyframes fadeDown { 0%{opacity:0;transform:translateY(-18px)} 100%{opacity:1;transform:translateY(0)} }

/* Note display */
.note-display {
  margin-bottom: 16px;
  animation: fadeDown 0.5s 0.1s ease both;
}
.note-name {
  display: inline-block;
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  font-size: 2rem;
  color: var(--text);
  min-width: 60px;
  text-align: center;
  transition: color 0.15s, transform 0.15s;
}
.note-name.pop {
  animation: notePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes notePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* Piano container */
.piano-container {
  width: 100%;
  display: flex;
  justify-content: center;
  animation: fadeDown 0.5s 0.2s ease both;
}

.piano {
  position: relative;
  display: flex;
  background: var(--card);
  border-radius: 0 0 16px 16px;
  box-shadow: 0 12px 40px rgba(61, 44, 46, 0.15), inset 0 -4px 8px rgba(0,0,0,0.05);
  padding: 0;
  overflow: hidden;
  border: 2px solid rgba(0,0,0,0.08);
  border-top: 6px solid #2C2C2A;
}

/* White keys */
.white-key {
  position: relative;
  width: 68px;
  height: 240px;
  background: linear-gradient(to bottom, #FAFAFA, #F0F0F0, #E8E8E8);
  border-right: 1px solid #D0D0D0;
  cursor: pointer;
  z-index: 1;
  transition: background 0.06s, box-shadow 0.06s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 12px;
}
.white-key:last-child { border-right: none; }
.white-key:active, .white-key.pressed {
  background: linear-gradient(to bottom, #E8E8E8, #E0E0E0);
}
.white-key.pressed {
  box-shadow: inset 0 0 30px var(--glow-color), 0 0 20px var(--glow-color);
  background: linear-gradient(to bottom, var(--glow-light), var(--glow-color));
}

.white-key .key-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.65rem;
  font-weight: 700;
  color: #BBB;
  pointer-events: none;
  transition: color 0.1s;
}
.white-key.pressed .key-label { color: #fff; }

/* Black keys */
.black-key {
  position: absolute;
  width: 44px;
  height: 150px;
  background: linear-gradient(to bottom, #2C2C2A, #1A1A1A);
  border-radius: 0 0 5px 5px;
  z-index: 2;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 -3px 4px rgba(0,0,0,0.4);
  transition: background 0.06s, box-shadow 0.06s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
}
.black-key:active, .black-key.pressed {
  background: linear-gradient(to bottom, #3A3A3A, #2A2A2A);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.black-key.pressed {
  box-shadow: inset 0 0 20px var(--glow-color), 0 0 15px var(--glow-color);
  background: linear-gradient(to bottom, var(--glow-color), color-mix(in srgb, var(--glow-color) 70%, #000));
}

.black-key .key-label {
  font-family: 'Nunito', sans-serif;
  font-size: 0.55rem;
  font-weight: 700;
  color: #666;
  pointer-events: none;
  transition: color 0.1s;
}
.black-key.pressed .key-label { color: #fff; }

/* Sparkle on key */
.key-sparkle {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  animation: sparklePop 0.5s ease-out forwards;
}
@keyframes sparklePop {
  0% { opacity: 1; transform: translate(0,0) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

/* Keyboard hint */
.keyboard-hint {
  margin-top: 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  opacity: 0.6;
  animation: fadeDown 0.5s 0.35s ease both;
}

@media (max-width: 580px) {
  .white-key { width: 52px; height: 200px; }
  .black-key { width: 34px; height: 125px; }
  .keyboard-hint { display: none; }
}
@media (max-width: 420px) {
  .white-key { width: 44px; height: 180px; }
  .black-key { width: 28px; height: 110px; }
}