:root {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: var(--page); font-synthesis: none; color-scheme: light;
  --page: #d3cfc4; --theme-color: #f3ecdd;
  --ivory: #f3ecdd; --paper: #f8f2e6; --ink: #29271f; --muted: #746d5e; --brass: #a48e68;
  --line: #c3b59b; --border: var(--line); --soft: #e9e0cf; --green: #276344; --red: #a13b34; --accent: #843c31;
  --serif: Baskerville, "Palatino Linotype", "Book Antiqua", Georgia, "Times New Roman", serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --history-band: #c9d8b5; --history-grid: #c6bca8; --history-faint: #d9cfba; --history-trace: #803a32;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 30px 24px; min-width: min(280px, 100%); font-size: 15px; background: radial-gradient(ellipse at 45% 10%, #ede8dd88, #b7b2a300 75%); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { border: 0; background: none; transition: background .15s, box-shadow .15s; }
button:disabled, input:disabled, select:disabled { opacity: .43; cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
a { color: inherit; text-decoration: none; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-library { display: none; }
dialog { border: 1px solid var(--line); border-radius: 4px; padding: 26px; width: min(620px, calc(100% - 32px)); max-height: 90dvh; color: var(--ink); background: var(--paper); box-shadow: 0 25px 100px #30271d22; }
dialog::backdrop { background: #302c2366; backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 23px; }
.dialog-heading h2 { font-size: 20px; font-weight: 600; }
.close-button { border: 1px solid var(--line); border-radius: 50%; font-size: 25px; font-weight: 300; width: 40px; height: 40px; line-height: 28px; flex-shrink: 0; color: var(--muted); }
.close-button:hover { background: var(--soft); }
.field-label { display: block; font-size: 14px; margin-bottom: 9px; }
select { max-width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 4px; padding: 0 26px 0 10px; background-color: var(--paper); color: var(--ink); font-size: 14px; }
select, optgroup, option { font-style: normal; }
optgroup { font-weight: 600; }
option { font-weight: 400; }
.tuning-fields { display: grid; grid-template-columns: minmax(0, 1fr) 94px; gap: 16px; }
.tuning-fields select { width: 100%; }
.tuning-fields.generic-tuning { grid-template-columns: minmax(0, 1fr); }
.reference-settings { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 16px; margin-top: 18px; }
.reference-settings select, .reference-settings input, .scale-generator input { width: 100%; min-width: 0; }
.reference-settings input, .scale-generator input, #custom-pitches { border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); padding: 10px; font-size: 14px; }
#custom-editor { border-bottom: 1px solid var(--line); margin-top: 16px; }
.scale-generator { display: grid; grid-template-columns: 65px minmax(0, 1fr); gap: 12px; margin: 0 0 18px; }
.scale-generator button { grid-column: 1 / -1; justify-self: start; }
.editor-hint { font-size: 12px; line-height: 1.6; color: var(--muted); margin-bottom: 12px; }
.custom-note-head, .custom-note-row { display: grid; grid-template-columns: 20px minmax(0, 1fr) minmax(0, 1fr) 36px; align-items: center; gap: 6px; }
.custom-note-head { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.custom-notes { max-height: 310px; overflow-y: auto; scrollbar-gutter: stable; padding: 4px; margin: -4px; }
.custom-note-row { margin-bottom: 6px; }
.custom-note-number { font: 11px var(--mono); color: var(--muted); text-align: center; }
.custom-note-row input { width: 100%; min-width: 0; height: 44px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); color: var(--ink); padding: 8px; font-size: 16px; }
.custom-note-row input::placeholder { font-size: 12px; color: var(--muted); opacity: 1; }
.custom-pitch-input { font-family: var(--mono); }
.custom-remove-note { height: 44px; font-size: 20px; color: var(--muted); border-radius: 4px; }
.custom-remove-note:hover { background: var(--soft); }
#custom-add-note { margin-top: 12px; }
#custom-text-editor { margin-top: 12px; }
#custom-text-editor summary { font-size: 13px; color: var(--muted); }
#custom-pitches { width: 100%; resize: vertical; min-height: 120px; max-height: 360px; font: 13px/1.7 var(--mono); }
.custom-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 14px 0 20px; }
.form-error { color: var(--red); font-size: 13px; line-height: 1.6; margin-top: 10px; }
.a4-control > label { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stretch-card { background: var(--soft); border: 1px solid var(--line); border-radius: 4px; padding: 17px; margin-bottom: 15px; }
#stretch-details { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-top: 23px; }
.detail-state { float: right; font-size: 12px; color: var(--muted); }
.detail-state.enabled { color: var(--accent); font-weight: 600; }
.stretch-heading { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
.toggle-button { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; color: var(--muted); min-height: 36px; }
.switch-track { display: inline-block; width: 34px; height: 20px; border-radius: 4px; background: var(--line); position: relative; transition: background .2s; flex-shrink: 0; }
.switch-track i { display: block; width: 14px; height: 14px; border-radius: 50%; background: white; position: absolute; top: 3px; left: 3px; box-shadow: 0 1px 3px #0001; transition: left .2s; }
.toggle-button[aria-pressed=true] .switch-track, .toggle-button[aria-checked=true] .switch-track { background: var(--accent); }
.toggle-button[aria-pressed=true] .switch-track i, .toggle-button[aria-checked=true] .switch-track i { left: 17px; background: #fff6e5; }
.stretch-controls { display: grid; grid-template-columns: auto minmax(40px, 1fr) 36px; align-items: center; column-gap: 13px; row-gap: 8px; margin-top: 12px; font-size: 13px; }
.stretch-controls output { text-align: right; font-family: var(--mono); }
.stretch-controls > span { grid-column: 2 / 4; text-align: right; font-size: 11px; color: var(--muted); }
input[type=range] { height: 4px; accent-color: var(--accent); cursor: pointer; width: 100%; margin: 8px 0; }
#stretch-chart { width: 100%; height: 105px; display: block; margin-top: 8px; }
#stretch-chart text { fill: var(--muted); font: 11px var(--mono); }
.stretch-grid { fill: none; stroke: var(--line); stroke-dasharray: 4 5; stroke-width: 1; }
.stretch-path { fill: none; stroke: var(--line); stroke-width: 2; }
.enabled .stretch-path { stroke: var(--accent); }
.detection-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 23px 0; }
.compact-field { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.compact-field select { width: 100%; }
.sensitivity-label { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 14px; }
.sensitivity-label output { font: 12px var(--mono); color: var(--muted); }
#sensitivity { margin: 24px 0 0; }
#tuning-details { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
summary { padding: 15px 0; cursor: pointer; font-size: 14px; }
.table-scroll { max-height: 38dvh; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
table { border-collapse: collapse; width: 100%; }
th { font-size: 11px; text-align: left; background: var(--soft); color: var(--muted); position: sticky; top: 0; font-weight: 500; padding: 11px 9px; white-space: nowrap; }
td { padding: 10px 9px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 12px; }
td input { width: 70px; border: 1px solid var(--line); border-radius: 4px; padding: 6px 4px; font: 12px var(--mono); color: var(--accent); }
td input:disabled { background: var(--soft); }
.outline-button { border: 1px solid var(--line); border-radius: 4px; padding: 11px 16px; font-size: 13px; min-height: 44px; }
#custom-copy { margin: 14px 0; }
.dialog-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; }
.subtle-button { color: var(--muted); font-size: 13px; padding: 8px; min-height: 44px; }

.instrument { width: min(1120px, 100%); margin: 0 auto; border: 4px double var(--brass); border-radius: 4px; background: linear-gradient(115deg, #fff9ef55, #e8ddc422), var(--ivory); box-shadow: 0 3px 16px #302a2230, inset 0 0 0 2px #fff9ec88; }
.site-header { height: 72px; padding: 0 27px; border-bottom: 1px solid var(--brass); display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.brand { min-width: 0; display: flex; align-items: center; }
.brand img { display: none; }
.brand h1 { font: 40px/1 var(--serif); font-weight: 400; letter-spacing: -1.2px; white-space: nowrap; }
.brand-light { font-weight: inherit; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.icon-button, .language-button { min-width: 42px; height: 42px; display: inline-flex; justify-content: center; align-items: center; border-radius: 4px; }
.icon-button:hover, .language-button:hover { background: #c6b69830; }
.workspace { padding: 16px 16px 10px; }
.tuner-panel { min-width: 0; }
.panel-top { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 0 7px; }
.mic-controls { display: flex; align-items: center; gap: 16px; min-width: 0; }
.mic-button, .quick-tuning-button { width: 44px; height: 44px; display: inline-flex; justify-content: center; align-items: center; border: 1px solid var(--brass); border-radius: 5px; background: linear-gradient(#fbf5e8, #e8ddc7); box-shadow: inset 0 0 0 1px #fff9ec88, 0 1px 2px #4a3b2420; flex-shrink: 0; }
.mic-button .icon { width: 25px; height: 25px; }
.mic-button:hover, .quick-tuning-button:hover { background: #e7dcc5; }
.mic-button.is-listening { color: var(--green); background: linear-gradient(#edf0df, #e3e2c9); box-shadow: inset 0 1px 3px #49644522; }
.mic-button.is-pending { color: #906321; }
.reference-controls { display: flex; align-items: center; gap: 8px; min-width: 0; }
.quick-tuning-button { width: 48px; gap: 2px; }
.quick-tuning-button .icon { width: 23px; height: 23px; }
.quick-tuning-button .chevron, .quick-tuning-button .small-chevron { width: 12px; height: 12px; }
.a4-control { display: flex; align-items: center; height: 44px; border: 1px solid var(--line); border-radius: 4px; background: #fff8ed30; overflow: hidden; min-width: 0; }
.a4-control > label { font: 21px var(--serif); padding-left: 13px; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.a4-control > label { font-variant-numeric: lining-nums; }
.frequency-input { display: flex; align-items: center; gap: 4px; padding: 0 10px 0 5px; height: 100%; min-width: 0; }
.frequency-input input { width: 78px; min-width: 0; padding: 0; border: 0; background: transparent; font: 22px var(--serif); font-variant-numeric: tabular-nums; text-align: right; appearance: textfield; }
.frequency-input input::-webkit-inner-spin-button { appearance: none; }
.frequency-input span { font: 18px var(--serif); }
.step-button { width: 42px; height: 100%; border-left: 1px solid var(--line); font: 25px var(--serif); flex-shrink: 0; }
.step-button:hover { background: #cab99335; }
.input-level { display: flex; align-items: center; flex-shrink: 0; }
.input-level > span { display: none; }
#level-bars { display: flex; align-items: center; gap: 3px; height: 24px; }
#level-bars i { width: 4px; height: 17px; border-radius: 1px; background: #c7bfaf; }
#level-bars i.on { background: #3e7058; }
.mic-hint { padding: 10px 9px 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.mic-hint.error { color: var(--red); }
.tuner-body { position: relative; display: flex; flex-direction: column; height: var(--dial-height, 400px); min-height: 220px; max-height: 600px; padding: 14px 18px 26px; }
.dial { width: 100%; max-width: 1000px; min-height: 0; flex: 1; display: flex; flex-direction: column; margin: 0 auto; color: #857c6c; }
.dial-scale { width: 100%; height: 0; min-height: 0; flex: 1; display: block; overflow: visible; }
.dial-track { stroke: var(--ink); stroke-width: 1; fill: none; }
.dial-good { display: none; }
.dial-scale text { fill: var(--ink); font: 15px var(--serif); }
.dial-tick { stroke: var(--ink); stroke-width: 1; }
.dial-tick.major { stroke-width: 1.5; }
#dial-needle { opacity: 0; fill: #857c6c; }
.dial.has-signal #dial-needle { opacity: 1; fill: var(--green); }
.note-readout { flex: none; font-size: var(--note-size, 104px); pointer-events: none; }
.note-line { display: flex; align-items: baseline; justify-content: center; gap: 0; height: 1.05em; min-height: 0; font-family: var(--serif); font-variant-numeric: lining-nums; line-height: 1; }
#detected-note { font-size: 1em; font-weight: 400; letter-spacing: -.03em; }
#detected-octave { font-size: 1em; font-weight: 400; white-space: pre; }
.note-readout .long-note { font-size: .46em !important; letter-spacing: -1px !important; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-line:has(.long-note) #detected-octave { font-size: .46em; }
.dial.has-signal .note-line { color: var(--green); }
.dial.has-signal.off-pitch .note-line { color: var(--red); }
.dial.has-signal.off-pitch #dial-needle { fill: var(--red); }
.readings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); flex: none; width: 100%; text-align: center; margin: 10px auto 0; max-width: 650px; }
.readings > div { min-width: 0; padding: 0 12px; }
.readings > div + div { border-left: 1px solid var(--line); }
.readings p { display: flex; justify-content: center; align-items: baseline; gap: 7px; white-space: nowrap; }
.readings strong { font: 29px var(--serif); font-variant-numeric: tabular-nums; font-weight: 400; }
.readings small { font: 23px var(--serif); }
.history-area, .reference-panel { border: 1px solid var(--line); border-radius: 4px; background: #fff9ec18; }
.history-area { position: relative; }
.history-heading { position: relative; font-size: 14px; font-weight: 400; }
.history-heading h2 { font-size: inherit; font-weight: inherit; }
.history-settings-button { position: absolute; top: 0; right: 40px; width: 33px; height: 33px; display: flex; align-items: center; justify-content: center; border-radius: 3px; color: var(--muted); }
.history-settings-button .icon { width: 18px; height: 18px; }
.history-settings-button:hover, .history-settings-button[aria-expanded=true] { background: #cbbd9e35; color: var(--ink); }
.history-heading:has(.history-toggle[aria-expanded=false]) .history-settings-button { display: none; }
.history-toggle, .reference-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 8px 16px; text-align: left; font-size: 14px; font-weight: 500; }
.history-toggle:hover, .reference-toggle:hover { background: #cbbd9e20; }
.history-toggle:focus-visible, .reference-toggle:focus-visible { outline-offset: -3px; }
.history-toggle[aria-expanded=true], .reference-toggle[aria-expanded=true] { min-height: 33px; padding-top: 5px; padding-bottom: 5px; }
.history-toggle[aria-expanded=true] .section-label, .reference-toggle[aria-expanded=true] .section-label { visibility: hidden; }
.reference-toggle > .icon:not(.reference-chevron) { display: none; }
.history-chevron, .reference-chevron { margin-left: auto; width: 17px; height: 17px; transition: transform .2s; }
.history-toggle[aria-expanded=true] .history-chevron, .reference-toggle[aria-expanded=true] .reference-chevron { transform: rotate(180deg); }
.history-legend { display: none; }
.history-content { padding: 0 20px 20px 48px; }
.chart-wrap { height: var(--history-height, 160px); position: relative; }
#history-chart { width: 100%; height: 100%; display: block; }
.chart-label { position: absolute; left: -36px; width: 26px; text-align: right; font: 12px var(--serif); color: var(--muted); line-height: 1; }
.chart-label.top { top: 0; } .chart-label.center { top: calc(50% - 6px); } .chart-label.bottom { bottom: 0; }
.chart-times { display: flex; justify-content: space-between; margin-top: 8px; font: 12px var(--serif); color: var(--muted); }
#history-resize, #keyboard-resize, #dial-resize { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); display: flex; justify-content: center; align-items: center; width: 72px; height: 20px; cursor: ns-resize; touch-action: none; user-select: none; border-radius: 3px; }
#history-resize::after, #keyboard-resize::after, #dial-resize::after { content: ""; width: 36px; height: 2px; border-radius: 1px; background: var(--brass); }
#history-resize:hover::after, #history-resize:focus-visible::after, #keyboard-resize:hover::after, #keyboard-resize:focus-visible::after, #dial-resize:hover::after, #dial-resize:focus-visible::after { background: var(--accent); height: 3px; }
.history-settings-panel { position: fixed; inset: auto; margin: 0; width: 264px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 16px; border: 1px solid var(--brass); border-radius: 4px; background: linear-gradient(120deg, #fff9ed66, transparent), var(--ivory); color: var(--ink); box-shadow: 0 4px 16px #30271d35; font-size: 14px; }
.history-settings-panel::backdrop { background: transparent; }
.history-settings-panel .field-label { margin-bottom: 8px; }
.history-settings-panel input[type=range] { display: block; margin: 12px 0 23px; }
.history-range-field, .history-range-input { display: flex; align-items: center; }
.history-range-field { justify-content: space-between; gap: 12px; }
.history-range-field + .history-range-field { margin-top: 12px; }
.history-range-field > label { min-width: 0; }
.history-range-input { gap: 5px; }
#history-range, #history-seconds { width: 65px; min-width: 0; min-height: 36px; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); padding: 5px 4px; font: 15px var(--serif); font-variant-numeric: tabular-nums; }
.history-range-input > span:last-child { min-width: 26px; color: var(--muted); font: 14px var(--serif); }
#history-reset { margin-top: 14px; padding-left: 0; padding-bottom: 0; min-height: 32px; }
.reference-panel { margin-top: 8px; min-width: 0; overflow: hidden; }
.reference-panel h2 { font-weight: 400; }
.reference-content { min-width: 0; position: relative; padding-bottom: 20px; }
.keyboard-top { display: flex; align-items: center; justify-content: flex-end; padding: 0 14px; gap: 14px; }
#playing-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.keyboard-actions { display: flex; align-items: center; gap: 16px; }
.keyboard-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 14px 18px; padding: 0 16px 12px; }
.range-controls, .keyboard-range { display: flex; align-items: center; gap: 12px; min-width: 0; }
.range-controls { min-width: max-content; }
.octave-control { display: flex; align-items: center; flex-shrink: 0; height: 39px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.octave-control > span { display: none; }
.octave-control button { width: 32px; height: 100%; flex-shrink: 0; font: 21px var(--serif); }
.octave-control button:hover { background: #cab99330; }
.octave-control strong { font: 16px var(--serif); min-width: 78px; text-align: center; white-space: nowrap; }
.octave-count-control { display: flex; align-items: center; flex-shrink: 0; gap: 7px; font-size: 12px; }
.octave-count-control label { color: var(--muted); }
.octave-count-control select { min-width: 52px; height: 39px; padding-left: 8px; }
.toggle-button { display: inline-flex; align-items: center; gap: 9px; min-height: 39px; padding: 4px 0; font-size: 13px; white-space: nowrap; }
.switch-track { display: inline-block; width: 42px; height: 24px; border-radius: 14px; background: #bdb3a0; box-shadow: inset 0 1px 2px #584d3928; position: relative; transition: background .2s; flex-shrink: 0; }
.switch-track i { display: block; width: 18px; height: 18px; border-radius: 50%; background: #faf3e5; position: absolute; top: 3px; left: 3px; box-shadow: 0 1px 3px #493a2535; transition: left .2s; }
.toggle-button[aria-pressed=true] .switch-track, .toggle-button[aria-checked=true] .switch-track { background: var(--accent); }
.toggle-button[aria-pressed=true] .switch-track i, .toggle-button[aria-checked=true] .switch-track i { left: 21px; }
.sound-controls { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.sound-controls > label { display: none; }
.sound-controls select { height: 39px; min-width: 114px; font-size: 14px; }
.sound-controls .volume-icon { width: 21px; height: 21px; margin-left: 6px; }
.sound-controls input { min-width: 50px; width: 110px; max-width: 180px; flex: 1; margin: 0; }
#volume-label { font: 11px var(--mono); color: var(--muted); white-space: nowrap; }
.reference-layout-control { display: inline-flex; align-items: stretch; flex-shrink: 0; height: 39px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.reference-layout-control button { display: inline-flex; align-items: center; justify-content: center; width: 40px; min-height: 37px; color: var(--muted); }
.reference-layout-control button + button { border-left: 1px solid var(--line); }
.reference-layout-control button:hover { background: var(--soft); color: var(--ink); }
.reference-layout-control button[aria-pressed=true] { background: var(--soft); color: var(--ink); box-shadow: inset 0 0 0 1px var(--brass); }
.reference-layout-control button:focus-visible { outline-offset: -3px; }
.reference-layout-control .icon { width: 21px; height: 21px; }
.piano-scroll { overflow-x: auto; min-width: 0; scrollbar-color: var(--brass) var(--soft); }
.piano-scroll.sustain-scroll, .piano-scroll.sustain-scroll .piano-key { cursor: grab; }
.piano-scroll.sustain-scroll.is-dragging, .piano-scroll.sustain-scroll.is-dragging .piano-key { cursor: grabbing; }
.piano { --black-half: calc(3.1% / var(--octaves, 1)); height: var(--keyboard-height, 160px); min-width: var(--piano-min-width, 0px); position: relative; display: grid; grid-template-columns: repeat(var(--white-keys, 7), minmax(0, 1fr)); gap: 0; isolation: isolate; touch-action: none; }
.piano-key { display: flex; align-items: center; justify-content: flex-end; flex-direction: column; min-width: 0; user-select: none; -webkit-user-select: none; touch-action: none; position: relative; border-radius: 0 0 2px 2px; }
.piano-key.white { color: var(--ink); background: linear-gradient(100deg, #fffaf0, #eee3ce); border: 1px solid #ad9a79; padding: 0 4px 17px; z-index: 1; }
.piano-key.white + .piano-key.white { border-left: 0; }
.piano-key.white:hover { background: #eee0c9; }
.piano-key.black { position: absolute; top: 0; width: calc(var(--black-half) * 2); height: 55%; z-index: 2; color: #fbf5e9; background: linear-gradient(100deg, #3c3a35, #242420); box-shadow: inset 0 0 0 2px #52504877, 0 2px 1px #352f2570; border: 1px solid #151511; padding: 0 2px 7px; }
.piano-key.black:hover { background: #464139; }
.piano-key strong { font: 23px var(--serif); font-weight: 400; font-variant-numeric: lining-nums; }
.piano-key strong .note-register { font-size: inherit; vertical-align: baseline; color: inherit; }
.piano-key.black strong { font-size: 11px; }
.key-frequency, .key-shortcut { display: none; }
.piano-key.white.playing { color: #6d281e; background: #d8afa0; box-shadow: inset 0 3px 6px #926b5228; }
.piano-key.black.playing { background: #8b4233; }
.piano-key:focus-visible { outline-offset: -3px; }
.piano-key.black:focus-visible { z-index: 3; }
.degree-keys .piano-key strong { font-size: 17px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.degree-keys .period-start { border-left: 3px solid var(--brass); }
.piano-scroll.note-grid-scroll { height: var(--keyboard-height, 240px); overflow-x: hidden; overflow-y: auto; touch-action: pan-y; overscroll-behavior-y: contain; scrollbar-gutter: stable; scroll-padding: 10px; }
.piano.note-grid { display: block; height: auto; min-height: 100%; min-width: 0; padding: 0 12px 12px; touch-action: pan-y; }
.reference-group { min-width: 0; touch-action: pan-y; }
.reference-group + .reference-group { margin-top: 14px; }
.reference-group-heading { display: flex; align-items: center; justify-content: center; min-height: 30px; margin: 0 0 8px; padding: 5px 8px; border-radius: 3px; background: var(--soft); color: var(--muted); font: 14px/1.3 var(--serif); touch-action: pan-y; user-select: none; }
.reference-note-grid { display: grid; grid-template-columns: repeat(var(--note-columns, 6), minmax(0, 1fr)); gap: 6px; min-width: 0; touch-action: pan-y; }
.note-grid .note-key { justify-content: center; width: 100%; min-height: 56px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: linear-gradient(110deg, #fffaf066, transparent), var(--paper); touch-action: none; scroll-margin: 8px; }
.note-grid .note-key:hover { background: var(--soft); }
.note-grid .note-key strong { max-width: 100%; font: 20px/1.3 var(--serif); font-variant-numeric: lining-nums; white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
.note-grid .note-key.playing { color: #6d281e; background: #d8afa0; border-color: var(--accent); box-shadow: inset 0 2px 4px #926b5228; }
.piano-scroll.note-grid-scroll.sustain-scroll { touch-action: none; }
dialog { border: 3px double var(--brass); border-radius: 5px; padding: 25px; width: min(620px, calc(100% - 32px)); max-height: 90dvh; color: var(--ink); background: linear-gradient(120deg, #fff9ed66, transparent), var(--ivory); box-shadow: 0 16px 60px #30271d55; }
dialog::backdrop { background: #302c2366; backdrop-filter: blur(2px); }
.quick-tuning-dialog { width: min(420px, calc(100% - 32px)); }
.language-dialog { width: min(340px, calc(100% - 32px)); }
.language-options { display: grid; gap: 8px; }
.language-options button { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; padding: 11px 15px; border: 1px solid var(--line); border-radius: 4px; text-align: left; }
.language-options button:hover { background: var(--soft); }
.language-options button[aria-pressed=true] { background: var(--soft); border-color: var(--brass); font-weight: 600; }
.language-check { visibility: hidden; color: var(--green); width: 20px; height: 20px; }
.language-options button[aria-pressed=true] .language-check { visibility: visible; }
.close-button { border-radius: 4px; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border: 1px solid var(--accent); border-radius: 4px; padding: 10px 17px; font-size: 13px; background: var(--accent); color: #fff6e5; }
.primary-button:hover { background: #713127; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); border: 1px solid var(--brass); background: #3b352b; color: #fff6e6; font-size: 13px; line-height: 1.6; padding: 11px 18px; border-radius: 4px; box-shadow: 0 4px 20px #30271d30; max-width: calc(100% - 32px); z-index: 10; }
@media (max-width: 1050px) {
  .keyboard-toolbar { gap: 10px 14px; }
  .range-controls, .keyboard-range { gap: 8px; }
  .octave-count-control label { display: none; }
  .sound-controls { gap: 9px; }
  .sound-controls select { min-width: 100px; }
  #volume-label { display: none; }
}
@media (max-width: 700px) {
  body { padding: 18px 12px; }
  .site-header { height: 65px; padding: 0 17px; }
  .brand h1 { font-size: 34px; }
  .header-actions { gap: 2px; }
  .icon-button, .language-button { min-width: 38px; }
  .workspace { padding: 12px 9px 8px; }
  .panel-top { padding: 0 3px; flex-wrap: wrap; gap: 10px; }
  .mic-controls { flex-basis: 100%; gap: 15px; }
  .reference-controls { margin-left: auto; }
  .a4-control { height: 42px; }
  .a4-control > label { font-size: 19px; padding-left: 10px; max-width: 100px; }
  .frequency-input { padding-right: 9px; }
  .frequency-input input { width: 72px; font-size: 20px; }
  .frequency-input span { font-size: 17px; }
  .step-button { width: 38px; }
  .quick-tuning-button { width: 43px; height: 42px; }
  .tuner-body { height: var(--dial-height, 240px); padding: 13px 5px 24px; }
  .dial-scale text { font-size: 13px; }
  .readings { margin-top: 8px; }
  .readings strong { font-size: 25px; }
  .readings small { font-size: 19px; }
  .readings > div { padding: 0 6px; }
  .readings p { gap: 4px; }
  .history-toggle, .reference-toggle { padding-left: 12px; padding-right: 12px; }
  .history-content { padding-left: 37px; padding-right: 12px; }
  .chart-label { left: -31px; }
  .keyboard-toolbar { padding: 0 10px 10px; gap: 9px 12px; }
  .range-controls, .keyboard-range { flex: 1; }
  .octave-count-control { margin-left: auto; }
  .octave-count-control select { min-width: 47px; padding-left: 6px; padding-right: 20px; }
  .sound-controls { flex-basis: calc(100% - 56px); gap: 8px; }
  .sound-controls select { width: 108px; min-width: 108px; flex: 0 0 108px; }
  .sound-controls input { width: 60px; min-width: 38px; }
  .sound-controls .volume-icon { margin-left: 1px; }
  .piano { --black-half: calc(3.7% / var(--octaves, 1)); }
  .piano-key.white { padding-bottom: 15px; }
  .piano-key strong { font-size: 19px; }
  .piano-key.black { height: 53%; }
  .piano-key.black strong { font-size: 10px; }
  .reference-layout-control { margin-left: auto; margin-right: auto; }
  .reference-content:has(.note-grid) .octave-control strong { min-width: 40px; }
  .note-grid .note-key strong { font-size: 16px; }
  dialog { padding: 18px; max-height: 92dvh; }
  .dialog-heading h2 { font-size: 18px; }
  .tuning-fields { grid-template-columns: minmax(0, 1fr) 72px; gap: 10px; }
  .tuning-fields select { font-size: 13px; }
  .reference-settings { grid-template-columns: minmax(0, 1fr) 78px; gap: 12px; }
  .reference-settings .field-label, .reference-settings select { font-size: 13px; }
  .stretch-card { padding: 13px; }
  .stretch-controls { font-size: 12px; column-gap: 9px; }
  .detection-fields { grid-template-columns: 1fr; gap: 20px; }
  .compact-field { flex-direction: row; align-items: center; justify-content: space-between; }
  .compact-field select { width: 115px; }
  #sensitivity { margin: 15px 0 0; }
  .table-scroll { max-height: 40dvh; }
  th, td { padding: 10px 7px; }
  td { font-size: 11px; }
  td input { width: 62px; }
}
@media (max-width: 390px) {
  body { padding: 10px 7px; }
  .site-header { padding: 0 12px; height: 60px; }
  .brand h1 { font-size: 30px; }
  .header-actions { gap: 0; }
  .language-button, .icon-button { min-width: 34px; }
  .workspace { padding: 10px 7px 7px; }
  .reference-controls { width: 100%; justify-content: flex-end; gap: 6px; }
  .a4-control { flex: 1; }
  .a4-control > label { padding-left: 8px; font-size: 18px; }
  .frequency-input { flex: 1; padding-right: 6px; }
  .frequency-input input { width: 100%; font-size: 19px; }
  .frequency-input span { font-size: 16px; }
  .step-button { width: 34px; }
  .dial-scale text { font-size: 13px; }
  .readings strong { font-size: 22px; }
  .readings small { font-size: 17px; }
  .octave-control button { width: 26px; }
  .octave-control strong { min-width: 68px; font-size: 14px; }
  .range-controls, .keyboard-range { gap: 6px; }
  .keyboard-toolbar { gap: 9px; padding-left: 8px; padding-right: 8px; }
  .toggle-button { gap: 6px; font-size: 12px; }
  .switch-track { width: 36px; height: 22px; }
  .switch-track i { width: 16px; height: 16px; }
  .toggle-button[aria-pressed=true] .switch-track i, .toggle-button[aria-checked=true] .switch-track i { left: 17px; }
}
:root[data-theme=dark] {
    color-scheme: dark;
    --page: #171915; --theme-color: #242720;
    --ivory: #242720; --paper: #2b2e26; --ink: #e8dfcb; --muted: #b6b29f; --brass: #a18d69;
    --line: #595b49; --soft: #30342a; --green: #88bd98; --red: #ee9585; --accent: #c89478;
    --history-band: #46614a; --history-grid: #565a47; --history-faint: #3e4335; --history-trace: #e1a091;
}
:root[data-theme=dark] body { background: radial-gradient(ellipse at 45% 10%, #383a2b88, #17191500 75%); }
:root[data-theme=dark] .instrument { background: linear-gradient(115deg, #66704d12, #161a1410), var(--ivory); box-shadow: 0 3px 16px #00000060, inset 0 0 0 2px #a18d6918; }
:root[data-theme=dark] :is(.icon-button, .language-button):hover { background: #a18d6926; }
:root[data-theme=dark] :is(.mic-button, .quick-tuning-button) { background: linear-gradient(#414638, #30352a); box-shadow: inset 0 0 0 1px #a18d6920, 0 1px 2px #00000050; }
:root[data-theme=dark] :is(.mic-button, .quick-tuning-button):hover { background: #444b39; }
:root[data-theme=dark] .mic-button.is-listening { background: linear-gradient(#354738, #2c3b2e); box-shadow: inset 0 1px 3px #101d1366; }
:root[data-theme=dark] .mic-button.is-pending { color: #d8b770; }
:root[data-theme=dark] .a4-control { background: #151a1430; }
:root[data-theme=dark] :is(.step-button, .octave-control button):hover { background: #a18d6926; }
:root[data-theme=dark] #level-bars i { background: #5a604d; }
:root[data-theme=dark] #level-bars i.on { background: #88bd98; }
:root[data-theme=dark] .dial { color: #9b9f89; }
:root[data-theme=dark] #dial-needle { fill: #9b9f89; }
:root[data-theme=dark] .dial.has-signal #dial-needle { fill: var(--green); }
:root[data-theme=dark] .dial.has-signal.off-pitch #dial-needle { fill: var(--red); }
:root[data-theme=dark] :is(.history-area, .reference-panel) { background: #141a1018; }
:root[data-theme=dark] :is(.history-settings-button:hover, .history-settings-button[aria-expanded=true]) { background: #a18d6930; }
:root[data-theme=dark] :is(.history-toggle, .reference-toggle):hover { background: #a18d6920; }
:root[data-theme=dark] :is(.history-settings-panel, dialog) { background: linear-gradient(120deg, #66704d12, transparent), var(--ivory); box-shadow: 0 8px 32px #00000066; }
:root[data-theme=dark] dialog::backdrop { background: #090c09a6; }
:root[data-theme=dark] .switch-track { background: #686b58; box-shadow: inset 0 1px 2px #00000050; }
:root[data-theme=dark] .switch-track i { background: #bcb49e; box-shadow: 0 1px 3px #00000060; }
:root[data-theme=dark] :is(.toggle-button[aria-pressed=true], .toggle-button[aria-checked=true]) .switch-track i { background: #262920; }
:root[data-theme=dark] .piano-key.white { color: #f0e7d3; background: linear-gradient(100deg, #625b4d, #494437); border-color: #8e8067; }
:root[data-theme=dark] .piano-key.white:hover { background: #6c6250; }
:root[data-theme=dark] .piano-key.black { color: #e7dcc5; background: linear-gradient(100deg, #292a24, #111710); border-color: #0b0f09; box-shadow: inset 0 0 0 2px #5c624044, 0 2px 1px #00000066; }
:root[data-theme=dark] .piano-key.black:hover { background: #3d4233; }
:root[data-theme=dark] .piano-key.white.playing { color: #fff0d8; background: #855f4e; box-shadow: inset 0 3px 6px #271b1660; }
:root[data-theme=dark] .piano-key.black.playing { color: #fff0d8; background: #8d5e49; }
:root[data-theme=dark] .note-grid .note-key { color: #f0e7d3; background: linear-gradient(110deg, #a18d690a, transparent), var(--paper); border-color: #706b54; }
:root[data-theme=dark] .note-grid .note-key:hover { background: #414638; }
:root[data-theme=dark] .note-grid .note-key.playing { color: #fff0d8; background: #855f4e; border-color: var(--accent); box-shadow: inset 0 2px 4px #271b1660; }
:root[data-theme=dark] .primary-button { color: #1c2019; }
:root[data-theme=dark] .primary-button:hover { background: #dbab92; }
:root[data-theme=dark] .toast { background: #343a2c; color: var(--ink); box-shadow: 0 4px 20px #00000060; }
.reference-content .keyboard-toolbar { display: flex; flex-wrap: nowrap; gap: 8px; padding: 0 16px 12px; }
.reference-content .range-controls { flex: none; gap: 6px; }
.playback-controls { display: flex; align-items: center; flex: none; gap: 6px; min-width: 0; }
.playback-controls > #waveform { width: 114px; min-width: 0; height: 40px; font-size: 14px; }
.toolbar-divider { width: 1px; height: 27px; background: var(--brass); flex: none; margin: 0 3px; }
.toolbar-layout-divider { margin-left: auto; }
.toolbar-icon-button, .sustain-button { display: inline-flex; align-items: center; justify-content: center; flex: none; height: 40px; min-height: 40px; border: 1px solid var(--line); border-radius: 4px; padding: 0; background: var(--paper); }
.toolbar-icon-button { width: 40px; gap: 2px; }
.toolbar-icon-button .icon { width: 22px; height: 22px; }
.toolbar-icon-button .toolbar-chevron { width: 10px; height: 10px; }
.toolbar-icon-button:hover, .toolbar-icon-button[aria-expanded=true], .sustain-button:hover { background: var(--soft); }
.sustain-button { padding: 0 12px; font-size: 13px; white-space: nowrap; }
.sustain-button[aria-pressed=true] { background: #d8afa0; border-color: var(--accent); color: #6d281e; box-shadow: inset 0 2px 4px #926b5228; }
.reference-content .reference-layout-control { height: 40px; margin: 0; }
.reference-layout-control button { min-height: 38px; }
.compact-toolbar-control { display: none; }
.reference-popover { position: fixed; inset: auto; margin: 0; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow: auto; padding: 12px; border: 1px solid var(--brass); border-radius: 4px; color: var(--ink); background: var(--ivory); box-shadow: 0 5px 18px #30271d38; }
.reference-popover::backdrop { background: transparent; }
.volume-panel { width: 52px; height: 172px; padding: 14px 20px; overflow: visible; }
#volume { display: block; writing-mode: vertical-lr; direction: rtl; width: 4px; height: 142px; min-width: 4px; max-width: none; padding: 0; margin: 0; accent-color: var(--accent); touch-action: none; }
.range-menu { width: 238px; }
.compact-range-step { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.compact-range-step button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 3px; font: 22px var(--serif); }
.compact-range-step strong { min-width: 0; text-align: center; font: 16px var(--serif); }
.range-menu > label { display: inline-block; max-width: 135px; margin-right: 8px; font-size: 14px; }
.range-menu > select { min-width: 48px; }
.reference-option-menu { min-width: 172px; padding: 6px; }
.reference-option-menu button { width: 100%; display: flex; align-items: center; gap: 9px; min-height: 42px; padding: 8px 11px; border: 1px solid transparent; border-radius: 3px; text-align: left; font-size: 14px; }
.reference-option-menu button:hover { background: var(--soft); }
.reference-option-menu button[aria-pressed=true] { border-color: var(--brass); background: var(--soft); }
:root[data-theme=dark] .sustain-button[aria-pressed=true] { color: #fff0d8; background: #855f4e; border-color: var(--accent); box-shadow: inset 0 2px 4px #271b1660; }
:root[data-theme=dark] .reference-popover { box-shadow: 0 5px 18px #00000066; }
@media (max-width: 840px) {
  .reference-content .keyboard-toolbar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .reference-content .range-controls, .playback-controls > #waveform, .reference-content .reference-layout-control { display: none; }
  .compact-toolbar-control { display: inline-flex; }
  .playback-controls { gap: 4px; }
  .toolbar-icon-button { width: 36px; }
  #range-menu-open { width: 42px; font: 16px var(--serif); }
  #waveform-open .icon:first-child { width: 20px; }
  .sustain-button { padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 479.98px) {
  .toolbar-divider { display: none; }
  #reference-layout-open { margin-left: auto; }
}
@media (max-width: 359px) {
  .reference-content .keyboard-toolbar { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .playback-controls { gap: 3px; }
  .toolbar-icon-button { width: 32px; }
  #range-menu-open { width: 36px; }
  .sustain-button { padding-left: 7px; padding-right: 7px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
