:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --border: #dad6cc;
  --accent: #1f4e5f;
  --accent-text: #ffffff;
  --mine: #e8f1f3;
  --danger: #a33a2a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161716;
    --surface: #212321;
    --text: #ecebe6;
    --muted: #9c9b95;
    --border: #3a3c39;
    --accent: #6fb3c8;
    --accent-text: #0e1a1e;
    --mine: #1d3138;
    --danger: #e0806f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161716;
  --surface: #212321;
  --text: #ecebe6;
  --muted: #9c9b95;
  --border: #3a3c39;
  --accent: #6fb3c8;
  --accent-text: #0e1a1e;
  --mine: #1d3138;
  --danger: #e0806f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Component display rules (e.g. button { display: inline-flex }) would
   otherwise override the hidden attribute. The panel animates its own. */
[hidden]:not(.panel) { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--accent);
  color: var(--accent-text);
}
header h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
main { max-width: 640px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1rem; margin: 24px 0 8px; }
.muted { color: var(--muted); font-size: 0.92rem; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { color: var(--danger); margin-top: 32px; }
.wide { width: 100%; margin-top: 16px; }
.icon-btn { min-height: 36px; padding: 0 10px; background: transparent; border: none; color: inherit; font-size: 1.3rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.library { list-style: none; padding: 0; margin: 0; }
.library li { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.library li > button:first-child { flex: 1; min-width: 0; gap: 12px; justify-content: flex-start; padding-left: 8px; text-align: left; }
.library .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library .thumb { width: 36px; height: 48px; flex: none; border-radius: 4px; overflow: hidden; background: var(--border); }
.library .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.library small { color: var(--muted); font-weight: 400; }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 0; margin: 16px 0 0; list-style: none; }
.pages li { position: relative; }
.pages img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.pages .remove { position: absolute; top: 4px; right: 4px; min-height: 28px; padding: 0 8px; font-size: 0.85rem; }
.pages .rotate { position: absolute; top: 4px; left: 4px; min-height: 28px; padding: 0 8px; font-size: 1rem; }
.pages .num { position: absolute; bottom: 4px; left: 4px; background: var(--surface); border-radius: 6px; padding: 0 6px; font-size: 0.8rem; }

.name-field { display: grid; gap: 4px; margin-top: 16px; font-size: 0.95rem; }
.name-field input { min-height: 44px; font: inherit; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.status { margin-top: 16px; white-space: pre-line; }
.discard { margin-top: 24px; color: var(--muted); }
.status progress { width: 100%; height: 8px; }

.title-wrap { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.title-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-bottom: 1px dashed var(--muted);
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text);
}
.title-input:focus { border-color: var(--border); background: var(--surface); outline: none; }

.lock-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.lock-row .muted { font-size: 0.85rem; }
#panel.locked #auto-part, #panel.locked #marked-part, #panel.locked .octave-row { opacity: 0.55; }
.marked-part p { margin: 0 0 10px; }
.danger-text { color: var(--danger); }
#auto-part > .muted { margin: 14px 0 8px; }
#start-markup { width: 100%; }
.markup-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--transport-h);
  padding: 8px 16px max(8px, env(safe-area-inset-bottom));
  background: var(--mine);
  border-top: 2px solid #e0902a;
}
.markup-bar[hidden] { display: none; }
.markup-bar p { flex: 1; margin: 0; font-size: 0.92rem; }
body.marking .transport { display: none; }
select { min-height: 40px; font: inherit; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.link { min-height: 0; padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; font-weight: 400; }
.photo-list .mark { fill: #e0902a; fill-opacity: 0.16; stroke: #e0902a; stroke-opacity: 0.6; stroke-width: 4; }
.photo-list .mark-label { fill: #b86a12; font-family: system-ui, sans-serif; font-weight: 600; }
.lines { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.lines li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.lines li.mine { background: var(--mine); border-color: var(--accent); }
.lines .pick { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 32px; }
.lines .range { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.lines .include { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 4px; }
input[type="radio"], input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

.controls { display: grid; gap: 14px; margin-top: 20px; }
.controls label { display: grid; gap: 4px; font-size: 0.95rem; }
.controls input[type="range"] { width: 100%; accent-color: var(--accent); }
.bars { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.bars input[type="number"] { width: 72px; min-height: 40px; font: inherit; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.bars .check { display: flex; align-items: center; gap: 6px; min-height: 40px; }

/* Practice screen: music fills the page; transport is fixed at the bottom and
   the detailed controls slide up above it. */
:root { --transport-h: calc(72px + env(safe-area-inset-bottom)); }
#practice { padding-bottom: var(--transport-h); }
.transport {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  height: var(--transport-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.icon-round { width: 50px; height: 50px; min-height: 0; padding: 0; border-radius: 50%; }
.icon-round svg { width: 26px; height: 26px; fill: currentColor; }
#play { width: 60px; height: 60px; }
#play .i-pause, #play.playing .i-play { display: none; }
#play.playing .i-pause { display: block; }
#settings[aria-expanded="true"] { background: var(--mine); border-color: var(--accent); }
.position { font-variant-numeric: tabular-nums; font-size: 1.05rem; min-width: 64px; text-align: center; }

.panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--transport-h);
  z-index: 2;
  max-height: min(70vh, calc(100vh - var(--transport-h) - 64px));
  overflow-y: auto;
  padding: 4px 16px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 24px rgb(0 0 0 / 0.18);
  transform: translateY(0);
  transition: transform 0.25s ease, visibility 0.25s;
}
.panel[hidden] { display: block; visibility: hidden; transform: translateY(110%); }
.panel > * { max-width: 608px; margin-left: auto; margin-right: auto; }
.panel { padding-top: 0; }
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  margin: 0 -16px;
  max-width: none;
  background: var(--bg);
  touch-action: none;
  cursor: grab;
}
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--border); }
.panel-close { position: absolute; right: 12px; min-height: 34px; padding: 0 14px; font-weight: 600; color: var(--accent); }
.panel-backdrop { position: fixed; inset: 0; z-index: 1; background: rgb(0 0 0 / 0.18); }
.error-toast { position: fixed; top: 64px; left: 12px; right: 12px; z-index: 10; padding: 10px 14px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 0.9rem; box-shadow: 0 6px 18px rgb(0 0 0 / 0.25); }
.title-row { display: flex; align-items: center; gap: 4px; }
.title-row .title-wrap { flex: 1; min-width: 0; }
.share-btn { flex: none; width: 44px; height: 44px; min-height: 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--accent); }
.import-offer { margin: 16px 0; padding: 14px 16px; border: 2px solid var(--accent); border-radius: 12px; background: var(--mine); }
.import-offer p { margin: 0 0 10px; }
.share-spacer { flex: none; width: 44px; }
.share-btn svg { width: 24px; height: 24px; fill: currentColor; }
.share-status { margin: 0 8px; font-size: 0.85rem; }
.share-status:empty { display: none; }
.panel .danger { margin: 24px auto 8px; display: flex; }

details { margin-top: 24px; }
.view-toggle { flex-direction: column; gap: 0; font-size: 0.62rem; font-weight: 600; line-height: 1.1; }
.view-toggle[hidden] { display: none; }
.view-toggle svg { width: 20px; height: 20px; }
.view-toggle .i-pages, .view-toggle.on-read .i-read { display: none; }
.view-toggle.on-read .i-pages { display: block; }
.follow { margin-top: 12px; }
.read-view { margin-top: 12px; }
.read-view .muted { margin: 0 0 8px; }
.read-page { position: relative; cursor: pointer; }
.read-bar, .read-playhead { position: absolute; pointer-events: none; }
.read-bar[hidden], .read-playhead[hidden] { display: none; }
.read-bar { background: rgb(31 78 95 / 0.12); border: 2px solid #1f4e5f; border-radius: 4px; }
.read-playhead { background: #e0902a; border-radius: 2px; }
.photo-list { display: grid; gap: 8px; }
.photo-list .page { position: relative; }
.photo-list img { width: 100%; display: block; border-radius: 8px; border: 1px solid var(--border); }
.photo-list svg { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.photo-list .bar { fill: var(--accent); fill-opacity: 0.12; stroke: var(--accent); stroke-width: 6; }
.photo-list .playhead { stroke: #e0902a; stroke-width: 8; stroke-linecap: round; }
.photo-list .note { fill: none; stroke: #e0902a; stroke-width: 7; }

summary { cursor: pointer; min-height: 32px; }
#osmd { background: #fff; border-radius: 8px; overflow-x: auto; }
