.melody-page {
  --melody-ink: #252921;
  --melody-paper: #f5f0dc;
  --melody-pink: #e8b8c8;
  --melody-dark: #34322e;
  text-align: center;
}

.melody-page [hidden] {
  display: none !important;
}

.melody-stage {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 112px 20px 36px;
}

.melody-heading {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(100%, 1120px);
  margin-bottom: 26px;
}

.melody-heading h1 {
  margin: 0;
  font-size: clamp(40px, 7vw, 68px);
}

.melody-intro {
  max-width: 82ch;
  margin: auto 0 0;
  padding-top: 26px;
  font-size: clamp(15px, 2.4vw, 19px);
  line-height: 1.6;
}

.melody-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-areas: "game player";
  align-items: start;
  gap: 22px;
  width: min(100%, 1120px);
}

.melody-card {
  grid-area: game;
  min-width: 0;
  width: 100%;
  padding: clamp(18px, 2.5vw, 28px);
  border: 2px solid var(--melody-ink);
  border-radius: 3px;
  background: var(--melody-paper);
  box-shadow: 6px 6px 0 var(--melody-ink);
}

.player-sidebar {
  grid-area: player;
  display: grid;
  gap: 22px;
  min-width: 0;
}

.song-library {
  min-width: 0;
  padding: 20px;
  border: 2px solid var(--melody-ink);
  border-radius: 3px;
  background: var(--melody-paper);
  box-shadow: 6px 6px 0 var(--melody-ink);
  text-align: left;
}

.song-library h2 { font-weight: 400; }

.song-list { display: grid; gap: 10px; }

.song-list-button {
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid var(--melody-ink);
  background: #fffdf1;
  color: var(--melody-ink);
  font: bold 14px/1.3 "Courier New", Courier, monospace;
  cursor: pointer;
  touch-action: manipulation;
  text-align: left;
}

.cue-label {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.game-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 2px solid var(--melody-ink);
  border-radius: 3px;
  background: var(--melody-paper);
  box-shadow: 3px 3px 0 var(--melody-ink);
  color: var(--melody-ink);
  font: bold 14px/1.35 "Courier New", Courier, monospace;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.primary-action { background: #fffdf1; }

.song-player {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 12px;
  align-items: center;
  margin-top: 0;
  padding: 16px;
  border: 2px solid var(--melody-ink);
  background: #fffdf1;
  box-shadow: 3px 3px 0 var(--melody-ink);
  text-align: center;
}

.song-player-art {
  width: 72px;
  height: 72px;
  overflow: hidden;
  border: 1px solid var(--melody-ink);
  background: var(--melody-pink);
}

.song-player-art img { display: block; width: 100%; height: 100%; object-fit: cover; }

.song-player-main { min-width: 0; width: 100%; }

.song-player-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.song-player-heading p { margin: 0; }

.song-player-artist {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.song-player-title {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
}

.song-player-tag {
  padding: 3px 6px;
  border: 1px solid var(--melody-ink);
  font-size: 10px;
  line-height: 1.3;
  white-space: nowrap;
}

.song-player-controls {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.song-play-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--melody-ink);
  border-radius: 50%;
  background: var(--melody-pink);
  color: var(--melody-ink);
  font: bold 18px/1 "Courier New", Courier, monospace;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 140ms ease, background-color 140ms ease;
}

.song-timeline { min-width: 0; }

.song-seek {
  display: block;
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  touch-action: auto;
}

.song-seek:disabled { cursor: default; }

.song-seek::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid var(--melody-ink);
  background: linear-gradient(to right, var(--melody-pink) var(--seek-progress, 0%), #e7e0c7 var(--seek-progress, 0%));
}

.song-seek::-moz-range-track {
  height: 8px;
  border: 1px solid var(--melody-ink);
  background: linear-gradient(to right, var(--melody-pink) var(--seek-progress, 0%), #e7e0c7 var(--seek-progress, 0%));
}

.song-seek::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -4px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--melody-ink);
  border-radius: 50%;
  background: #fffdf1;
}

.song-seek::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 2px solid var(--melody-ink);
  border-radius: 50%;
  background: #fffdf1;
}

.song-time {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.song-play-button:focus-visible,
.song-seek:focus-visible {
  outline: 3px solid var(--melody-ink);
  outline-offset: 3px;
}

.song-play-button:active { transform: translate(1px, 1px); }

@media (hover: hover) and (pointer: fine) {
  .song-play-button:hover { background: #fffdf1; }
}

.game-status {
  min-height: 1.5em;
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
}

.note-keyboard {
  position: relative;
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  width: 100%;
  height: 170px;
  margin: 0 auto;
}

.keyboard-frame { width: 100%; padding-bottom: 6px; }

.octave-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  font-weight: 700;
}

.octave-shift { min-width: 44px; font-size: 20px; }
.octave-shift:disabled { opacity: .45; cursor: default; box-shadow: none; }

.note-key {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 8px 2px;
  border: 2px solid var(--melody-ink);
  border-radius: 0 0 3px 3px;
  color: var(--melody-ink);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.note-key::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  pointer-events: none;
}

.note-key[data-face="a"]::before { background-image: url("/arcade/melodie/assets/faces/face-a.jpg"); }
.note-key[data-face="b"]::before { background-image: url("/arcade/melodie/assets/faces/face-b.jpg"); }
.note-key[data-face="c"]::before { background-image: url("/arcade/melodie/assets/faces/face-c.jpg"); }

.note-key > span { position: relative; z-index: 1; }

.note-key--white {
  grid-row: 1;
  justify-content: flex-end;
  padding-bottom: 14px;
  background: #fffdf4;
  box-shadow: inset 0 -5px 0 #d2cbbb;
}

.note-key--white::before {
  filter: grayscale(1) brightness(1.25);
  opacity: .32;
}

.note-key--black {
  position: absolute;
  z-index: 1;
  top: 0;
  width: 4.8%;
  height: 60%;
  margin-left: -2.4%;
  justify-content: flex-end;
  padding-bottom: 8px;
  background: var(--melody-dark);
  color: #fffdf4;
  box-shadow: 2px 3px 0 #171715;
}

.note-key--black::before {
  filter: grayscale(1) invert(1) brightness(.75) contrast(1.2);
  opacity: .55;
}

.note-name {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(12px, 2vw, 17px);
  font-weight: 700;
}

.note-octave {
  display: block;
  font-size: 11px;
  line-height: 1.2;
  opacity: .8;
}

.note-key--black .note-name { font-size: 10px; }
.note-key--black .note-octave { font-size: 9px; }

.completion-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: min(440px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  margin: auto;
  padding: 20px 16px;
  border: 2px solid var(--melody-ink);
  background: #efe5c9;
  color: var(--melody-ink);
  box-shadow: 6px 6px 0 var(--melody-ink);
}

.completion-card:not([open]) { display: none; }
.completion-card::backdrop { background: rgb(20 20 20 / 70%); }
.completion-card.is-celebrating { animation: prize-pop 800ms ease-out both; }

.farbe-call { gap: 18px; padding: 28px; }
.farbe-call > .ringing-phone { display: block; }
.ringing-phone { animation: phone-ring 600ms ease-in-out infinite; }
.phone-cursor { display: none; position: fixed; z-index: 10; width: 48px; height: 48px; pointer-events: none; transform: translate(-50%, -50%); }
.phone-cursor img { display: block; }

@media (hover: hover) and (pointer: fine) {
  .melody-page.phone-ringing.phone-pointer-ready,
  .melody-page.phone-ringing.phone-pointer-ready * { cursor: none !important; }
  .melody-page.phone-ringing .phone-cursor.has-position { display: block; }
}

@keyframes phone-ring {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}

.completion-flash {
  position: absolute;
  z-index: 3;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.completion-card.is-celebrating .completion-flash { animation: prize-flash 2200ms ease-out both; }

.completion-sparkles { position: absolute; z-index: 2; inset: 0; pointer-events: none; }
.completion-sparkles span {
  position: absolute;
  color: #c72f5c;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1;
  opacity: .75;
  filter: drop-shadow(0 0 4px #fff);
}
.completion-card.is-celebrating .completion-sparkles span {
  animation: prize-sparkle 1400ms ease-in-out infinite alternate;
  animation-delay: var(--sparkle-delay);
}
.completion-sparkles span:nth-child(1) { top: 8px; left: 8px; --sparkle-delay: -200ms; }
.completion-sparkles span:nth-child(2) { top: 12px; right: 8px; --sparkle-delay: -950ms; }
.completion-sparkles span:nth-child(3) { bottom: 8px; left: 8px; --sparkle-delay: -500ms; }
.completion-sparkles span:nth-child(4) { bottom: 8px; right: 8px; --sparkle-delay: -1200ms; }
.completion-sparkles span:nth-child(5) { top: 33%; left: 5px; --sparkle-delay: -750ms; }
.completion-sparkles span:nth-child(6) { top: 42%; right: 5px; --sparkle-delay: -350ms; }
.completion-sparkles span:nth-child(7) { bottom: 28%; left: 12px; --sparkle-delay: -1100ms; }
.completion-sparkles span:nth-child(8) { bottom: 24%; right: 12px; --sparkle-delay: -100ms; }
.completion-sparkles span:nth-child(even) { color: #a46b00; }

@keyframes prize-pop {
  0% { opacity: 0; transform: scale(.88); }
  55% { opacity: 1; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes prize-flash {
  0% { opacity: 0; }
  12% { opacity: .95; }
  30% { opacity: 0; }
  47% { opacity: .82; }
  67%, 100% { opacity: 0; }
}

@keyframes prize-sparkle {
  0% { opacity: .35; transform: translateY(3px) scale(.65) rotate(-25deg); }
  50% { opacity: 1; transform: translateY(-4px) scale(1.35) rotate(12deg); }
  100% { opacity: .55; transform: translateY(1px) scale(.85) rotate(25deg); }
}

.completion-card h2,
.completion-card p { margin: 0; }

.completion-card h2 { max-width: 25ch; font-size: clamp(24px, 4vw, 32px); }

.completion-card p {
  max-width: 60ch;
  font-size: 14px;
  line-height: 1.6;
}

.completion-link { margin-top: 4px; }

.note-key:focus-visible,
.game-action:focus-visible,
.song-list-button:focus-visible {
  outline: 3px solid var(--melody-ink);
  outline-offset: 4px;
}

.note-key:focus-visible { z-index: 2; }

.note-key.is-pressed { transform: translateY(1px); }

.game-action:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--melody-ink);
}

@media (hover: hover) and (pointer: fine) {
  .note-key:hover { transform: translateY(-1px); }
  .game-action:not(:disabled):hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 5px 0 var(--melody-ink);
  }

  .note-key--black:hover { background: #4a4741; }
  .note-key--white:hover,
  .game-action:not(:disabled):hover { background-color: var(--melody-pink); }
  .song-list-button:hover { background: #e7e0c7; }
}

@media (max-width: 760px) {
  .melody-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "game" "player"; }
  .song-player { grid-template-columns: 72px minmax(0, 1fr); justify-items: stretch; text-align: left; }
  .song-player-heading { flex-direction: row; align-items: start; justify-content: space-between; }
}

@media (max-width: 640px) {
  .melody-stage { padding: 104px 8px 28px; }
  .melody-card { padding: 14px 8px; }
  .note-keyboard { height: 142px; }
  .note-name { font-size: clamp(11px, 3.5vw, 15px); }
  .note-octave { font-size: 10px; }
  .note-key--black .note-name,
  .note-key--black .note-octave { display: none; }
  .song-player { grid-template-columns: 54px minmax(0, 1fr); gap: 12px; padding: 12px; }
  .song-player-art { width: 54px; height: 54px; }
  .song-player-tag { display: none; }
}

@media (max-width: 360px) {
  .song-player { grid-template-columns: minmax(0, 1fr); }
  .song-player-art { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .note-key,
  .game-action,
  .song-play-button { transition: none; }
  .note-key:hover,
  .note-key:active,
  .game-action:hover,
  .game-action:active { transform: none; }
  .completion-card.is-celebrating,
  .completion-card.is-celebrating .completion-sparkles span,
  .completion-card.is-celebrating .completion-flash,
  .ringing-phone { animation: none; }
  .completion-flash { display: none; }
  .completion-sparkles span { opacity: 1; filter: none; }
}
