:root {
  --bg-color: #151917;
  --panel-bg: #1c2320;
  --surface-bg: #232c28;
  --text-color: #f5f2eb;
  --muted-color: #9cb1a5;
  --accent-color: #7da490;
  --accent-glow: rgba(125, 164, 144, 0.45);
  --cyan-highlight: #38bdf8;
  --cyan-glow: rgba(56, 189, 248, 0.4);
  --success-color: #4ade80;
  --success-glow: rgba(74, 222, 128, 0.45);
  --error-color: #f87171;
  --error-glow: rgba(248, 113, 113, 0.45);
  --link-color: #d47a5b;
  --font-serif: 'Noto Serif KR', 'Georgia', serif;
  --font-sans: 'Montserrat', 'Noto Sans KR', sans-serif;
  --key-white-bg: #f9f8f4;
  --key-white-border: #d3cfc5;
  --key-black-bg: #1e2220;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body.piano-app-body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app-layout {
  width: 100%;
  max-width: 900px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem max(1.2rem, env(safe-area-inset-right, 1.2rem)) 0.5rem max(1.2rem, env(safe-area-inset-left, 1.2rem));
  gap: 0.8rem;
}

/* Header & Badges */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
  border-bottom: 1px solid rgba(125, 164, 144, 0.15);
  padding-bottom: 0.7rem;
}

.header-left {
  display: flex;
  flex-direction: column;
}

.brand-link {
  color: var(--muted-color);
  text-decoration: none;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  transition: color 0.2s;
}

.brand-link:hover {
  color: var(--link-color);
}

.brand-link .diag-icon {
  font-size: 0.7rem;
  color: var(--link-color);
}

.app-heading {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-color);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border-radius: 9999px;
  background: var(--surface-bg);
  border: 1px solid rgba(163, 184, 172, 0.25);
  color: var(--text-color);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.status-badge:hover {
  border-color: var(--accent-color);
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #fbbf24; /* yellow/amber disconnected */
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.6);
  transition: background-color 0.3s, box-shadow 0.3s;
}

.badge-dot.connected {
  background-color: var(--success-color);
  box-shadow: 0 0 8px var(--success-glow);
}

.wake-badge.active {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.lang-badge {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.lang-badge:hover {
  background: rgba(125, 164, 144, 0.15);
  border-color: var(--accent-color);
}

/* Ribbon Controls */
.game-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-bg);
  padding: 0.5rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(125, 164, 144, 0.18);
  gap: 0.8rem;
  flex-wrap: wrap;
}

.ribbon-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ribbon-label {
  font-size: 0.75rem;
  color: var(--muted-color);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.level-select {
  background: var(--surface-bg);
  color: var(--text-color);
  border: 1px solid rgba(163, 184, 172, 0.3);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

.ribbon-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-color);
}

.streak-flame {
  font-size: 1rem;
  filter: grayscale(1);
  transition: filter 0.3s;
}

.streak-flame.lit {
  filter: grayscale(0);
}

.best-box {
  border-left: 1px solid rgba(125, 164, 144, 0.2);
  padding-left: 0.5rem;
}

.best-trophy {
  font-size: 0.95rem;
  filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.5));
}

/* Challenge Stage */
.challenge-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem 0;
}

/* Phase Banner */
.phase-banner {
  width: 100%;
  max-width: 580px;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem 1.2rem;
  border-radius: 14px;
  background: rgba(35, 44, 40, 0.85);
  border: 1px solid rgba(125, 164, 144, 0.3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.phase-banner.listen-mode {
  border-color: #fbbf24;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.25);
}

.phase-banner.play-mode {
  border-color: var(--cyan-highlight);
  box-shadow: 0 0 20px var(--cyan-glow);
}

.phase-banner.success-mode {
  border-color: var(--success-color);
  box-shadow: 0 0 22px var(--success-glow);
}

.phase-icon {
  font-size: 1.8rem;
}

.phase-text-group {
  display: flex;
  flex-direction: column;
}

.phase-main {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.phase-sub {
  font-size: 0.75rem;
  color: var(--muted-color);
}

/* Musical Staff SVG */
.staff-container {
  width: 100%;
  max-width: 620px;
  height: 160px;
  background: #1e2522;
  border-radius: 16px;
  border: 1px solid rgba(125, 164, 144, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.8rem;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.notation-svg {
  width: 100%;
  height: 100%;
}

/* Note Sequence Chips */
.sequence-chips {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.note-chip {
  min-width: 52px;
  height: 52px;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  background: var(--surface-bg);
  border: 1px solid rgba(163, 184, 172, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-weight: 700;
  color: var(--muted-color);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chip-note {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.chip-finger {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.chip-finger.rh {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.chip-finger.lh {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.4);
}

.note-chip.active {
  border-color: var(--cyan-highlight);
  color: var(--cyan-highlight);
  box-shadow: 0 0 12px var(--cyan-glow);
  transform: translateY(-2px);
}

.note-chip.playing-call {
  border-color: #fbbf24;
  color: #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.4);
  transform: scale(1.08);
}

.note-chip.matched {
  border-color: var(--success-color);
  background: rgba(74, 222, 128, 0.15);
  color: var(--success-color);
  box-shadow: 0 0 12px var(--success-glow);
}

.note-chip.error {
  border-color: var(--error-color);
  background: rgba(248, 113, 113, 0.15);
  color: var(--error-color);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Controls */
.stage-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border-radius: 9999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--accent-color);
  color: var(--bg-color);
  border: none;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover {
  background: #8fb6a2;
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: var(--text-color);
  border: 1px solid var(--accent-color);
}

.btn-secondary:hover {
  background: rgba(125, 164, 144, 0.15);
}

.audio-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted-color);
  cursor: pointer;
}

.audio-toggle-label input {
  accent-color: var(--accent-color);
  cursor: pointer;
}

/* Keyboard Shelf */
.keyboard-shelf {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--panel-bg);
  border-radius: 18px 18px 10px 10px;
  padding: 0.7rem 0.8rem 0.5rem;
  border: 1px solid rgba(125, 164, 144, 0.2);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
}

.keyboard-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted-color);
  padding: 0 0.3rem;
}

.last-played-note {
  font-weight: 600;
  color: var(--accent-color);
}

/* Piano Keys & Player Hands Visualization (Stationary, Non-Scrolling Layout) */
.piano-viewport {
  width: 100%;
  overflow: hidden;
  position: relative;
  padding-top: 1.8rem;
  padding-bottom: 0.3rem;
}

.piano-track {
  display: block;
  position: relative;
  width: 100%;
  min-width: 0;
}

.hands-overlay {
  position: absolute;
  top: -24px;
  left: 0;
  width: 100%;
  height: calc(100% + 24px);
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.hand-group {
  transition: opacity 0.25s ease;
}

.hand-group.inactive-hand {
  opacity: 0.22;
}

@keyframes fingerStrikePulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}

.finger-pulse {
  transform-box: fill-box;
  transform-origin: center;
  animation: fingerStrikePulse 0.45s ease-out infinite;
}

.piano-keys {
  display: flex;
  position: relative;
  height: 125px;
  width: 100%;
  min-width: 0;
}

.key-white {
  flex: 1 1 0;
  min-width: 0;
  width: calc(100% / 23);
  height: 100%;
  background: linear-gradient(to bottom, #edeae1 0%, var(--key-white-bg) 80%, #eae5d8 100%);
  border: 1px solid var(--key-white-border);
  border-radius: 0 0 5px 5px;
  position: relative;
  z-index: 1;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.35rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  transition: background 0.1s, transform 0.05s;
  box-sizing: border-box;
}

.key-white .key-label {
  font-size: clamp(0.48rem, 1.3vw, 0.68rem);
  color: #717672;
  font-weight: 600;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.key-white.middle-c-key .key-label {
  color: var(--cyan-highlight);
  font-weight: 700;
}

.middle-c-dot {
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: var(--cyan-highlight);
  margin-top: 2px;
  box-shadow: 0 0 4px var(--cyan-glow);
}

.key-white.active-user {
  background: #7dd3fc !important;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 12px var(--cyan-glow);
  transform: translateY(2px);
}

.key-white.active-call {
  background: #fde68a !important;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 14px rgba(251, 191, 36, 0.5);
  transform: translateY(2px);
}

.key-white.active-error {
  background: #fca5a5 !important;
}

.key-black {
  position: absolute;
  top: 0;
  height: 62%;
  background: linear-gradient(to bottom, #111412 0%, #29302c 85%, #181d1a 100%);
  border: 1px solid #000;
  border-radius: 0 0 3px 3px;
  z-index: 2;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.25rem;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6);
  transition: background 0.1s, transform 0.05s;
  box-sizing: border-box;
}

.key-black .key-label {
  font-size: clamp(0.4rem, 1.0vw, 0.55rem);
  color: #adb5af;
  font-weight: 500;
  pointer-events: none;
  line-height: 1;
}

.key-black.active-user {
  background: #0284c7 !important;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4), 0 0 12px var(--cyan-glow);
  transform: translateY(2px);
}

.key-black.active-call {
  background: #d97706 !important;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4), 0 0 12px rgba(251, 191, 36, 0.6);
  transform: translateY(2px);
}

.key-black.active-error {
  background: #dc2626 !important;
}

/* Floating Key Fingering Indicator Badge */
.key-finger-badge {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
  animation: badgePop 0.16s ease-out;
}

.key-finger-badge.rh {
  background: rgba(21, 25, 23, 0.95);
  color: #38bdf8;
  border: 1px solid #38bdf8;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

.key-finger-badge.lh {
  background: rgba(21, 25, 23, 0.95);
  color: #fbbf24;
  border: 1px solid #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

@keyframes badgePop {
  0% { transform: translate(-50%, 6px) scale(0.8); opacity: 0; }
  100% { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

@media (max-width: 600px) {
  .app-layout {
    padding: 0.6rem 0.6rem 0.4rem;
  }
  .piano-keys {
    height: 105px;
  }
  .staff-container {
    height: 120px;
  }
}

/* Audio Gate Overlay (Forced User Interaction for Web Audio Autoplay Policy) */
.audio-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 15, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 1.25rem;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  user-select: none;
  -webkit-user-select: none;
}

.audio-gate-overlay.dismissed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.audio-gate-card {
  max-width: 480px;
  width: 100%;
  background: linear-gradient(145deg, rgba(29, 36, 32, 0.98), rgba(21, 25, 23, 0.98));
  border: 1px solid rgba(125, 164, 144, 0.35);
  border-radius: 20px;
  padding: 2.2rem 1.8rem;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7), 0 0 30px rgba(125, 164, 144, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  animation: gateCardPop 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes gateCardPop {
  0% { transform: scale(0.92) translateY(12px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.gate-top-row {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  margin-bottom: -0.5rem;
}

.gate-lang-btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

.gate-icon-halo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(125, 164, 144, 0.25) 0%, rgba(125, 164, 144, 0.05) 70%, transparent 100%);
  border: 1px solid rgba(125, 164, 144, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(125, 164, 144, 0.2);
}

.gate-icon {
  font-size: 2.2rem;
}

.gate-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.gate-subtitle {
  margin: -0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--accent-color);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.gate-desc {
  margin: 0.25rem 0 0.5rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.btn-gate-start {
  width: 100%;
  padding: 0.95rem 1.6rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  box-shadow: 0 8px 24px rgba(125, 164, 144, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-gate-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(125, 164, 144, 0.45);
}

.btn-gate-start:active {
  transform: translateY(1px);
}

.gate-features {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  margin-top: 0.4rem;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(125, 164, 144, 0.15);
}

.gate-feat-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  justify-content: center;
}

.gate-feat-pill .pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-color);
}

@media (max-width: 600px) {
  .audio-gate-card {
    padding: 1.5rem 1.2rem;
    gap: 0.75rem;
  }
  .gate-icon-halo {
    width: 56px;
    height: 56px;
  }
  .gate-icon {
    font-size: 1.7rem;
  }
  .gate-title {
    font-size: 1.25rem;
  }
  .gate-desc {
    font-size: 0.88rem;
  }
  .btn-gate-start {
    padding: 0.85rem 1.2rem;
    font-size: 0.95rem;
  }
}

@media (max-height: 520px) {
  .audio-gate-card {
    padding: 0.9rem 1.2rem;
    gap: 0.4rem;
    max-height: 92vh;
    overflow-y: auto;
  }
  .gate-icon-halo {
    width: 40px;
    height: 40px;
  }
  .gate-icon {
    font-size: 1.2rem;
  }
  .gate-desc {
    font-size: 0.82rem;
    line-height: 1.35;
  }
  .gate-features {
    display: none;
  }
}

