@import url('../editor/editor.css');

:root {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-synthesis: none;
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --ink: #17202b;
    --muted: #4b5866;
    --border: #dde2e8;
    --soft: #eef1f5;
    --primary: #17202b;
    --on-primary: #ffffff;
    /* Brand note head: off the tile, and on the ink tile (docs/brand). */
    --fretrito-note: #c2410c;
    --brand-paper: #ffffff;
    --fretrito-tile-note: #fb8a4c;
    --focus: #1d4ed8;
    --danger-bg: #fff1ee;
    --danger-border: #e4a79b;
    --danger-ink: #8a2c1a;
    --scope-section: #1d4ed8;
    --scope-bar: #6d28d9;
    --scope-note: #c2410c;
    --chord: #0e7490;
    --control-radius: 8px;
    --header-height: 64px;
    color: var(--ink);
    background: var(--bg);
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111318;
    --surface: #1a1d24;
    --ink: #eef1f5;
    --muted: #a7b0bd;
    --border: #2e3440;
    --soft: #232833;
    --primary: #eef1f5;
    --on-primary: #111318;
    --fretrito-note: #fb8a4c;
    --brand-paper: #111318;
    --fretrito-tile-note: #c2410c;
    --focus: #7aa2ff;
    --danger-bg: #3a1f1b;
    --danger-border: #7a3b31;
    --danger-ink: #ffb4a6;
    --scope-section: #7aa2ff;
    --scope-bar: #b794f6;
    --scope-note: #fb923c;
    --chord: #67d4f0;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); }
body { margin: 0; overflow-x: hidden; }
button, input, select, textarea { font: inherit; }
button, .file-button {
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--control-radius);
    padding: 8px 12px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    font-size: 14px;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover:not(:disabled), .file-button:hover { border-color: var(--muted); background: var(--soft); }
button:active:not(:disabled) { background: var(--border); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, .file-button:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
input, textarea, select {
    min-height: 40px;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 10px;
    background: var(--surface);
    color: var(--ink);
}
input::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"] { min-height: 0; width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
::selection { color: var(--on-primary); background: var(--primary); }

.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--header-height);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-size: 20px;
    font-weight: 740;
    letter-spacing: -.5px;
    text-decoration: none;
    white-space: nowrap;
}
/* The header lockup (docs/brand) draws in the ink colour and reads the note tokens. */
.brand-lockup { display: block; height: 32px; width: auto; }
.prototype-badge { padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px; color: var(--muted); font-size: 10px; font-weight: 650; letter-spacing: 1px; }
.library-toggle[aria-expanded="true"] { border-color: var(--primary); background: var(--soft); font-weight: 650; }
.save-state { color: var(--muted); font-size: 13px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.viewer-toggle { display: inline-flex; min-height: 40px; align-items: center; gap: 8px; padding: 0 6px; font-size: 14px; white-space: nowrap; }
.theme-toggle { width: 40px; padding: 0; display: inline-grid; place-items: center; }
.theme-toggle svg, .close-library svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.workspace { display: flex; min-height: calc(100vh - var(--header-height)); align-items: stretch; }
.editor-workspace { flex: 1 1 auto; min-width: 0; padding: 0; }
.editor-surface { min-height: 480px; overflow: clip; background: var(--surface); }

/* Library drawer: overlays below 1400px, pushes the editor at 1400px and wider. */
.library-panel {
    position: fixed;
    z-index: 50;
    top: 0;
    bottom: 0;
    left: 0;
    display: flex;
    width: min(320px, 90vw);
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 16px;
    border-right: 1px solid var(--border);
    background: var(--soft);
    box-shadow: 4px 0 24px #00000033;
}
/* Items keep their natural height; the drawer scrolls instead of squeezing them together. */
.library-panel > * { flex-shrink: 0; }
.library-panel[hidden], .library-backdrop[hidden] { display: none; }
.library-backdrop { position: fixed; z-index: 40; inset: 0; background: #0009; }
@media (min-width: 1400px) {
    .library-panel { position: sticky; top: var(--header-height); z-index: auto; height: calc(100vh - var(--header-height)); flex: 0 0 300px; width: 300px; box-shadow: none; }
    .library-backdrop { display: none; }
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading .library-count { margin-left: auto; }
.close-library { width: 40px; padding: 0; display: inline-grid; place-items: center; }
.eyebrow, .list-heading { color: var(--muted); font-size: 11px; font-weight: 680; letter-spacing: 1.4px; }
.library-count { padding: 3px 8px; border-radius: 5px; background: var(--border); font-size: 12px; font-variant-numeric: tabular-nums; }
h1 { margin: 12px 0 18px; font-size: 24px; letter-spacing: -.5px; line-height: 1.15; }
/* FocusOnNavigate targets this heading; keyboard controls retain their own ring. */
h1[tabindex="-1"]:focus { outline: none; }
.primary { border-color: var(--primary); background: var(--primary); color: var(--on-primary); font-weight: 650; }
.primary:hover:not(:disabled) { border-color: var(--primary); background: var(--primary); color: var(--on-primary); opacity: .88; }
.wide { width: 100%; }
.library-tools { display: flex; gap: 8px; margin: 10px 0 16px; }
.library-tools > * { flex: 1; min-width: 0; padding-inline: 8px; text-align: center; }
.file-button { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.file-button input { position: absolute; inset: 0; width: 100%; padding: 0; opacity: 0; cursor: pointer; }
.search-label input { width: 100%; font-size: 14px; }
.examples-folder { margin: 16px 0 0; }
.examples-folder > summary { cursor: pointer; list-style: none; padding: 8px 12px; border: 1px solid transparent; border-radius: 8px; }
.examples-folder > summary::-webkit-details-marker { display: none; }
.examples-folder > summary::after { margin-left: 8px; color: var(--muted); content: "▸"; }
.examples-folder[open] > summary::after { content: "▾"; }
.examples-folder > summary .library-count { margin-left: auto; }
.examples-folder > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.example-list { display: grid; gap: 4px; padding: 4px 0 4px 18px; }
.example-card { width: 100%; }
.example-hint { margin: 2px 0 0 10px; color: var(--muted); font-size: 12px; }
.folder-navigation { display: flex; max-height: 240px; flex-direction: column; gap: 3px; overflow: auto; margin: 16px 0 10px; }
.folder-row { display: flex; align-items: center; gap: 9px; width: 100%; min-width: 0; border-color: transparent; background: transparent; text-align: left; overflow-wrap: anywhere; }
.folder-row.selected { border-color: var(--border); background: var(--surface); font-weight: 650; }
.folder-row.nested { padding-left: 12px; }
.folder-indent { flex: 0 0 0; border-top: 1px solid var(--muted); }
.folder-indent[data-depth="1"] { margin-left: 8px; }
.folder-indent[data-depth="2"] { margin-left: 16px; }
.folder-indent[data-depth="3"] { margin-left: 24px; }
.folder-symbol { position: relative; width: 15px; height: 11px; flex: 0 0 15px; border: 1.5px solid var(--muted); border-radius: 2px; }
.folder-symbol::before { position: absolute; top: -4px; left: 1px; width: 6px; height: 3px; border: 1.5px solid var(--muted); border-bottom: 0; border-radius: 2px 2px 0 0; content: ""; }
.folder-form { display: flex; gap: 6px; }
.folder-form input { width: 100%; min-width: 0; font-size: 14px; }
.folder-form button { width: 42px; padding-inline: 8px; font-size: 18px; }
.folder-context { margin: 8px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.list-heading { margin-bottom: 10px; }
.document-list { display: grid; gap: 5px; }
.document-card { display: flex; min-width: 0; align-items: center; gap: 11px; padding: 10px; border-color: transparent; background: transparent; text-align: left; }
.document-card.active { border-color: var(--border); background: var(--surface); }
.document-card strong { display: block; overflow-wrap: anywhere; font-size: 14px; line-height: 1.4; }
.document-copy { min-width: 0; }
.document-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.document-icon { display: grid; width: 25px; flex: 0 0 25px; place-items: center; color: var(--muted); }
.document-icon svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.document-icon circle { fill: currentColor; }
.empty-library { color: var(--muted); font-size: 13px; line-height: 1.7; }
.library-footer { margin-top: auto; padding-top: 28px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.library-footer strong { color: var(--ink); }
.library-footer p { margin: 5px 0; }

.error-banner { display: flex; justify-content: space-between; gap: 12px; margin: 12px 16px; padding: 12px; border: 1px solid var(--danger-border); border-radius: var(--control-radius); background: var(--danger-bg); color: var(--danger-ink); font-size: 14px; overflow-wrap: anywhere; }
.error-banner button { min-height: 32px; padding: 0 8px; background: transparent; color: inherit; }
.editor-workspace > p[role="status"] { margin: 12px 16px; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
#blazor-error-ui { position: fixed; z-index: 1000; right: 0; bottom: 0; left: 0; display: none; padding: 15px; background: #fff0dc; color: #17202b; }

@media (max-width: 760px) {
    .app-header { padding: 8px 12px; }
    .prototype-badge { display: none; }
    .save-state { margin-left: auto; }
    .header-actions { width: 100%; justify-content: flex-start; margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

/* Practice mode is a distraction-free reading page; its own bar has Done. */
.app-shell:has(.tm-editor.is-practice) .app-header { display: none; }

/* Library management */
.list-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sort-label select { min-height: 32px; padding: 3px 6px; font-size: 12px; letter-spacing: 0; }
button.small, .small { min-height: 32px; padding: 4px 9px; font-size: 13px; }
button.danger { border-color: var(--danger-border); color: var(--danger-ink); }
.trash-symbol { position: relative; width: 12px; height: 13px; flex: 0 0 15px; border: 1.5px solid var(--muted); border-top-width: 3px; border-radius: 0 0 3px 3px; box-sizing: border-box; }
.trash-row { margin-top: 6px; }
.trash-item { display: grid; gap: 6px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--control-radius); }
.trash-actions, .card-menu-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.crumb { min-height: 28px; padding: 2px 6px; border-color: transparent; background: transparent; font-size: 13px; }
.crumb[aria-current="page"] { color: var(--ink); font-weight: 650; }
.folder-actions { display: grid; gap: 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--control-radius); }
.folder-actions > summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.folder-actions[open] { gap: 8px; }
.folder-actions[open] > * + * { margin-top: 8px; }
.folder-actions select { flex: 1 1 auto; min-width: 0; }
.document-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.document-row > .document-card { flex: 1 1 auto; }
.card-menu { position: relative; }
.card-menu-button { display: grid; width: 32px; min-height: 32px; padding: 0; place-items: center; border-color: transparent; background: transparent; color: var(--muted); font-weight: 800; }

.card-menu-button[aria-expanded="true"] { background: var(--soft); }
.card-menu-body { position: absolute; right: 0; z-index: 10; display: grid; gap: 8px; width: 230px; padding: 10px; border: 1px solid var(--border); border-radius: var(--control-radius); background: var(--surface); box-shadow: 0 8px 24px #0002; }
.card-menu-body label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.versions { display: grid; gap: 8px; margin-top: 14px; }
.version-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.version-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.version-list small { color: var(--muted); }
.backup-tools { margin-top: 18px; }
.notice-banner { display: flex; justify-content: space-between; gap: 12px; margin: 12px 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--control-radius); background: var(--soft); font-size: 14px; }

/* Lesson dialogs */
.dialog-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: #0008; }
.lesson-dialog { display: grid; gap: 14px; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 18px 48px #0004; }
.lesson-dialog h2 { margin: 0; font-size: 20px; }
/* Welcome: the ways to start, as large choices. */
.welcome-dialog { width: min(640px, 100%); padding: 0 0 20px; }
.lesson-dialog.welcome-dialog > :not(.welcome-brand) { margin-inline: 20px; }
/* The bare lockup on paper, with the brand guide's clear space (at least the wordmark's x-height) around it. */
.welcome-brand { display: grid; justify-items: center; gap: 6px; padding: 30px 20px 22px; border-bottom: 1px solid var(--border); background: var(--brand-paper); color: var(--ink); text-align: center; }
.welcome-lockup { display: block; width: min(280px, 72%); height: auto; margin-bottom: 8px; }
.welcome-tagline { margin: 0; color: var(--muted); font-size: 17px; font-style: italic; }
.welcome-intro { margin: 0; color: var(--muted); line-height: 1.45; }
.welcome-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.welcome-choice { display: grid; align-content: start; gap: 6px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--soft); color: var(--ink); text-align: left; }
.welcome-choice strong { font-size: 16px; }
.welcome-choice small { color: var(--muted); font-size: 13px; line-height: 1.35; }
button.welcome-choice { min-height: 84px; cursor: pointer; }
.welcome-row { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 520px) { .welcome-choices { grid-template-columns: 1fr; } }
.lesson-dialog fieldset { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.lesson-dialog legend { margin-bottom: 6px; font-weight: 650; }
.lesson-dialog label.choice { display: flex; align-items: center; gap: 8px; }
.lesson-dialog .field { display: grid; gap: 4px; }
.lesson-dialog .dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.lesson-dialog .hint { margin: 0; color: var(--muted); font-size: 13px; }

/* The printed sheet is only the music page. */
@media print {
  .app-header, .library-panel, .library-backdrop, .error-banner, .notice-banner, .dialog-backdrop { display: none !important; }
  .workspace, .editor-workspace { display: block; min-height: 0; }
  body, :root { background: #fff; }
}
.folder-actions .folder-form > input, .folder-actions .folder-form > select { flex: 1 1 auto; width: auto; min-width: 0; }
.folder-actions .folder-form > button { flex: none; width: auto; font-size: 14px; }
.text-tab-dialog { width: min(760px, 100%); }
.text-tab-source { width: 100%; font: 13px/1.35 ui-monospace, Consolas, monospace; white-space: pre; overflow-x: auto; }
.text-tab-preview { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--control-radius); background: var(--soft); font-size: 13px; }
.text-tab-preview p { margin: 0 0 4px; }
.text-tab-preview ul { margin: 0; padding-left: 18px; }
