:root {
  color-scheme: light;
  --paper: #f5f1e6;
  --surface: #fffef9;
  --ink: #223b38;
  --text: #304340;
  --muted: #75807a;
  --line: #dedfd5;
  --accent: #2c6258;
  --accent-soft: #eaf0e7;
  --danger: #a84134;
  --serif: "Noto Serif SC", "Noto Serif CJK SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Noto Sans SC", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image: url("./parchment.svg");
  background-size: 320px 320px;
  color: var(--text);
  font: 14px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; outline-offset: 4px; }
button { cursor: pointer; color: inherit; transition: background .16s, color .16s, border-color .16s; }
button:disabled { cursor: not-allowed; opacity: .46; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); }
a { color: inherit; }
button, select, input { border-radius: 6px; }
input, select { min-width: 0; }
button:not(:disabled):active { transform: translateY(1px); }
[hidden] { display: none !important; }

.workspace { max-width: 1440px; margin: 0 auto; padding: 0 56px; }
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  min-height: 112px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.page-title { margin: 0; color: var(--ink); font: 600 28px/1.5 var(--serif); letter-spacing: .5px; }
.service-state { display: flex; align-items: center; gap: 9px; flex-shrink: 0; font-size: 12px; color: var(--muted); }
.state-dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: #acb29f; }
.service-state.is-ready .state-dot { background: #56876a; box-shadow: 0 0 0 4px #56876a0c; }
.service-state.is-error .state-dot { background: var(--danger); }
.eyebrow { margin: 0 0 12px; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 2px; }
.creation-layout { display: grid; grid-template-columns: minmax(0, 1fr) 305px; gap: 22px; align-items: start; }
.paper-card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 3px 12px #31403b03; }
.score-card { min-height: 500px; overflow: hidden; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 27px 28px 24px; }
.card-heading .eyebrow { margin-bottom: 7px; }
.card-heading h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 21px; color: var(--ink); letter-spacing: .5px; }
.card-heading h2.section-heading { font-family: var(--sans); font-size: 21px; letter-spacing: 0; }

.notation-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafaf4; flex-wrap: wrap; }
.tool-group { display: flex; gap: 3px; align-items: center; }
.notation-button { display: flex; min-height: 53px; min-width: 43px; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 7px; border: 1px solid transparent; background: none; color: #54625a; font-size: 9px; line-height: 1.2; }
.notation-button:hover:not(:disabled) { background: #eeeee5; }
.notation-button.is-selected { color: var(--accent); border-color: #bed0bb; background: var(--accent-soft); }
.music-glyph { font-family: "Noto Music", "Bravura", serif; font-size: 25px; line-height: 1.1; height: 28px; display: flex; align-items: center; }
.compact-tool { min-width: 33px; min-height: 40px; padding: 3px 6px; }
.accidental-glyph { font-size: 28px; line-height: 1; }
.dot-glyph { font-size: 31px; line-height: 1; }
.tie-glyph { font-size: 24px; line-height: 1; }
.rest-tool { min-width: 39px; }
.expression-tools { border-left: 1px solid var(--line); padding-left: 10px; }
.editor-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 22px 5px; }
.clef-label { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.clef-label select { border: 1px solid var(--line); background: var(--surface); padding: 5px 7px; color: var(--text); font-size: 11px; }
.edit-actions { display: flex; align-items: center; gap: 7px; }
.icon-button { padding: 0; width: 28px; height: 28px; line-height: 1; font-size: 21px; border: 0; background: none; color: #65776d; }
.small-button { border: 0; background: none; padding: 4px 5px; font-size: 11px; color: var(--muted); }
.small-button:hover { background: #f0f0e9; color: var(--ink); }
.action-divider { display: block; width: 1px; height: 15px; background: var(--line); margin: 0 3px; }
.staff-editor { min-height: 210px; margin: 0 14px; overflow-x: auto; overscroll-behavior-x: contain; color: var(--ink); }
.staff-editor svg { max-width: 100%; display: block; }
#staff-editor { width: auto; }
.theme-audio-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 20px 24px 24px; }
.secondary-button { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 36px; border: 1px solid #c4d2c4; padding: 7px 15px; color: var(--accent); background: #f3f6ee; font-size: 12px; }
.secondary-button:hover:not(:disabled) { background: #e8eee1; }
.secondary-button span { font-size: 10px; }
.theme-audio-row audio { height: 34px; max-width: 100%; width: 265px; }
.theme-audio-row .muted { font-size: 11px; }
.saved-themes-area { padding: 18px 24px 24px; border-top: 1px solid var(--line); }
.saved-theme-row { display: flex; gap: 10px; align-items: end; }
.saved-theme-row + .saved-theme-row { margin-top: 15px; }
.saved-theme-row .field { flex: 1; min-width: 0; }
.saved-theme-row > button { min-height: 39px; flex-shrink: 0; }
#saved-theme-error { margin: 12px 0 0; }

.settings-card .card-heading { padding: 27px 23px 25px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 19px 12px; padding: 0 23px; }
.field { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.field > span:first-child { display: flex; justify-content: space-between; align-items: center; color: #5a6b63; font-size: 11px; }
.field input:not([type=range]), .field select { width: 100%; height: 39px; border: 1px solid #dbdfd5; background: #fffefb; color: var(--ink); padding: 7px 9px; font-size: 12px; }
.field select { padding-right: 5px; }
.input-with-unit { display: flex; align-items: center; position: relative; }
.input-with-unit input { padding-right: 36px !important; -moz-appearance: textfield; }
.input-with-unit input::-webkit-outer-spin-button, .input-with-unit input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-with-unit > span { position: absolute; right: 9px; pointer-events: none; font-size: 10px; color: var(--muted); }
.duration-estimate { margin: 16px 23px 20px; font-size: 11px; color: var(--muted); }
.advanced-settings { border-top: 1px solid var(--line); margin: 0 23px; }
.advanced-settings summary { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; font-size: 11px; color: var(--muted); cursor: pointer; list-style: none; }
.advanced-settings summary::-webkit-details-marker { display: none; }
.advanced-settings summary span { font-size: 16px; }
.advanced-settings[open] summary span { transform: rotate(45deg); }
.advanced-content { display: flex; flex-direction: column; gap: 17px; padding-bottom: 20px; }
.field input[type=range] { margin: 0; width: 100%; accent-color: var(--accent); }
.field .range-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.field-hint { font-size: 10px; color: var(--muted); line-height: 1.7; }
.generation-action { padding: 9px 23px 23px; }
.primary-button { display: flex; width: 100%; align-items: center; justify-content: center; gap: 20px; min-height: 45px; padding: 10px 15px; border: 1px solid var(--accent); background: var(--accent); color: #fffdf3; font-size: 13px; letter-spacing: .5px; }
.primary-button:hover:not(:disabled) { background: #214e45; }
.primary-button:disabled { opacity: .58; }
.primary-button #generate-arrow { font-size: 20px; line-height: 1; }
.creation-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 23px 20px; font-size: 11px; color: var(--accent); }
.creation-progress .muted { margin-left: auto; font-variant-numeric: tabular-nums; }
.progress-pulse { width: 5px; height: 5px; background: var(--accent); border-radius: 50%; animation: pulse 1.8s infinite; }
.error-message { margin: 0 23px 20px; padding: 10px 12px; font-size: 12px; background: #fbefea; border: 1px solid #edcfc4; border-radius: 5px; color: var(--danger); overflow-wrap: anywhere; }
.spinner { width: 14px; height: 14px; border: 2px solid #ffffff50; border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }

.result-card { margin-top: 28px; overflow: hidden; }
.result-heading { border-bottom: 1px solid var(--line); }
.result-heading-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap; }
.result-empty { padding: 38px 20px 40px; text-align: center; }
.result-empty p { margin: 9px 0; font-size: 13px; color: #65756a; }
.result-overview { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 28px 17px; }
.result-title { margin: 0; color: var(--ink); font-size: 14px; font-weight: 600; }
#result-meta { margin: 6px 0 0; font-size: 11px; }
.download-links { display: flex; flex-wrap: wrap; gap: 10px; }
.download-link { display: inline-flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 5px; padding: 7px 10px; color: var(--accent); font-size: 11px; text-decoration: none; white-space: nowrap; }
.download-link:hover { background: var(--accent-soft); }
#result-audio { display: block; width: calc(100% - 56px); height: 43px; margin: 0 28px 20px; accent-color: var(--accent); }
.musicxml-import-area { padding: 18px 28px 0; border-bottom: 1px solid var(--line); }
.musicxml-import-area:not(:has(> :not([hidden]))) { display: none; }
.musicxml-import-area .error-message { margin: 0 0 15px; }
.import-controls { display: grid; grid-template-columns: minmax(150px, 1.5fr) minmax(90px, .7fr) minmax(90px, .7fr) auto; gap: 15px; align-items: end; padding: 3px 0 20px; }
.import-controls > .secondary-button { min-height: 39px; white-space: nowrap; }

.history-section { margin: 33px 0 44px; }
.history-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.history-heading h2 { font-family: var(--serif); font-size: 18px; letter-spacing: .5px; font-weight: 600; margin: 0; color: var(--ink); }
.history-heading .muted { font-size: 11px; }
.history-section > p { font-size: 12px; }
.local-library-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 16px; }
.local-library-controls p { margin: 0; font-size: 12px; line-height: 1.7; flex: 1 1 320px; }
.local-library-actions { display: flex; gap: 10px; }
#local-storage-status:empty { display: none; }
.history-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.history-item { display: flex; flex-direction: column; min-width: 0; background: #fffef980; border: 1px solid var(--line); border-radius: 7px; }
.history-open { display: flex; flex: 1; width: 100%; text-align: left; align-items: center; justify-content: space-between; gap: 10px; padding: 15px 16px 10px; border: 0; background: none; border-radius: 7px 7px 0 0; }
.history-open:hover:not(:disabled) { background: #fefdf6; }
.history-item.is-active { border-color: #96b099; background: #edf2e7; }
.history-item-title { display: block; color: var(--text); font-size: 12px; font-weight: 500; }
.history-item-meta { display: block; font-size: 10px; color: var(--muted); margin-top: 5px; }
.history-item-status { color: var(--accent); font-size: 10px; white-space: nowrap; }
.history-item.is-failed .history-item-status { color: var(--danger); }
.history-item-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 12px 9px; }
.history-item-actions button { min-height: 32px; border: 0; background: none; }
.history-item-actions button:hover:not(:disabled) { background: #e8eee1; }
.history-favorite { min-width: 34px; padding: 0 5px; color: var(--muted); font-size: 24px; line-height: 1; }
.history-favorite[aria-pressed="true"] { color: #92722e; }
.history-delete { padding: 4px 8px; color: var(--muted); font-size: 11px; }
.history-delete:hover:not(:disabled) { color: var(--danger); }
#history-error { margin: 0 0 15px; }
.muted { color: var(--muted); }
.skip-link { position: fixed; top: 12px; left: 12px; z-index: 20; padding: 8px 14px; color: white; background: var(--accent); transform: translateY(-200%); }
.skip-link:focus { transform: translateY(0); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .3; } }

@media (min-width: 1350px) {
  .creation-layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .notation-button { min-width: 49px; }
  .compact-tool { min-width: 36px; }
}

@media (max-width: 1100px) {
  .workspace { padding: 0 30px; }
  .creation-layout { grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; }
  .card-heading { padding: 24px 21px 21px; }
  .notation-toolbar { padding: 11px 16px; gap: 8px; }
  .expression-tools { border-left: 0; padding-left: 0; }
  .notation-button { min-width: 39px; }
  .settings-card .card-heading { padding: 24px 19px 23px; }
  .settings-grid { padding: 0 19px; gap: 17px 10px; }
  .duration-estimate { margin-left: 19px; margin-right: 19px; }
  .advanced-settings { margin: 0 19px; }
  .generation-action { padding-left: 19px; padding-right: 19px; }
  .editor-meta { padding-left: 15px; padding-right: 15px; }
  .edit-actions { gap: 2px; }
  .history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 800px) {
  .workspace { padding: 0 23px; }
  .masthead { min-height: 96px; margin-bottom: 24px; }
  .page-title { font-size: 25px; }
  .service-state { font-size: 10px; }
  .creation-layout { grid-template-columns: 1fr; gap: 18px; }
  .score-card { min-height: 0; }
  .notation-toolbar { justify-content: flex-start; gap: 20px; }
  .expression-tools { border-left: 1px solid var(--line); padding-left: 16px; }
  .notation-button { min-width: 43px; }
  .compact-tool { min-width: 33px; }
  .settings-card .card-heading { padding: 22px 24px 20px; }
  .settings-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 0 24px; gap: 15px; }
  .duration-estimate { margin-left: 24px; margin-right: 24px; }
  .advanced-settings { margin: 0 24px; }
  .generation-action { padding: 10px 24px 20px; }
  .primary-button { min-height: 47px; }
  .advanced-content { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
  .creation-progress, .error-message { margin-left: 24px; margin-right: 24px; }
  .result-overview { align-items: flex-start; flex-direction: column; gap: 15px; }
  .history-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .import-controls { grid-template-columns: 1fr 1fr; }
  .import-controls .field:first-child { grid-column: 1 / -1; }
  .import-controls > .secondary-button { grid-column: 1 / -1; }
  .musicxml-import-area { padding: 18px 20px 0; }
}

@media (max-width: 520px) {
  .workspace { padding: 0 16px; }
  .masthead { min-height: 108px; align-items: flex-start; justify-content: center; flex-direction: column; gap: 8px; padding: 18px 0; margin-bottom: 20px; }
  .page-title { font-size: 23px; letter-spacing: 0; }
  .service-state { gap: 7px; font-size: 10px; }
  .eyebrow { font-size: 9px; letter-spacing: 1.4px; }
  .card-heading { padding: 22px 17px 19px; gap: 10px; }
  .card-heading h2 { font-size: 19px; }
  .notation-toolbar { padding: 10px 12px; gap: 7px 10px; }
  .duration-tools { gap: 2px; width: 100%; justify-content: space-between; }
  .duration-button { min-width: 43px; padding-left: 5px; padding-right: 5px; min-height: 48px; font-size: 9px; }
  .expression-tools { padding-left: 0; border-left: 0; gap: 5px; }
  .compact-tool { min-height: 33px; min-width: 35px; }
  .rest-tool { min-height: 38px; flex-direction: row; gap: 6px; padding: 2px 8px; }
  .rest-tool .music-glyph { font-size: 22px; }
  .editor-meta { flex-wrap: wrap; gap: 7px; padding: 12px 13px 4px; }
  .clef-label { font-size: 10px; gap: 6px; }
  .edit-actions { margin-left: auto; }
  .icon-button { width: 24px; }
  .small-button { font-size: 10px; padding: 3px; }
  .staff-editor { margin: 0 8px; }
  .theme-audio-row { padding: 17px 15px 20px; gap: 10px; }
  .theme-audio-row audio { width: 100%; }
  .saved-themes-area { padding: 17px 15px 20px; }
  .saved-theme-row { gap: 7px; }
  .saved-theme-row > button { padding-left: 10px; padding-right: 10px; }
  .settings-card .card-heading { padding: 22px 19px 20px; }
  .settings-grid { grid-template-columns: 1fr 1fr; padding: 0 19px; gap: 17px 14px; }
  .duration-estimate { margin-left: 19px; margin-right: 19px; }
  .advanced-settings { margin: 0 19px; }
  .advanced-content { grid-template-columns: 1fr; gap: 17px; }
  .generation-action { padding-left: 19px; padding-right: 19px; }
  .creation-progress, .error-message { margin-left: 19px; margin-right: 19px; }
  .result-card { margin-top: 22px; }
  .result-overview { padding: 19px 17px 15px; }
  .result-empty { padding: 31px 13px 32px; }
  .result-heading-actions { gap: 8px; max-width: 160px; }
  .result-heading-actions .secondary-button { font-size: 10px; padding: 7px 9px; gap: 7px; }
  .download-links { gap: 7px; }
  .download-link { padding: 6px 9px; font-size: 10px; }
  #result-audio { width: calc(100% - 34px); margin: 0 17px 18px; }
  .musicxml-import-area { padding: 18px 16px 0; }
  .import-controls { gap: 12px; }
  .history-section { margin-top: 27px; }
  .history-list { grid-template-columns: 1fr; }
  .history-open { padding: 13px 15px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
