:root {
    --ink: #1c1612;
    --muted: #6b5e52;
    --paper: #f6f1e8;
    --paper-2: #efe6d8;
    --card: #fffaf3;
    --line: #e0d4c4;
    --wine: #7a2e2a;
    --wine-dark: #5c1f1c;
    --wine-soft: #f3e4e0;
    --forest: #3d5a45;
    --warn: #9a6700;
    --warn-bg: #f8edc8;
    --danger: #9b1c1c;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(28, 22, 18, 0.08);
    --sidebar: #241c18;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans: "Segoe UI", system-ui, sans-serif;
    --app-footer-h: 0px;
}
html {
    --text-scale: 1;
    font-size: calc(16px * var(--text-scale));
}
@media (max-width: 840px) {
    html:not([data-text-scale]) { --text-scale: 1.15; }
    html[data-text-scale="100"] { --text-scale: 1; }
    html[data-text-scale="115"] { --text-scale: 1.15; }
    html[data-text-scale="130"] { --text-scale: 1.3; }
    html[data-text-scale="145"] { --text-scale: 1.45; }
    html[data-text-scale="160"] { --text-scale: 1.6; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
body {
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
    line-height: 1.5;
}
a { color: var(--wine); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: var(--sidebar);
    color: #f3ebe3;
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
    font-weight: 650;
    letter-spacing: 0.04em;
}
.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--wine);
    display: grid;
    place-items: center;
    font-size: 0.78rem;
    font-weight: 700;
}
.brand-mark-lg { width: 48px; height: 48px; margin: 0 auto 12px; font-size: 0.9rem; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a {
    color: #d9cdc2;
    text-decoration: none;
    padding: 8px 10px;
    border-radius: 8px;
}
.side-nav a:hover, .side-nav a.is-active { background: rgba(255,255,255,0.08); color: #fff; }
.side-book {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 14px;
}
.side-book-label { margin: 0; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: #b4a497; }
.side-book-title { margin: 4px 0 10px; font-weight: 650; }
.side-foot {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.85rem;
    color: #b4a497;
}
.side-foot a { color: #f3ebe3; }

.app-main { min-width: 0; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 20px 28px 0;
}
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
}
.nav-toggle-bar {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--ink);
    border-radius: 2px;
}
.nav-backdrop { display: none; }
.topbar h1 { margin: 0; font-family: var(--serif); font-size: 1.7rem; font-weight: 600; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page { padding: 20px 28px 48px; }

.lede, .muted, .hint { color: var(--muted); }
.hint { font-size: 0.88rem; }
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.92rem; }
input, textarea, select {
    font: inherit;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}
textarea { resize: vertical; }
.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 9px;
    padding: 8px 14px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; background: var(--paper-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.catalog-heading {
    font-family: var(--serif);
    font-size: 1.35rem;
    font-weight: 600;
    margin: 28px 0 14px;
}
.catalog-heading:first-of-type { margin-top: 8px; }
.songs-toolbar { margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.songs-toolbar input { width: min(420px, 100%); }
.album-filter-card { cursor: pointer; transition: border-color 0.12s ease, box-shadow 0.12s ease; }
.album-filter-card:hover,
.album-filter-card:focus-visible {
    border-color: var(--wine);
    box-shadow: 0 8px 22px rgba(90, 40, 36, 0.12);
}
.album-filter-card.is-active {
    border-color: var(--wine);
    box-shadow: 0 0 0 2px rgba(122, 46, 46, 0.22);
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table-wrap .table { margin: 0; border-radius: 0; }
.table th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.table th[data-sort]::after { content: ""; margin-left: 6px; color: var(--muted); font-size: 0.75em; }
.table th[data-dir="asc"]::after { content: "▲"; }
.table th[data-dir="desc"]::after { content: "▼"; }
.cell-action {
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--wine);
    cursor: pointer;
    text-align: left;
}
.cell-action:hover { text-decoration: underline; }
.cell-action.is-empty { color: var(--muted); font-style: italic; }
.cell-action--title {
    font-family: var(--serif);
    font-size: 1.08rem;
    font-weight: 650;
    color: var(--ink);
}
.cell-action--title:hover { color: var(--wine); }

body.editor-open { overflow: hidden; }
.editor-root[hidden] { display: none !important; }
.editor-root {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: var(--paper);
}
.lyrics-editor {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100%;
    min-height: 0;
}
.lyrics-editor-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
}
.lyrics-editor-ident { min-width: 0; flex: 1; }
.lyrics-editor-head h2 { margin: 0; font-family: var(--serif); font-size: 1.35rem; }
.story-title-field {
    display: block;
    margin: 0;
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--muted);
}
.story-title-field input {
    display: block;
    width: 100%;
    max-width: 36rem;
    margin-top: 4px;
    font-family: var(--serif);
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid transparent;
    padding: 2px 0 4px;
}
.story-title-field input:focus {
    outline: none;
    border-bottom-color: var(--wine);
}
.story-wordcount { margin: 0 0 10px; font-weight: 650; }
.story-lyrics-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
}
.story-lyrics-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
    flex: 1 1 auto;
}
.story-lyrics-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 4px 6px 4px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    font-size: 0.88rem;
}
.story-lyrics-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.story-lyrics-chip-x {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 4px;
}
.story-lyrics-chip-x:hover { color: var(--wine); }
.lyric-pick-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    align-items: end;
}
.lyric-pick-toolbar input[type="search"] {
    flex: 1 1 14rem;
    min-width: 12rem;
    margin: 0;
}
.lyric-pick-toolbar select { margin: 0; min-width: 10rem; }
.lyric-pick-rel {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--muted);
    margin: 0;
}
.lyric-pick .table-wrap { max-height: min(55vh, 28rem); }
.lyric-pick .table td:last-child { white-space: nowrap; }
.story-quick-prompts {
    margin: 8px 0 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 0 10px;
}
.story-quick-prompts > summary {
    cursor: pointer;
    font-weight: 650;
    padding: 8px 0;
    color: var(--wine);
    list-style: none;
}
.story-quick-prompts > summary::-webkit-details-marker { display: none; }
.story-quick-prompts > summary::after {
    content: "▾";
    float: right;
    color: var(--muted);
}
.story-quick-prompts[open] > summary::after { content: "▴"; }
.story-quick-prompts-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 0 10px;
}
.story-quick-prompts-list .btn { text-align: left; width: 100%; justify-content: flex-start; }
.story-texts { margin: 10px 0; padding: 0; border: 0; }
.story-texts legend { font-weight: 650; margin-bottom: 6px; }
.story-char {
    background: #eceff7;
    border-bottom: 2px solid #5a6d9a;
    border-radius: 3px;
    padding: 0 2px;
    cursor: pointer;
}
.story-char:hover { background: #dde2f0; }
.story-person-hint {
    background: #f8e6a0;
    border-bottom: 2px solid #c47a32;
    border-radius: 3px;
    padding: 0 2px;
    cursor: pointer;
}
.story-person-hint:hover { background: #f3d778; }
.story-people-banner { margin: 0 0 10px; }
.story-people-list { margin: 0; padding-left: 1.2em; }
.story-people-list li { margin: 0 0 12px; }
.story-people-list .btn { margin-top: 6px; }
.story-review-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15em;
    height: 1.15em;
    margin-left: 6px;
    border-radius: 50%;
    background: #c47a32;
    color: #fff;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    vertical-align: middle;
}
.reader-prose .story-char { cursor: inherit; }
.wysiwyg.story-wysiwyg h2 {
    font-family: var(--serif);
    font-size: 1.45rem;
    margin: 0.85em 0 0.4em;
}
.wysiwyg.story-wysiwyg h3 {
    font-family: var(--serif);
    font-size: 1.2rem;
    margin: 0.75em 0 0.3em;
}
.wysiwyg.story-wysiwyg ul,
.wysiwyg.story-wysiwyg ol { margin: 0.35em 0 0.85em 1.35em; padding: 0; }
.reader-prose h2 {
    font-family: var(--serif);
    font-size: 1.4rem;
    margin: 1.2em 0 0.4em;
}
.reader-prose h3 {
    font-family: var(--serif);
    font-size: 1.18rem;
    margin: 1em 0 0.35em;
}
.reader-prose ul,
.reader-prose ol { margin: 0.4em 0 1em 1.35em; }
.lyrics-editor-kicker { margin: 0 0 2px; font-size: 0.82rem; }
.lyrics-player { margin-top: 10px; max-width: 42rem; }
.lyrics-player-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.lyrics-player-seek { flex: 1; min-width: 80px; accent-color: var(--wine); height: 6px; padding: 0; }
.lyrics-player-time { font-variant-numeric: tabular-nums; font-size: 0.8rem; color: var(--muted); min-width: 2.4em; }
.btn.btn-player {
    width: 36px;
    height: 36px;
    padding: 0;
    color: #fff;
}
.btn.btn-player-play { background: #3d5a45; border-color: #3d5a45; }
.btn.btn-player-play:hover { background: #2f4636; }
.btn.btn-player-pause { background: #c47a32; border-color: #c47a32; }
.btn.btn-player-pause:hover { background: #a05e22; }
.btn.btn-player-stop { background: var(--wine); border-color: var(--wine); }
.btn.btn-player-stop:hover { background: var(--wine-dark); }
.lyrics-editor-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-ico {
    width: 1.05em;
    height: 1.05em;
    flex-shrink: 0;
    display: block;
}
.btn.btn-save {
    background: #3d5a45;
    border-color: #3d5a45;
    color: #fff;
}
.btn.btn-save:hover { background: #2f4636; border-color: #2f4636; color: #fff; }
.btn.btn-save-close {
    background: var(--wine);
    border-color: var(--wine);
    color: #fff;
}
.btn.btn-save-close:hover { background: var(--wine-dark); border-color: var(--wine-dark); color: #fff; }
.btn.btn-align {
    background: #3f6f72;
    border-color: #3f6f72;
    color: #fff;
}
.btn.btn-align:hover { background: #33595c; border-color: #33595c; color: #fff; }
.btn.btn-close-editor {
    width: 40px;
    height: 40px;
    padding: 0;
    background: #f3e4e0;
    border-color: #e0c8c4;
    color: var(--wine);
}
.btn.btn-close-editor:hover { background: #ead3cd; color: var(--wine-dark); }
.btn.btn-send {
    background: #5a6d9a;
    border-color: #5a6d9a;
    color: #fff;
}
.btn.btn-send:hover { background: #4a5c86; border-color: #4a5c86; color: #fff; }
.btn.btn-apply {
    background: #3d5a45;
    border-color: #3d5a45;
    color: #fff;
}
.btn.btn-apply:hover { background: #2f4636; border-color: #2f4636; color: #fff; }
.btn.btn-dismiss {
    background: #f3e4e0;
    border-color: #e0c8c4;
    color: var(--wine-dark);
}
.btn.btn-dismiss:hover { background: #ead3cd; }
.lyrics-editor-split {
    display: grid;
    grid-template-columns: 1.35fr minmax(280px, 1fr);
    min-height: 0;
    height: 100%;
}
.lyrics-pane, .lyrics-chat {
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 14px 16px 18px;
}
.lyrics-pane { border-right: 1px solid var(--line); }
.lyrics-chat { background: var(--paper-2); }
.lyrics-chat h3 { margin: 0 0 6px; font-size: 1rem; }
.lyrics-core { margin: 8px 0 0; font-weight: 600; }
.lyrics-core textarea {
    font-weight: 400;
    min-height: 4.6em;
    line-height: 1.4;
}
.lyrics-core-actions { margin: 6px 0 10px; }
.lyrics-char-insert {
    display: flex;
    gap: 8px;
    margin: 8px 0 0;
    align-items: stretch;
}
.lyrics-char-insert select { flex: 1; min-width: 0; font-weight: 400; }
.lyrics-char-linked { margin: 6px 0 0; }
.wysiwyg-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}
.wysiwyg-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.toolbar-sep { width: 1px; background: var(--line); margin: 0 4px; }
body.editor-open .modal-root { z-index: 90; }
.translate-label {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--muted);
}
.translate-preview {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    max-height: 28vh;
    overflow: auto;
    line-height: 1.65;
}
.translate-preview--orig {
    color: var(--muted);
    background: var(--paper-2);
    white-space: pre-wrap;
}
.translate-preview p { margin: 0 0 0.6em; }
.translate-preview p:last-child { margin-bottom: 0; }
.wysiwyg {
    flex: 1;
    min-height: 240px;
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px 18px;
    font-size: 1.02rem;
    line-height: 1.65;
    outline: none;
}
.wysiwyg:focus { border-color: var(--wine); }
.wysiwyg p { margin: 0 0 0.65em; }
.wysiwyg p:last-child { margin-bottom: 0; }
.lyric-part {
    border-left: 3px solid var(--wine);
    background: var(--wine-soft);
    padding: 6px 12px 8px;
    margin: 10px 0;
    border-radius: 0 8px 8px 0;
    line-height: 1.55;
}
.lyric-part p,
.lyric-part div {
    margin: 0;
    padding: 0;
}
.lyric-part::before {
    content: attr(data-label);
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--wine);
    margin-bottom: 4px;
}
.lyric-part--verse { border-color: #3d5a45; background: #e8f0ea; }
.lyric-part--verse::before { color: #3d5a45; }
.lyric-part--pre-chorus { border-color: #c47a32; background: #f8eee3; }
.lyric-part--pre-chorus::before { color: #a05e22; }
.lyric-part--chorus { border-color: #7a2e2a; background: #f3e4e0; }
.lyric-part--chorus::before { color: #7a2e2a; }
.lyric-part--interlude { border-color: #3f6f72; background: #e6f1f2; }
.lyric-part--interlude::before { color: #3f6f72; }
.lyric-part--prelude { border-color: #5a6d9a; background: #eceff7; }
.lyric-part--prelude::before { color: #4a5c86; }
.lyric-part--intro { border-color: #6a7c38; background: #eef3e0; }
.lyric-part--intro::before { color: #55632c; }
.lyric-part--outro { border-color: #7a4a62; background: #f4e8ee; }
.lyric-part--outro::before { color: #6a3d54; }
.part-btn { border-left-width: 4px; }
.btn.part-btn--verse { border-left-color: #3d5a45; background: #e8f0ea; }
.btn.part-btn--verse:hover { background: #d7e4da; }
.btn.part-btn--pre-chorus { border-left-color: #c47a32; background: #f8eee3; }
.btn.part-btn--pre-chorus:hover { background: #f0e0cc; }
.btn.part-btn--chorus { border-left-color: #7a2e2a; background: #f3e4e0; }
.btn.part-btn--chorus:hover { background: #ead3cd; }
.btn.part-btn--interlude { border-left-color: #3f6f72; background: #e6f1f2; }
.btn.part-btn--interlude:hover { background: #d4e6e8; }
.btn.part-btn--prelude { border-left-color: #5a6d9a; background: #eceff7; }
.btn.part-btn--prelude:hover { background: #dde2f0; }
.btn.part-btn--intro { border-left-color: #6a7c38; background: #eef3e0; }
.btn.part-btn--intro:hover { background: #e0e8cc; }
.btn.part-btn--outro { border-left-color: #7a4a62; background: #f4e8ee; }
.btn.part-btn--outro:hover { background: #ead7e1; }
.lyric-trail { min-height: 1.8em; }
.wysiwyg > p.lyric-trail:last-child {
    margin-top: 6px;
    padding-top: 4px;
}
.lyric .lyric-part { margin: 8px 0; }
.lyrics-chat-log {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0;
    min-height: 80px;
}
.lyrics-chat-msg {
    padding: 8px 10px;
    border-radius: 10px;
    white-space: pre-wrap;
    font-size: 0.9rem;
    max-width: 100%;
}
.lyrics-chat-msg--user { background: #fff; align-self: flex-end; }
.lyrics-chat-msg--assistant { background: var(--card); border: 1px solid var(--line); }
.lyrics-chat-form { display: flex; flex-direction: column; gap: 8px; }
.lyrics-suggest {
    position: absolute;
    inset: 0;
    background: rgba(28,22,18,0.45);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 2;
}
.lyrics-editor { position: relative; }
.lyrics-suggest[hidden] { display: none !important; }
.lyrics-suggest-card {
    width: min(640px, 96vw);
    max-height: 80vh;
    overflow: auto;
    background: var(--card);
    border-radius: 16px;
    padding: 18px 20px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.lyrics-suggest-preview {
    border: 1px dashed var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    margin: 10px 0 16px;
    background: #fff;
}

@media (max-width: 840px) {
    .lyrics-editor-split { grid-template-columns: 1fr; }
    .lyrics-pane { border-right: 0; border-bottom: 1px solid var(--line); }
}
.btn-primary { background: var(--wine); border-color: var(--wine); color: #fff; }
.btn-primary:hover { background: var(--wine-dark); }
.btn-small { padding: 5px 10px; font-size: 0.85rem; }
.btn-ghost { background: transparent; }
.btn-icon {
    border: 0; background: transparent; font-size: 1.4rem; cursor: pointer; color: var(--muted);
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.toolbar { margin-bottom: 16px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
a.card.book-card {
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
a.card.book-card:hover,
a.card.book-card:focus-visible {
    border-color: var(--wine);
    box-shadow: 0 10px 28px rgba(90, 40, 36, 0.14);
    transform: translateY(-2px);
}
a.card.book-card h2 { color: inherit; }
.card h2 { margin: 0 0 8px; font-size: 1.15rem; font-family: var(--serif); }
.char-card-photo {
    width: 100%;
    aspect-ratio: 1;
    max-height: 220px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--paper-2);
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.char-card-photo img,
.char-profile-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.char-profile-photo {
    max-height: 240px;
    border-radius: 10px;
    height: auto;
    aspect-ratio: auto;
}
.char-card-initial {
    font-family: var(--serif);
    font-size: 3rem;
    color: var(--wine);
    opacity: 0.55;
}
.char-photo-edit img[data-photo-preview] {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: 10px;
}
.char-profile-text {
    white-space: pre-wrap;
    line-height: 1.55;
}
.card-foot { font-size: 0.85rem; color: var(--muted); margin: 12px 0 0; }
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}
.dashboard-grid--single { grid-template-columns: 1fr; }
.dashboard-panel h2 {
    margin: 0 0 14px;
    font-family: var(--serif);
    font-size: 1.2rem;
}
.recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.recent-list li {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.recent-list li:last-child { padding-bottom: 0; border-bottom: 0; }
.recent-main {
    display: block;
    width: 100%;
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    font: inherit;
    font-weight: 650;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
}
a.recent-main { color: var(--ink); }
.recent-main:hover { color: var(--wine); text-decoration: underline; }
.recent-meta { margin: 4px 0 0; font-size: 0.85rem; }
@media (max-width: 840px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}
.cover { width: 100%; height: 140px; object-fit: cover; border-radius: 8px; margin-bottom: 10px; }
.badge {
    display: inline-block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--paper-2);
    color: var(--muted);
}
.badge-open { background: #e5efe8; color: var(--forest); }
.badge-closed { background: var(--wine-soft); color: var(--wine); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.card-meta { display: flex; gap: 6px; margin-bottom: 8px; }

.empty-state {
    text-align: center;
    padding: 48px 16px;
    background: var(--card);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}
.empty-inline { margin: 12px 0; padding: 24px; }

.banner {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
.banner-warn { background: var(--warn-bg); color: #5c3d00; }
.lyrics-story-review {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: center;
}
.lyrics-story-review .btn { margin-left: auto; }
.lyric-propose-preview {
    max-height: min(50vh, 22rem);
    overflow: auto;
    background: #fff;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
}
.lyric-propose-preview .lyric-part { margin: 0 0 12px; }
.story-review-ignore {
    margin-left: 6px;
    font-size: 0.78rem;
    padding: 2px 8px;
}
.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; }
.alert-error { background: #fde8e8; color: var(--danger); }

.timeline { max-width: 1080px; }
.timeline-node {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
}
.timeline-head {
    display: flex;
    gap: 12px 20px;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.timeline-thumb {
    width: 96px;
    height: 54px;
    object-fit: cover;
    border-radius: 8px;
    flex: 0 0 auto;
    background: var(--paper-2);
    border: 1px solid var(--line);
    display: block;
}
.timeline-head-main {
    display: flex;
    gap: 10px;
    align-items: baseline;
    flex-wrap: wrap;
    min-width: 0;
    flex: 1 1 180px;
}
.timeline-head h2 { margin: 0; font-family: var(--serif); font-size: 1.25rem; }
.timeline-lyrics {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
    text-align: right;
    max-width: 42%;
}
.timeline-lyrics li {
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--muted);
}
.timeline-lyric-title { color: var(--ink); font-weight: 650; }
.timeline-lyric-album { display: block; }
.timeline-split {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(200px, 0.9fr);
    gap: 16px 22px;
    align-items: start;
}
.timeline-summary {
    background: var(--paper-2, #f6f1ea);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px 12px;
}
.timeline-summary h3 {
    margin: 0 0 6px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.timeline-summary p { margin: 0; font-size: 0.88rem; line-height: 1.5; }
.timeline-gap {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 12px 8px 12px 28px;
    border-left: 2px dashed var(--line);
    margin-left: 18px;
}
.char-badge-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 0;
    margin: 0 0 10px;
}
.story-image-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper-2);
}
.story-image-bar img[data-story-image-preview] {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}
.story-image-upload {
    position: relative;
    overflow: hidden;
    cursor: pointer;
}
.story-image-upload input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    font-size: 0;
}
.char-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
}
.char-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    background: #eceff7;
    border: 1px solid #c5cde0;
    color: #3d4a6b;
    font-size: 0.8rem;
    font-weight: 650;
    line-height: 1.4;
}
.char-links-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.char-links-list li strong { display: block; }
.char-links-list li p { margin: 4px 0 0; }
.text-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; list-style: none; }
.text-chips li {
    background: var(--wine-soft);
    color: var(--wine-dark);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 0.8rem;
}

.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table tbody tr {
    transition: background-color 0.12s ease;
}
.table tbody tr:hover td {
    background: var(--wine-soft);
}
.table tbody tr:hover td:first-child {
    box-shadow: inset 3px 0 0 var(--wine);
}
.table tbody tr:hover .cell-action--title {
    color: var(--wine-dark);
}
.check-list { display: flex; flex-direction: column; gap: 8px; }
.check-row { flex-direction: row; align-items: center; font-weight: 500; gap: 8px; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    cursor: pointer;
    font-weight: 500;
}
.choice-card:has(input:checked) {
    border-color: var(--wine, #7a2e2a);
    background: var(--wine-soft, #f6ebe9);
}
.choice-card input {
    margin-top: 3px;
    flex: 0 0 auto;
}
.choice-card span { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.choice-card .muted { font-weight: 400; }

.settings-form { max-width: 640px; display: flex; flex-direction: column; gap: 18px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 16px; }
legend { font-weight: 650; padding: 0 6px; }
.form-status { color: var(--forest); }

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(900px 400px at 80% -10%, rgba(122, 46, 42, 0.18), transparent 60%),
        var(--paper);
}
.auth-card {
    width: min(420px, 92vw);
    background: var(--card);
    padding: 32px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}
.auth-card h1 { font-family: var(--serif); margin: 0 0 6px; text-align: center; }
.auth-card .muted { text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

.modal-root[hidden] { display: none; }
.modal-root { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(28,22,18,0.45); }
.modal {
    position: relative;
    width: min(720px, 94vw);
    max-height: 90vh;
    overflow: auto;
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.modal.modal-wide { width: min(920px, 96vw); }
.catalog-toggle { margin: 4px 0 20px; max-width: 42rem; }
label.toggle {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-weight: 500;
    user-select: none;
    width: auto;
}
.toggle input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.toggle-track {
    position: relative;
    flex: 0 0 auto;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: #d4c8b8;
    box-shadow: inset 0 1px 3px rgba(28, 22, 18, 0.12);
    transition: background 0.2s ease;
}
.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(28, 22, 18, 0.25);
    transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track {
    background: var(--wine);
}
.toggle input:checked + .toggle-track .toggle-thumb {
    transform: translateX(20px);
}
.toggle input:focus-visible + .toggle-track {
    outline: 2px solid var(--wine);
    outline-offset: 3px;
}
.toggle-text { line-height: 1.35; }
@media (prefers-reduced-motion: reduce) {
    .toggle-track, .toggle-thumb { transition: none; }
}
.btn-count {
    border: 0;
    background: var(--wine-soft);
    color: var(--wine-dark);
    font: inherit;
    font-weight: 700;
    min-width: 2rem;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.btn-count:hover { background: var(--wine); color: #fff; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.story-preview { max-height: 55vh; overflow: auto; background: #fff; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); }
.import-overlay[hidden] { display: none !important; }
.import-overlay {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    background: rgba(28, 22, 18, 0.5);
    padding: 20px;
}
.import-card {
    width: min(440px, 94vw);
    background: var(--card);
    border-radius: 16px;
    padding: 22px 24px 20px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.28);
}
.import-card h2 { margin: 0 0 8px; font-family: var(--serif); font-size: 1.25rem; }
.import-status { margin: 0 0 14px; min-height: 1.4em; }
.progress {
    height: 12px;
    border-radius: 999px;
    background: var(--paper-2);
    overflow: hidden;
    border: 1px solid var(--line);
}
.progress-bar {
    height: 100%;
    width: 0;
    background: var(--wine);
    border-radius: 999px;
    transition: width 0.25s ease;
}
.modal-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 18px; }

.reader { max-width: 680px; margin: 0 auto; font-family: var(--serif); }
.reader-title h2 { font-size: 2rem; margin: 0 0 12px; }
.reader-blurb { font-style: italic; color: var(--muted); }
.reader-chapter { padding: 28px 0; border-top: 1px solid var(--line); }
.reader-scene {
    margin: 0 0 1.2em;
}
.reader-scene img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
    background: var(--paper-2);
}
.reader-prose { font-size: 1.12rem; line-height: 1.75; }
.reader-appendix { margin-top: 20px; background: var(--paper-2); padding: 12px 14px; border-radius: 10px; }
.lyric { font-family: var(--sans); font-size: 0.92rem; }
.lyric p { margin: 0 0 0.55em; }
.reader-toolbar { display: flex; gap: 10px; align-items: end; margin-bottom: 20px; max-width: 680px; margin-left: auto; margin-right: auto; }

.chat-box { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.chat-log { min-height: 40px; font-size: 0.9rem; color: var(--muted); }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; }
.hidden { display: none !important; }
.busy { opacity: 0.65; pointer-events: none; }

.pwa-banner {
    position: fixed;
    z-index: 50;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    background: var(--sidebar);
    color: #f3ebe3;
    padding: 14px 16px;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}
.pwa-banner[hidden] { display: none !important; }
.pwa-banner-text { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
.pwa-banner-text span { font-size: 0.88rem; color: #d9cdc2; }
.pwa-banner-actions { display: flex; gap: 8px; }
.pwa-banner .btn { background: #fff; }
.pwa-banner .btn-primary { background: var(--wine); color: #fff; border-color: var(--wine); }
@media (display-mode: standalone) {
    .pwa-banner { display: none !important; }
}

.app-footer {
    display: none;
}

@media (max-width: 840px) {
    :root { --app-footer-h: calc(3.4rem + env(safe-area-inset-bottom, 0px)); }
    html, body { overflow-x: hidden; }
    .app-shell { grid-template-columns: 1fr; }
    .nav-toggle { display: inline-flex; }
    .nav-backdrop[hidden] { display: none !important; }
    body.nav-open { overflow: hidden; }
    body.nav-open .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(28, 22, 18, 0.45);
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(18rem, 86vw);
        z-index: 60;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        padding-bottom: calc(var(--app-footer-h) + 12px);
        overflow: auto;
    }
    body.nav-open .sidebar { transform: translateX(0); }
    .side-nav { flex-direction: column; flex-wrap: nowrap; }
    .side-nav a { padding: 12px 12px; font-size: 1.05rem; }
    .side-book, .side-foot { width: 100%; }
    .topbar {
        flex-wrap: wrap;
        align-items: center;
        padding: 12px 16px 0;
        gap: 10px;
    }
    .topbar h1 {
        flex: 1;
        min-width: 0;
        font-size: 1.35rem;
        line-height: 1.2;
    }
    .topbar-actions {
        flex-basis: 100%;
        justify-content: flex-start;
    }
    .topbar-actions .btn { min-height: 2.6rem; }
    .page { padding: 16px 16px calc(var(--app-footer-h) + 20px); }
    .btn, button.btn { min-height: 2.6rem; padding: 10px 14px; }
    .btn-small { min-height: 2.4rem; }
    .card-grid { grid-template-columns: 1fr; }
    .timeline-split { grid-template-columns: 1fr; }
    .timeline-lyrics { max-width: 100%; align-items: flex-start; text-align: left; }
    .reader-toolbar, .chat-input, .timeline-gap, .timeline-head {
        flex-wrap: wrap;
    }
    .chat-input { flex-direction: column; align-items: stretch; }
    .lyrics-editor-head {
        flex-direction: column;
        padding: 10px 12px;
        gap: 10px;
    }
    .lyrics-editor-actions { width: 100%; }
    .lyrics-editor-actions .btn { flex: 1 1 auto; }
    .lyrics-player { max-width: none; }
    .lyrics-player-row { flex-wrap: wrap; }
    .editor-root { bottom: var(--app-footer-h); }
    .modal { width: calc(100vw - 20px); max-height: calc(100vh - var(--app-footer-h) - 24px); }
    .auth-card { width: min(420px, calc(100vw - 24px)); padding: 22px 18px; margin-bottom: var(--app-footer-h); }
    .auth-body { align-items: start; padding: 24px 12px calc(var(--app-footer-h) + 24px); }

    .table-wrap {
        border: 0;
        background: transparent;
        overflow: visible;
    }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td {
        display: block;
        width: 100%;
    }
    .table {
        background: transparent;
        overflow: visible;
    }
    .table tbody { display: flex; flex-direction: column; gap: 12px; }
    .table tr {
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 10px 14px;
        box-shadow: var(--shadow);
    }
    .table tbody tr:hover {
        background: var(--wine-soft);
    }
    .table tbody tr:hover td {
        background: transparent;
    }
    .table tbody tr:hover td:first-child {
        box-shadow: none;
    }
    .table td {
        display: grid;
        grid-template-columns: 7.5rem 1fr;
        gap: 8px;
        align-items: start;
        border-bottom: 1px solid var(--line);
        padding: 8px 0;
    }
    .table td:last-child { border-bottom: 0; }
    .table td::before {
        content: attr(data-label);
        font-weight: 650;
        color: var(--muted);
        font-size: 0.78em;
        letter-spacing: 0.02em;
        padding-top: 0.2em;
    }
    .table td[data-label=""] {
        grid-template-columns: 1fr;
    }
    .table td[data-label=""]::before { display: none; }
    .table td.table-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 10px;
    }
    .table td.table-actions::before { display: none; }

    .app-footer {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 72;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
        background: var(--card);
        border-top: 1px solid var(--line);
        box-shadow: 0 -8px 24px rgba(28, 22, 18, 0.08);
    }
    .app-footer-label {
        font-weight: 650;
        color: var(--muted);
    }
    .text-scale {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .text-scale-value {
        min-width: 3.6em;
        text-align: center;
        font-variant-numeric: tabular-nums;
        font-weight: 650;
    }
    .text-scale .btn { min-width: 2.8rem; font-weight: 700; }
    .pwa-banner { bottom: calc(var(--app-footer-h) + 10px); }
}
