:root { --ink:#233630; --muted:#62776e; --accent:#186b58; --accent-light:#e6f3ec; --line:#d9e3dc; --surface:#ffffff; --background:#f3f6f1; --danger:#ac4030; }
    * { box-sizing:border-box; }
    body { margin:0; color:var(--ink); background:var(--background); font:14px/1.65 "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, "Noto Sans CJK JP", sans-serif; }
    button, input, select { font:inherit; }
    button { cursor:pointer; color:var(--ink); background:#fff; border:1px solid var(--line); border-radius:9px; min-height:39px; padding:6px 12px; font-weight:600; transition:background .12s, border-color .12s; touch-action:manipulation; }
    button:hover:not(:disabled) { background:#f0f6f1; border-color:#9fbbae; }
    button:disabled { opacity:.38; cursor:not-allowed; }
    button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, #scoreViewport:focus-visible { outline:3px solid #dbab42; outline-offset:3px; }
    button.primary { background:var(--accent); color:#fff; border-color:var(--accent); }
    button.primary:hover:not(:disabled) { background:#125541; }
    button.danger { color:var(--danger); }
    input[type=text], select { width:100%; min-height:41px; background:#fff; border:1px solid #cbd8d0; border-radius:8px; color:var(--ink); padding:8px 10px; }
    input[type=checkbox] { accent-color:var(--accent); }
    label { display:block; font-size:12px; font-weight:700; color:var(--muted); }
    [hidden] { display:none !important; }
    .app-header { background:#fff; border-bottom:1px solid var(--line); }
    .header-inner { max-width:1660px; margin:0 auto; padding:17px 26px; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:14px; }
    .brand { display:flex; align-items:center; gap:12px; }
    .brand-mark { width:42px; height:42px; flex:none; }
    h1 { margin:0; font-size:20px; letter-spacing:.03em; line-height:1.45; }
    .brand-sub { margin:2px 0 0; font-size:11px; color:var(--muted); letter-spacing:.07em; }
    .file-actions { display:flex; align-items:center; flex-wrap:wrap; gap:7px; }
    main { max-width:1660px; margin:0 auto; padding:23px 26px 45px; }
    .document-settings { display:flex; align-items:end; flex-wrap:wrap; gap:14px; margin-bottom:18px; }
    .title-field { flex:1; min-width:240px; }
    .title-field input { font-size:18px; font-weight:600; min-height:46px; }
    .meter-field { width:124px; }
    .meter-field select { min-height:46px; }
    .history-actions { display:flex; gap:7px; align-self:end; }
    .history-actions button { min-height:46px; }
    .workspace { display:grid; grid-template-columns:260px minmax(0,1fr); gap:19px; align-items:start; }
    .rail { display:grid; gap:14px; position:sticky; top:12px; }
    .palette-card { order:1; }
    .editor-card { order:2; }
    .rail.has-selection .editor-card { order:1; }
    .rail.has-selection .palette-card { order:2; }
    .card { background:#fff; border:1px solid var(--line); border-radius:14px; padding:17px; }
    .card h2 { margin:0 0 12px; font-size:14px; display:flex; align-items:center; gap:8px; }
    .section-number { width:22px; height:22px; display:inline-flex; align-items:center; justify-content:center; background:var(--accent-light); color:var(--accent); border-radius:6px; font-size:12px; }
    .small { font-size:12px; color:var(--muted); }
    .palette-caption { font-weight:700; font-size:11px; color:var(--muted); margin:12px 0 6px; }
    .palette-grid { display:grid; grid-template-columns:repeat(4, 1fr); gap:5px; }
    .palette-tool { min-width:0; padding:3px 1px 7px; border-radius:9px; display:flex; align-items:center; flex-direction:column; }
    .palette-tool svg { width:43px; height:53px; display:block; }
    .palette-tool .tool-name { font-size:10px; line-height:1.3; white-space:nowrap; }
    .palette-tool .tool-beats { font-size:10px; line-height:1.3; color:var(--muted); font-weight:400; }
    .triplet-palette { display:grid; grid-template-columns:1fr 1fr; gap:6px; }
    .triplet-tool { min-width:0; padding:7px 5px; }
    .triplet-tool svg { width:100%; max-width:102px; height:48px; display:block; margin:auto; }
    .triplet-tool span { display:block; font-size:11px; line-height:1.6; }
    .triplet-tool .tool-beats { color:var(--muted); font-weight:400; }
    .triplet-tool[aria-pressed=true] { background:var(--accent-light); border-color:var(--accent); box-shadow:inset 0 0 0 1px var(--accent); }
    .triplet-editor { background:#f0f6ed; border:1px solid var(--line); border-radius:8px; padding:9px; margin-bottom:11px; }
    .triplet-editor p { margin:0 0 7px; font-size:11px; color:var(--muted); }
    .triplet-editor button { width:100%; font-size:12px; }
    .palette-tool[aria-pressed=true] { background:var(--accent-light); border:2px solid var(--accent); padding:2px 0 6px; color:var(--accent); }
    .hint { margin:12px 0 0; color:var(--muted); font-size:12px; line-height:1.75; }
    .selected-summary { display:flex; justify-content:space-between; align-items:center; gap:8px; padding-bottom:11px; margin-bottom:11px; border-bottom:1px solid var(--line); }
    #selectedName { font-weight:700; font-size:18px; }
    #selectedPosition { font-size:11px; color:var(--muted); }
    .pitch-controls { display:grid; grid-template-columns:1fr 1fr; gap:7px; margin-bottom:12px; }
    .accidental-controls { display:flex; gap:5px; margin:5px 0 12px; }
    .accidental-controls button { flex:1; padding:2px 3px; font-size:19px; }
    .accidental-controls button:first-child { font-size:11px; }
    .accidental-controls button[aria-pressed=true] { background:var(--accent-light); border-color:var(--accent); box-shadow:inset 0 0 0 1px var(--accent); }
    .two-fields { display:grid; grid-template-columns:1fr 1fr; gap:9px; margin-bottom:11px; }
    #lyricInput { font-weight:500; font-size:16px; }
    .note-actions { display:flex; gap:6px; margin-top:12px; }
    .note-actions button { flex:1; padding:6px 5px; font-size:11px; }
    .empty-selection { margin:12px 0; color:var(--muted); font-size:12px; min-height:85px; display:flex; align-items:center; }
    .score-area { min-width:0; }
    .score-toolbar { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px; padding:0 2px 10px; font-size:12px; }
    #scoreSummary { font-weight:700; }
    #draftStatus { color:var(--muted); font-size:11px; }
    #scoreViewport { background:#eaf0e9; border:1px solid var(--line); border-radius:14px; overflow:auto; padding:22px; min-height:390px; }
    .score-paper { background:#fff; padding:28px 20px 27px; min-width:1000px; min-height:325px; box-shadow:0 4px 19px #2b4b3510; border-radius:3px; }
    #printTitle { color:#17231c; margin:0 0 8px; font-size:27px; text-align:center; line-height:1.65; overflow-wrap:anywhere; white-space:pre-wrap; }
    #paperMeta { font-size:12px; color:#66776b; text-align:center; margin:0 0 13px; }
    .score-row { break-inside:avoid; page-break-inside:avoid; margin-bottom:13px; }
    .score-row:last-child { margin-bottom:0; }
    .measure-tools { background:#fff; border:1px solid var(--line); border-radius:12px; padding:13px 15px; margin:0 0 12px; }
    .measure-tools-top { display:flex; align-items:center; flex-wrap:wrap; gap:8px 16px; margin-bottom:9px; }
    .measure-tools h2 { margin:0; font-size:13px; }
    #measureSelectionLabel { font-weight:700; color:var(--accent); font-size:12px; }
    #clipboardStatus { margin-left:auto; font-size:11px; color:var(--muted); }
    .measure-tool-actions { display:flex; flex-wrap:wrap; gap:7px; align-items:center; }
    .measure-tool-actions button { font-size:12px; }
    .measure-tool-actions .paste-start { margin-left:8px; }
    .measure-tools .hint { margin:8px 0 0; font-size:11px; }
    .row-actions { display:flex; align-items:center; gap:10px; margin:6px 0 10px; padding-left:3.12%; font-size:11px; color:var(--muted); }
    .row-actions button { font-size:11px; min-height:33px; padding:4px 10px; }
    .measure-selector { cursor:pointer; }
    .measure-selector:hover rect { stroke:#87ad98; }
    .measure-selector:focus-visible { outline:none; }
    .measure-selector:focus-visible rect { stroke:#c48d22; stroke-width:3; }
    @media(max-width:720px) {
      .measure-tools { padding:12px; }
      .measure-tool-actions { display:grid; grid-template-columns:1fr 1fr; }
      .measure-tool-actions button { padding:7px 5px; }
      .measure-tool-actions .paste-start { margin-left:0; }
      #clipboardStatus { margin-left:0; flex-basis:100%; }
    }
    .score-row svg { display:block; width:100%; height:auto; user-select:none; -webkit-user-select:none; overflow:visible; }
    .measure-hit { cursor:crosshair; }
    .event-hit { cursor:pointer; }
    .event-hit:hover .event-selection { stroke:#76a38e; stroke-width:1.5; }
    .keyboard-help { margin:12px 0 0; color:var(--muted); font-size:11px; line-height:2.1; }
    kbd { border:1px solid #cdd9cf; border-bottom-width:2px; border-radius:4px; background:#fff; color:var(--ink); padding:1px 5px; font:11px/1.3 inherit; }
    details.help { margin-top:17px; font-size:12px; color:var(--muted); }
    details.help summary { cursor:pointer; font-weight:700; }
    details.help p { margin:8px 0; }
    .mini-legend { display:flex; flex-wrap:wrap; gap:10px; margin-top:10px; font-size:11px; color:var(--muted); }
    .badge { background:#e6f1e7; color:#32684d; border-radius:4px; padding:2px 6px; }
    #toast { position:fixed; left:50%; bottom:24px; transform:translateX(-50%); padding:13px 20px; max-width:min(640px,calc(100vw - 24px)); width:max-content; background:#244b3d; color:#fff; border-radius:11px; box-shadow:0 5px 25px #0002; font-size:13px; z-index:50; }
    #toast[data-error=true] { background:#943a2b; }
    #fatalError { padding:20px; background:#fff1eb; border:1px solid #b9442e; margin:20px; color:#6d2419; }
    .screen-reader-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }
    .view-controls { display:flex; align-items:center; flex-wrap:wrap; gap:8px 12px; }
    .view-controls label { display:flex; align-items:center; gap:6px; font-size:12px; white-space:nowrap; }
    #textScaleInput { width:120px; accent-color:var(--accent); }
    #textScaleValue { display:inline-block; min-width:42px; text-align:right; font-weight:700; color:var(--accent); }
    #layoutModeSelect { width:112px; min-height:36px; padding:5px 7px; }
    .rail-toggle { display:none; }
    .rail-backdrop { display:none; }
    .rail-drawer-head { display:none; }
    @media(max-width:2100px) {
      .workspace { grid-template-columns:1fr; }
      .rail { position:fixed; top:10px; right:10px; bottom:10px; width:min(390px,calc(100vw - 20px)); z-index:31; overflow:auto; overscroll-behavior:contain; padding:12px; background:#eef3ed; border:1px solid var(--line); border-radius:16px; box-shadow:0 14px 50px #172b2340; transform:translateX(calc(100% + 28px)); transition:transform .18s ease; align-content:start; scroll-behavior:smooth; }
      .rail.is-open { transform:translateX(0); }
      .rail-drawer-head { display:flex; align-items:center; justify-content:space-between; gap:10px; position:sticky; top:-12px; z-index:2; margin:-12px -12px 4px; padding:11px 12px; background:#eef3ed; border-bottom:1px solid var(--line); }
      .rail-drawer-head button { min-width:38px; padding:3px 9px; font-size:20px; }
      .rail-toggle { display:inline-flex; align-items:center; gap:6px; position:fixed; right:16px; bottom:16px; z-index:29; background:var(--accent); color:#fff; border-color:var(--accent); box-shadow:0 5px 22px #173a2e42; }
      .rail-backdrop { position:fixed; inset:0; z-index:30; background:#10261e52; }
      .rail-backdrop.is-open { display:block; }
      .palette-tool svg { width:45px; height:54px; }
      .palette-tool .tool-name { font-size:11px; }
      .palette-grid { gap:8px; }
      .palette-card .palette-caption { margin-top:8px; }
      .editor-card .pitch-controls { margin-bottom:8px; }
      .editor-card .accidental-controls { margin-bottom:8px; }
      .editor-card .selected-summary { margin-bottom:8px; padding-bottom:8px; }
      .editor-card .two-fields { margin-bottom:7px; }
    }
    @media(max-width:720px) {
      .header-inner { padding:13px 14px; }
      main { padding:16px 13px 34px; }
      h1 { font-size:18px; }
      .brand-sub { font-size:10px; }
      .file-actions { gap:5px; }
      .file-actions button { font-size:11px; padding:6px 9px; }
      .rail { width:min(390px,calc(100vw - 12px)); top:6px; right:6px; bottom:6px; }
      .document-settings { gap:9px; }
      .title-field { flex-basis:100%; }
      .history-actions { margin-left:auto; }
      .history-actions button { font-size:12px; }
      #scoreViewport { padding:8px; }
      .view-controls { width:100%; justify-content:space-between; gap:7px; }
      #textScaleInput { width:100px; }
      .rail-toggle { right:10px; bottom:10px; }
      .card { padding:14px; }
    }
    @media print {
      @page { size:A4 landscape; margin:12mm; }
      body { margin:0; background:#fff; }
      .app-header, .document-settings, .rail, .rail-toggle, .rail-backdrop, .score-toolbar, .measure-tools, .keyboard-help, .help, .mini-legend, #toast, #fatalError, noscript { display:none !important; }
      main { margin:0; padding:0; max-width:none; }
      .workspace { display:block; }
      #scoreViewport { display:block; border:0; border-radius:0; background:#fff; padding:0; overflow:visible; min-height:0; outline:none !important; }
      .score-paper { min-width:0 !important; min-height:0; border:0; padding:0; box-shadow:none; }
      #printTitle { font-size:22pt; margin-bottom:2mm; }
      #paperMeta { font-size:9pt; margin-bottom:3mm; }
      .score-row { margin-bottom:3mm; break-inside:avoid; page-break-inside:avoid; }
      .score-row.empty-row { display:none !important; }
      .edit-only, .empty-placeholder { display:none !important; }
      svg { print-color-adjust:exact; -webkit-print-color-adjust:exact; }
    }

    .playback-tools { background:#fff; border:1px solid var(--line); border-radius:12px; padding:12px 15px; margin:0 0 12px; position:sticky; top:8px; z-index:5; box-shadow:0 2px 10px #23363008; }
    .playback-controls { display:flex; align-items:center; flex-wrap:wrap; gap:8px; }
    .playback-controls button { font-size:12px; }
    .palette-tool[data-duration="6"] { grid-column:1 / -1; flex-direction:row; justify-content:center; gap:12px; padding:3px 9px; }
    .palette-tool[data-duration="6"][aria-pressed=true] { padding:2px 8px; }
    .palette-tool[data-duration="6"] svg { width:44px; height:45px; }
    .palette-tool[data-duration="6"] .tool-name { font-size:12px; }
    .instrument-control { display:flex; align-items:center; gap:6px; font-size:12px; }
    #instrumentSelect { width:154px; min-height:38px; padding:5px 7px; }

    .tempo-control, .volume-control { display:flex; align-items:center; gap:6px; font-size:12px; margin-left:6px; }
    #tempoInput { width:70px; min-height:38px; border:1px solid var(--line); border-radius:8px; padding:5px 6px; font:inherit; color:var(--ink); }
    #volumeInput { width:85px; accent-color:var(--accent); }
    #playbackStatus { margin:7px 0 0; font-size:11px; color:var(--muted); min-height:18px; }
    #playbackStatus[data-error=true] { color:var(--danger); }
    .event-hit.is-playing .event-selection { fill:#ffe9aa !important; stroke:#ad700c !important; stroke-width:2.5 !important; }
    .playing-measure .measure-hit { stroke:#c28b29 !important; stroke-width:2 !important; }
    .app-modal { position:fixed; inset:0; z-index:10000; display:flex; align-items:center; justify-content:center; padding:14px; background:#142c2870; }
    .app-modal .app-dialog { color:var(--ink); background:#fff; border:1px solid var(--line); border-radius:16px; padding:24px; width:min(660px,100%); max-height:calc(100vh - 28px); max-height:calc(100dvh - 28px); overflow:auto; overscroll-behavior:contain; box-shadow:0 18px 70px #132b3740; }
    .build-label { display:inline-block; font-size:10px; letter-spacing:0; color:#285d48; background:#e6f3ec; padding:0 5px; margin-right:5px; border-radius:4px; }
    .dialog-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; }
    .dialog-heading .modal-close { flex:none; font-size:20px; padding:0 9px; min-width:36px; min-height:36px; }
    .import-file-option { margin:14px 0; font-size:12px; }
    .import-file-option summary { cursor:pointer; color:var(--muted); }
    .import-check-row { display:flex; align-items:center; flex-wrap:wrap; gap:8px; }
    .app-dialog textarea:focus-visible { outline:3px solid #dbab42; outline-offset:2px; }
    .import-readiness { font-size:12px; color:var(--danger); }
    .app-dialog h2 { margin:0 0 10px; font-size:19px; }
    .app-dialog p { margin:8px 0 14px; }
    .app-dialog input[type=file] { display:block; width:100%; margin-top:8px; padding:12px; font:inherit; background:#f3f7f1; border:1px solid var(--line); border-radius:9px; }
    .app-dialog input::file-selector-button { cursor:pointer; border:1px solid #bbcec1; border-radius:6px; padding:7px 10px; margin-right:10px; background:#fff; font:inherit; color:var(--ink); }
    .dialog-actions { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:8px; margin-top:20px; }
    .dialog-actions .backup-button { margin-right:auto; }
    #importStatus { font-size:12px; white-space:pre-wrap; overflow-wrap:anywhere; min-height:22px; }
    #importStatus[data-error=true] { color:var(--danger); }
    .import-preview { margin-top:14px; padding:13px; border:1px solid #b4d4c2; border-radius:10px; background:var(--accent-light); }
    .import-preview strong { display:block; font-size:16px; overflow-wrap:anywhere; }
    .import-preview p { margin:3px 0 0; font-size:12px; }
    .json-paste { margin-top:16px; font-size:12px; }
    .json-paste summary { cursor:pointer; color:var(--muted); }
    #jsonInput { width:100%; min-height:180px; height:24vh; max-height:360px; margin:8px 0; padding:9px; border:1px solid var(--line); border-radius:8px; font:12px/1.6 monospace; resize:vertical; }
    #confirmMessage { white-space:pre-wrap; }
    .audio-credit { font-size:11px; color:var(--muted); margin-top:14px; }
    .audio-credit a { color:var(--accent); }
    @media(max-width:720px) {
      .playback-tools { position:static; padding:11px; }
      .playback-controls { gap:6px; }
      .tempo-control { margin-left:0; }
      .app-modal .app-dialog { padding:18px; }
      .dialog-actions { gap:6px; }
    }
    @media print {
      .playback-tools, .app-modal, .audio-credit { display:none !important; }
    }
  /* Practice view is isolated from the editor and has no hosting dependencies. */
body.practice-open { overflow:hidden; }
body.practice-open > .app-header, body.practice-open > main,
body.practice-open > .rail-toggle, body.practice-open > .rail-backdrop { display:none !important; }
#practiceRoot { position:fixed; inset:0; z-index:9000; display:flex; flex-direction:column; background:#edf3ef; color:#233630; height:100vh; height:100dvh; overflow:hidden; }
#practiceRoot:fullscreen { width:100vw; height:100vh; }
.practice-chrome { flex:none; background:#fff; border-bottom:1px solid #d9e3dc; padding:10px 18px; max-height:45vh; overflow:auto; }
.practice-primary { display:flex; align-items:center; flex-wrap:wrap; gap:8px 12px; }
.practice-brand { display:flex; align-items:center; gap:9px; margin-right:6px; font-weight:700; white-space:nowrap; }
.practice-brand small { font-size:10px; color:#62776e; letter-spacing:.06em; }
.practice-primary button, .practice-primary select { min-height:36px; font-size:12px; }
.practice-primary select { width:auto; max-width:200px; padding:5px 8px; }
.practice-primary label { display:flex; align-items:center; gap:6px; font-size:11px; }
.practice-right { margin-left:auto; display:flex; gap:7px; align-items:center; }
.practice-options { margin-top:8px; font-size:12px; }
.practice-options summary { cursor:pointer; color:#466959; width:max-content; }
.practice-options-grid { display:flex; flex-wrap:wrap; align-items:end; gap:8px 16px; padding:9px 0 0; }
.practice-options-grid label { display:flex; flex-direction:column; gap:4px; font-size:11px; }
.practice-options-grid label.inline { flex-direction:row; align-items:center; padding:7px 0; }
.practice-options-grid select { width:135px; min-height:34px; padding:4px 7px; font-size:12px; }
.practice-options-grid input[type=number] { width:80px; border:1px solid #cbd8d0; border-radius:7px; padding:5px 7px; min-height:34px; color:#233630; }
.practice-options-grid input[type=range] { width:108px; accent-color:#186b58; }
.practice-stage-wrap { flex:1; min-height:0; min-width:0; display:flex; align-items:center; justify-content:center; overflow:hidden; padding:12px; }
#practiceCanvas { display:block; background:#fff; border-radius:8px; box-shadow:0 8px 30px #24463712; max-width:100%; max-height:100%; outline:none; touch-action:manipulation; }
#practiceCanvas:focus-visible { outline:2px solid #186b58; outline-offset:3px; }
.practice-footer { flex:none; background:#fff; padding:7px 18px; border-top:1px solid #d9e3dc; display:flex; align-items:center; flex-wrap:wrap; gap:6px 18px; font-size:11px; line-height:1.6; }
#practiceStatus { margin:0; color:#466959; flex:1; min-width:180px; }
#practiceStatus[data-error=true] { color:#ac4030; }
.practice-keyhelp { color:#62776e; }
#practiceRoot.is-clean .practice-chrome, #practiceRoot.is-clean .practice-footer { display:none; }
#practiceRoot.is-clean .practice-stage-wrap { padding:0; background:#fff; }
#practiceRoot.is-clean #practiceCanvas { border-radius:0; box-shadow:none; cursor:none; }
#practiceRoot.is-clean { background:#fff; }
@media(max-width:900px) {
 .practice-chrome { padding:7px 10px; }
 .practice-brand { font-size:13px; }
 .practice-brand small { display:none; }
 .practice-primary { gap:5px 7px; }
 .practice-right { margin-left:0; }
 .practice-primary button { min-height:34px; padding:5px 9px; }
 .practice-footer { padding:5px 10px; }
 .practice-keyhelp { display:none; }
 .practice-stage-wrap { padding:6px; }
}
@media print { #practiceRoot { display:none !important; } body.practice-open > main { display:block !important; } }
#practiceRoot.is-clean #practiceCanvas:focus-visible { outline:none; }

    .site-info { margin:16px 0 4px; font-size:12px; color:var(--muted); }
    .site-info a { color:var(--accent); }
    @media print { .site-info { display:none !important; } }
