:root {
  color-scheme: light;
  --paper: #f4efe5;
  --matte: #e9e1d3;
  --ink: #25231e;
  --muted: #5f584d;
  --rule: #c9bfae;
  --brand: #a43820;
  --signal: #acdfe5;
  --screen: #152124;
  --plot: #101a1d;
  --glint: #adbdba;
  --grid: #253538;
  --plot-rule: color-mix(in srgb, var(--grid) 65%, var(--plot));
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --display: Georgia, "Songti SC", "SimSun", serif;
  --mono: ui-monospace, Consolas, monospace;
}
html[data-theme="aurora"] { --screen:#19261e; --plot:#141e18; --grid:#293a2d; --signal:#c0e389; }
html[data-theme="ember"] { --screen:#30241e; --plot:#261c17; --grid:#40312a; --signal:#ffbd8f; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font: 14px/1.5 var(--sans); }
button, input, select { font: inherit; }
button, select { cursor: pointer; color: inherit; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.app { width: min(1320px, calc(100% - 2 * clamp(18px, 4vw, 64px))); margin: auto; }
.masthead { min-height: 102px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.identity, .header-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { color: var(--brand); width: 42px; height: 42px; flex: none; }
.wordmark h1 { margin: 0; white-space: nowrap; font: 700 31px/.95 var(--display); letter-spacing: -.065em; }
.wordmark h1 span { font: 600 11px/1 var(--sans); letter-spacing: .08em; margin-left: 10px; vertical-align: 3px; }
.wordmark p { margin: 6px 0 0; color: var(--muted); font-size: 11px; letter-spacing: .07em; }
.theme-control { display: grid; grid-template-columns: 9px auto 14px; align-items: center; position: relative; gap: 8px; padding: 0 5px; }
.theme-chip { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); border: 1px solid var(--muted); pointer-events: none; }
.theme-control svg { pointer-events: none; }
#theme-select { appearance: none; border: 0; background: transparent; min-height: 42px; min-width: 0; padding: 0 20px 0 0; font-size: 12px; font-weight: 650; grid-column: 2 / 4; grid-row: 1; }
.theme-control svg { grid-column: 3; grid-row: 1; }
.file-picker { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 0 14px; border: 1px solid var(--ink); border-radius: 3px; background: var(--ink); color: var(--paper); white-space: nowrap; font-weight: 650; }
.file-picker:hover:not(:disabled) { background: var(--brand); border-color: var(--brand); }
.file-picker:disabled, .screen-import:disabled { opacity: .55; }

/* Shared chassis: display and source sit side by side; transport bridges both. */
.instrument { display: grid; grid-template-columns: minmax(0, 1fr) clamp(215px, 23%, 310px); grid-template-areas: "monitor source" "transport transport"; border: 1px solid var(--rule); border-radius: 8px; background: var(--matte); }
.monitor { grid-area: monitor; min-width: 0; background: var(--screen); color: #f2eee3; border-radius: 7px 0 0 0; border-bottom: 1px solid #25221d; }
.monitor :focus-visible { outline-color: var(--signal); }
.monitor-top { min-height: 63px; padding: 0 clamp(16px, 2.2vw, 31px); display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--grid); }
.screen-label { color: #d2d4cb; font-size: 12px; font-weight: 650; letter-spacing: .12em; white-space: nowrap; }
.screen-label > span { display: inline-block; width: 5px; height: 10px; margin-right: 9px; background: var(--signal); vertical-align: -1px; }
.mode-switch { display: flex; align-items: stretch; gap: clamp(10px, 2.2vw, 32px); }
.mode-switch button { min-height: 47px; padding: 0 0 1px; display: flex; align-items: center; gap: 6px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #b8c1bb; font-size: 13px; font-weight: 600; white-space: nowrap; }
.mode-switch button span { color: #a4aeaa; font: 10px var(--mono); }
.mode-switch button:hover:not(:disabled), .mode-switch button.selected, .mode-switch button.selected span { color: var(--signal); }
.mode-switch button.selected { border-bottom-color: var(--signal); }
.mode-switch button:disabled { opacity: .55; }
.screen-inner { position: relative; padding: 15px clamp(16px, 2.2vw, 31px) 0; }
.plot { position: relative; height: clamp(385px, 58vh, 610px); background: var(--plot); }
.plot:not(:has(.canvas-hint:not([hidden]))) { background-image: linear-gradient(to right, var(--plot-rule) 1px, transparent 1px), linear-gradient(to bottom, var(--plot-rule) 1px, transparent 1px); background-size: 12.5% 100%, 100% 25%; }
.monitor:has(#mode-ring.selected) .plot:not(:has(.canvas-hint:not([hidden]))) { background-image: linear-gradient(var(--plot-rule),var(--plot-rule)), linear-gradient(var(--plot-rule),var(--plot-rule)); background-size: 1px 100%, 100% 1px; background-position: center; background-repeat: no-repeat; }
#spectrum-canvas { display: block; width: 100%; height: 100%; }
.plot:has(.canvas-hint:not([hidden])) canvas { visibility: hidden; }
.canvas-hint { position: absolute; inset: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); align-items: center; gap: 16px; padding: clamp(24px, 4vw, 58px); overflow: hidden; }
.input-copy { position: relative; z-index: 1; min-width: 0; }
.input-off { display: inline-flex; align-items: center; gap: 7px; color: var(--signal); font-size: 11px; letter-spacing: .11em; white-space: nowrap; }
.input-off i { width: 7px; height: 7px; border: 1px solid currentColor; }
.input-copy h2 { margin: 9px 0 12px; font: 700 clamp(35px, 4vw, 58px)/1.12 var(--display); letter-spacing: -.045em; }
.input-copy p { margin: 0; color: #d0d7cc; font-size: 14px; }
.screen-import { display: inline-flex; align-items: center; gap: 14px; margin-top: 14px; padding: 0 1px; min-height: 44px; border: 0; border-bottom: 1px solid var(--signal); background: none; color: var(--signal); font-weight: 650; white-space: nowrap; }
.screen-import:hover:not(:disabled) { color: #fff6e9; }
.input-format { display: block; margin-top: 9px; color: var(--glint); font-size: 12px; }
.input-mark { color: var(--signal); display: block; width: min(100%, 340px); height: auto; justify-self: center; opacity: .88; pointer-events: none; }
.mark-fine { stroke: var(--grid); }
.mark-accent { stroke: currentColor; }
.screen-key { min-height: 46px; color: var(--glint); font-size: 11px; }
.screen-key > div { min-height: 46px; align-items: center; justify-content: space-between; gap: 8px; }
#spectrum-scale { display: flex; }
.key-wave, .key-ring { display: none; }
.monitor:has(#mode-waveform.selected) .key-wave, .monitor:has(#mode-ring.selected) .key-ring { display: flex; }
.drop-hint { position: absolute; z-index: 3; inset: 15px 14px 14px; display: grid; place-items: center; border: 2px solid var(--signal); background: var(--screen); color: var(--signal); font-weight: 650; pointer-events: none; }

.source { grid-area: source; min-width: 0; padding: 24px clamp(18px, 2vw, 28px); border-inline-start: 1px solid var(--rule); }
.source-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; min-height: 39px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.source-head h2, .source-help h3 { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.35; font-weight: 700; letter-spacing: .055em; }
.status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; flex: none; border: 1px solid; border-radius: 50%; }
.status-dot.ready, .status-dot.playing { color: #326247; background: currentColor; }
.status-dot.paused { color: #80530f; background: currentColor; }
.status-dot.error { color: var(--brand); background: currentColor; }
.status:has(.playing) { color: #2e5940; }
.status:has(.error) { color: #8b2c1c; }
.source-filename { min-width: 0; margin: 14px 0 6px; overflow: auto; scrollbar-color: #96836f transparent; scrollbar-width: thin; font: 700 clamp(22px, 2.05vw, 29px)/1.24 var(--display); height: 2lh; }
.file-name { margin: 0; letter-spacing: -.025em; overflow-wrap: anywhere; }
.source-feedback { min-height: 48px; }
.message { margin: 0; padding-left: 10px; border-left: 2px solid var(--rule); color: var(--muted); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.message.error { border-color: var(--brand); color: #8b2c1c; }
.source-help { margin-top: 22px; }
.source-help h3 { padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.shortcuts { margin: 0; font-size: 13px; }
.shortcuts div { display: flex; justify-content: space-between; align-items: center; min-height: 38px; gap: 8px; border-bottom: 1px solid var(--rule); }
.shortcuts dd { margin: 0; white-space: nowrap; }
kbd { display: inline-block; padding: 2px 5px; border: 1px solid var(--rule); border-radius: 3px; color: var(--muted); background: var(--paper); font: 650 12px/1.2 var(--sans); }

.transport { grid-area: transport; min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(173px, 18%); align-items: end; gap: clamp(16px, 2.4vw, 32px); padding: 14px clamp(16px, 2.2vw, 31px); border-top: 1px solid var(--rule); border-radius: 0 0 7px 7px; background: #f0eade; }
.play-btn { align-self: center; min-width: 96px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border: 1px solid transparent; border-radius: 5px; background: var(--brand); color: #fff6ea; font-weight: 700; }
.play-btn:hover:not(:disabled) { background: #87301f; }
.play-btn:disabled { background: #e5dccf; border-color: #d4c8b7; color: var(--muted); }
.timeline { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 0 8px; }
.timeline-label { align-self: center; color: var(--muted); font-size: 13px; font-weight: 650; }
.time-display { display: flex; align-items: baseline; gap: 8px; color: var(--muted); white-space: nowrap; font: 14px/1.1 var(--mono); font-variant-numeric: tabular-nums; }
#time-current { color: var(--ink); font-size: 26px; font-weight: 650; letter-spacing: -.045em; }
#seek-range { grid-column: 1 / -1; }
.slider { --fill: 0%; --fill-color: var(--brand); --track: #a49582; --thumb: var(--brand); --rail: 4px; --knob-w: 10px; --knob-h: 17px; appearance: none; width: 100%; min-width: 0; height: 44px; margin: 0; border-radius: 4px; cursor: pointer; touch-action: pan-y; background: linear-gradient(to right, var(--fill-color) var(--fill), var(--track) var(--fill)) center / 100% var(--rail) no-repeat; }
.slider:disabled { --fill-color: #938776; --thumb: #968a79; opacity: .7; cursor: not-allowed; }
.slider:hover:not(:disabled) { --track: #8a7964; --thumb: #87301f; }
.slider:active:not(:disabled), #seek-range.is-scrubbing:not(:disabled) { --rail: 5px; --knob-h: 21px; cursor: grabbing; }
.slider::-webkit-slider-thumb { appearance: none; width: var(--knob-w); height: var(--knob-h); border: 0; border-radius: 2px; background: var(--thumb); }
.slider::-moz-range-thumb { width: var(--knob-w); height: var(--knob-h); border: 0; border-radius: 2px; background: var(--thumb); }
.volume-group { display: grid; grid-template-columns: 44px minmax(0, 1fr) 4ch; align-items: center; gap: 8px; min-width: 0; padding-left: 12px; border-left: 1px solid var(--rule); }
#volume-range { --fill-color: #675848; --thumb: #675848; --rail: 2px; --knob-w: 9px; --knob-h: 9px; }
#volume-range::-webkit-slider-thumb { border-radius: 50%; }
#volume-range::-moz-range-thumb { border-radius: 50%; }
#volume-range:active { --rail: 3px; --knob-w: 12px; --knob-h: 12px; }
#mute-btn { display: grid; place-items: center; min-height: 44px; border: 0; border-radius: 4px; background: none; }
#mute-btn:hover, #mute-btn[aria-pressed="true"] { background: #ded4c5; color: var(--brand); }
#volume-value { color: var(--muted); white-space: nowrap; text-align: right; font: 13px var(--mono); font-variant-numeric: tabular-nums; }
.app-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); padding: 12px 0 20px; font-size: 11px; }

@media (max-width: 860px) {
  .instrument { grid-template-columns: minmax(0,1fr) clamp(174px, 27%, 215px); }
  .source { padding: 16px; }
  .monitor-top { padding-inline: 16px; }
  .mode-switch { gap: 13px; }
  .canvas-hint { padding: 22px; }
}
@media (max-width: 680px) {
  .app { width: calc(100% - 28px); }
  .masthead { min-height: 63px; }
  .wordmark h1 { font-size: 24px; }
  .wordmark h1 span, .wordmark p { display: none; }
  .brand-mark { width: 30px; height: 30px; }
  .identity, .header-actions { gap: 5px; }
  .instrument { grid-template-columns: minmax(0,1fr); grid-template-areas: "monitor" "transport" "source"; }
  .monitor { border-radius: 7px 7px 0 0; }
  .monitor-top { min-height: 44px; padding-inline: 12px; }
  .mode-switch { flex: 1; justify-content: flex-end; gap: 6px; }
  .mode-switch button { min-height: 44px; min-width: 44px; justify-content: center; padding-inline: 5px; font-size: 13px; }
  .mode-switch button span { display: none; }
  .screen-inner { padding: 10px 10px 0; }
  .plot { height: clamp(240px, 40svh, 450px); }
  .screen-key, .screen-key > div { min-height: 34px; }
  .canvas-hint { grid-template-columns: 1fr; padding: 21px; }
  .input-copy h2 { font-size: clamp(33px, 10vw, 46px); }
  .input-mark { position: absolute; right: -42px; bottom: -47px; width: 57%; opacity: .35; }
  .transport { grid-template-columns: auto minmax(0,1fr); gap: 2px 12px; padding: 12px; border-radius: 0; }
  .play-btn { min-width: 68px; gap: 5px; font-size: 13px; }
  .play-btn svg { width: 15px; height: 15px; }
  .timeline-label { font-size: 12px; }
  #time-current { font-size: 21px; }
  .time-display { gap: 5px; font-size: 12px; }
  .volume-group { grid-column: 2; justify-self: end; width: min(100%, 186px); border: 0; padding: 0; }
  .source { padding: 12px; border-inline-start: 0; border-top: 1px solid var(--rule); }
  .source-head { min-height: 31px; padding-bottom: 6px; }
  .source-filename { margin: 8px 0 0; font-size: 22px; }
  .source-help { display: none; }
  .source-feedback { min-height: 0; }
  .source-feedback:has(.message:not([hidden])) { margin-top: 6px; }
}
@media (max-width: 400px) {
  .masthead { gap: 12px; }
  .import-extra { display: none; }
  .file-picker { padding-inline: 9px; gap: 5px; font-size: 13px; }
  .file-picker svg { width: 13px; }
  .theme-control { grid-template-columns: 7px auto 12px; gap: 5px; padding: 0; }
  .theme-chip { width: 7px; height: 7px; }
  #theme-select { font-size: 12px; padding-right: 15px; }
  .screen-label { font-size: 11px; letter-spacing: .03em; }
  .screen-label > span { margin-right: 4px; }
  .mode-switch { gap: 2px; }
}
@media (max-width: 360px) {
  .masthead { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 10px 0 7px; }
  .identity { min-height: 32px; gap: 8px; }
  .wordmark h1 span { display: inline; margin-left: 8px; }
  .header-actions { justify-content: space-between; }
  .import-extra { display: inline; }
  .source-filename { font-size: 19px; }
}
@media (pointer: coarse) {
  #seek-range { --knob-w: 12px; --knob-h: 20px; }
  #volume-range { --knob-w: 12px; --knob-h: 12px; }
}
.file-picker, .play-btn, #mute-btn, #theme-select, .mode-switch button, .screen-import {
  transition: color 120ms ease-out, background-color 120ms ease-out, border-color 120ms ease-out;
}
.file-picker, #theme-select { min-height: 44px; }
#theme-select:hover { color: var(--brand); }
.play-btn:active:not(:disabled), .file-picker:active:not(:disabled) { background: #752d1f; }
#mute-btn:active:not(:disabled) { background: #d2c4b1; }
.drop-hint { inset: 12px 14px; background: color-mix(in srgb, var(--screen) 88%, transparent); }
@media (prefers-reduced-motion: reduce) {
  .file-picker, .play-btn, #mute-btn, #theme-select, .mode-switch button, .screen-import { transition: none; }
}
@media (forced-colors: active) {
  .mode-switch button.selected { border-color: Highlight; }
  .slider, #theme-select { appearance: auto; }
  .theme-control svg { display: none; }
}
