/* Neutral shadcn/ui token conventions and control sizes; native HTML controls. */
:root {
    color-scheme: dark;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-synthesis: none;
    --background: #000;
    --foreground: #fafafa;
    --card: #09090b;
    --primary: #fafafa;
    --primary-foreground: #18181b;
    --muted: #18181b;
    --muted-foreground: #a1a1aa;
    --accent: #27272a;
    --border: #27272a;
    --input: #71717a;
    --ring: #a1a1aa;
    --radius: 8px;
    --diagram-ink: #e4e4e7;
    --diagram-body: #141416;
    --diagram-outline: #71717a;
    --diagram-open: #000;
    --diagram-covered: #e4e4e7;
    --diagram-muted: #a1a1aa;
    --staff-line: #71717a;
    --staff-paper: #000;
    background: var(--background);
    color: var(--foreground);
}
:root[data-theme='light'] {
    color-scheme: light;
    --background: #fff;
    --foreground: #09090b;
    --card: #fff;
    --primary: #18181b;
    --primary-foreground: #fafafa;
    --muted: #f4f4f5;
    --muted-foreground: #52525b;
    --accent: #e4e4e7;
    --border: #e4e4e7;
    --input: #71717a;
    --ring: #71717a;
    --diagram-ink: #27272a;
    --diagram-body: #f4f4f5;
    --diagram-outline: #71717a;
    --diagram-open: #fff;
    --diagram-covered: #27272a;
    --diagram-muted: #52525b;
    --staff-line: #71717a;
    --staff-paper: #fff;
}
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; background: var(--background); }
body:has(dialog[open]) { overflow: hidden; }
button, select, input, output { font: inherit; }
button, select, input, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .3; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }
button, select { transition: background .12s, border-color .12s; }
a { color: inherit; text-underline-offset: 4px; }
[hidden] { display: none !important; }
.app { overflow-anchor: none; width: 100%; max-width: 1000px; margin: 0 auto; padding: 0 max(20px, env(safe-area-inset-right)) 24px max(20px, env(safe-area-inset-left)); }
.app:focus { outline: none; }
.toolbar { display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 0 10px; border-bottom: 1px solid var(--border); }
.song-picker { position: relative; flex: 0 1 360px; min-width: 0; }
.select-chevron { position: absolute; right: 10px; top: 8px; width: 16px; height: 16px; color: var(--muted-foreground); pointer-events: none; }
#song-select { appearance: none; -webkit-appearance: none; display: block; width: 100%; min-width: 0; height: 32px; padding: 0 36px 0 10px; border: 1px solid var(--input); border-radius: 6px; color: var(--foreground); background: var(--card); font-size: 14px; text-overflow: ellipsis; }
.toolbar-actions { display: flex; gap: 4px; margin-left: auto; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 7px; flex-shrink: 0; height: 36px; padding: 0 12px; border: 1px solid transparent; border-radius: 6px; background: transparent; font-size: 14px; font-weight: 500; white-space: nowrap; }
.button.ghost:hover:not(:disabled) { background: var(--muted); }
.button.outline { border-color: var(--input); background: var(--background); }
.button.outline[aria-pressed='true'] { color: var(--foreground); border-color: var(--foreground); background: var(--muted); }
.button.outline[aria-pressed='false'] { color: var(--muted-foreground); }
.button.primary { background: var(--primary); color: var(--primary-foreground); min-width: 88px; }
.button.primary:hover { opacity: .88; }
.icon-button { width: 32px; height: 32px; padding: 0; }
.icon { display: inline-flex; width: 16px; height: 16px; align-items: center; justify-content: center; flex-shrink: 0; pointer-events: none; }
.icon svg { display: block; width: 16px; height: 16px; }
.notation-toggle { position: relative; color: var(--muted-foreground); cursor: pointer; }
.notation-toggle input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.notation-toggle:has(input:checked) { background: var(--accent); color: var(--foreground); }
.notation-toggle:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 3px; }
.player { display: grid; grid-template-columns: 112px minmax(0,1fr); align-items: center; gap: 16px; padding: 20px 0 0; }
.note-panel { display: flex; flex-direction: column; gap: 14px; align-self: center; }
.pitch-button { display: flex; align-items: baseline; gap: 3px; width: fit-content; min-width: 72px; min-height: 68px; padding: 0; border: 0; border-radius: 6px; background: transparent; }
#note-name { display: block; min-width: .8em; font-size: 64px; font-weight: 500; line-height: 1; letter-spacing: -3px; }
#note-octave { font-size: 20px; font-weight: 400; color: var(--muted-foreground); }
.pitch-button .icon { align-self: center; margin-left: 8px; color: var(--muted-foreground); }
.note-details { display: flex; flex-direction: column; gap: 5px; color: var(--muted-foreground); font-size: 12px; font-variant-numeric: tabular-nums; }
.diagram { min-width: 0; width: 100%; }
.fingering-svg { display: block; width: 100%; max-width: 100%; height: auto; margin: auto; }
#fingering { width: 100%; height: 290px; }
#fingering .fingering-svg { height: 100%; }
.hole-key { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 30px; font-size: 11px; color: var(--muted-foreground); }
.hole-key > span { display: flex; align-items: center; gap: 6px; }
.hole-key i { width: 9px; height: 9px; border: 1px solid var(--diagram-ink); border-radius: 50%; }
.covered-hole { background: var(--diagram-covered); }
.open-hole { background: var(--diagram-open); }
.playback-panel { grid-column: 1/-1; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 0; border-top: 1px solid var(--border); }
.main-controls { display: flex; align-items: center; gap: 8px; }
.playback-settings { display: flex; align-items: center; gap: 18px; }
.play-options { display: flex; gap: 6px; }
.tempo-control { display: flex; align-items: center; gap: 12px; width: 215px; }
#tempo { min-width: 0; width: 100%; height: 32px; margin: 0; accent-color: var(--primary); cursor: pointer; }
#tempo-value { min-width: 55px; color: var(--muted-foreground); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.melody { min-width: 0; padding-top: 12px; border-top: 1px solid var(--border); }
.note-strip { display: flex; height: 142px; gap: 8px; padding: 6px 5px 10px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--input) transparent; overscroll-behavior-x: contain; position: relative; }
.note-tile { flex: 0 0 100px; min-width: 0; padding: 10px 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); color: var(--foreground); }
.note-tile:hover { border-color: var(--input); }
.note-tile.current { background: var(--muted); border-color: var(--foreground); }
.note-tile .fingering-svg { width: 100%; height: 58px; margin-bottom: 6px; }
.note-tile > strong { display: block; font-size: 19px; font-weight: 500; line-height: 1.3; }
.note-tile strong small { font-size: 11px; color: var(--muted-foreground); margin-left: 1px; }
.tile-beats { display: block; margin-top: 4px; color: var(--muted-foreground); font-size: 11px; }
.sheet-music { margin-top: 14px; padding: 12px 0; border-top: 1px solid var(--border); min-width: 0; }
.checkbox-label { display: flex; align-items: center; justify-content: flex-end; gap: 7px; min-height: 32px; color: var(--muted-foreground); font-size: 12px; cursor: pointer; }
.checkbox-label input { width: 14px; height: 14px; margin: 0; accent-color: var(--primary); }
.staff-scroll { overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--input) transparent; }
.staff-svg { display: block; max-width: none; height: 188px; }
.staff-svg [data-current] { --staff-note: var(--primary); --staff-weight: 700; }
.status { min-height: 20px; font-size: 13px; line-height: 1.5; color: var(--muted-foreground); margin: 12px 0; }
.status:empty { visibility: hidden; }
dialog { width: 480px; max-width: calc(100% - 24px); max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom))); padding: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--foreground); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #000b; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; padding: 14px 20px; gap: 12px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { font-size: 16px; font-weight: 600; margin: 0; }
.dialog-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px; display: grid; gap: 20px; }
dialog p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--muted-foreground); }
.help-controls, .details-content { display: grid; gap: 12px; }
.keyboard-shortcuts { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted-foreground); font-size: 12px; }
.keyboard-shortcuts > span { white-space: nowrap; }
.help-details { border-top: 1px solid var(--border); }
.help-details details + details { border-top: 1px solid var(--border); }
.help-details summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; list-style: none; font-size: 13px; font-weight: 500; cursor: pointer; }
.help-details summary::-webkit-details-marker { display: none; }
.help-details summary::after { content: ''; width: 6px; height: 6px; margin-right: 3px; border-right: 1.5px solid var(--muted-foreground); border-bottom: 1.5px solid var(--muted-foreground); transform: rotate(45deg); }
.help-details details[open] > summary::after { transform: rotate(225deg); }
.details-content { padding-bottom: 16px; }
.details-content strong { font-weight: 500; color: var(--foreground); }
.help-links { display: grid; gap: 2px; font-size: 13px; }
.help-links a { width: fit-content; padding-block: 6px; }
.dialog-footer { flex-shrink: 0; display: grid; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.version-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; color: var(--muted-foreground); font-size: 12px; }
.version-row > span { white-space: nowrap; }
#app-version { color: var(--foreground); font-size: 12px; }
.dialog-footer .button { height: 32px; padding-inline: 10px; font-size: 12px; }
.dialog-footer p { font-size: 12px; line-height: 1.5; }
kbd { font: 12px ui-monospace, monospace; padding: 2px 4px; border: 1px solid var(--input); border-radius: 3px; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link:focus { position: fixed; top: 8px; left: 8px; z-index: 20; padding: 8px 12px; border-radius: 6px; color: var(--foreground); background: var(--background); outline: 2px solid var(--ring); }
@media (max-width: 767px) {
    .app { padding: 0 max(12px, env(safe-area-inset-right)) calc(120px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
    .toolbar { position: sticky; top: 0; z-index: 5; background: var(--background); padding-block: max(8px, env(safe-area-inset-top)) 8px; }
    .song-picker { flex: 1; }
    #song-select { font-size: 16px; }
    .toolbar-actions { margin: 0; }
    .player { grid-template-columns: 1fr; gap: 8px; padding-top: 14px; }
    .note-panel { flex-direction: row; justify-content: space-between; align-items: center; padding-inline: 4px; }
    .pitch-button { min-height: 56px; }
    #note-name { font-size: 52px; }
    #note-octave { font-size: 17px; }
    .note-details { text-align: right; font-size: 12px; }
    #fingering { height: auto; aspect-ratio: 470 / 337; max-height: 290px; }
    .hole-key { min-height: 28px; }
    .playback-panel { position: fixed; inset: auto 0 0; z-index: 8; flex-direction: column; gap: 6px; padding: 8px max(12px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: var(--background); }
    .main-controls { justify-content: center; width: 100%; max-width: 460px; }
    .main-controls .icon-button { width: 36px; height: 36px; }
    #play { flex: 1; max-width: 240px; height: 40px; }
    .playback-settings { justify-content: space-between; width: 100%; max-width: 460px; gap: 14px; }
    .tempo-control { width: auto; flex: 1; }
    .play-options .icon-button { width: 32px; height: 32px; }
    .melody { margin-top: 8px; }
    html { scroll-padding-top: 60px; scroll-padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
}
@media (orientation: portrait) and (max-width: 767px) and (max-height: 740px) {
    .player { padding-top: 10px; gap: 6px; }
    .pitch-button { min-height: 44px; }
    #note-name { font-size: 44px; }
    #fingering { max-height: clamp(160px, calc(100svh - 368px), 240px); }
    .melody { margin-top: 4px; }
    .melody { padding-top: 8px; }
    .note-strip { height: 76px; }
    .note-tile { padding-block: 8px; }
    .note-tile .fingering-svg, .note-tile .rest-tile { display: none; }
}
@media (orientation: landscape) and (max-width: 1023px) and (max-height: 540px) {
    .app { max-width: none; padding-bottom: 16px; }
    .toolbar { position: static; padding-block: 6px; }
    .song-picker { flex: 0 1 360px; }
    #song-select { font-size: 16px; }
    .player { grid-template-columns: 76px minmax(0,1fr) 148px; gap: 10px; padding-top: 10px; }
    .note-panel { flex-direction: column; align-items: flex-start; gap: 9px; padding: 0; }
    #note-name { font-size: 48px; }
    #note-octave { font-size: 16px; }
    .pitch-button .icon { display: none; }
    .note-details { text-align: left; font-size: 11px; }
    #fingering { aspect-ratio: auto; height: clamp(130px, calc(100svh - 110px), 200px); }
    .hole-key { font-size: 10px; min-height: 22px; }
    .playback-panel { grid-column: 3; position: static; padding: 0 0 0 10px; flex-direction: column; justify-content: center; align-self: stretch; gap: 12px; border: 0; border-left: 1px solid var(--border); }
    .main-controls { display: grid; grid-template-columns: 32px minmax(0,1fr) 32px; grid-template-rows: 36px 32px; gap: 6px; }
    #play { grid-column: 1/-1; grid-row: 1; width: 100%; height: 36px; }
    #restart { grid-column: 1; grid-row: 2; }
    #previous { grid-column: 2; grid-row: 2; justify-self: center; }
    #next { grid-column: 3; grid-row: 2; }
    .main-controls .icon-button { width: 32px; height: 32px; }
    .playback-settings { flex-direction: column; align-items: stretch; gap: 10px; }
    .play-options { justify-content: center; gap: 10px; }
    .tempo-control { width: 100%; gap: 8px; }
    .melody { margin-top: 12px; }
    html { scroll-padding-block: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; } }

.svg-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.pitch-button[data-accidental="true"] #note-name { font-size: 44px; }
.pitch-button[data-rest="true"] #note-name { font-size: 32px; letter-spacing: -1px; }
.pitch-button[data-rest="true"] { opacity: 1; }
.pitch-button[data-rest="true"] .icon { visibility: hidden; }
#fingering[data-rest="true"] { opacity: .18; }
.rest-tile { display: block; height: 58px; margin-bottom: 6px; font-size: 44px; line-height: 58px; }
