:root {
  --bg: #111114;
  --surface: #1a1a1f;
  --tile-bg: #24242b;
  --tile-border: #35353f;
  --tile-filled-border: #55556a;
  --correct: #22c55e;
  --correct-dim: #166534;
  --incorrect: #3a3a45;
  --text: #eaeaef;
  --text-dim: #8b8b9e;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-dim: #6d28d9;
  --key-bg: #2a2a34;
  --key-hover: #3a3a48;
  --key-active: #4a4a58;
  --danger: #ef4444;
  --submit-bg: #22c55e;
  --submit-hover: #16a34a;
  --radius: 10px;
  --radius-lg: 16px;
  --replay-track-width: 52px;
}

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

html {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body {
  min-height: 100%;
  overflow-x: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/*
 * Pull-to-refresh needs a scrollable root on the menu, but that breaks %-height on
 * mobile: #app / .screen were laid out for a taller layout viewport → gap under the
 * keyboard. While playing, restore the old locked root (same as before overflow-y:auto).
 */
html.app-game-active {
  overflow-y: hidden;
  height: 100%;
}

html.app-game-active body {
  height: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

#app {
  height: 100%;
  min-height: 100%;
  position: relative;
}

/* ============ SCREENS ============ */

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* Mode pick: fill height without clipping — scroll if short viewport */
#mode-screen {
  min-height: 0;
  position: relative;
}

/* ============ MODE SELECTION ============ */

.mode-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 14px 20px 18px;
  padding-top: max(12px, env(safe-area-inset-top, 0px));
  gap: 18px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  /* Pull tagline up toward the mark */
  margin-bottom: -18px;
}

.logo {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, var(--accent) 0%, #c084fc 50%, #e879f9 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-mark {
  max-height: 85px;
  width: auto;
  max-width: min(100%, 124px);
  object-fit: contain;
  display: block;
  margin-top: -5px;
  /* PNG asset is pre-masked (transparent) and tinted purple → pink to match .logo */
  filter: drop-shadow(0 3px 10px rgba(139, 92, 246, 0.22));
}

.tagline {
  color: #d4d4e0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: -5px;
  text-align: center;
}

/* Lifetime medal totals (gold / silver / platinum) on mode cards */
.mode-card-medals {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 5px 6px;
  margin-top: 6px;
  max-width: 100%;
}

.mode-card-medals.hidden {
  display: none !important;
}

.menu-medal-chip {
  display: inline-flex;
  flex-shrink: 0;
}

.menu-medal-disk {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 4px;
  box-sizing: border-box;
  border-radius: 50%;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  border: 1px solid rgba(0, 0, 0, 0.22);
}

/* Outer ring = solid background; inner face = ::before gradient (even ring all around). */
.menu-medal-disk::before {
  content: '';
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.menu-medal-disk__num {
  position: relative;
  z-index: 1;
  line-height: 1;
}

.menu-medal-disk--gold {
  background: #8f7318;
}

.menu-medal-disk--gold::before {
  background: linear-gradient(165deg, #f0d078 0%, #c9a227 50%, #b89224 100%);
}

.menu-medal-disk--silver {
  background: #6b7280;
}

.menu-medal-disk--silver::before {
  background: linear-gradient(165deg, #e5e7eb 0%, #9ca3af 50%, #8a9099 100%);
}

.menu-medal-disk--platinum {
  background: #5b21b6;
}

.menu-medal-disk--platinum::before {
  background: linear-gradient(165deg, #ddd6fe 0%, #8b5cf6 50%, #7c4deb 100%);
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--tile-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}

.mode-card:hover:not(.locked) {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.15);
}

.mode-card:active:not(.locked) {
  transform: translateY(0);
}

.mode-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.mode-icon {
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--text);
}

/* Melodurdle mark on Musician card — monochrome light to match UI text */
.mode-icon.mode-icon-img {
  height: 2rem;
  width: auto;
  max-width: 4.25rem;
  object-fit: contain;
  display: block;
  letter-spacing: normal;
  filter: brightness(0) invert(1);
  opacity: 0.88;
}

.mode-icon.mode-icon-bolt {
  letter-spacing: normal;
  font-size: 1.65rem;
  font-variant-emoji: text;
  color: var(--text);
}

.mode-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.mode-card p {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.mode-badge {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(139, 92, 246, 0.15);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 4px;
}

.mode-card.locked .mode-badge {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}

.mode-check {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 1.35rem;
  line-height: 1;
  display: none;
  color: var(--text-dim);
}

.mode-check.mode-check-done {
  color: #8b8b9e;
}

.mode-card-streak {
  position: absolute;
  top: 44px;
  right: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  pointer-events: none;
  max-width: 42%;
}

.mode-card-streak-current {
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-dim);
}

.mode-card-streak-best {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-dim);
}

.mode-check.done {
  display: block;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ============ GAME SCREEN ============ */

#game-screen {
  position: relative;
}

.tap-to-hear-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 20, 0.92);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tap-to-hear-overlay.hidden {
  display: none !important;
}
.tap-to-hear-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  pointer-events: none;
}

.tap-to-hear-subtext {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0.9;
}

.rotate-portrait-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17, 17, 20, 0.96);
  padding: 0 24px;
  text-align: center;
}

.rotate-portrait-overlay.hidden {
  display: none !important;
}

.rotate-portrait-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

.rotate-portrait-subtext {
  display: block;
  margin-top: 8px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-dim);
}

.game-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tile-border);
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--key-bg);
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.header-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.header-mode {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.header-right {
  min-width: 36px;
  text-align: right;
}

.guess-counter {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* Help — absolutely positioned; does not shift layout */
.help-btn {
  -webkit-tap-highlight-color: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  z-index: 4;
}

.help-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

.help-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top-right actions: out of flow, ? and ✉ stacked on one vertical axis */
.corner-actions {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  z-index: 4;
  width: var(--corner-btn-size, 28px);
}

.corner-actions--menu {
  --corner-btn-size: 28px;
  --corner-btn-font: 0.95rem;
  --feedback-icon-size: 25px;
  top: max(10px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
}

.corner-actions--game {
  --corner-btn-size: 24px;
  --corner-btn-font: 0.84rem;
  --feedback-icon-size: 22px;
  top: calc(100% + 3px);
  right: 12px;
  gap: 6px;
  z-index: 8;
}

.corner-actions--game.corner-actions--hidden-for-hint {
  display: none;
}

.corner-actions .help-btn {
  position: static;
  box-sizing: border-box;
  width: var(--corner-btn-size);
  height: var(--corner-btn-size);
  min-width: var(--corner-btn-size);
  min-height: var(--corner-btn-size);
  font-size: var(--corner-btn-font);
  flex-shrink: 0;
}

/* Optical center for envelope — same circle as ? */
.corner-actions .feedback-btn {
  padding: 0;
  line-height: 1;
}

.corner-actions .feedback-btn__icon {
  display: block;
  line-height: 1;
  font-size: var(--feedback-icon-size, 17px);
  transform: translate(0, -2px);
  font-variant-emoji: text;
  color: var(--text-dim);
}

.corner-actions .feedback-btn:hover .feedback-btn__icon {
  color: var(--text);
}

.corner-actions .support-btn {
  padding: 0;
  line-height: 1;
}

.corner-actions .support-btn__icon {
  display: block;
  line-height: 1;
  font-size: calc(var(--corner-btn-font, 0.95rem) * 0.92);
  transform: translate(0, -1px);
  font-variant-emoji: text;
  color: var(--text-dim);
}

.corner-actions .support-btn:hover .support-btn__icon {
  color: #f472b6;
}

/* Practice lock hint — tooltip on hover; hidden on touch (toast used instead) */
.practice-lock-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(280px, 88vw);
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--tile-border);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-dim);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 5;
}

.practice-lock-hint.hidden {
  display: none !important;
}

@media (hover: none), (pointer: coarse) {
  .practice-lock-hint {
    display: none !important;
  }
}

.toggle-btn--locked {
  opacity: 0.72;
}

.toggle-btn--locked:hover:not(.active) {
  color: var(--text-dim);
}

.support-body {
  margin-bottom: 16px;
}

.support-body .help-text {
  margin: 0 0 10px;
}

.support-body .help-text:last-child {
  margin-bottom: 0;
}

.support-intro {
  margin-bottom: 16px;
}

.support-link {
  display: block;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

.support-dismiss {
  margin-top: 10px;
  width: 100%;
}

.first-support-overlay {
  z-index: 110;
}

.support-overlay {
  z-index: 90;
}

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}

.help-overlay.hidden {
  display: none !important;
}

.help-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--tile-border);
  border-radius: 16px;
  padding: 22px 22px 20px;
  max-width: 340px;
  width: 100%;
  max-height: min(90vh, 520px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.help-panel.support-panel {
  max-width: 400px;
}

@media (min-width: 480px) {
  .support-overlay .help-title {
    white-space: nowrap;
  }
}

.help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  padding: 0;
}

.help-close:hover {
  background: var(--key-bg);
  color: var(--text);
}

.help-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0 36px 14px 0;
  letter-spacing: 0.04em;
}

.feedback-panel {
  max-width: 380px;
}

.feedback-intro {
  margin-bottom: 14px;
}

.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.feedback-form.feedback-form--hidden {
  display: none;
}

.feedback-topics {
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.feedback-legend {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  padding: 0;
}

.feedback-topic {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
  cursor: pointer;
}

.feedback-topic input {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.feedback-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feedback-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.feedback-optional {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.feedback-textarea,
.feedback-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.feedback-textarea:focus,
.feedback-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.feedback-textarea {
  min-height: 88px;
}

.feedback-honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.feedback-submit {
  width: 100%;
  margin-top: 4px;
}

.feedback-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.feedback-success {
  margin: 8px 0 0;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
  font-size: 0.9rem;
  text-align: center;
}

.feedback-success.hidden {
  display: none;
}

/* Desktop: show full feedback form without scrolling inside the panel */
@media (min-width: 640px) and (pointer: fine) {
  .feedback-overlay .feedback-panel {
    max-height: calc(100vh - 48px);
    overflow-y: visible;
    padding: 18px 20px 18px;
  }

  .feedback-intro {
    margin-bottom: 10px;
  }

  .feedback-form {
    gap: 10px;
  }

  .feedback-topics {
    gap: 6px;
  }

  .feedback-topic {
    font-size: 0.85rem;
  }

  .feedback-textarea {
    min-height: 64px;
  }

  .feedback-submit {
    margin-top: 2px;
  }
}

.help-text {
  margin: 0 0 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.help-text--flush {
  margin-bottom: 6px;
}

.help-text strong {
  color: var(--text);
  font-weight: 600;
}

/* Inline chip evoking the in-game Play Melody control (smaller than the real button) */
.help-play-mimic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin: 0 2px;
  padding: 4px 10px;
  background: var(--accent-dim);
  color: white;
  border-radius: 50px;
  font-size: 0.68rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.2;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.help-visuals {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 14px;
}

.help-demo-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.help-demo-row:last-child {
  margin-bottom: 0;
}

/* Same tile styling as the grid; only scale down so five tiles fit in the help panel */
.help-panel .help-demo-row .tile {
  width: 48px;
  height: 48px;
  font-size: 0.95rem;
  flex-shrink: 0;
}

/* Play Section */
.play-section {
  display: flex;
  justify-content: center;
  padding: 16px 16px 8px;
  flex-shrink: 0;
}

.game-hint {
  display: block;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1.4;
  margin: 4px auto 10px;
  padding: 0 14px;
  max-width: min(360px, 94vw);
  opacity: 0;
  transition: opacity 0.5s ease;
  flex-shrink: 0;
  pointer-events: none;
}

.game-hint.game-hint-visible {
  opacity: 1;
}

.game-hint.hidden {
  display: none !important;
}

/* Repeated-wrong-note hint — directly above .grid-container in DOM */
.elim-note-hint {
  display: block;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1.4;
  margin: 4px auto 10px;
  padding: 0 14px;
  max-width: min(360px, 94vw);
  opacity: 0;
  transition: opacity 0.5s ease;
  flex-shrink: 0;
  pointer-events: none;
}

.elim-note-hint.elim-note-hint-visible {
  opacity: 1;
}

.elim-note-hint.hidden {
  display: none !important;
}

.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: var(--accent-dim);
  color: white;
  border: none;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.play-btn:hover {
  background: var(--accent);
  transform: scale(1.03);
}

.play-btn:active {
  transform: scale(0.98);
}

.play-btn.playing {
  animation: pulse 0.6s ease infinite alternate;
}

.play-btn.small {
  padding: 7px 16px;
  font-size: 0.8rem;
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}

/* Grid */
.grid-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  overflow: hidden;
  min-height: 0;
}

.guess-replay-hint {
  position: fixed;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  max-width: min(240px, 92vw);
  padding: 0 10px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.45s ease;
  pointer-events: none;
  text-align: center;
}

.guess-replay-hint-text {
  display: block;
}

.guess-replay-hint-arrow {
  display: block;
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 700;
  color: var(--accent);
}

.guess-replay-hint.guess-replay-hint-visible {
  opacity: 1;
}

.guess-replay-hint.hidden {
  display: none !important;
}

/*
 * Rows: 1fr | tiles (max-content) | 1fr — five tiles stay centred on screen; replay lives
 * only in column 3 and does not shift the tile block (same layout before/after a guess).
 */
.guess-grid {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 100%;
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr max-content 1fr;
  column-gap: 8px;
  align-items: center;
  width: 100%;
  cursor: default;
  position: relative;
  transition: transform 0.22s ease;
  transform-origin: center;
}

.guess-row.guess-row-playback-active {
  transform: scale(1.04);
  z-index: 2;
  animation: pulse 0.6s ease infinite alternate;
}

.guess-row-tiles {
  grid-column: 2;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.replay-wrap {
  grid-column: 3;
  justify-self: start;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: var(--replay-track-width);
  min-width: var(--replay-track-width);
  flex-shrink: 0;
  box-sizing: border-box;
}

.replay-placeholder-inline {
  display: block;
  width: 36px;
  height: 36px;
  visibility: hidden;
  pointer-events: none;
  flex-shrink: 0;
}

.guess-row.playable {
  cursor: pointer;
}

.guess-row.playable:hover .tile {
  opacity: 0.85;
}

.row-play-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  background: var(--accent-dim);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 0.55rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.15s;
  padding: 0;
}

.row-play-btn:hover {
  opacity: 1;
  transform: scale(1.12);
}

.row-play-btn.guess-playback-active {
  background: var(--accent);
  opacity: 1;
  transition: transform 0.15s;
  z-index: 1;
}

.row-play-btn.guess-playback-active:hover {
  transform: none;
}

.row-play-btn svg {
  width: 15px;
  height: 15px;
}

.tile {
  width: 56px;
  height: 56px;
  border: 2px solid var(--tile-border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  background: var(--tile-bg);
  transition: border-color 0.15s, transform 0.1s;
  user-select: none;
}

.tile.active-row {
  border-color: var(--tile-filled-border);
}

.tile.filled {
  border-color: var(--text-dim);
  animation: popIn 0.1s ease;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: white;
}

.tile.incorrect {
  background: var(--incorrect);
  border-color: var(--incorrect);
  color: var(--text-dim);
}

.tile.reveal {
  animation: flipReveal 0.5s ease;
}

.tile.tile-repeated-wrong {
  outline: 2px solid rgba(244, 114, 182, 0.95);
  outline-offset: -2px;
  box-shadow: 0 0 0 2px rgba(244, 114, 182, 0.2), 0 0 14px rgba(244, 114, 182, 0.28);
}

@keyframes popIn {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

@keyframes flipReveal {
  0% { transform: scaleY(1); }
  50% { transform: scaleY(0); }
  100% { transform: scaleY(1); }
}

/* Keyboard */
.keyboard-section {
  flex-shrink: 0;
  padding: 8px 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.key-sound-toggle-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.key-sound-toggle-wrap.hidden {
  display: none !important;
}

.key-sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 12px;
  min-height: 24px;
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.key-sound-toggle:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

.key-sound-toggle.is-on {
  color: var(--text);
  border-color: rgba(139, 92, 246, 0.45);
  background: rgba(139, 92, 246, 0.1);
}

.key-sound-toggle__label {
  line-height: 1;
}

.key-sound-toggle__pill {
  position: relative;
  width: 28px;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.key-sound-toggle.is-on .key-sound-toggle__pill {
  background: rgba(139, 92, 246, 0.55);
}

.key-sound-toggle__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}

.key-sound-toggle.is-on .key-sound-toggle__knob {
  transform: translateX(14px);
  background: #fff;
}

.key-sound-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Mode Toggle */
.mode-toggle {
  position: relative;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--tile-border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  padding: 8px 24px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.toggle-btn.active {
  background: var(--accent);
  color: white;
}

.toggle-btn:hover:not(.active) {
  color: var(--text);
}

/* Piano Keyboard */
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.piano-octave-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.piano-octave-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.piano-keys {
  display: flex;
  align-items: flex-start;
}

.piano-key {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-family: inherit;
  border: none;
  transition: filter 0.1s, background 0.1s;
}

button,
.piano-key,
.boss-key,
.action-btn,
.play-btn,
.toggle-btn,
.mode-card {
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

.piano-key.white {
  width: 44px;
  height: 110px;
  background: linear-gradient(180deg, #e4e4ea 0%, #f5f5f8 100%);
  color: #444;
  border: 1px solid #a8a8b4;
  border-radius: 0 0 7px 7px;
  padding-bottom: 10px;
  font-size: 0.82rem;
  z-index: 1;
  margin: 0 1px;
}

.piano-key.white:hover {
  background: linear-gradient(180deg, #d0d0da 0%, #e8e8ee 100%);
}

.piano-key.white:active {
  background: linear-gradient(180deg, #bcbcc8 0%, #dcdce4 100%);
}

.piano-key.black {
  width: 30px;
  height: 70px;
  background: linear-gradient(180deg, #333 0%, #1a1a20 100%);
  color: #bbb;
  border: 1px solid #0a0a0a;
  border-radius: 0 0 4px 4px;
  padding-bottom: 6px;
  font-size: 0.65rem;
  z-index: 2;
  margin: 0 -15px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.5);
}

.piano-key.black:hover {
  background: linear-gradient(180deg, #484850 0%, #2a2a32 100%);
}

.piano-key.black:active {
  background: linear-gradient(180deg, #555 0%, #3a3a42 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.piano-key.high-c-marker {
  border-top: 3px solid var(--accent);
}

/* Beginner / Musician: tall piano row, grey keys (same palette as compact boss keys) */
.keyboard-piano {
  gap: 8px;
}
.keyboard-piano .piano-keys {
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.keyboard-piano .piano-key.white {
  width: 50px;
  height: 122px;
  background: var(--key-bg);
  color: var(--text);
  border: 1px solid var(--tile-border);
  border-radius: 0 0 8px 8px;
  padding-bottom: 12px;
  font-size: 0.8rem;
  margin: 0 2px;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.keyboard-piano .piano-key.white:hover {
  background: var(--key-hover);
}
.keyboard-piano .piano-key.white:active {
  background: #454550;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.25);
}
.keyboard-piano .piano-key.key-tap {
  animation: keyTapPop 0.24s ease-out;
  background: #454550;
  box-shadow:
    0 0 0 1px rgba(139, 92, 246, 0.45),
    0 2px 12px rgba(139, 92, 246, 0.18);
}

/* Boss Compact Keyboard */
.keyboard.boss-compact {
  gap: 4px;
}

.boss-row {
  display: flex;
  gap: 3px;
  align-items: center;
}

.boss-row-label {
  width: 18px;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
}

.boss-key {
  min-width: 28px;
  height: 32px;
  border: none;
  border-radius: 5px;
  background: var(--key-bg);
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  padding: 0 4px;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.boss-key:hover {
  background: var(--key-hover);
}

.boss-key:active {
  background: #454550;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.25);
}

.boss-key.key-tap {
  animation: keyTapPop 0.24s ease-out;
  background: #454550;
  color: var(--text);
  box-shadow:
    0 0 0 1px rgba(139, 92, 246, 0.45),
    0 2px 12px rgba(139, 92, 246, 0.18);
}

@keyframes keyTapPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.055); }
  100% { transform: scale(1); }
}

.boss-key.sharp.key-tap {
  background: #2f2f3d;
  box-shadow:
    0 0 0 1px rgba(139, 92, 246, 0.35),
    0 2px 10px rgba(139, 92, 246, 0.12);
}

.boss-key.sharp {
  background: #1a1a24;
  color: #aaa;
}

.boss-key.sharp:hover {
  background: #2a2a36;
}

.game-screen-boss .play-section {
  padding: 8px 16px 4px;
}

.game-screen-boss .keyboard-section {
  padding: 6px 12px 12px;
}

/* Result guess count */
.result-guesses {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.result-guesses-count {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
}

.result-guesses-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
}

.action-keys {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.action-btn {
  flex: 1;
  height: 46px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.delete-btn {
  background: var(--key-bg);
  color: var(--text);
  flex: 0.6;
}

.delete-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.submit-btn {
  background: var(--submit-bg);
  color: white;
  letter-spacing: 0.06em;
}

.submit-btn:hover {
  background: var(--submit-hover);
}

.submit-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.submit-btn:disabled:hover {
  background: var(--submit-bg);
}

/* ============ RESULT MODAL ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

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

.modal {
  background: var(--surface);
  border: 1px solid var(--tile-border);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: slideUp 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.result-emoji {
  font-size: 3rem;
  line-height: 1;
  color: var(--text);
}

/* Win: medal disk or ✅. Loss: hollow □ */
.result-emoji.result-emoji-win {
  font-variant-emoji: emoji;
}

.result-emoji.result-emoji-medal {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.35rem;
  line-height: 1;
  vertical-align: middle;
  animation: medalPop 0.55s ease-out;
}

.result-medal-disk {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.25rem;
  height: 3.25rem;
  padding: 0 8px;
  box-sizing: border-box;
  border-radius: 50%;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
  border: 2px solid rgba(0, 0, 0, 0.22);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.result-medal-disk::before {
  content: '';
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

.result-medal-disk__num {
  position: relative;
  z-index: 1;
  line-height: 1;
}

.result-medal-disk--gold {
  background: #8f7318;
}

.result-medal-disk--gold::before {
  background: linear-gradient(165deg, #f0d078 0%, #c9a227 50%, #b89224 100%);
}

.result-medal-disk--silver {
  background: #6b7280;
}

.result-medal-disk--silver::before {
  background: linear-gradient(165deg, #e5e7eb 0%, #9ca3af 50%, #8a9099 100%);
}

.result-medal-disk--platinum {
  background: #5b21b6;
}

.result-medal-disk--platinum::before {
  background: linear-gradient(165deg, #ddd6fe 0%, #8b5cf6 50%, #7c4deb 100%);
}

@keyframes medalPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  55% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-emoji.result-emoji-fail {
  color: #8b8b9e;
  font-size: 2.75rem;
  line-height: 1;
}

.result-badge {
  font-size: 1.75rem;
  line-height: 1;
}
.result-badge.hidden {
  display: none;
}
.result-badge.badge-won {
  animation: badgeWon 0.6s ease-out;
}
@keyframes badgeWon {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.35);
    opacity: 1;
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-title {
  font-size: 1.5rem;
  font-weight: 800;
}

.result-message {
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

.boss-unlock-overlay {
  z-index: 95;
}

.boss-unlock-panel {
  max-width: 360px;
}

.boss-unlock-card {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  text-align: center;
  background: linear-gradient(
    135deg,
    rgba(251, 191, 36, 0.14) 0%,
    rgba(139, 92, 246, 0.18) 55%,
    rgba(232, 121, 249, 0.12) 100%
  );
  border: 1px solid rgba(251, 191, 36, 0.45);
  box-shadow: 0 0 24px rgba(139, 92, 246, 0.15);
  animation: bossUnlockPop 0.55s ease-out;
  margin-bottom: 16px;
}

.boss-unlock-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 6px;
}

.boss-unlock-text {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-dim);
  margin: 0;
}

#boss-unlock-dismiss-btn {
  width: 100%;
}

@keyframes bossUnlockPop {
  0% {
    transform: scale(0.92);
    opacity: 0;
  }
  60% {
    transform: scale(1.02);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-melody {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--tile-bg);
  border-radius: var(--radius-lg);
  width: 100%;
}

.result-melody-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.result-notes {
  display: flex;
  gap: 8px;
}

.result-note {
  width: 46px;
  height: 46px;
  background: var(--correct);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: white;
}

.result-stats {
  display: flex;
  gap: 40px;
  padding: 8px 0;
}

.next-puzzle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.countdown {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.primary-btn.secondary {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--tile-border);
}
.primary-btn.secondary:hover {
  background: var(--key-bg);
  border-color: var(--text-dim);
}

/* ============ TOAST ============ */

.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 200;
  animation: toastIn 0.3s ease;
  pointer-events: none;
}

.toast.hidden {
  display: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ RESPONSIVE ============ */

/* Phones / narrow width: roomier mode menu; cards sit lower like pre-logo layout */
@media (max-width: 599px) {
  #mode-screen .mode-content {
    gap: 20px;
    padding: 16px 18px 22px;
    padding-top: max(14px, env(safe-area-inset-top, 0px));
  }

  #mode-screen .mode-cards {
    margin-top: auto;
  }
}

@media (max-width: 400px) {
  .tile {
    width: 48px;
    height: 48px;
    font-size: 0.95rem;
  }

  .keyboard-piano .piano-key.white {
    width: 42px;
    height: 108px;
    font-size: 0.74rem;
    padding-bottom: 10px;
    margin: 0 1px;
  }

  .piano-key.white {
    width: 36px;
    height: 90px;
    font-size: 0.72rem;
    padding-bottom: 8px;
  }

  .piano-key.black {
    width: 24px;
    height: 56px;
    font-size: 0.58rem;
    margin: 0 -12px;
  }

  #mode-screen .mode-content {
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: 20px;
  }

  .logo {
    font-size: 1.65rem;
  }

  .brand-lockup {
    margin-bottom: -14px;
  }

  .logo-mark {
    max-height: 62px;
    max-width: min(100%, 97px);
    margin-top: -3px;
  }

  .tagline {
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.25;
    color: #d8d8e4;
    margin-top: -4px;
  }

  .mode-cards {
    gap: 10px;
  }

  .mode-card {
    padding: 14px 16px;
  }

  .mode-card-streak {
    top: 40px;
    right: 14px;
    max-width: 46%;
  }

  .mode-card-streak-current {
    font-size: 0.58rem;
  }

  .mode-card-streak-best {
    font-size: 0.72rem;
  }

  .modal {
    padding: 24px 20px;
  }

  .guess-grid {
    gap: 6px;
  }

  .guess-row {
    column-gap: 6px;
  }

  .guess-row-tiles {
    gap: 6px;
  }
}

@media (max-width: 599px) {
  .guess-grid {
    transform: translateX(10px);
  }
}

@media (min-width: 600px) {
  .tile {
    width: 64px;
    height: 64px;
    font-size: 1.2rem;
  }

  .keyboard-piano .piano-key.white {
    width: 56px;
    height: 128px;
    font-size: 0.88rem;
  }

  .piano-key.white {
    width: 50px;
    height: 120px;
    font-size: 0.9rem;
  }

  .piano-key.black {
    width: 34px;
    height: 76px;
    margin: 0 -17px;
    font-size: 0.72rem;
  }
}
