/* 认识五线谱 · Piano — staff on top, one-octave keyboard below, one stacked
   layout for portrait and landscape. brand.css provides the body baseline.
   Pitch colors follow Boomwhackers tuned toward the site palette; the note
   colors themselves are set from app.js (single source of truth there). */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

/* ---------------------------------------------------------- shell layout */

.piano-shell {
  /* leave room for the brand chrome header */
  height: calc(100dvh - 64px);
  display: flex;
  flex-direction: column;
}

.staff-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(4px, 1.5vmin, 14px) clamp(8px, 2vw, 24px);
}

#staff-svg {
  width: 100%;
  height: 100%;
  touch-action: none;          /* taps are notes, not scroll/zoom */
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------- toolbar */

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 18px);
  padding: clamp(6px, 1.5vmin, 12px) 12px;
}

.note-label {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35em;
  min-width: clamp(110px, 18vmin, 160px);
  padding: 0.15em 0.7em;
  background: var(--paper-card);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 3px 0 var(--ink);
  transition: background-color 160ms ease;
}

.note-label-solfege {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(26px, 5vmin, 38px);
  line-height: 1.2;
  color: var(--ink);
}

.note-label-letter {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(14px, 2.4vmin, 20px);
  color: var(--ink-2);
}

@keyframes label-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.note-label.pop { animation: label-pop 220ms ease-out; }

.tool-btn {
  font-family: var(--font-cn-display);
  font-weight: 800;
  font-size: clamp(15px, 2.4vmin, 20px);
  color: var(--ink);
  background: var(--paper-card);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.4em 1em;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 160ms ease;
}
.tool-btn:hover:not(:disabled)  { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.tool-btn:active:not(:disabled) { transform: translateY(2px);  box-shadow: 0 1px 0 var(--ink); }
.tool-btn:disabled { opacity: 0.45; cursor: default; }

/* English copy on the play button reads better in the Latin display font */
#play-btn { font-family: var(--font-display); }

/* circular restart icon-button, same style as chess-pieces' reset */
.reset-btn {
  width: clamp(42px, 7vmin, 52px);
  height: clamp(42px, 7vmin, 52px);
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

/* ---------------------------------------------------------- keyboard */

.keyboard {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  height: clamp(150px, 30vh, 240px);
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 3px solid var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.white-key {
  position: relative;
  flex: 1 1 0;                 /* 8 keys → 12.5% each */
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: clamp(8px, 2vmin, 16px);
  background: var(--key-color, var(--paper-card));
  border-right: 3px solid var(--ink);
  box-shadow: inset 0 -8px 0 rgba(42, 53, 84, 0.14);
  cursor: pointer;
  transition: transform 80ms ease, filter 80ms ease;
}
.white-key:first-child { border-left: 3px solid var(--ink); }
.white-key.active {
  transform: translateY(5px);
  filter: brightness(1.14) saturate(1.15);
  box-shadow: inset 0 -2px 0 rgba(42, 53, 84, 0.14);
}

.key-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(14px, 2.6vmin, 20px);
  line-height: 1;
  color: var(--ink);
  pointer-events: none;
}

.black-key {
  position: absolute;
  top: 0;
  width: 7%;
  height: 58%;
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 0 rgba(42, 53, 84, 0.35);
  z-index: 2;
  cursor: pointer;
}

@keyframes key-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
.black-key.shake { animation: key-shake 160ms ease-in-out; }

/* ---------------------------------------------------------- staff skin */

.staff-line { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.staff-ledger { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.staff-clef { fill: var(--ink); stroke: none; pointer-events: none; }

.staff-hit { fill: transparent; cursor: pointer; }

.staff-note .note-head { stroke: var(--ink); stroke-width: 3; }
.staff-note .note-stem { stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.staff-note {
  cursor: pointer;
  transition: transform 300ms ease;   /* slides when the FIFO queue shifts */
}
.note-inner {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 140ms ease;
}

/* the bounce that pulls a kid's eyes to where the note landed */
@keyframes note-pop {
  0%   { transform: scale(0); }
  55%  { transform: scale(1.4); }
  80%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.staff-note.new .note-inner { animation: note-pop 340ms cubic-bezier(.34, 1.56, .64, 1); }

.staff-note.sounding .note-inner { transform: scale(1.3); }
.staff-note.sounding .note-head {
  filter: drop-shadow(0 0 10px rgba(42, 53, 84, 0.55));
}

/* ---------------------------------------------------------- small screens */

@media (max-width: 480px) {
  .keyboard { height: clamp(130px, 26vh, 200px); }
  #play-btn { padding: 0.35em 0.8em; }
}
