/* Piano: home tile, the toy piano (keys, glow, the strip of notes) and the song list.
   Shared look lives in css/style.css. */

/* ---------- home tile ---------- */
#tile-piano .tile-art { display: flex; align-items: center; justify-content: center; }
#tile-piano .piano-tile-svg { width: 92px; height: 92px; display: block; }

/* ---------- header ---------- */
.piano-hud { gap: 10px; }
.piano-hud .hud-mid { min-width: 0; }
/* the title and its line are the shell's bar (.bar-title, css/style.css) */
.bar-spacer[hidden] { display: none; }
.btn.piano-pill {
  flex: none;
  min-width: 60px;
  height: 60px;
  padding: 0 16px 0 12px;
  gap: 6px;
  border-radius: 20px;
  background: #fff;
  color: var(--primary);
  font-size: 1.05rem;
  font-weight: 900;
  box-shadow: 0 5px 0 #c9c1ff, 0 8px 16px rgba(59, 47, 168, 0.15);
}
.btn.piano-pill:active { box-shadow: 0 1px 0 #c9c1ff; }
.btn.piano-pill svg { width: 26px; height: 26px; }
.btn.piano-pill.small { height: var(--bz-target); min-width: 0; padding: 0 16px; font-size: var(--bz-text-m); }

/* ---------- sound off ---------- */
.piano-muted {
  flex: none;
  margin: 2px 12px 0;
  padding: 6px 8px 6px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  font-weight: 800;
  color: var(--ink-soft);
}
.piano-muted[hidden] { display: none; }

/* ---------- playing along: listen, and the notes to come ---------- */
.piano-songbar {
  flex: none;
  width: min(100% - 24px, 760px);
  margin: 2px auto 0;
  padding: 8px 10px 8px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 0 #d6cff7;
}
.piano-songbar[hidden] { display: none; }
#piano-listen { height: 56px; border-radius: 18px; background: var(--bz-accent); color: var(--bz-on-accent); box-shadow: 0 5px 0 var(--bz-accent-dark), 0 8px 16px rgba(217, 102, 63, 0.25); }
#piano-listen:active { box-shadow: 0 1px 0 var(--bz-accent-dark); }
#piano-listen[aria-pressed="true"] { background: var(--primary); box-shadow: 0 5px 0 var(--primary-dark); }
.piano-notes { flex: 1; min-width: 0; }
.piano-strip { height: 42px; display: flex; align-items: center; gap: 6px; padding-left: 4px; overflow: hidden; }
.pnote {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--key);
  border: 3px solid var(--ink);
  transition: opacity 0.15s ease;
}
.pnote.long { width: 38px; }
.pnote.short { width: 18px; height: 18px; }
.pnote.past { opacity: 0.3; width: 14px; height: 14px; border-width: 2px; }
.pnote.now { width: 32px; height: 32px; border-width: 4px; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--gold); margin: 0 6px 0 4px; }
.pnote.now.long { width: 48px; }
.piano-status { margin: 0; min-height: 1.2em; font-size: 0.9rem; font-weight: 800; color: var(--ink-soft); line-height: 1.2; }

/* ---------- the toy piano ---------- */
#piano-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 4px 12px;
}
.piano-body {
  --pad: 5px;
  width: min(100%, 980px);
  height: min(100%, 520px, calc((100vw - 8px) * 1.3));
  display: flex;
  flex-direction: column;
  padding: 0 var(--pad) 8px;
  border-radius: 28px;
  background: linear-gradient(180deg, #6f60ee, var(--primary) 40%);
  box-shadow: 0 8px 0 var(--primary-dark), 0 14px 26px rgba(59, 47, 168, 0.3);
}
.piano-top { flex: none; height: 30px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.piano-top span { width: 12px; height: 12px; border-radius: 999px; background: var(--primary-dark); }
.piano-top span:first-child { background: var(--gold); }
.piano-top span:last-child { background: #ff7ac8; }
.piano-keys {
  position: relative;
  flex: 1;
  min-height: 0;
  --gap: 2px;
  display: flex;
  gap: var(--gap);
  touch-action: none; /* fingers play, they never scroll or zoom */
  -webkit-user-select: none;
  user-select: none;
}
.pkey {
  font: inherit;
  margin: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.pkey:focus-visible { outline: 4px solid var(--bz-focus); outline-offset: 2px; z-index: 3; }
.pkey.white {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  border-radius: 6px 6px 16px 16px;
  background: linear-gradient(180deg, var(--key-hi) 0%, var(--key) 22%, var(--key) 100%);
  box-shadow: inset 0 -10px 0 var(--key-lo), 0 4px 0 var(--primary-dark);
  transition: transform 0.05s ease, box-shadow 0.05s ease, filter 0.05s ease;
}
.pkey.black {
  position: absolute;
  top: 0;
  z-index: 2;
  /* between white key `slot - 1` and `slot`: keys share the width minus their gaps */
  --kw: calc((100% - (var(--whites) - 1) * var(--gap)) / var(--whites));
  left: calc(var(--slot) * (var(--kw) + var(--gap)) - var(--gap) / 2 - var(--kw) * 0.31);
  width: calc(var(--kw) * 0.62);
  height: 56%;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #3d3580, var(--ink) 70%);
  box-shadow: inset 0 -8px 0 #17123f, 0 3px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.pkey.white.down {
  transform: translateY(3px);
  filter: brightness(0.86) saturate(1.15);
  box-shadow: inset 0 -4px 0 var(--key-lo), 0 1px 0 var(--primary-dark);
}
.pkey.black.down { transform: translateY(2px); box-shadow: inset 0 -3px 0 #17123f; background: #4a4196; }

/* the mark at the bottom of a key: shows on the key to press, and while the song plays itself */
.pkey-mark {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: min(70%, 34px);
  aspect-ratio: 1;
  transform: translateX(-50%) scale(0);
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.45);
  transition: transform 0.15s ease;
  pointer-events: none;
}
.pkey.black .pkey-mark { bottom: 12px; width: min(70%, 22px); }
.pkey.glow { z-index: 1; animation: piano-glow 1s ease-in-out infinite; }
.pkey.black.glow { z-index: 2; }
.pkey.glow .pkey-mark { transform: translateX(-50%) scale(1); animation: piano-bob 1s ease-in-out infinite; }
.pkey.white.glow { box-shadow: inset 0 -10px 0 var(--key-lo), 0 4px 0 var(--primary-dark), 0 0 0 4px #fff, 0 0 18px 6px #fff; }
.pkey.lit { filter: brightness(1.15); }
.pkey.white.lit {
  z-index: 1;
  transform: translateY(3px);
  background: var(--key-hi);
  box-shadow: inset 0 -6px 0 var(--key-lo), 0 0 0 4px var(--gold), 0 0 22px 8px #fff;
}
.pkey.black.lit { transform: translateY(2px); background: #6a5fd0; box-shadow: 0 0 0 3px var(--gold); }
.pkey.lit .pkey-mark { transform: translateX(-50%) scale(1); }
.pkey.nudge { animation: piano-nudge 0.4s ease-in-out 2; }
.piano-keys.listening .pkey.glow { animation: none; }

@keyframes piano-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}
@keyframes piano-bob {
  0%, 100% { transform: translateX(-50%) translateY(0) scale(1); }
  50% { transform: translateX(-50%) translateY(-8px) scale(1.1); }
}
@keyframes piano-nudge {
  0%, 100% { translate: 0 0; }
  25% { translate: -5px 0; }
  75% { translate: 5px 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pkey.glow, .pkey.glow .pkey-mark, .pkey.nudge { animation: none; }
}

/* ---------- the 7-10 piano: two octaves, a window on them when they do not fit ---------- */
.piano-view { position: relative; flex: 1; min-height: 0; display: flex; }
/* clip, not hidden: a hidden overflow can still be scrolled, and the browser scrolls it to show a
   key that gets focus on a tap, which would put the keys out of step with the window */
.piano-body.windowed .piano-view { overflow: hidden; overflow: clip; }
.piano-body.windowed .piano-keys { flex: none; }
.piano-body.windowed .piano-top { display: none; }
.piano-keys.sliding { transition: transform 0.25s ease; }
@media (prefers-reduced-motion: reduce) { .piano-keys.sliding { transition: none; } }
/* the black keys a little wider than on the toy piano: songs use them now */
.piano-body.big .pkey.black {
  left: calc(var(--slot) * (var(--kw) + var(--gap)) - var(--gap) / 2 - var(--kw) * 0.34);
  width: calc(var(--kw) * 0.68);
}
.pkey-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  text-align: center;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1;
  color: rgba(43, 35, 112, 0.62);
  pointer-events: none;
}
.piano-body.big .pkey.white .pkey-mark { bottom: 40px; }
/* the map of the whole keyboard: a finger on it moves the window */
.piano-map {
  flex: none;
  position: relative;
  height: 40px;
  margin: 8px 2px 8px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--primary-dark);
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.piano-map[hidden] { display: none; }
.piano-map:focus-visible { outline: 4px solid var(--bz-focus); outline-offset: 2px; }
.piano-map svg { width: 100%; height: 100%; display: block; }
.piano-map-frame {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 4px solid #fff;
  border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(26, 18, 86, 0.5);
  transition: left 0.25s ease;
  pointer-events: none;
}
.piano-turn {
  flex: none;
  margin: 2px 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink-soft);
  text-align: center;
}
.piano-turn[hidden] { display: none; }
.piano-turn svg { flex: none; width: 26px; height: 26px; color: var(--primary); }
/* the notes to come: higher on the strip the higher they sound; a black key's note is dark */
.piano-strip.big { height: 52px; }
.piano-strip.big .pnote { translate: 0 var(--lift, 0px); }
.pnote.sharp { background: radial-gradient(circle, #fff 0 26%, var(--ink) 30%); }

/* ---------- the song list: the shell's segments and option cards (css/style.css) ---------- */
.piano-levels { margin: 0 0 var(--bz-space-4); }
.piano-songlist .option-card.wide .option-art { width: 76px; height: 56px; }

/* ---------- small and sideways screens ---------- */
@media (max-width: 360px) {
  .btn.piano-pill { padding: 0 12px 0 10px; font-size: 0.95rem; }
  #piano-listen { padding: 0 14px; }
  #piano-listen span { display: none; } /* the play sign says it; the strip gets the room */
  .piano-body { --pad: 3px; border-radius: 22px; }
  #piano-stage { padding-inline: 3px; }
}
/* short sideways phones: the bar and the notes share one row, the keys get the rest */
@media (orientation: landscape) and (max-height: 520px) {
  #screen-piano.active {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .piano-hud { grid-column: 1; grid-row: 1; padding: 6px 8px 2px 12px; }
  #screen-piano[data-mode="free"] .piano-hud { grid-column: 1 / 3; }
  .piano-hud .btn.icon, .btn.piano-pill, #piano-listen { height: 50px; }
  .piano-hud .btn.icon { width: 50px; }
  .piano-hud .hud-mid { flex: 1 1 auto; max-width: 40vw; }
  #screen-piano[data-mode="free"] .piano-hud .hud-mid { max-width: none; }
  .piano-hud .bar-spacer { display: none; }
  .piano-hud .piano-title { font-size: var(--bz-text-l); }
  .piano-songbar { grid-column: 2; grid-row: 1; width: auto; margin: 6px 12px 0 0; padding: 4px 8px 4px 4px; align-self: center; }
  .piano-strip { height: 36px; }
  .piano-status { display: none; }
  .piano-muted { grid-column: 1 / 3; grid-row: 2; }
  #piano-stage { grid-column: 1 / 3; grid-row: 3; padding: 6px 6px 8px; }
  .piano-body { --pad: 8px; }
  .piano-keys { --gap: 3px; }
  .piano-body { height: 100%; }
  .piano-top { height: 18px; }
  .piano-top span { width: 9px; height: 9px; }
  .pkey-mark { bottom: 14px; }
  .piano-body.big .pkey.white .pkey-mark { bottom: 34px; }
  .pkey-name { bottom: 10px; }
  .piano-map { height: 32px; margin: 4px 2px 6px; }
}
