/* Piano Scribe — warm paper, so a page of engraved music looks at home on it. */

:root {
  --paper: #faf6ef;
  --surface: #fffdf9;
  --surface-sunk: #f2ece2;
  --ink: #241f19;
  --ink-soft: #5f564b;
  --ink-faint: #8d8378;
  --rule: #e2d9cb;
  --rule-strong: #cec2ae;

  --accent: #a8451c;
  --accent-hover: #8d3915;
  --accent-wash: #f6e7de;
  --record: #c0392b;
  --good: #3f6b45;
  --warn: #8a5a12;
  --warn-wash: #fbf0d9;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgb(60 45 25 / 0.06), 0 6px 20px rgb(60 45 25 / 0.06);

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17140f;
    --surface: #211d16;
    --surface-sunk: #2c261d;
    --ink: #f2ebe0;
    --ink-soft: #b8ac9c;
    --ink-faint: #8b8072;
    --rule: #362f25;
    --rule-strong: #4a4133;

    --accent: #e8834f;
    --accent-hover: #f39a6b;
    --accent-wash: #33231a;
    --record: #e05a4a;
    --good: #8cc194;
    --warn: #e0b463;
    --warn-wash: #33290f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
  }
}

* {
  box-sizing: border-box;
}

/* Several components below set `display`, which would otherwise beat the user
   agent's `[hidden] { display: none }` on specificity. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 1.25rem 4rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
}

/* ── Masthead ──────────────────────────────────────────────────────── */

.masthead {
  max-width: 54rem;
  margin: 0 auto;
  padding: 3rem 0 2rem;
  text-align: center;
}

.masthead h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

/* ── Step cards ────────────────────────────────────────────────────── */

main {
  max-width: 54rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.step {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: opacity 0.25s ease;
}

.step[data-state="locked"] {
  opacity: 0.5;
}

.step[data-state="locked"] .step-body > *:not(.step-hint) {
  pointer-events: none;
}

.step[data-state="done"] .step-number {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
}

.step-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(to bottom, var(--surface), var(--surface-sunk));
}

.step-heading h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.step-number {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  transition: background 0.25s ease, color 0.25s ease;
}

.step-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.step-hint {
  margin: 0;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 0.94rem;
}

/* ── Controls ──────────────────────────────────────────────────────── */

.btn {
  font: inherit;
  font-size: 0.94rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-sunk);
  border-color: var(--ink-faint);
}

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

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

.btn-primary {
  align-self: flex-start;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.input-row label {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

select {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  max-width: min(24rem, 100%);
}

select:disabled {
  opacity: 0.5;
}

/* ── Record console ────────────────────────────────────────────────── */

.record-console {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.record-button {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1.5rem 0.7rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.record-button:hover:not(:disabled) {
  border-color: var(--record);
}

.record-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.record-dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--record);
  flex: none;
}

.record-button[data-recording="true"] {
  background: var(--record);
  border-color: var(--record);
  color: #fff;
}

.record-button[data-recording="true"] .record-dot {
  background: #fff;
  border-radius: 2px;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .record-button[data-recording="true"] .record-dot {
    animation: none;
  }
}

.timer {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ── Level meter ───────────────────────────────────────────────────── */

.meter {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meter-track {
  flex: 1;
  height: 0.5rem;
  max-width: 22rem;
  border-radius: 999px;
  background: var(--surface-sunk);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(to right, var(--good), var(--accent) 78%, var(--record));
  transition: width 0.06s linear;
}

.meter-label,
.playback-meta {
  color: var(--ink-faint);
  font-size: 0.85rem;
}

/* ── Waveform ──────────────────────────────────────────────────────── */

.waveform {
  width: 100%;
  height: 120px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface-sunk);
}

.playback {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ── File import ───────────────────────────────────────────────────── */

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

input[type="file"] {
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 100%;
}

input[type="file"]::file-selector-button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  margin-right: 0.6rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
  background: var(--surface-sunk);
}

/* ── Progress ──────────────────────────────────────────────────────── */

.progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-track {
  flex: 1;
  max-width: 26rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--surface-sunk);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.2s ease;
}

.progress-label {
  color: var(--ink-soft);
  font-size: 0.88rem;
}

/* ── Notices ───────────────────────────────────────────────────────── */

.notice {
  padding: 0.75rem 1rem;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-wash);
  color: var(--ink);
  font-size: 0.92rem;
}

.notice-warn {
  border-left-color: var(--warn);
  background: var(--warn-wash);
  color: var(--warn);
}

.notice-error {
  border-left-color: var(--record);
  background: var(--warn-wash);
  color: var(--record);
}

/* ── Advanced disclosure ───────────────────────────────────────────── */

.advanced {
  border-top: 1px solid var(--rule);
  padding-top: 0.9rem;
}

.advanced summary {
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.advanced p {
  margin: 0.75rem 0;
  max-width: 52ch;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.advanced input[type="range"] {
  width: min(24rem, 100%);
  accent-color: var(--accent);
}

.range-ends {
  display: flex;
  justify-content: space-between;
  width: min(24rem, 100%);
  color: var(--ink-faint);
  font-size: 0.78rem;
}

/* ── MIDI panel ────────────────────────────────────────────────────── */

.midi-panel {
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  background: var(--surface-sunk);
}

.midi-panel summary {
  cursor: pointer;
  font-size: 0.94rem;
}

.midi-panel summary strong {
  margin-right: 0.4rem;
}

.midi-panel p {
  margin: 0.75rem 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  max-width: 52ch;
}

#midi-device-name {
  color: var(--ink-faint);
  font-size: 0.88rem;
}

/* ── Score ─────────────────────────────────────────────────────────── */

.score-placeholder {
  display: grid;
  place-items: center;
  min-height: 9rem;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  color: var(--ink-faint);
  font-size: 0.92rem;
}

.score-controls {
  display: flex;
  align-items: flex-end;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
}

.score-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.score-controls select,
.score-controls input {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.score-controls input[type="number"] {
  width: 5rem;
}

.score-controls .btn {
  margin-left: auto;
}

/* Sheet music is black ink on white paper in every theme — a score tinted to
   match a dark UI stops looking like music. */
.score-viewport {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.75rem;
  overflow-x: auto;
}

.score-page {
  display: block;
  margin: 0 auto;
}

.score-page svg {
  width: 100%;
  height: auto;
  display: block;
}

.score-page + .score-page {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed #d8d8d8;
}

/* Verovio draws noteheads inside g.note; make them feel clickable. */
.score-page g.note {
  cursor: pointer;
}

.score-page g.note:hover * {
  fill: var(--accent);
  stroke: var(--accent);
}

.score-page g.note.is-selected * {
  fill: #c0392b;
  stroke: #c0392b;
}

/* ── Note editor ───────────────────────────────────────────────────── */

.note-editor {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface-sunk);
}

.note-editor-label {
  font-weight: 600;
  font-size: 0.94rem;
}

.note-editor-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.btn-danger {
  color: var(--record);
  border-color: color-mix(in srgb, var(--record) 40%, var(--rule-strong));
}

/* ── Export ────────────────────────────────────────────────────────── */

.export-fields {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.export-fields label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.export-fields input {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-width: 14rem;
}

.export-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ── Printing ──────────────────────────────────────────────────────── */

.print-only {
  display: none;
}

@media print {
  body > *:not(.print-only) {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  .print-page {
    page-break-after: always;
    break-after: page;
  }

  .print-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .print-page svg {
    width: 100%;
    height: auto;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

/* ── Colophon ──────────────────────────────────────────────────────── */

.colophon {
  max-width: 54rem;
  margin: 2.5rem auto 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 0.85rem;
  text-align: center;
}

.colophon a {
  color: inherit;
}

/* ── Narrow screens ────────────────────────────────────────────────── */

@media (max-width: 34rem) {
  .step-heading,
  .step-body {
    padding-inline: 1.1rem;
  }

  .record-console {
    justify-content: space-between;
    gap: 0.75rem;
  }

  .input-row label {
    width: 100%;
  }

  select {
    flex: 1;
  }
}
