/* Layout layer — loaded after polish.css. One information architecture for the workspace.
   The older layers (style / workflow / mobile-language) each switched sections on per mode, so
   controls from every mode piled up. This layer decides, per mode, what is on screen and where:

     header      brand · 曲目库 (drawer) ·············· status · 反馈 · 退出 · 新任务
     heading     song name + meta ······································· ⋯ (project menu)
                 [音轨 | 乐谱 | 练习 | 导出]
     toolbar     one row: what you are editing (乐谱/练习) · how it plays (试听) · 更多
     content     tracks / score / export cards
     transport   fixed at the bottom

   layout.js builds the two wrappers this needs (.workspace-toolbar, the export cards) and moves
   existing nodes into them; no element id changes, so app.js keeps working untouched. */

/* ---------- The library is a drawer at every width, not a permanent column ---------- */
body[data-screen="workspace"] #library-toggle { display: inline-flex; align-items: center; }
#library { display: none; z-index: 12; width: 288px; box-shadow: var(--float); background: var(--paper); border-right: 0; }
#library.open { display: block; }
main { margin-left: 0; }
.transport { left: 0; }
body[data-screen="workspace"] main {
  max-width: 1240px;
  margin-inline: auto;
  padding-inline: clamp(16px, 4vw, 40px);
}
/* The song name is the page heading; repeating it in the header is noise. */
body[data-screen="workspace"] header #song-title { visibility: hidden; }

/* ---------- Heading: song name, meta, project menu, then the mode tabs ---------- */
#workspace { display: flex; flex-direction: column; }
.workspace-heading {
  position: relative;
  display: block;
  order: 0;
  margin: 0 0 18px;
  padding-right: 48px; /* room for the ⋯ menu */
}
.workspace-heading .section-kicker { display: none; }
.workspace-heading #mode-title {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 30px);
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.workspace-heading #project-meta { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.workspace-heading > div #delete-project { display: none; } /* lives in the project menu */
.workspace-heading nav { display: inline-flex; width: fit-content; max-width: 100%; margin-top: 18px; }

.project-menu { position: absolute; top: 0; right: 0; }
.project-menu > summary {
  list-style: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}
.project-menu > summary::-webkit-details-marker { display: none; }
.project-menu > summary:active { transform: scale(0.95); }
@media (hover: hover) and (pointer: fine) { .project-menu > summary:hover { background: rgb(20 32 51 / .05); color: var(--ink); } }
.project-menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 180px;
  padding: 6px;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--float);
  transform-origin: top right;
  transition: opacity 150ms var(--ease-out), transform 150ms var(--ease-out);
}
@starting-style { .project-menu[open] > div { opacity: 0; transform: scale(0.97); } }
.project-menu > div > button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  font-size: 14px;
}
.project-menu #delete-project { display: block; color: #b42318; margin: 0; }

/* ---------- One toolbar row: editing controls · 试听 · 更多 ---------- */
.workspace-toolbar {
  order: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--card);
}
.workspace-toolbar .score-tools,
.workspace-toolbar .score-tools-main { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; margin: 0; padding: 0; }
/* Older layers give these their own card; inside the toolbar that would be a card in a card. */
.workspace-toolbar .score-tools, .workspace-toolbar .score-tools-main, .workspace-toolbar .listening-bar, .workspace-toolbar #practice { background: none; box-shadow: none; border: 0; border-radius: 0; }
.workspace-toolbar .score-tools-main label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.workspace-toolbar .score-tools-main select { min-width: 120px; }
.workspace-toolbar .more-actions { position: relative; }

/* 试听: a single segmented control, the same in every mode that plays audio. */
.workspace-toolbar .listening-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}
.workspace-toolbar .listening-bar::before { content: attr(data-caption); font-size: 13px; color: var(--muted); }  /* data-caption is translated (i18n.js) */
.workspace-toolbar #viewing-label,
.workspace-toolbar #export-current-audio,
.workspace-toolbar #export-backing-audio { display: none; }
.workspace-toolbar #listening-label {
  order: 3;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.workspace-toolbar .listening-bar > div {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--wash);
}
.workspace-toolbar .listening-bar > div > button {
  padding: 6px 12px;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  font-size: 13px;
  white-space: nowrap;
}
.workspace-toolbar .listening-bar > div > button[aria-pressed="true"] { background: var(--paper); box-shadow: 0 1px 2px rgb(20 32 51 / .1); color: var(--ink); }

/* 练习: two buttons and a hint, inline in the toolbar instead of a separate hero card. */
.workspace-toolbar #practice { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0; background: none; box-shadow: none; }
.workspace-toolbar #practice[hidden] { display: none; }
.workspace-toolbar #practice h3 { display: none; }
.workspace-toolbar #practice p { margin: 0 6px 0 0; font-size: 13px; color: var(--muted); }

/* Per mode: the toolbar shows only what that mode is for. */
body[data-mode="listen"] .workspace-toolbar .score-tools { display: none; }
body[data-mode="listen"] .workspace-toolbar .listening-bar,
body[data-split-only="true"] .workspace-toolbar .listening-bar { margin-left: 0; }
body[data-mode="export"] .workspace-toolbar { display: none; }
/* 练习 is for playing: keep the part choice, drop the editing tools and the correction panel. */
body[data-mode="practice"] .workspace-toolbar #notation,
body[data-mode="practice"] .workspace-toolbar #add-note,
body[data-mode="practice"] .workspace-toolbar .more-actions,
body[data-mode="practice"] .note-panel { display: none; }
body[data-mode="practice"] .workbench { grid-template-columns: minmax(0, 1fr); }
body[data-split-only="true"] .workspace-toolbar .score-tools { display: none; }

/* ---------- Content order ---------- */
#score-entry { order: 1; }
.timeline { order: 3; }
#result-notice { order: 4; }
#exports { order: 5; }
#stems-bundle { order: 6; }
.workbench { order: 7; }
#save-status { order: 8; }
#output-path { order: 9; }
#result-notice:empty { display: none; }

/* ---------- Track rows: name · waveform · [试听] [看乐谱] [下载] ---------- */
.track-actions { display: flex; align-items: center; gap: 6px; }
.track-actions > button { padding: 7px 11px; font-size: 13px; white-space: nowrap; }
.track-actions .include-button { min-width: 74px; }
.track-actions .include-button:not(.active) { color: var(--muted); }

/* ---------- Export: three cards instead of one row of unrelated buttons ---------- */
#exports > h3 { display: none; }
#exports .export-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
#exports .export-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--card);
}
#exports .export-card h4 { margin: 0; font-size: 16px; }
#exports .export-card > p { margin: 0; font-size: 13px; color: var(--muted); }
#exports .export-card .export-buttons,
#exports .export-card .card-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
#exports .export-card label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
#exports .export-card .export-note { font-size: 12px; line-height: 1.6; color: var(--muted); margin: 2px 0 0; }
/* MIDI parts: one tickable chip per part that has notes. */
.midi-parts { display: flex; flex-wrap: wrap; gap: 6px; }
.midi-part {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--wash);
  font-size: 13px;
  color: var(--ink) !important;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms var(--ease-out);
}
.midi-part:active { transform: scale(0.97); }
.midi-part:has(input:checked) { background: var(--blue-soft); }
.midi-part input { margin: 0; accent-color: var(--blue); }
.midi-part small { color: var(--muted); font-size: 11px; }
.midi-empty { margin: 0; font-size: 13px; color: var(--muted); }
#exports .export-card [data-export="mid"]:not(:disabled) { background: var(--blue); color: #fff; box-shadow: none; }
/* Track rows: the MIDI button is a quiet secondary action next to 下载. */
.track-actions [data-midi] { font-variant: all-small-caps; letter-spacing: 0.02em; }
/* The stems bundle (hosted) and the project package sit in their own cards. */
#exports .export-card #stems-bundle { display: block; margin: 0; padding: 0; background: none; box-shadow: none; }
#exports .export-card #stems-bundle h4 { display: none; }
body[data-mode="export"] #exports { margin-bottom: 24px; background: none; box-shadow: none; padding: 0; }

@media (max-width: 820px) {
  body[data-screen="workspace"] main { padding-inline: 16px; }
  .workspace-heading nav { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
  .workspace-toolbar { padding: 10px; }
  .workspace-toolbar .listening-bar { margin-left: 0; flex-wrap: wrap; }
  /* The old mobile grid (style.css) would size these as a 2×2 of big blocks; one compact row instead. */
  .workspace-toolbar .score-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; }
  .workspace-toolbar .score-tools-main { display: flex; flex-wrap: wrap; gap: 8px; flex: 1 1 auto; }
  .workspace-toolbar .score-tools-main label { flex: 1 1 100%; display: flex; }
  .workspace-toolbar .score-tools-main select { flex: 1; margin-left: 0; }
  .workspace-toolbar .score-tools-main > button { flex: 1 1 0; padding: 9px 10px; font-size: 14px; min-height: 0; }
  .workspace-toolbar .more-actions > summary { padding: 9px 12px; font-size: 14px; }
  .workspace-toolbar #listening-label { max-width: 100%; }
  .workspace-toolbar #practice { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  .project-menu > div { transition: opacity 150ms ease; }
  @starting-style { .project-menu[open] > div { transform: none; } }
}
@media print {
  .workspace-toolbar, .project-menu { display: none !important; }
}

/* ---------- Proofreading roll (roll.js): spectrogram + notes, edited in place ---------- */
.view-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--wash); margin-left: 4px; }
.view-switch button { padding: 6px 12px; border-radius: 8px; background: none; box-shadow: none; font-size: 13px; white-space: nowrap; }
.view-switch button[aria-pressed="true"] { background: var(--paper); box-shadow: 0 1px 2px rgb(20 32 51 / .1); color: var(--ink); }
body:not([data-mode="edit"]) .view-switch { display: none; }
body[data-score-view="roll"][data-mode="edit"] .note-panel,
body[data-score-view="roll"][data-mode="edit"] .paper,
body[data-score-view="roll"][data-mode="edit"] .follow-score { display: none; }
body[data-score-view="roll"][data-mode="edit"] .workbench { grid-template-columns: minmax(0, 1fr); }
#roll { margin: 0 0 16px; border-radius: 16px; background: var(--paper); box-shadow: var(--card); overflow: hidden; }
#roll[hidden] { display: none; }
.roll-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.roll-hint { min-height: 0; padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(49,93,204,.35); background: rgba(49,93,204,.07); color: var(--blue); font-size: 13px; white-space: nowrap; }
.roll-hint[hidden] { display: none; }
.roll-more { min-height: 0; padding: 4px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap; }
.roll-more[hidden] { display: none; }
.roll-review { display: inline-flex; align-items: center; gap: 4px; }
.roll-doubt { font-size: 13px; font-weight: 650; color: #7a5212; margin-right: 4px; white-space: nowrap; }
/* Review progress: how many of the part's doubtful notes are checked. Moves on every confirm, so only
   a short transform transition; green once the part is done. */
.roll-progress { position: relative; width: 72px; height: 6px; margin-right: 6px; border-radius: 3px; background: rgba(122,82,18,.14); overflow: hidden; }
.roll-progress i { position: absolute; inset: 0; border-radius: inherit; background: #c08a2c; transform: scaleX(0); transform-origin: left; transition: transform 200ms var(--ease-out), background-color 200ms ease; }
.roll-progress[data-complete="true"] i { background: #287a5d; }
.roll-done { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; padding: 8px 12px; background: rgba(40,122,93,.08); border-bottom: 1px solid var(--line); }
.roll-done p { flex: 1 1 260px; margin: 0; font-size: 13px; color: #1f5f48; }
.roll-done button { min-height: 0; padding: 5px 10px; border-radius: 8px; font-size: 13px; }
.roll-done [data-done="close"] { border: 0; background: transparent; color: var(--muted); }
/* First-run guide: a card in the roll's corner. Seen once, so it may arrive with a little motion. */
.roll-guide { position: absolute; top: 28px; right: 12px; z-index: 3; width: min(320px, calc(100% - 24px)); padding: 14px 16px 12px; border-radius: 14px; background: #fff;
  box-shadow: 0 1px 2px rgb(20 32 51 / .12), 0 12px 32px rgb(20 32 51 / .18);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
@starting-style { .roll-guide { opacity: 0; transform: translateY(-6px) scale(.98); } }
.roll-guide-step { margin: 0 0 2px; font-size: 12px; color: var(--blue); font-weight: 600; }
.roll-guide-title { display: block; font-size: 15px; }
.roll-guide-body { margin: 6px 0 10px; font-size: 13px; line-height: 1.55; color: var(--ink); }
.roll-guide-actions { display: flex; justify-content: flex-end; gap: 8px; }
.roll-guide-actions button { min-height: 0; padding: 5px 12px; border-radius: 8px; font-size: 13px; }
.roll-guide [data-guide="skip"] { border: 0; background: transparent; color: var(--muted); }
.roll-guide [data-guide="done"] { background: var(--blue); border-color: var(--blue); color: #fff; }
/* A consent question: both answers look the same, so neither is the default the page leans on. */
.roll-consent [data-consent] { min-width: 88px; }
.roll-consent { width: min(400px, calc(100% - 24px)); }
.roll-consent .roll-guide-body p { margin: 0 0 6px; color: var(--ink); }
.roll-consent ul { margin: 0 0 6px; padding-left: 18px; }
.roll-consent li { margin: 0 0 4px; }
.roll-stats { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.roll-stats label { display: inline-flex; align-items: center; gap: 4px; }
.roll-stats button { min-height: 0; padding: 3px 8px; border-radius: 7px; font-size: 12px; }
@media (prefers-reduced-motion: reduce) {
  .roll-progress i { transition: background-color 200ms ease; }
  @starting-style { .roll-guide { opacity: 0; transform: none; } }
}
.roll-review button, .roll-actions button { min-width: 0; min-height: 0; padding: 5px 10px; border-radius: 8px; font-size: 13px; }
.roll-selected { flex: 1 1 220px; margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.roll-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
/* Floats over the bottom of the roll, so selecting a note never moves the notes under the finger.
   No entrance animation: it comes and goes dozens of times a session, often from the keyboard. */
.roll-batch { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; width: max-content; max-width: calc(100% - 24px); padding: 5px; border-radius: 12px; background: rgb(255 255 255 / .96); box-shadow: 0 1px 2px rgb(20 32 51 / .12), 0 6px 20px rgb(20 32 51 / .14); }
.roll-batch[data-empty="true"] { display: none; }
.roll-actions button[data-act="pick"][aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.roll-batch button { min-width: 0; min-height: 0; padding: 5px 9px; border-radius: 7px; font-size: 13px; }
.roll-batch button[data-batch="delete"] { color: #b4381f; }
.roll-listen { display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px; background: rgba(20,32,51,.06); }
.roll-listen button { min-height: 0; padding: 4px 9px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; color: var(--muted); white-space: nowrap; }
.roll-listen button[aria-pressed="true"] { background: var(--paper, #fff); color: var(--ink); box-shadow: 0 1px 2px rgb(20 32 51 / .12); }
.roll-volume { width: 72px; }
.roll-help { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--wash); font-size: 12px; color: var(--muted); }
.roll-help[hidden] { display: none; }
.roll-help b { color: var(--ink); font-weight: 650; margin-right: 4px; }
.roll-stage { position: relative; }
.roll-stage canvas { display: block; width: 100%; height: clamp(320px, 52vh, 560px); touch-action: none; outline: none; }
.roll-stage canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--blue); }
.roll-status { position: absolute; left: 56px; top: 28px; margin: 0; padding: 4px 10px; border-radius: 8px; background: rgb(255 255 255 / .9); font-size: 12px; color: var(--muted); pointer-events: none; }
.roll-status:empty { display: none; }
@media (max-width: 820px) {
  .view-switch { margin-left: 0; }
  .roll-stage canvas { height: 360px; }
  .roll-volume { width: 56px; }
  /* Nothing above or over the roll may change height when a note is tapped, or the next tap lands on
     the wrong note: the status keeps two lines, and the batch bar is one row that scrolls sideways. */
  .roll-selected { flex-basis: 100%; line-height: 1.45; min-height: 2.9em; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  /* On a phone the bar would cover a fifth of the roll: it sits under it instead, its row always kept. */
  .roll-batch { position: static; transform: none; width: auto; max-width: none; margin: 8px 0 0; box-shadow: none; background: rgba(49,93,204,.07);
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  .roll-batch[data-empty="true"] { display: flex; visibility: hidden; }
  .roll-batch button { flex: none; }
  /* On a phone the guide sits above the roll instead of covering its top rows; it only goes away when
     the reader taps 跳过 / 开始校对, so the roll moves at a moment they chose. */
  .roll-guide { position: static; width: auto; margin: 8px 0; box-shadow: 0 1px 2px rgb(20 32 51 / .12), 0 4px 14px rgb(20 32 51 / .10); }
}
@media print { #roll, .view-switch { display: none !important; } }

/* Score note hit targets (score-follow.js): invisible until hovered; a click opens the note in the roll. */
#score { position: relative; }
#score .note-hit {
  position: absolute; z-index: 3; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 6px;
  background: transparent; box-shadow: none; cursor: pointer;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  #score .note-hit:hover { background: rgb(49 93 204 / .12); box-shadow: 0 0 0 1.5px rgb(49 93 204 / .55); }
}
#score .note-hit:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--blue); }
#score .note-hit:active { background: rgb(49 93 204 / .2); }
@media print { #score .note-hit { display: none !important; } }

/* Language switch (studio/i18n.js): quiet, in the header next to the account button. */
#lang-switch { min-height: 0; height: 34px; padding: 0 8px; border-radius: 9px; font-size: 13px; color: var(--muted); background: transparent; max-width: 9.5em; }
@media (max-width: 820px) { #lang-switch { max-width: 6.5em; font-size: 12px; } }

/* Cookie notice (server.js): shown once per visitor, so it may arrive with a little motion. */
.cookie-notice { position: fixed; left: 16px; bottom: 104px; z-index: 40; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px));
  padding: 12px 14px; border-radius: 14px; background: var(--paper, #fff); box-shadow: 0 1px 2px rgb(20 32 51 / .12), 0 12px 32px rgb(20 32 51 / .18);
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out); }
@starting-style { .cookie-notice { opacity: 0; transform: translateY(8px); } }
.cookie-notice p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--ink); }
.cookie-notice a { margin-left: 4px; white-space: nowrap; }
.cookie-notice button { flex: none; min-height: 0; padding: 6px 14px; border-radius: 9px; font-size: 13px; }
@media (prefers-reduced-motion: reduce) { @starting-style { .cookie-notice { opacity: 0; transform: none; } } }
@media (max-width: 820px) { .cookie-notice { left: 12px; right: 12px; bottom: 96px; max-width: none; } }

/* Waiting states (waiting.js): a button waiting on the server, and the "opening a song" pill. */
button[aria-busy="true"] { cursor: progress; }
button[aria-busy="true"] > .st-loader { margin-right: 0.45em; }
#wait-pill { position: fixed; left: 50%; top: 88px; transform: translateX(-50%); z-index: 45; margin: 0; padding: 8px 14px; border-radius: 999px;
  background: var(--paper, #fff); color: var(--ink); font-size: 13px; box-shadow: 0 1px 2px rgb(20 32 51 / .12), 0 8px 24px rgb(20 32 51 / .16); }
/* Only the workspace has the player bar at the bottom; elsewhere the notice sits at the edge instead of
   over the page's main action. */
body:not([data-screen="workspace"]) .cookie-notice { bottom: 16px; }
