/* piano/piano.css: the Piano's layout. Page parts (header, buttons, windows,
 * footer) come from shared/ui/page.css.
 * Everything lives in #stage, which piano.js sizes to the window, or turns
 * sideways on an upright phone (body.turned; body.flipped turns it the other
 * way round). body.compact: a short stage (a sideways phone): no title or
 * footer, the About and Settings buttons in the bar, the footer links beside
 * the scroll bar. Sizes in compact are plain px, since vw/vh would measure
 * the upright screen when the stage is turned.
 */

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { min-height: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* The safe areas (notch, home bar) follow the turn: on an upright phone the
   screen's top edge is the stage's left edge. */
#stage {
  position: fixed; top: 0; left: 0; overflow: hidden; container-type: size;
  --safe-t: env(safe-area-inset-top); --safe-r: env(safe-area-inset-right);
  --safe-b: env(safe-area-inset-bottom); --safe-l: env(safe-area-inset-left);
}
body.turned #stage {
  transform-origin: 0 0; transform: rotate(90deg) translateY(-100%);
  --safe-t: env(safe-area-inset-right); --safe-r: env(safe-area-inset-bottom);
  --safe-b: env(safe-area-inset-left); --safe-l: env(safe-area-inset-top);
}
body.turned.flipped #stage {
  transform: rotate(-90deg) translateX(-100%);
  --safe-t: env(safe-area-inset-left); --safe-r: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-right); --safe-l: env(safe-area-inset-bottom);
}
/* Thin theme frames on phones and short windows, so they don't eat the keys. */
body.phone, body.compact { --fx: min(var(--frame-sides), 8px); --fy-top: min(var(--frame-top), 8px); --fy-bottom: min(var(--frame-bottom), 8px); }
.centered-modal { width: min(400px, calc(100cqw - 32px)); max-height: calc(100cqh - 24px); }

.piano-page {
  position: absolute; inset: 0; max-width: none; min-height: 0; gap: 10px;
  padding: calc(var(--fy-top) + 12px + var(--safe-t)) calc(var(--fx) + 16px + var(--safe-r))
           calc(var(--fy-bottom) + 12px + var(--safe-b)) calc(var(--fx) + 16px + var(--safe-l));
}
.piano-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 12px; }

/* --- The bar: chord name and controls --- */
.pbar { position: relative; z-index: 5; display: flex; align-items: center; gap: 12px 20px; }
.readout { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 16px; opacity: 0.8; transition: opacity 1.5s ease-out; }
.readout.lit { opacity: 1; transition: none; }
.chord-big { flex: none; font-family: var(--font-display); font-size: clamp(56px, 7vw, 96px); font-weight: 800; letter-spacing: -0.02em; line-height: 1; white-space: nowrap; color: var(--color-title); }
.chord-big .acc { font-size: 0.6em; position: relative; top: -0.55em; }
.chord-qual { font-size: 0.55em; color: var(--color-right); margin-left: 0.06em; }
.chord-qual .acc { font-size: 0.75em; top: -0.35em; }
.chord-lines { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chord-lines > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.chord-words { font-size: 18px; font-weight: 700; }
.chord-notes { font-size: 15px; letter-spacing: 0.02em; color: color-mix(in srgb, var(--color-text) 82%, transparent); }
.chord-also { font-size: 14px; color: var(--color-right); }

/* The controls, one row on the right: how a key sounds, then the sound. The
   note names live in Settings. On phones Home starts the bar, well away from
   About and Settings at its end, so a thumb can't hit the wrong one. */
.controls { flex: none; margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sound-group { flex: none; width: 190px; }
.bar-home, .bar-icons { display: none; }
.bar-icons { flex: none; gap: 8px; margin-left: 4px; }
a.icon-btn { box-sizing: border-box; }

/* A segmented switch (the mode, and the name settings): 44 px tall, its border included. */
.seg { display: flex; box-sizing: border-box; height: 44px; border: var(--border-width) solid var(--border-panel); border-radius: var(--radius-control); overflow: hidden; }
.seg button {
  font-family: var(--font-main); font-weight: 600; font-size: 14px; line-height: 1.15;
  height: 100%; padding: 0 14px; color: var(--color-btn-text); background: var(--color-panel); border: 0; cursor: pointer;
  touch-action: manipulation; transition: background 0.15s, color 0.15s;
}
.seg button + button { border-left: 1px solid var(--border-panel); }
.seg button[aria-pressed="true"] { background: var(--color-left); color: var(--color-text-pinched); }
:is(.seg button, .track):focus-visible { outline: 2px solid var(--color-right); outline-offset: 2px; }

/* What the chosen mode does, in one line under the bar. */
.mode-hint { flex: none; margin: 0; font-size: 14px; line-height: 1.3; color: var(--color-text-inactive); text-wrap: balance; }
.mode-hint strong { color: var(--color-text); font-weight: 700; }

/* --- The keys (positions and --kw, the white key width, set in piano.js) --- */
.keys-wrap { position: relative; flex: 1 1 auto; min-height: 110px; max-height: 380px; overflow: hidden; touch-action: none; }
.kb { position: absolute; top: 0; left: 0; height: 100%; will-change: transform; }
.key {
  position: absolute; top: 0; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  font-family: var(--font-main); font-weight: 700; line-height: 1; cursor: pointer; overflow: hidden;
}
.key.white {
  height: 100%; padding-bottom: 10px; border-radius: 0 0 7px 7px; background: var(--key-white); color: var(--key-white-text);
  box-shadow: inset -1px 0 0 var(--key-edge), inset 0 10px 10px -10px rgba(0, 0, 0, 0.45);
  font-size: clamp(9px, calc(var(--kw) * 0.22), 16px);
}
.key.black {
  height: 60%; z-index: 2; padding-bottom: 7px; border-radius: 0 0 5px 5px; background: var(--key-black); color: var(--key-black-text);
  box-shadow: 0 0 0 1px var(--key-black-edge), 0 4px 7px rgba(0, 0, 0, 0.55);
  font-size: clamp(7px, calc(var(--kw) * 0.17), 12px);
}
.key.middle-c { box-shadow: inset -1px 0 0 var(--key-edge), inset 0 10px 10px -10px rgba(0, 0, 0, 0.45), inset 0 -5px 0 -1px var(--color-right); }
/* --lit: a sounding key. Ring notes show it as a light that fades with the sound
   (--ring, the fade's length, set in piano.js). */
.key.white { --lit: color-mix(in srgb, var(--color-right) 50%, var(--key-white)); }
.key.black { --lit: color-mix(in srgb, var(--color-right) 70%, var(--key-black)); }
.key.on { background: var(--lit); }
.key.black.on { color: var(--color-text-pinched); }
.key > span { position: relative; z-index: 1; }
.key::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--lit); opacity: 0; pointer-events: none; }
.key.ring::after { animation: ring-fade var(--ring, 2s) cubic-bezier(0.2, 0.6, 0.4, 1) forwards; }
@keyframes ring-fade { from { opacity: 1; } to { opacity: 0; } }
.key.white.drone { background: color-mix(in srgb, var(--color-right) 25%, var(--key-white)); }
.key.black.drone { background: color-mix(in srgb, var(--color-right) 40%, var(--key-black)); }
.key.drone::before {
  content: ''; position: absolute; top: 10px; left: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%;
  background: var(--color-right); box-shadow: 0 0 0 2px var(--key-black-text), 0 0 10px var(--color-right);
}
.kname { white-space: nowrap; }
.kletter { position: absolute; top: 22px; font-size: 11px; opacity: 0.9; }
.key.black .kletter { top: 20px; font-size: 10px; }
.loading {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4; margin: 0; padding: 8px 12px; text-align: center; pointer-events: none;
  font-size: 13px; font-weight: 700; background: var(--bg-overlay); color: var(--color-text);
}

/* --- The scroll bar --- */
.scrub-row { flex: none; display: flex; align-items: center; gap: 10px; height: 40px; }
.track {
  position: relative; flex: 1; align-self: stretch; box-sizing: border-box; border: var(--border-width) solid var(--border-panel); border-radius: var(--radius-control);
  background: var(--color-panel); touch-action: none; overflow: hidden; cursor: pointer;
}
.thumb {
  position: absolute; top: 3px; bottom: 3px; box-sizing: border-box; border-radius: var(--radius-control); pointer-events: none;
  background: color-mix(in srgb, var(--color-right) 28%, transparent); border: 1px solid var(--color-right);
}
.tick { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: var(--color-text-inactive); pointer-events: none; }
.tick.here { color: var(--color-text); }
.scrub-link { display: none; padding-block: 15px; margin-block: -15px; font-size: 11px; font-weight: 700; text-decoration: none; white-space: nowrap; line-height: 1.2; }
.designer-link { color: var(--color-right); }

/* Settings: one row per setting, the label on the left; two columns on short
   screens (sideways phones), so the window never needs scrolling. */
#settings-modal .setting-row.control-group { flex-direction: row; align-items: center; gap: 12px; }
.settings-grid { display: flex; flex-direction: column; }
#settings-modal .setting-row .custom-select { width: 190px; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper output { min-width: 2ch; text-align: center; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; }
.round-btn.small { width: 44px; height: 44px; font-size: 22px; }
.round-btn:disabled { opacity: 0.4; cursor: default; }
.volume-row { flex-wrap: nowrap; }
.volume-row .range { flex: 1 1 0; width: auto; min-width: 80px; }
#volume-out { min-width: 3.2em; text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 700; }
.flip-row { display: none; }
body.turned .flip-row { display: flex; }

/* Narrow, tall windows: the chord name above the controls. */
body.narrow .pbar { flex-wrap: wrap; }
body.narrow .readout { flex-basis: 100%; }
body.narrow .controls { margin-left: 0; align-items: flex-start; }

/* --- Short stages: sideways phones (and short windows) --- */
body.compact .tool-header, body.compact .tool-footer { display: none; }
body.compact .bar-home { display: inline-flex; }
body.compact .bar-icons { display: flex; }
body.compact .scrub-link { display: block; }
body.compact .piano-page {
  gap: 6px;
  padding: calc(var(--fy-top) + 6px + var(--safe-t)) calc(var(--fx) + 10px + var(--safe-r))
           calc(var(--fy-bottom) + 6px + var(--safe-b)) calc(var(--fx) + 10px + var(--safe-l));
}
/* One 44 px bar instead of two rows and a hint line: the height goes to the keys. */
body.compact .piano-main { position: relative; gap: 8px; justify-content: flex-start; }
body.compact .pbar { flex: none; height: 44px; gap: 12px; }
body.compact .readout { flex: 1 1 auto; gap: 10px; }
body.compact .chord-big { font-size: 38px; }
body.compact .chord-lines { gap: 2px; }
body.compact .chord-lines > div { line-height: 1.2; }
body.compact .chord-words { font-size: 13px; }
body.compact .chord-notes { font-size: 12px; letter-spacing: 0.02em; }
body.compact .chord-also { display: none; }
body.compact .sound-group { width: 132px; }
body.compact .sound-group .custom-select { font-size: 12px; }
/* The mode hint shows for a moment over the top of the keys (piano.js), and
   never catches a tap. */
body.compact .mode-hint {
  position: absolute; z-index: 6; top: 60px; left: 50%; width: max-content; max-width: min(540px, calc(100% - 32px)); box-sizing: border-box;
  padding: 9px 16px; border-radius: var(--radius-control); border: var(--border-width) solid var(--border-panel);
  background: var(--bg-select); color: var(--color-select-text); box-shadow: 0 14px 30px -14px rgba(0, 0, 0, 0.6);
  font-size: 13px; line-height: 1.3; text-align: center; text-wrap: balance; pointer-events: none;
  opacity: 0; transform: translate(-50%, -6px); transition: opacity 0.3s cubic-bezier(0.2, 0.7, 0.2, 1), transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}
body.compact .mode-hint strong { color: inherit; }
body.compact .mode-hint.show { opacity: 1; transform: translate(-50%, 0); }
body.compact .sound-group .select-selected { padding: 0 30px 0 10px; min-height: 44px; box-sizing: border-box; line-height: 1.2; }
body.compact .icon-btn { width: 44px; height: 44px; }
body.compact .icon-btn svg { width: 18px; height: 18px; }
body.compact .seg button { padding: 0 10px; font-size: 13px; }
body.compact .keys-wrap { max-height: none; min-height: 90px; }
body.compact .scrub-row { height: 36px; gap: 8px; }
body.tight .scrub-row { height: 44px; }
body.tight .scrub-row .seg { flex: none; }
body.tight .track { min-width: 120px; }
body.compact .tick { font-size: 10px; }
body.compact #settings-modal { width: min(680px, calc(100cqw - 32px)); padding: 12px 20px; gap: 2px; }
body.compact .settings-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; }
body.compact .settings-grid > .setting-row { border-top: 1px solid color-mix(in srgb, var(--border-panel) 50%, transparent); }
body.compact .settings-grid > .setting-row:nth-child(-n+2) { border-top: 0; }
body.compact #settings-modal .modal-header { padding-bottom: 6px; }
body.compact #settings-modal .setting-row { min-height: 44px; }
body.compact #settings-modal .round-btn.small { width: 44px; height: 44px; }

/* Theme shapes and sizes */
body[data-theme="pink"] .seg button:not([aria-pressed="true"]) { background: var(--color-panel); color: var(--color-left); }
body[data-theme="bw"] .key { border-radius: 0; }
body[data-theme="y2k"] .chord-big, body[data-theme="retro"] .chord-big { text-shadow: 0 0 var(--shadow-blur) color-mix(in srgb, var(--color-left) 60%, transparent); }
/* Rouge: the blush accent vanishes on bone keys, so keys light up cherry. */
body[data-theme="rouge"] .key.white { --lit: color-mix(in srgb, var(--color-left) 55%, var(--key-white)); }
body[data-theme="rouge"] .key.black { --lit: color-mix(in srgb, var(--color-left) 75%, var(--key-black)); }
body[data-theme="rouge"] .key.white.drone { background: color-mix(in srgb, var(--color-left) 22%, var(--key-white)); }
body[data-theme="rouge"] .key.black.drone { background: color-mix(in srgb, var(--color-left) 45%, var(--key-black)); }
body[data-theme="snap"] .key.black.on { color: var(--key-white); }
/* Monochrome: the accent is the key colour, so pressed and drone keys darken
   (or lighten) instead. */
body[data-theme="bw"] .key.white { --lit: color-mix(in srgb, var(--key-black) 38%, var(--key-white)); }
body[data-theme="bw"] .key.white.drone { background: color-mix(in srgb, var(--key-black) 16%, var(--key-white)); }
body[data-theme="bw"] .key.black { --lit: color-mix(in srgb, var(--key-white) 50%, var(--key-black)); }
body[data-theme="bw"] .key.black.on { color: var(--key-white-text); }
body[data-theme="bw"] .key.black.drone { background: color-mix(in srgb, var(--key-white) 25%, var(--key-black)); }
body[data-theme="bw"] .key.white.drone::before { background: var(--key-black); box-shadow: none; }
body[data-theme="bw"] .key.black.drone::before { background: var(--key-white); box-shadow: none; }
