/*
 * All of Notar's styles, in one light theme. Design tokens sit on :root; base rules and the shared pieces (panels,
 * trays, buttons, the menu) come first, then each part of the page, then media queries that retune tokens and
 * layout for medium widths, touch screens, phones, reduced motion and print.
 *
 *   - app.js builds the keyboard and the staff, and shows state through classes (.octave.active and .reach,
 *     .key.struck, .sounding and .held, .held on a length chip and the Dot toggle, .keyboard-frame.fade-start and
 *     .fade-end, .note-group.active and .current, .selection-band, .playhead.shown, .ghost.remove, .status.error),
 *     aria-disabled on Cut, Copy and Paste, and through custom properties: --whites on each octave's keys, --slot
 *     on each black key. Exported images take their styles from here too: app.js reads each element's computed
 *     style into the SVG file, so what is styled here is what an export looks like.
 *   - scripts/icons.mjs takes the icon colours from this file by regex: the --accent token, the .key.black and
 *     .key.white.sounding backgrounds and the .key.sounding box-shadow. Keep those as hex colours.
 *   - This file is part of the precached shell: after editing it, run node scripts/sw-version.mjs.
 */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
	--ink: #1a1a1a;
	--muted: #595966;
	--paper: #fffef8;
	--panel: #fafafa;
	--border: #d2d2f2;
	--border-strong: #9999cc;
	--accent: #3b4a7a;
	--accent-hover: #2d3a63;
	--accent-soft: #eef0fa;
	--region: #e8eaf4;
	--danger: #9b2c2c;
	--danger-soft: #fdf1f1;
	--focus: #3b4a7a;
	--shadow: 0 10px 30px rgba(40, 40, 80, 0.08);
	/* One rhythm for the whole control system: tight inside a group, loose between groups. */
	--gap-in: 0.25rem;
	--gap-between: 1rem;
	--radius: 10px;
	--control-h: 2.75rem; /* 44px — minimum touch target */
	/* Piano keys: white keys never shrink below --white-min; the row scrolls instead. */
	--white-min: 2.5rem;
	--white-h: 8rem;
	--key-gap: 2px;
	--octave-gap: 0.625rem;
	color-scheme: light; /* light only: form controls and scrollbars stay light in OS dark mode too */
}

/* ── Base: reset, touch and iOS behaviour ──────────────────────────────── */
* {
	box-sizing: border-box;
}

/* !important so the attribute beats class display rules: #updateBtn is a .btn, which is display: inline-flex. */
[hidden] {
	display: none !important;
}

/*
 * Rapid taps on the piano keys and transport buttons were triggering
 * double-tap-to-zoom on phones (iOS Safari in particular). `manipulation`
 * disables only double-tap zoom — panning and pinch-to-zoom keep working,
 * so the page stays zoomable for accessibility. It also drops the legacy
 * ~300ms click delay, so fast note entry registers every tap.
 */
html,
body,
button,
a,
input,
select,
textarea,
label,
[role="button"],
.piano,
.piano button,
.transport,
.region,
.btn,
.segmented label,
.staff-scroll,
#staffSvg,
.note-group {
	touch-action: manipulation;
}

button,
[role="button"],
.piano button {
	-webkit-tap-highlight-color: transparent;
}

/* iOS zooms in on focus when a text field's font-size is below 16px. */
input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select,
textarea {
	font-size: max(16px, 1rem);
}

/* No rubber-band bounce or scroll chaining: installed, Notar should feel like an app, not a page. The
 * background matches the page so an edge never shows a different colour. Pinch-zoom stays (accessibility). */
html {
	overscroll-behavior: none;
	background: #f7f7fb;
}

body {
	margin: 0;
	/* viewport-fit=cover: keep content clear of the notch, rounded corners and home indicator. */
	padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
	overscroll-behavior: none;
	font-family: Georgia, "Times New Roman", serif;
	background: linear-gradient(180deg, #ffffff 0%, #f7f7fb 100%);
	color: var(--ink);
	line-height: 1.5;
	min-height: 100vh;
}

a {
	color: var(--accent);
}

/* The page grows with the viewport (up to a wide desktop) so big screens
 * get more staff and more octaves, not more empty margin. */
.page {
	max-width: 92rem;
	margin: 0 auto;
	padding: 2rem clamp(1rem, 2.5vw, 2rem) 3rem;
}

/* ── Header and update hint ────────────────────────────────────────────── */
.hero {
	margin-bottom: 2rem;
}

.hero-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin: 0 0 0.35rem;
}

.hero h1 {
	margin: 0;
	font-size: 2.4rem;
	letter-spacing: -0.02em;
}

.hero p {
	margin: 0;
	color: var(--muted);
	max-width: 38rem;
}

/* A new version is ready (pwa.js; hidden while playing). Quiet: the accent colour, three slow nudges, no modal. */
.update-hint {
	flex: none;
	color: var(--accent);
	font-size: 0.9rem;
}

.update-hint .icon {
	animation: update-nudge 2.4s ease-in-out 3;
}

@keyframes update-nudge {
	0%, 70%, 100% { transform: none; }
	80% { transform: translateY(2px); }
	90% { transform: translateY(-1px); }
}

/* ── Panels ────────────────────────────────────────────────────────────── */
/* min-width: 0 lets a panel, a flex item of .workspace, shrink below its content, so the wide staff and keyboard
 * scroll inside it instead of widening the page. */
.panel {
	background: var(--panel);
	border: 2px solid var(--border);
	border-radius: 12px;
	padding: 1.25rem;
	box-shadow: var(--shadow);
	min-width: 0;
}

/* One control tall, so a heading lines up with any controls beside it (.panel-head, .staff-toolbar). */
.panel h2 {
	margin: 0 0 0.85rem;
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--muted);
	font-weight: 600;
	line-height: var(--control-h);
	height: var(--control-h);
}

/* ── Common region ─────────────────────────────────────────────────────────
 * A region is a soft tinted tray: controls that belong together share one,
 * and nothing else is drawn around them. Same tray everywhere = same meaning. */
.region {
	display: flex;
	align-items: center;
	gap: var(--gap-in);
	padding: var(--gap-in);
	background: var(--region);
	border: 1px solid #d8dae8;
	border-radius: calc(var(--radius) + var(--gap-in)); /* the controls' radius plus the padding: concentric corners */
}

/* ── Buttons: one shape, one height; colour and fill encode role ─────────── */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
	min-height: var(--control-h);
	min-width: var(--control-h);
	padding: 0 1rem;
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1;
	color: var(--ink);
	background: #fff;
	border: 1.5px solid var(--border);
	border-radius: var(--radius);
	cursor: pointer;
	transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.btn .icon {
	width: 1.15rem;
	height: 1.15rem;
	flex: none;
}

.btn:hover {
	border-color: var(--border-strong);
	background: var(--accent-soft);
}

.btn:active {
	transform: translateY(1px);
}

.btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
	transform: none;
}

.btn:disabled:hover {
	background: #fff;
	border-color: var(--border);
}

/* aria-disabled (Cut, Copy, Paste with nothing to act on): looks like :disabled, but stays focusable and pressable,
 * so a press can say what to do first. */
.btn[aria-disabled="true"] {
	opacity: 0.45;
	cursor: default;
}

.btn.quiet[aria-disabled="true"]:hover {
	background: transparent;
	border-color: transparent;
}

/* Primary — the focal point. Only Play gets a solid fill, extra width and weight. */
.btn.primary {
	min-height: 3.25rem;
	padding: 0 1.6rem;
	font-size: 1.05rem;
	color: #fff;
	background: var(--accent);
	border-color: var(--accent);
	box-shadow: 0 4px 14px rgba(59, 74, 122, 0.3);
}

.btn.primary .icon {
	width: 1.3rem;
	height: 1.3rem;
}

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

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

/* Toggle — same shape as its neighbours; "on" borrows the accent so state reads at a glance. */
.btn.toggle[aria-pressed="true"] {
	color: var(--accent);
	background: var(--accent-soft);
	border-color: var(--accent);
	box-shadow: inset 0 0 0 1px var(--accent);
}

.btn.icon-only {
	padding: 0;
}

/* Quiet — secondary actions inside a segmented tray: no outline of their own, the tray is the outline. */
.btn.quiet {
	background: transparent;
	border-color: transparent;
}

.btn.quiet:hover {
	background: #fff;
	border-color: var(--border);
}

/* Destructive — the only red button in the interface. */
.btn.danger {
	color: var(--danger);
}

.btn.danger:hover {
	background: var(--danger-soft);
	border-color: #e2b4b4;
}

/* ── Focus: always visible, same ring on every control ──────────────────── */
.btn:focus-visible,
.key:focus-visible,
.octave-tab:focus-visible,
.segmented input:focus-visible + span,
.menu-item:focus-visible,
input[type="range"]:focus-visible,
a:focus-visible {
	outline: 3px solid var(--focus);
	outline-offset: 2px;
}

/* ── Workspace: one flex flow ──────────────────────────────────────────────
 * Staff and keyboard take full rows; Playback, Edit and Import/Export are
 * three sibling panels that share a row when there is room (similarity:
 * same panel, same heading style; proximity: the gap between them is the
 * same everywhere). */
.workspace {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: 1.25rem;
}

.staff-panel,
.compose-panel {
	flex: 1 1 100%;
}

.playback-panel {
	flex: 3 1 32rem;
}

/* Three labelled actions (Import, Export with its caret, Share): basis enough for them on one row, so where the
 * row is too narrow the panel wraps onto its own instead of squeezing its buttons into each other. */
.file-panel {
	flex: 1 1 22rem;
}

/* Four actions (Undo, Redo, Delete, Clear): basis enough for them on one row. */
.edit-panel {
	flex: 2 1 24rem;
}

.deck h2 {
	margin-bottom: 0.6rem;
}

/* ── Playback: transport tray | mix tray, on one baseline ───────────────── */
.playback-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: var(--gap-between);
}

.transport {
	flex: none;
}

/* Sound takes a row of its own under the transport and the mix: the label, then the three sounds as chips. */
.sound-picker {
	flex: 1 1 100%;
}

/* minmax(0, 1fr): two equal columns, which may shrink below their content's width (plain 1fr may not). */
.mix {
	flex: 1 1 20rem;
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.5rem 1.5rem;
	padding: 0.4rem 1rem;
}

.control {
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 0.1rem;
	min-width: 0;
}

.control-head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 0.5rem;
}

.control label,
.tool-label {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--ink);
}

.control output {
	font-variant-numeric: tabular-nums;
	color: var(--muted);
	font-size: 0.9rem;
}

input[type="range"] {
	width: 100%;
	height: 1.75rem;
	margin: 0;
	accent-color: var(--accent);
	cursor: pointer;
}

/* ── Edit / Import-Export: trays whose buttons share them evenly ───────── */
.actions {
	width: 100%;
}

.actions .btn {
	flex: 1 1 0;
	padding: 0 0.85rem;
}

/* Edit's two trays, history and the clipboard, one above the other: the gap between them is wider than inside
 * either (proximity), so they read as two groups of one kind (similarity). */
.tray-stack {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

/* ── The Export menu: a card under its tray ────────────────────────────────
 * It opens below the Export button, right-aligned with the tray, over whatever follows; one item per format, its
 * extension right-aligned in the muted monospace of the key hints. */
.menu-anchor {
	position: relative;
}

.menu {
	position: absolute;
	top: calc(100% + 0.4rem);
	right: 0;
	z-index: 10;
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 15rem;
	padding: var(--gap-in);
	background: #fff;
	border: 1.5px solid var(--border-strong);
	border-radius: calc(var(--radius) + var(--gap-in));
	box-shadow: 0 12px 30px rgba(40, 40, 80, 0.18);
}

.menu-item {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	min-height: var(--control-h);
	padding: 0 0.85rem;
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--ink);
	text-align: left;
	background: transparent;
	border: 0;
	border-radius: var(--radius);
	cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
	background: var(--accent-soft);
}

.menu-item .icon {
	width: 1.15rem;
	height: 1.15rem;
	flex: none;
	color: var(--muted);
}

.menu-hint {
	margin-left: auto;
	padding-left: 1rem;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.78rem;
	font-weight: 500;
	color: var(--muted);
}

/* The caret turns over while the menu is open, and the button keeps its hover chip, so it reads as the menu's. */
.menu-btn .caret {
	width: 0.9rem;
	height: 0.9rem;
	margin-left: -0.2rem;
	transition: transform 0.15s;
}

.menu-btn[aria-expanded="true"] {
	background: #fff;
	border-color: var(--border);
}

.menu-btn[aria-expanded="true"] .caret {
	transform: rotate(180deg);
}

/* ── Compose head: heading left, three tools right, all on one baseline ─ */
.panel-head {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem var(--gap-between);
	margin-bottom: 0.85rem;
}

.panel-head h2 {
	margin: 0;
}

.compose-tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: flex-end;
	gap: 0.75rem 1.5rem;
}

/* 0.5rem: a little closer than the length picker's own 0.6rem, so Apply reads with the lengths it applies. */
.entry-tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
}

/* .length-picker and .sound-picker are fieldsets: no frame, and min-width: 0, since a fieldset won't shrink below
 * its content. */
.octave-nav,
.length-picker,
.sound-picker {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin: 0;
	padding: 0;
	border: 0;
	min-width: 0;
}

/* A floated legend is not drawn in the fieldset's border: it becomes an ordinary flex item beside the tray. */
.length-picker legend,
.sound-picker legend {
	float: left;
	padding: 0;
}

.octave-tabs {
	display: flex;
	gap: var(--gap-in);
}

/* Segmented control: one tray, options inside it, the chosen one lifts out
 * as a white chip. Octave tabs and note lengths look identical on purpose. */
.segmented label {
	position: relative;
	display: flex;
}

/* The real radio, invisible, covers its whole chip: all of it is the hit target, and the radio keeps its keyboard
 * and screen-reader behaviour. Its focus ring is drawn on the span after it (Focus, above). */
.segmented input {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
	cursor: pointer;
}

.segmented label span,
.octave-tab {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 3.25rem;
	min-height: var(--control-h);
	padding: 0 0.75rem;
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--muted);
	background: transparent;
	border: 1.5px solid transparent;
	border-radius: var(--radius);
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.segmented label:hover span,
.octave-tab:hover {
	color: var(--ink);
}

.segmented input:checked + span,
.octave-tab[aria-pressed="true"] {
	color: var(--accent);
	background: #fff;
	border-color: var(--border-strong);
	box-shadow: 0 1px 3px rgba(40, 40, 80, 0.12);
}

.octave-nav .btn.icon-only:disabled {
	opacity: 0.3;
}

/* .held: the current note's length (app.js), edged in the accent like its keys on the keyboard (.key.held below),
 * so the chosen chip (new notes) and the edged one (the highlighted note) read apart, and Apply joins them. */
.segmented label.held span {
	box-shadow: inset 0 -3px 0 var(--accent);
}

.segmented label.held input:checked + span {
	box-shadow: inset 0 -3px 0 var(--accent), 0 1px 3px rgba(40, 40, 80, 0.12);
}

.btn.toggle.held {
	box-shadow: inset 0 -3px 0 var(--accent);
}

.btn.toggle.held[aria-pressed="true"] {
	box-shadow: inset 0 -3px 0 var(--accent), inset 0 0 0 1px var(--accent);
}

/* Apply: an action, not a mode, so a plain button beside the length it applies (Rest's and Chord's shape). */
.apply-btn {
	gap: 0.5rem;
	padding: 0 0.75rem;
}

/* Rest: not a pitch, so it lives with note length, not on the keyboard.
 * Dashed outline echoes the rest symbol on the staff. */
.rest-btn {
	border-style: dashed;
	background: #f6f6f8;
	gap: 0.5rem;
}

.rest-glyph {
	width: 1.5rem;
	height: 0.75rem;
	fill: #888;
	stroke: #666;
	stroke-width: 1.2;
}

.rest-btn .hint,
.chord-btn .hint {
	font-weight: 500;
	color: var(--muted);
}

/* Chord: a mode, so it is a toggle (the accent "on" state of Loop); its hint names the key that does the same. */
.chord-btn {
	gap: 0.5rem;
}

/* ── Keyboard: one continuous row, never wraps ─────────────────────────────
 * Each octave is its own tray (common region) with a label on top; octaves
 * are spaced further apart than keys inside an octave (proximity). When the
 * row is wider than the panel it scrolls, with fades at the clipped edges. */
.keyboard-frame {
	position: relative;
}

/* The edge fades sit over the black keys (z-index 2) and let taps through to the keys beneath. app.js toggles
 * .fade-start and .fade-end from the scroll position. */
.keyboard-frame::before,
.keyboard-frame::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0.75rem;
	width: 2rem;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s;
	z-index: 3;
}

/* A soft ink shadow rather than a white fade, so the edge still reads on
 * white keys: "there is more keyboard this way". */
.keyboard-frame::before {
	left: 0;
	background: linear-gradient(90deg, var(--panel) 0, rgba(250, 250, 250, 0.6) 0.35rem, rgba(59, 74, 122, 0.14) 0.4rem, rgba(59, 74, 122, 0));
}

.keyboard-frame::after {
	right: 0;
	background: linear-gradient(270deg, var(--panel) 0, rgba(250, 250, 250, 0.6) 0.35rem, rgba(59, 74, 122, 0.14) 0.4rem, rgba(59, 74, 122, 0));
}

.keyboard-frame.fade-start::before,
.keyboard-frame.fade-end::after {
	opacity: 1;
}

/* A swipe that runs off either end stays in the keyboard rather than chaining to the page. Proximity snapping
 * settles a fling on a centred octave only when it ends near one. */
.piano {
	display: flex;
	flex-wrap: nowrap;
	gap: var(--octave-gap);
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-x: contain;
	scroll-snap-type: x proximity;
	scrollbar-width: thin;
	padding-bottom: 0.75rem;
}

/* Spare width is shared out by white-key count (7 here, 1 for the closing C6 below), so keys widen alike in every
 * group. No shrinking: below the keys' minimum width the row scrolls instead. */
.octave {
	flex: 7 0 auto;
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
	padding: 0.3rem 0.35rem 0.35rem;
	background: var(--region);
	border: 1px solid #d8dae8;
	border-radius: calc(var(--radius) + var(--gap-in));
	scroll-snap-align: center;
	transition: background-color 0.15s, border-color 0.15s;
}

.octave[data-octave="6"] {
	flex: 1 0 auto;
}

.octave-label {
	padding: 0 0.3rem;
	font-size: 0.78rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	font-variant-numeric: tabular-nums;
	color: var(--muted);
	line-height: 1.3;
}

/* The octave your computer keyboard plays: accent label and a firmer outline. */
.octave.active {
	background: var(--accent-soft);
	border-color: var(--border-strong);
}

.octave.active .octave-label {
	color: var(--accent);
}

/* --kw is one white key's width: the row less its gaps, over --whites (set by app.js). The white keys grow equally
 * from the same basis, so each is exactly that wide; the black keys are sized and placed with it. */
.octave-keys {
	--kw: calc((100% - (var(--whites) - 1) * var(--key-gap)) / var(--whites));
	position: relative;
	display: flex;
	gap: var(--key-gap);
	height: var(--white-h);
}

.key {
	font-family: inherit;
	font-weight: 600;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	justify-content: flex-end;
	align-items: center;
	gap: 0.3rem;
	padding: 0 0 0.55rem;
	transition: background-color 0.12s, border-color 0.12s, box-shadow 0.1s, transform 0.08s;
}

.key.white {
	flex: 1 0 var(--white-min);
	min-width: var(--white-min);
	color: var(--ink);
	background: #fff;
	border: 1.5px solid var(--border);
	border-radius: 0 0 var(--radius) var(--radius);
	box-shadow: 0 2px 0 var(--border);
}

/* Black keys float over the whites, 64% of a white key wide and centred on the gap after the --slot-th white key
 * (app.js sets --slot): --slot keys and gaps in, back half a gap, back half its own width (0.32 = 0.64 / 2). */
.key.black {
	position: absolute;
	top: 0;
	z-index: 2;
	width: calc(var(--kw) * 0.64);
	left: calc(var(--slot) * (var(--kw) + var(--key-gap)) - var(--key-gap) / 2 - var(--kw) * 0.32);
	height: 58%;
	color: #fff;
	background: #2b2f45;
	border: 1.5px solid #1d2033;
	border-radius: 0 0 7px 7px;
	box-shadow: 0 2px 0 #1d2033;
	padding-bottom: 0.4rem;
}

.key .pitch {
	font-size: 1.15rem;
	line-height: 1;
}

.key.black .pitch {
	font-size: 0.72rem;
	letter-spacing: -0.02em;
}

.key .pitch sub {
	font-size: 0.62em;
	vertical-align: baseline;
	position: relative;
	top: 0.2em;
	margin-left: 0.05em;
	color: var(--muted);
}

.key.white:hover {
	background: var(--accent-soft);
	border-color: var(--border-strong);
}

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

/* Pressed: the key drops 2px onto its shadow. .struck is app.js's brief flash for a note just entered; .sounding
 * marks the key of the note playing, edged in the gold of the playing note on the staff. */
.key:active,
.key.struck {
	transform: translateY(2px);
	box-shadow: none;
}

.key.white.struck,
.key.white.sounding {
	background: #dfe6ff;
	border-color: var(--accent);
}

.key.black.struck,
.key.black.sounding {
	background: var(--accent);
}

/* .held: the keys of the current note (the one before the cursor), edged in the cursor's accent; they keep the
 * raised key's edge below. Declared before .sounding so a playing key's gold wins. */
.key.white.held {
	border-color: var(--border-strong);
	box-shadow: inset 0 -3px 0 var(--accent), 0 2px 0 var(--border);
}

.key.black.held {
	box-shadow: inset 0 -3px 0 #9aa8e8, 0 2px 0 #1d2033;
}

.key.sounding {
	box-shadow: inset 0 -3px 0 #d4a017;
}

.hint {
	min-width: 1.3rem;
	padding: 0.05rem 0.3rem;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.66rem;
	font-weight: 500;
	line-height: 1.4;
	text-align: center;
	color: var(--muted);
	background: var(--region);
	border-radius: 4px;
}

/* Shortcut letters only on the octave the computer keyboard plays (plus the
 * next C, reached with K), so the hints point at exactly one place. */
.key .hint {
	visibility: hidden; /* not display: none, so the key's name keeps its place */
}

.octave.active .key .hint,
.octave.reach .key.white:first-child .hint {
	visibility: visible;
}

.key.black .hint {
	color: #d7daf0;
	background: rgba(255, 255, 255, 0.14);
	font-size: 0.6rem;
	min-width: 0;
	padding: 0 0.2rem;
}

/* ── Staff panel ───────────────────────────────────────────────────────── */
/* overflow: hidden clips the white toolbar and footer to the panel's rounded corners. */
.panel.staff-panel {
	padding: 0;
	overflow: hidden;
}

.staff-toolbar {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 0.25rem var(--gap-between);
	padding: 0.35rem 1rem;
	border-bottom: 2px solid var(--border);
	background: #fff;
}

.staff-toolbar h2 {
	margin: 0;
}

.meta {
	margin: 0;
	color: var(--muted);
	font-size: 0.92rem;
	font-variant-numeric: tabular-nums;
}

/* The staff scrolls sideways here; app.js scrolls it to the newest note on each edit and along with playback. */
.staff-scroll {
	overflow-x: auto;
	overflow-y: hidden;
	background: var(--paper);
	scrollbar-width: thin;
}

/* STAFF_HEIGHT in app.js. The hand pointer: every point of the staff does something when clicked (hitTest). No
 * text selection or iOS callout: a long-press on the staff selects notes instead. */
#staffSvg {
	display: block;
	min-width: 100%;
	height: 284px;
	cursor: pointer;
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	user-select: none;
}

/* ── Staff drawing (SVG from app.js) ───────────────────────────────────── */
/* The ruler: a tinted strip (its own region) above the music. Dragging or clicking it moves the cursor. */
.ruler-band {
	fill: rgba(59, 74, 122, 0.05);
	cursor: ew-resize;
}

.ruler-edge {
	stroke: var(--border);
	stroke-width: 1;
}

.ruler-number {
	font-size: 11px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	fill: var(--muted);
	pointer-events: none;
}

/* The cursor and the current note share the accent: where the next note goes, and what edits act on. */
.cursor {
	pointer-events: none;
}

.cursor-line {
	stroke: var(--accent);
	stroke-width: 2;
}

.cursor-handle {
	fill: var(--accent);
}

.cursor-label {
	font-size: 10.5px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-anchor: middle;
	fill: #fff;
}

.current-band {
	fill: var(--accent-soft);
	stroke: #dde1f3;
	stroke-width: 1;
}

/* The selection: one region over all its columns (common region), a firmer tint than the current note's band and
 * edged in the accent, carried up through the ruler, so a run of notes reads as one block and never as one
 * current note. With Shift held, the mouse previews it dashed (.ghost-selection), as the cursor is previewed. */
.selection-band {
	fill: rgba(59, 74, 122, 0.12);
	stroke: var(--accent);
	stroke-width: 1.5;
}

.selection-ruler {
	fill: rgba(59, 74, 122, 0.22);
}

/* Hover preview: the same head as a real note, faint (it is not written yet). Removing shows red, like Clear. */
.ghost {
	pointer-events: none;
}

.ghost-head {
	fill: var(--accent);
	fill-opacity: 0.35;
	stroke: var(--accent);
	stroke-opacity: 0.6;
	stroke-width: 1.2;
}

.ghost-ledger {
	stroke: var(--accent);
	stroke-opacity: 0.5;
	stroke-width: 1;
}

/* paint-order puts a paper-coloured halo behind the letters, so the label reads over staff lines. */
.ghost-label {
	font-size: 12px;
	font-weight: 600;
	fill: var(--accent);
	paint-order: stroke;
	stroke: var(--paper);
	stroke-width: 3px;
	stroke-linejoin: round;
}

.ghost.remove .ghost-head {
	fill: none;
	stroke: var(--danger);
	stroke-opacity: 1;
	stroke-width: 2;
}

.ghost.remove .ghost-label {
	fill: var(--danger);
}

.ghost-cursor {
	stroke: var(--accent);
	stroke-width: 2;
	stroke-dasharray: 4 3;
	opacity: 0.6;
}

.ghost-selection {
	fill: rgba(59, 74, 122, 0.05);
	stroke: var(--accent);
	stroke-width: 1.5;
	stroke-dasharray: 5 4;
}

.chord-symbol {
	font-size: 13px;
	font-weight: 600;
	text-anchor: middle;
	fill: var(--ink);
}

.time-sig text {
	font-size: 23px;
	font-weight: 700;
	text-anchor: middle;
	fill: #1a1a1a;
}

/* Sheets for print and image export: white paper, and the tempo over the first system's clefs. */
.sheet-paper {
	fill: #fff;
}

.tempo-note {
	fill: var(--ink);
}

.tempo-stem {
	stroke: var(--ink);
	stroke-width: 1.3;
}

.tempo-text {
	font-size: 14px;
	font-weight: 700;
	fill: var(--ink);
}

.note-head {
	fill: var(--accent);
	stroke: #2f3d66;
	stroke-width: 1.2;
}

.note-head.open {
	fill: var(--paper);
	stroke: var(--accent);
	stroke-width: 2.2;
}

.note-head.rest {
	fill: #888;
	stroke: #666;
}

.rest-dot {
	fill: #888;
}

.note-dot {
	fill: #2f3d66;
}

.note-stem,
.note-flag {
	stroke: #2f3d66;
	stroke-width: 1.6;
	fill: none;
}

/* Beams and ties are filled shapes (a parallelogram, a crescent) in the stems' ink. */
.note-beam,
.note-tie {
	fill: #2f3d66;
}

.note-flag {
	stroke-width: 2;
	stroke-linecap: round;
}

.accidental path {
	fill: none;
	stroke: #2f3d66;
}

.accidental .acc-thin {
	stroke-width: 1.1;
}

.accidental .acc-thick {
	stroke-width: 2.4;
}

.accidental .acc-bowl {
	stroke-width: 1.6;
}

/* The note playing, in the same gold as its key's .sounding edge. */
.note-group.active .note-head {
	fill: #d4a017;
	stroke: #8a6500;
}

.note-group.active .note-head.open {
	fill: #fbeecb;
}

.note-group.active .note-stem,
.note-group.active .note-flag,
.note-group.active .accidental path {
	stroke: #8a6500;
}

.note-group.active .note-dot,
.note-group.active .note-tie {
	fill: #8a6500;
}

/* Hidden until playback moves it (setPlayhead toggles .shown); red, so it never reads as the accent cursor. */
.playhead {
	stroke: #d44;
	stroke-width: 2;
	opacity: 0;
	pointer-events: none;
}

.playhead.shown {
	opacity: 0.85;
}

.staff-line,
.ledger-line {
	stroke: #555;
	stroke-width: 1;
}

.bar-line,
.system-line {
	stroke: #222;
	stroke-width: 1.5;
}

.bar-line.final {
	stroke-width: 2.5;
}

.brace {
	fill: none;
	stroke: #222;
	stroke-width: 2;
}

.bass-clef .clef-fill {
	fill: #1a1a1a;
}

.bass-clef .clef-stroke {
	fill: none;
	stroke: #1a1a1a;
	stroke-width: 2.6;
	stroke-linecap: round;
}

/* ── Status line and shortcuts ─────────────────────────────────────────── */
.staff-footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: baseline;
	gap: 0.25rem var(--gap-between);
	padding: 0.6rem 1rem;
	border-top: 2px solid var(--border);
	background: #fff;
}

.staff-footer p {
	margin: 0;
	font-size: 0.88rem;
	color: var(--muted);
}

.status {
	min-height: 1.3rem;
}

/* The Bring back bar: a piece a share link replaced, offered back after a reload. A tray in the accent's soft tint
 * on a row of its own above the status line, so it reads as a notice about the composition, not a control set. */
.restore-bar {
	flex: 1 1 100%;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--gap-in) 0.5rem;
	padding: var(--gap-in) var(--gap-in) var(--gap-in) 0.75rem;
	font-size: 0.88rem;
	color: var(--ink);
	background: var(--accent-soft);
	border: 1px solid var(--border);
	border-radius: calc(var(--radius) + var(--gap-in));
}

.restore-bar span:first-child {
	flex: 1 1 14rem;
}

.status.error {
	color: var(--danger);
}

kbd {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 0.75rem;
	padding: 0.05rem 0.3rem;
	background: var(--region);
	border-radius: 4px;
}

/* ── Page footer ───────────────────────────────────────────────────────── */
/* The credit carries the release running (.version, stamped from package.json by scripts/app-version.mjs). Its tail,
 * "rebuilt 2026 · v1.3.0", stays on one line, so a narrow screen breaks before it rather than strand the version. */
.page-footer .credit-tail {
	white-space: nowrap;
}

/* The name links to eliasv.com, quietly: the footer's own grey until pointed at. */
.page-footer .credit {
	color: inherit;
	text-decoration: none;
}

.page-footer .credit:hover,
.page-footer .credit:focus-visible {
	text-decoration: underline;
}

.page-footer .version {
	font-variant-numeric: tabular-nums;
}

.page-footer {
	margin-top: 2rem;
	font-size: 0.9rem;
	color: #6b6b6b;
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

/* Below a wide desktop, Rest's and Chord's key hints give way to Apply, so the compose row breaks where it did
 * before Apply was there (the footer still lists every shortcut, and the buttons' titles name their keys). */
@media (max-width: 1459px) {
	.rest-btn .hint,
	.chord-btn .hint {
		display: none;
	}
}

/* Medium widths: the tools drop under the heading and line up on its left
 * edge (alignment) instead of hanging off the right. */
@media (max-width: 1099px) {
	.compose-tools {
		flex: 1 1 100%;
		justify-content: flex-start;
	}
}

/* ── Touch screens: bigger keys, no keyboard hints (Prägnanz) ─────────── */
@media (hover: none) and (pointer: coarse) {
	:root {
		--white-min: 2.9rem;
		--white-h: 8.5rem;
	}

	.shortcuts,
	.hint,
	.key-hint,
	.rest-btn .hint {
		display: none;
	}

	/* A touch browser keeps :hover on the last key tapped; undo the hover tint so it doesn't linger. */
	.key.white:hover {
		background: #fff;
		border-color: var(--border);
	}

	.key.black:hover {
		background: #2b2f45;
	}
}

/* Tablets: touch has no key hints to give up for Apply, so Apply shows its icon alone (its accessible name and
 * title stay) and the "Octave" and "Length" labels are visually hidden, as on a small phone (the .sr-only pattern;
 * screen readers still hear them). That keeps every row as it was before Apply came. A small phone gives Apply a
 * row with room for its word (below). */
@media (hover: none) and (pointer: coarse) and (min-width: 480px) {
	.apply-btn {
		padding: 0;
	}

	.apply-btn span {
		display: none;
	}

	.octave-nav .tool-label,
	.length-picker legend {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}
}

/* ── Phones ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
	:root {
		--white-min: 2.75rem; /* 44px */
		--white-h: 8rem;
		--octave-gap: 0.5rem;
		--key-gap: 1px;
	}

	/* Slimmer tray so neighbouring octaves peek in at both edges. */
	.octave {
		padding: 0.25rem 0.2rem 0.2rem;
	}

	.hero h1 {
		font-size: 2rem;
	}

	.hero {
		margin-bottom: 1.25rem;
	}

	.workspace {
		gap: 1rem;
	}

	.panel {
		padding: 1rem;
	}

	/* Play first on a phone: it is the one control you reach for most. */
	.playback-panel {
		order: -1;
	}

	/* The keyboard strip bleeds to the panel edges so a full octave fits. */
	.keyboard-frame {
		margin-inline: -1rem;
	}

	.piano {
		padding-inline: 0.75rem;
	}

	.compose-tools {
		flex: 1 1 100%;
		justify-content: space-between;
		gap: 0.6rem 1rem;
	}

	.transport {
		flex: 1 1 100%;
	}

	.transport .btn.primary {
		flex: 1 1 auto;
	}

	.mix {
		grid-template-columns: 1fr;
		padding: 0.5rem 0.9rem;
	}

	input[type="range"] {
		height: var(--control-h);
	}

	.segmented label span,
	.octave-tab {
		min-width: 2.75rem;
		padding: 0 0.45rem;
	}
}

/* ── Small phones: one tool per row ────────────────────────────────────── */
@media (max-width: 479px) {
	/* Each tool gets its own full-width row; tabs share it evenly. */
	.octave-nav,
	.entry-tools {
		flex: 1 1 100%;
	}

	.octave-nav .segmented,
	.octave-tabs {
		flex: 1 1 auto;
	}

	.octave-tab {
		flex: 1 1 0;
		min-width: 0;
	}

	/* The "Octave" label and the Rest button's word are visually hidden (the .sr-only pattern) to fit the row. */
	.octave-nav .tool-label {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}

	/* Lengths and dot fill the first row; "Length" is hidden like "Octave". Apply, Rest and Chord share the next,
	 * Apply first, right under the lengths it applies. */
	.length-picker {
		flex: 1 1 100%;
	}

	.length-picker legend {
		position: absolute;
		width: 1px;
		height: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}

	.length-picker .segmented {
		flex: 1 1 auto;
	}

	.length-picker .segmented label {
		flex: 1 1 0;
	}

	.length-picker .segmented label span {
		width: 100%;
		min-width: 0;
		padding: 0 0.2rem;
	}

	.apply-btn,
	.rest-btn,
	.chord-btn {
		flex: 1 1 0;
		padding: 0 0.75rem;
	}

	/* The three sounds share the row evenly, as the lengths do. */
	.sound-picker .segmented {
		flex: 1 1 auto;
	}

	.sound-picker .segmented label {
		flex: 1 1 0;
	}

	.sound-picker .segmented label span {
		width: 100%;
		min-width: 0;
	}
}

/* ── Print: the sheet alone ─────────────────────────────────────────────────
 * Printing (and Save as PDF) shows only #printSheet, which app.js fills on beforeprint with the music broken into
 * systems of whole measures; every control is hidden. Each system is its own SVG, scaled to the page width, and is
 * never split across a page break. */
.print-sheet {
	display: none;
}

@page {
	margin: 14mm 12mm;
}

@media print {
	html,
	body {
		background: #fff;
	}

	body {
		padding: 0;
		min-height: 0;
	}

	.page {
		display: none;
	}

	.print-sheet {
		display: block;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}

	.print-system {
		display: block;
		width: 100%;
		height: auto;
		margin: 0 0 5mm;
		break-inside: avoid;
		page-break-inside: avoid;
	}
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
/* !important beats each component's own transition and animation; pressed keys and buttons stop moving too. */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		transition: none !important;
		animation: none !important;
	}

	.btn:active,
	.key:active,
	.key.struck {
		transform: none;
	}
}
