:root {
  color-scheme: light;
  --ink: #17283a;
  --muted: #4a5b6d;
  --accent: #244e81;
  --accent-dark: #193b65;
  --tint: #eaf1fa;
  --canvas: #f5f2eb;
  --paper: #fff;
  --line: #cdd5de;
  --focus: #215ba0;
  --rule: #7d8b9b;
  --error: #802c36;
  --error-bg: #f9ecea;
  --success: #225941;
  --success-bg: #e8f4eb;
  --serif: Georgia, 'Times New Roman', serif;
  font: 16px/1.5 system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.frame { width: min(100% - 56px, 1320px); margin-inline: auto; }
h1, h2, h3, p, figure { margin: 0; }
p { color: var(--muted); }
h2 { font-size: 1rem; }
h3 { font-size: .9rem; }
button, input, select { font: inherit; }
button, summary, .upload { cursor: pointer; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .55rem .9rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 650;
  text-align: center;
}
button:hover, .button:hover { background: var(--accent-dark); }
button:disabled { opacity: .48; cursor: default; }
:focus-visible, .upload:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.secondary { border-color: var(--rule); background: white; color: var(--accent-dark); }
.secondary:hover { background: var(--tint); }
.text-button { min-height: 44px; padding-inline: 0; background: transparent; color: var(--accent); text-decoration: underline; text-underline-offset: .2em; }
.text-button:hover { background: transparent; color: var(--accent-dark); }
label { display: block; font-size: .86rem; font-weight: 650; }
label + select, label + input:not([type=checkbox]):not([type=file]) { margin-top: 4px; }
select, input:not([type=checkbox]):not([type=file]) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: white;
  color: var(--ink);
}
input[type=checkbox] { inline-size: 18px; block-size: 18px; accent-color: var(--accent); margin: 0; flex-shrink: 0; }
input[type=file] { width: 100%; }
.check { display: flex; align-items: flex-start; gap: 8px; padding-block: 7px; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }

.site-header { background: #fffdf8; border-bottom: 1px solid #dbd8d0; }
.header-inner { display: flex; min-height: 68px; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; gap: .62rem; align-items: center; font: 700 1.55rem/1 var(--serif); white-space: nowrap; }
.brand span {
  display: grid;
  place-items: center;
  inline-size: 35px;
  block-size: 35px;
  border-radius: 9px;
  background: var(--ink);
  color: #f6e5bb;
  font-size: 1.55rem;
}
#library { position: relative; }
#library > summary { padding: .55rem .85rem; border: 1px solid var(--rule); border-radius: 9px; color: var(--ink); font-size: .9rem; font-weight: 650; }
#library > summary:hover, #library[open] > summary { background: var(--tint); }
.library-panel {
  position: absolute;
  inset: calc(100% + 8px) 0 auto auto;
  z-index: 5;
  width: min(390px, calc(100vw - 32px));
  max-height: min(70dvh, 560px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--ink);
  box-shadow: 0 10px 30px #173e2f24;
}
.library-panel button { margin-top: 8px; }
#library-list { list-style: none; padding: 0; margin: 10px 0; }
#library-list li { display: flex; gap: 6px; border-top: 1px solid var(--line); }
#library-list button:first-child { flex: 1; justify-content: flex-start; overflow-wrap: anywhere; }
#library-owner, #library-status { overflow-wrap: anywhere; font-size: .87rem; }
#library-status:not(:empty) { margin-top: 8px; }

.steps {
  display: flex;
  align-items: center;
  gap: clamp(8px, 3vw, 36px);
  padding: 0;
  margin: 20px 0 16px;
  list-style: none;
  color: var(--muted);
  font-size: .83rem;
  font-weight: 650;
}
.steps li { display: flex; align-items: center; gap: .55rem; white-space: nowrap; }
.steps [aria-current] { color: var(--accent-dark); }
.steps [aria-current]::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
[data-stage="start"] .steps { display: none; }

.intake {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .9fr);
  gap: clamp(28px, 5vw, 72px);
  align-items: center;
  margin: clamp(28px, 7vw, 98px) auto 0;
  max-width: 1080px;
}
.upload-panel, .example-panel { min-width: 0; }
.upload-panel h1 {
  max-width: 12ch;
  font: 600 clamp(2.4rem, 5.2vw, 4.65rem)/1.02 var(--serif);
  letter-spacing: -.055em;
  text-wrap: balance;
}
.intro { margin-top: 16px; max-width: 40ch; font-size: 1.04rem; }
.file-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 24px; }
.file-actions > button, .file-actions > label { position: relative; min-width: 0; min-height: 48px; }
.file-actions .button { font-size: 1rem; }
.upload input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; margin: 0; }
.file-limits { margin-top: 10px; font-size: .83rem; }
#demo { margin-top: 6px; }
.example-panel {
  background: #e5e9ef;
  border: 1px solid #d5dbe2;
  padding: clamp(18px, 4vw, 45px);
  border-radius: 18px;
}
.example-paper {
  min-height: 225px;
  padding: 26px 12px 12px;
  overflow: hidden;
  border-radius: 6px;
  background: #fffdf8;
  box-shadow: 0 5px 16px #17283a18;
}
.example-title { text-align: center; font: 600 1.35rem var(--serif); color: var(--ink); }
#example-sheet { max-height: 240px; overflow: hidden; }

[data-stage="work"] .intake { display: block; max-width: none; margin-top: 0; }
[data-stage="work"] .upload-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}
[data-stage="work"] .upload-panel h1 {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
[data-stage="work"] .intro,
[data-stage="work"] .example-panel,
[data-stage="work"] .upload-panel .file-limits { display: none; }
[data-stage="work"] .file-actions, [data-stage="work"] #demo { margin: 0; }
[data-stage="work"] .file-actions > button, [data-stage="work"] .upload { min-height: 44px; }
#status { max-width: 1080px; margin-inline: auto; white-space: pre-line; overflow-wrap: anywhere; font-size: .9rem; }
#status:not(:empty) {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  margin-block: 12px;
  border: 1px solid #bdcfe3;
  background: var(--tint);
  color: var(--ink);
  border-radius: 9px;
}
#status[data-tone="error"] { border-color: #dcb4b8; color: var(--error); background: var(--error-bg); }
#status[data-tone="success"] { border-color: #adcfbd; color: var(--success); background: var(--success-bg); }
#status[data-tone="loading"]::before {
  content: '';
  flex: 0 0 15px;
  height: 15px;
  border: 2px solid #b6c8dd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: reading .9s linear infinite;
}
@keyframes reading { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #status[data-tone="loading"]::before { animation: none; } }
[data-stage="work"] #status { max-width: none; }

.workbench {
  display: grid;
  grid-template-columns: minmax(232px, 287px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 12px;
}
.work-controls { display: grid; min-width: 0; gap: 12px; }
.panel { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.pages ol { list-style: none; padding: 0; margin: 8px 0; }
.pages li { padding: 7px; border: 1px solid var(--line); border-radius: 7px; margin-bottom: 6px; }
.pages > button, .pages section button { width: 100%; }
.file-preview { gap: 8px; width: 100%; text-align: left; overflow-wrap: anywhere; justify-content: flex-start; font-size: .83rem; }
.file-preview[aria-pressed=true], #page-results button[aria-pressed=true] { background: var(--tint); border-color: var(--accent); }
.file-preview img {
  width: 30px; height: 38px; object-fit: contain;
  background: white; border: 1px solid var(--line); border-radius: 3px;
}
.file-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.file-tools button { min-height: 36px; padding: 4px 7px; font-size: .8rem; }
.file-name { overflow-wrap: anywhere; font-size: .85rem; }
#page-review { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
#page-results li { display: grid; gap: 3px; font-size: .8rem; color: var(--muted); }
#page-actions { margin: 8px 0; }
#page-correction { margin-top: 3px; font-size: .82rem; }

.viewer { padding: 12px; background: #e8ecf1; }
.viewer-toolbar, .view-switch, .paging, .downloads {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
}
.viewer-toolbar { justify-content: space-between; gap: 8px; }
.viewer-toolbar button, .mobile-compare button { min-height: 44px; padding: 4px 10px; font-size: .83rem; }
.view-switch button[aria-pressed=true] { background: var(--accent); color: white; border-color: var(--accent); }
.paging { font-size: .8rem; justify-content: flex-end; }
.paging button { min-width: 40px; font-size: 1.2rem; }
.mobile-compare { display: none; }
.sheets { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; margin-top: 8px; }
.viewer[data-view="compare"] .sheets { grid-template-columns: repeat(2,minmax(0,1fr)); }
.sheet-pane { min-width: 0; overflow: hidden; background: white; border-radius: 7px; border: 1px solid var(--line); }
.sheet-heading { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.sheet-heading h2 { font-size: .9rem; }
#count { font-size: .8rem; color: var(--muted); }
#preview-empty { padding: 24px 12px; font-size: .9rem; }
.score > svg { display: block; width: 100%; height: auto; }
.score > [data-inactive] { display: none; }
#original figure { padding: 6px; }
#original figcaption { padding: 3px; font-size: .78rem; overflow-wrap: anywhere; }
#original figure > a { display: inline-block; margin: 2px 3px 8px; color: var(--accent); font-size: .83rem; }
#original img, #original iframe { display: block; width: 100%; border: 0; }
#original img { height: auto; }
#original iframe { height: clamp(350px, 65vh, 900px); }
#original figure p { padding: 10px; font-size: .83rem; }
.downloads { justify-content: flex-start; margin-block: 8px 10px; }

.inspector h2 { margin-bottom: 12px; }
.inspector label:not(.check) { margin-top: 8px; }
.inspector details { border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.inspector summary { font-weight: 700; padding: 4px; }
#edit-apply, #edit-lyric-apply { width: 100%; margin-top: 8px; }
#edit-lyrics { margin: 12px 0 0; min-width: 0; padding: 4px 8px 8px; border: 1px solid var(--line); border-radius: 8px; }
#edit-lyrics legend { font-size: .84rem; font-weight: 650; }
#review { margin-top: 8px; background: var(--tint); border-radius: 8px; padding: 6px 8px; }
#parts { margin: 12px 0 3px; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
#parts legend { font-size: .84rem; font-weight: 650; }
#parts p, #key-hint, #interval { font-size: .8rem; overflow-wrap: anywhere; }
#part-list label { display: flex; gap: 6px; align-items: flex-start; font-weight: 500; }
#key-hint:not(:empty), #interval:not(:empty) { margin-top: 6px; }
#submit { width: 100%; margin-top: 12px; }
footer { max-width: 1080px; margin-inline: auto; padding-block: 24px; font-size: .78rem; color: var(--muted); }

#camera-dialog { width: min(540px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: white; color: var(--ink); }
#camera-dialog::backdrop { background: #13231fc4; }
#camera-dialog h2 { margin-bottom: 10px; font-size: 1.2rem; }
#camera-preview { display: block; width: 100%; max-height: 54dvh; border-radius: 8px; object-fit: contain; background: #18211e; }
#camera-status { margin: 10px 0; }
.camera-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#native-camera { grid-column: 1 / -1; }

@media (max-width: 760px) {
  .frame { width: calc(100% - 32px); }
  .header-inner { min-height: 60px; }
  .steps { gap: 12px; font-size: .72rem; margin-block: 13px; flex-wrap: wrap; }
  .intake, .workbench { grid-template-columns: minmax(0,1fr); gap: 16px; }
  .intake { margin-top: 30px; }
  .upload-panel h1 { max-width: 13ch; }
  .intro { margin-top: 12px; font-size: 1rem; }
  [data-stage="start"] .file-actions { display: grid; grid-template-columns: 1fr 1fr; margin-top: 19px; }
  .example-panel { padding: 16px; }
  .example-paper { min-height: 0; padding: 16px 8px 8px; }
  #example-sheet { max-height: 150px; }
  [data-stage="work"] #demo { margin: 0; min-height: 36px; }
  .file-actions { flex: 1 0 100%; }
  .pages ol { max-height: 220px; overflow: auto; }
  .viewer { padding: 8px; }
  .downloads { gap: 7px; }
  .downloads #pdf { flex-basis: 100%; }
  .viewer-toolbar button, .mobile-compare button { min-height: 44px; }
}
@media (max-width: 700px) {
  .viewer[data-view="compare"] .mobile-compare { display: flex; margin-top: 7px; }
  .mobile-compare button { flex: 1; }
  .viewer[data-view="compare"] .sheets { grid-template-columns: minmax(0,1fr); }
  .viewer[data-view="compare"][data-pane="sheet"] .original-pane,
  .viewer[data-view="compare"][data-pane="original"] #sheet-pane { display: none; }
}

@page { size: A4; margin: 8mm; }
@media print {
  :root, body { background: white; }
  .site-header, .steps, .intake, #status, .work-controls, .viewer-toolbar, .mobile-compare,
  #original-details, .sheet-heading, #preview-empty, .downloads, footer, #camera-dialog { display: none !important; }
  .frame { width: auto; }
  #workbench, #viewer, .sheets, #sheet-pane { display: block !important; padding: 0; margin: 0; border: 0; border-radius: 0; overflow: visible; background: white; }
  #preview > svg { display: block; width: 100%; max-height: 278mm; break-inside: avoid; }
  #preview > svg + svg { break-before: page; }
}

#settings, #editor { margin-top: 9px; }
#quality:not(:empty) { padding: 8px; background: #fff4d6; border-radius: 6px; }
#pdf { flex-grow: 1; }
#pagewise-option { font-weight: 500; }
