/* Trang thường: thư viện, thùng rác, hạt giống, nhân vật, thế giới. Lấy từ docs/prototype/novelscope.html;
   màu, font từ tokens.css. Biểu mẫu dùng cùng kiểu .fld với tinh đồ. */
.faint { color: var(--faint); }
.page.narrow { max-width: 820px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 2px 8px; font-size: 15px; line-height: 1.2; }
.btn.armed, .edit.armed { color: var(--warn) !important; border-color: var(--warn) !important; }
.hint-s { margin: 0; font-size: 11.5px; color: var(--faint); line-height: 1.45; }
.form-err { color: var(--warn); font-size: 13px; margin: 6px 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Biểu mẫu chung ---------- */
.fld { display: grid; gap: 5px; min-width: 0; margin: 0; }
.fld > label, .fld .lbl, .fld legend { font-size: 12px; font-weight: 600; color: var(--muted); }
.fld input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), .fld select, .fld textarea,
.idea-input, .idea-tags, .cast-new input {
  width: 100%; background: var(--deep); border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
  padding: 8px 10px; font: inherit; font-size: 13.5px; }
.fld textarea { resize: vertical; font-family: var(--prose); line-height: 1.5; }
.fld input:focus, .fld select:focus, .fld textarea:focus, .idea-input:focus, .idea-tags:focus, .cast-new input:focus { outline: none; border-color: var(--lamp); }
.fld .static { padding: 8px 0; color: var(--ink); font-size: 13.5px; }
fieldset.fld { border: 0; padding: 0; }
.fld-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.fld-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 620px) { .fld-row, .fld-row.three { grid-template-columns: minmax(0, 1fr); } }
.inline-form { display: grid; gap: 12px; padding: 12px 0 4px; }
.inline-form .row, .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.edit { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 6px; cursor: pointer; }
.edit:hover { color: var(--lamp); background: var(--panel-2); }
.edit.danger:hover { color: var(--warn); }
.row-acts { display: inline-flex; gap: 2px; align-items: center; }
.row-acts form { display: inline; }
.add-box { margin-top: 14px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; }
.add-box summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.add-box[open] summary { color: var(--star); }

/* ---------- Hộp thoại ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10,14,26,.5); display: grid; place-items: center; z-index: 30;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px)); }
.modal { width: min(580px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); display: grid; gap: 14px; padding: 20px 22px; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.modal h2 { font-family: var(--display); font-weight: 600; font-size: 28px; margin: 2px 0 0; color: var(--star); line-height: 1.1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; }
.xbtn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); flex: none; cursor: pointer; }
.xbtn:hover { background: #2f3b5c; border-color: var(--faint); color: var(--star); }
@media (pointer: coarse) { .xbtn { width: 44px; height: 44px; } }
.structures { display: grid; gap: 6px; }
.structure { display: flex; gap: 10px; align-items: start; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; cursor: pointer; }
.structure:has(input:checked) { border-color: var(--lamp); background: var(--lamp-soft); }
.structure input { margin-top: 3px; accent-color: var(--lamp); }
.structure b { display: block; font-weight: 600; color: var(--star); font-size: 13.5px; }
.structure small { color: var(--muted); font-size: 12px; }

/* ---------- Thư viện ---------- */
.lib-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.lib-head h1 { font-family: var(--display); font-weight: 600; font-size: clamp(32px, 5vw, 44px); line-height: 1.05; margin: 6px 0 0; color: var(--star); }
.lib-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-filters button { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 999px; font-size: 12.5px; }
.lib-filters button .num { color: var(--faint); margin-left: 3px; }
.lib-filters button[aria-pressed="true"] { color: var(--star); border-color: var(--faint); background: var(--panel); }
.lib-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; }
@media (max-width: 900px) { .lib-grid { grid-template-columns: minmax(0, 1fr); } }
.novels { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; align-content: start; }
.novel { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; color: inherit; transition: border-color .2s; }
.novel:hover, .novel:focus-within { border-color: var(--faint); }
.novel .novel-select { position: absolute; inset: 0; z-index: 1; border: 0; background: transparent; border-radius: 12px; cursor: pointer; }
.novel .novel-select:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }
.novel.selected { border-color: var(--lamp); box-shadow: 0 0 0 1px var(--lamp), 0 10px 40px rgba(232,182,90,.12); }
.novel.selected h3 { color: var(--lamp); }
.novel .sky { height: 118px; background: radial-gradient(120% 90% at 30% 20%, #2a3760 0%, var(--deep) 60%, var(--void) 100%); display: block; width: 100%; border-radius: 12px 12px 0 0; }
.novel .body { padding: 14px 16px 16px; display: grid; gap: 8px; }
.novel h3 { font-family: var(--display); font-size: 23px; font-weight: 600; margin: 0; line-height: 1.15; color: var(--star); }
.novel p { margin: 0; color: var(--muted); font-size: 13px; }
.novel .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.novel.new { border-style: dashed; align-items: center; justify-content: center; min-height: 240px; color: var(--muted); gap: 6px; background: transparent; }
.novel.new strong { font-family: var(--display); font-size: 22px; color: var(--ink); font-weight: 600; }
.novel.new:hover { color: var(--ink); }
.lib-empty { color: var(--faint); grid-column: 1 / -1; }
.lib-side { display: grid; align-content: start; min-width: 0; }

/* Panel thông tin tiểu thuyết đang chọn (cột phải; màn hình hẹp thì trượt lên từ đáy) */
.np-wrap { position: sticky; top: 16px; max-height: calc(100vh - var(--topbar) - 32px); overflow: auto; border-color: var(--faint); }
.np { display: grid; gap: 14px; }
.np-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.np-head h2 { font-family: var(--display); font-size: 28px; font-weight: 600; margin: 4px 0 0; line-height: 1.1; color: var(--star); }
.np-open { text-align: center; padding: 10px 14px; font-size: 14px; }
.np-links { display: flex; gap: 4px; flex-wrap: wrap; }
.np-links a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px; }
.np-links a:hover { color: var(--ink); border-color: var(--faint); }
.np-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.np-facts div { background: var(--deep); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.np-facts dt { font-size: 11px; color: var(--faint); letter-spacing: .04em; }
.np-facts dd { margin: 2px 0 0; color: var(--star); font-weight: 600; font-size: 14px; }
.np-facts dd span { font-weight: 400; font-size: 12px; }
.warn-t { color: var(--warn); }
.np-form { display: grid; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.np-acts { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 12px; }
.np-acts form { margin: 0; }
/* Màn hình rộng (Full HD trở lên): trang thư viện rộng hơn, panel thông tin rộng và thoáng hơn */
.lib-page { max-width: 1680px; }
@media (min-width: 1400px) {
  .lib-grid { grid-template-columns: minmax(0, 1fr) 380px; gap: 32px; }
  .lib-grid.has-panel { grid-template-columns: minmax(0, 1fr) 500px; }
  .np-wrap { padding: 22px 24px; }
  .np { gap: 16px; }
  .np-head h2 { font-size: 34px; }
  .np-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .np-facts dd { font-size: 16px; }
  .np-form .fld input:not([type="checkbox"]):not([type="radio"]), .np-form .fld select, .np-form .fld textarea { font-size: 14.5px; padding: 9px 11px; }
}
@media (max-width: 900px) {
  .np-wrap { position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 25; max-height: 82vh; border-radius: 16px 16px 0 0;
    box-shadow: 0 -20px 60px rgba(0,0,0,.6); padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
}
.side-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 14px; align-self: start; }
.side-card h2 { font-family: var(--display); font-size: 24px; font-weight: 600; margin: 0; color: var(--star); scroll-margin-top: 80px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--deep); border-radius: 8px; padding: 10px; }
.stat b { display: block; font-size: 18px; color: var(--star); font-weight: 600; }
.stat span { font-size: 11.5px; color: var(--muted); }
.idea-form { display: grid; gap: 8px; }
.idea-input { resize: vertical; min-height: 60px; }
.idea-form-row { display: flex; gap: 6px; }
.idea { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; display: grid; gap: 6px; }
.idea p { margin: 0; font-size: 13.5px; }
.idea.promoted p { color: var(--muted); }
.idea .tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.idea .acts { margin-left: auto; display: inline-flex; gap: 4px; align-items: center; font-size: 12px; }
.idea .acts form { display: inline; }
.trash-link { color: var(--muted); font-size: 12.5px; text-decoration: none; justify-self: start; }
.trash-link:hover { color: var(--ink); }
.trash-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; }
.trash-row h3 { font-family: var(--display); font-size: 22px; font-weight: 600; margin: 0; color: var(--star); }
.trash-row p { margin: 4px 0 0; font-size: 12.5px; }
.trash-row .acts { display: flex; gap: 8px; }

/* ---------- Hạt giống ---------- */
.seed-form { display: grid; gap: 18px; margin-top: 18px; }
.seed-sec { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 18px; display: grid; gap: 14px; }
.seed-sec h2 { font-family: var(--display); font-size: 22px; font-weight: 600; margin: 0; color: var(--star); }
.seed-foot { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding: 12px 0;
  background: linear-gradient(transparent, var(--void) 35%); }
.seed-foot .hint-s { margin-right: auto; }

/* ---------- Nhân vật ---------- */
.char-page { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; }
@media (max-width: 820px) { .char-page { grid-template-columns: minmax(0, 1fr); } }
.cast { display: grid; gap: 6px; align-content: start; }
.cast-head { padding: 0 10px 6px; }
.cast a { display: flex; gap: 10px; align-items: center; border: 1px solid transparent; padding: 8px 10px; border-radius: 10px; color: var(--ink); text-decoration: none; }
.cast a:hover { background: var(--panel); }
.cast a[aria-current="page"] { background: var(--panel); border-color: var(--line); }
.cast small { display: block; color: var(--muted); font-size: 11.5px; }
.cast .btn { justify-content: center; text-align: center; }
.cast-new { display: grid; }
.cast-new-row { display: flex; gap: 6px; }
.avatar { --c: var(--star); color: var(--c); border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.avatar.big { width: 64px; height: 64px; font-size: 30px; background: color-mix(in srgb, var(--c) 14%, transparent); }
.profile { min-width: 0; display: grid; gap: 20px; align-content: start; }
.p-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.p-head h1 { font-family: var(--display); font-weight: 600; font-size: clamp(32px, 4.5vw, 44px); margin: 0; line-height: 1; color: var(--star); }
.p-head .roles { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; font-size: 13px; }
.p-acts { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 9px 12px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-size: 13.5px; }
.tabs button[aria-selected="true"] { color: var(--star); border-bottom-color: var(--lamp); }
#tabpanel { display: grid; gap: 14px; }
#tabpanel.htmx-request { opacity: .6; transition: opacity .15s; }
.tab-lead { margin: 0; color: var(--muted); font-size: 13px; }
.sec-title { font-family: var(--display); font-size: 22px; font-weight: 600; margin: 18px 0 0; color: var(--star); scroll-margin-top: 80px; }
.sub-title { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 600; margin: 14px 0 6px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 620px) { .fields { grid-template-columns: minmax(0, 1fr); } }
.fields .field { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; margin: 0; align-content: start; }
.fields .field.wide { grid-column: 1 / -1; }
.fields .field.editing { border-color: var(--lamp); }
.fields .field .field-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.fields .field .lbl, .fields .field label { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.fields .field .edit { opacity: 0; }
.fields .field:hover .edit, .fields .field .edit:focus-visible { opacity: 1; }
@media (pointer: coarse) { .fields .field .edit { opacity: 1; } }
.fields .field .val { font-size: 14px; }
.fields .field .val.q { font-family: var(--prose); font-style: italic; }
.fields .field form { display: grid; gap: 8px; }
.fields .field input:not([type="color"]), .fields .field textarea { width: 100%; background: var(--deep); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); padding: 8px 10px; font: inherit; font-size: 14px; }
.fields .field textarea { font-family: var(--prose); line-height: 1.5; resize: vertical; }
.fields .field input:focus, .fields .field textarea:focus { outline: none; border-color: var(--lamp); }
.fields .field input[type="color"] { width: 64px; height: 34px; background: var(--deep); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; border: 1px solid var(--line); }
.arc { display: grid; gap: 0; position: relative; }
.arc-step { display: grid; grid-template-columns: 140px 22px minmax(0, 1fr); gap: 12px; align-items: start; padding-bottom: 18px; }
.arc-step .when { font-size: 12.5px; color: var(--muted); text-align: right; padding-top: 1px; }
.arc-step .when a { color: var(--ink); text-decoration: none; }
.arc-step .when small { display: block; color: var(--faint); font-size: 11px; }
.arc-step .mk { position: relative; height: 100%; }
.arc-step .mk::before { content: ""; position: absolute; left: 10px; top: 6px; bottom: -24px; width: 1px; background: var(--line); }
.arc-step:last-child .mk::before { display: none; }
.arc-step .mk i { position: absolute; left: 5px; top: 4px; width: 11px; height: 11px; transform: rotate(45deg); background: var(--lamp); }
.arc-step .txt b { display: block; color: var(--star); font-weight: 600; }
.arc-step .txt span { color: var(--muted); font-size: 13px; display: block; }
@media (max-width: 560px) { .arc-step { grid-template-columns: 90px 22px minmax(0, 1fr); } }
.rel-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.rel-table th { text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.rel-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rel-table td small { display: block; }
.rel-table td a { color: var(--star); text-decoration: none; }
.rel-table td a:hover { color: var(--lamp); }
.rel-table .rel-detail td { background: var(--deep); }
.rel-table .rel-detail p { margin: 0 0 8px; }
.table-wrap { overflow-x: auto; }
.phase { border-top: 1px dashed var(--line); padding: 8px 0; }
.phase-view { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.phase-view .when { color: var(--muted); font-size: 12.5px; }
.phase-view .row-acts { margin-left: auto; }
.profile.empty { align-content: start; }

/* ---------- Thế giới ---------- */
.world-lead { margin: -14px 0 18px; max-width: 720px; }
.world-add { margin: 0 0 22px; }
.world-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 22px; align-items: start; }
.world-group { display: grid; gap: 10px; }
.world-group h2 { font-family: var(--display); font-size: 24px; font-weight: 600; margin: 0; color: var(--star); }
.world-entry { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; scroll-margin-top: 80px; }
.world-entry:target { border-color: var(--lamp); }
.world-entry .we-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.world-entry h3 { font-size: 15px; font-weight: 600; margin: 0; color: var(--star); }
.world-entry p { margin: 6px 0 0; font-size: 13.5px; }
.we-nodes { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.node-picks .picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 10px; max-height: 220px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--deep); }
.pick { display: flex; gap: 6px; align-items: center; font-size: 13px; padding: 3px 0; cursor: pointer; }
.pick input { accent-color: var(--lamp); }
.pick small { margin-left: auto; color: var(--faint); font-size: 11px; }

/* ---------- Cài đặt ---------- */
.settings-page { max-width: 1400px; }
.set-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
@media (max-width: 900px) { .set-grid { grid-template-columns: minmax(0, 1fr); } }
.set-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px 18px; display: grid; gap: 12px; align-content: start; }
.set-card.wide { margin-bottom: 18px; }
.set-card h2 { font-family: var(--display); font-size: 24px; font-weight: 600; margin: 0; color: var(--star); }
.set-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; font-size: 13.5px; }
.set-dl dt { color: var(--muted); }
.set-dl dd { margin: 0; overflow-wrap: anywhere; }
.rel-table.compact td, .rel-table.compact th { padding: 6px 8px; font-size: 12.5px; }
.rel-table .r { text-align: right; }
.ok-t { color: var(--good); }
.prompt-list { display: grid; gap: 6px; }
.prompt { border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; background: var(--deep); scroll-margin-top: 80px; }
.prompt summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13.5px; }
.prompt summary code { color: var(--faint); font-size: 11.5px; }
.prompt summary .muted { margin-left: auto; font-size: 12px; }
.prompt .tier { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); min-width: 74px; }
.prompt textarea.mono, .prompt textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; line-height: 1.5; }
.versions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding-top: 6px; }
.versions form { margin: 0; }
.versions button.chip { background: transparent; cursor: pointer; }

/* ---------- Khối AI trên trang thường ---------- */
.ai-sec .row { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-cards { display: grid; gap: 10px; }
.profile-col { display: grid; gap: 18px; align-content: start; min-width: 0; }
.ai-box { background: var(--panel); border: 1px solid var(--p-theme); border-radius: 12px; padding: 14px 16px 16px; display: grid; gap: 10px; }
.ai-box-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ai-box h2 { font-family: var(--display); font-size: 22px; font-weight: 600; margin: 0; color: var(--star); }
.ai-box textarea, .ai-box input { width: 100%; background: var(--deep); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); padding: 8px 10px; font: inherit; font-size: 13.5px; }
.ai-box textarea:focus, .ai-box input:focus { outline: none; border-color: var(--lamp); }
.ai-box .ask { flex-wrap: nowrap; }
.ai-box .ask input { flex: 1; }
.ai-inline { display: grid; gap: 10px; margin-top: 12px; justify-items: start; }
.ai-inline .ai-cards { width: 100%; }

/* ---------- Lịch sử, so sánh ---------- */
.hist-page { max-width: 1500px; }
.hist-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 960px) { .hist-grid { grid-template-columns: minmax(0, 1fr); } }
.hist-side { display: grid; gap: 16px; position: sticky; top: 16px; }
@media (max-width: 960px) { .hist-side { position: static; } }
.snap-new { display: flex; gap: 6px; }
.snap-new input { flex: 1; min-width: 0; background: var(--deep); border: 1px solid var(--line); border-radius: 7px; color: var(--ink); padding: 6px 9px; font: inherit; font-size: 13px; }
.snap-new input:focus { outline: none; border-color: var(--lamp); }
.snaps { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.snap { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--deep); }
.snap.auto { opacity: .8; border-style: dashed; }
.snap-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.snap-head b { display: block; font-weight: 600; color: var(--star); font-size: 13.5px; }
.snap-head small { color: var(--muted); font-size: 11.5px; }
.snap-acts { display: grid; gap: 6px; padding-top: 8px; justify-items: start; }
.snap-acts form { margin: 0; }
.timeline { display: grid; gap: 2px; align-content: start; }
.timeline .day { font-family: var(--display); font-size: 21px; font-weight: 600; color: var(--star); margin: 14px 0 4px; }
.timeline .day:first-child { margin-top: 0; }
.tl-row { display: grid; grid-template-columns: 48px 76px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 6px 8px; border-radius: 8px; font-size: 13.5px; }
.tl-row:hover { background: var(--panel); }
.tl-row.undone .lbl { color: var(--faint); text-decoration: line-through; }
.tl-row .time { color: var(--muted); font-size: 12.5px; }
.tl-row .acts form { margin: 0; }
.src { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; text-align: center; color: var(--muted); }
.src-ai { color: var(--p-theme); border-color: rgba(110,201,214,.4); }
.src-system { color: var(--faint); }
.cmp-sum { color: var(--muted); margin: -12px 0 18px; }
.k-added { color: var(--good); } .k-deleted { color: var(--warn); } .k-modified { color: var(--p-theme); } .k-moved { color: var(--p-symbol); }
.cmp-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
@media (max-width: 960px) { .cmp-grid { grid-template-columns: minmax(0, 1fr); } }
.cmp-group { margin-bottom: 18px; }
.cmp-group h2 { font-family: var(--display); font-size: 21px; font-weight: 600; margin: 0 0 6px; color: var(--star); }
.cmp-row { display: grid; grid-template-columns: auto 52px minmax(0, 220px) minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.cmp-row input { accent-color: var(--lamp); }
.cmp-row .kind { font-size: 11.5px; font-weight: 600; }
.cmp-row.k-added .kind { color: var(--good); } .cmp-row.k-deleted .kind { color: var(--warn); }
.cmp-row.k-modified .kind { color: var(--p-theme); } .cmp-row.k-moved .kind { color: var(--p-symbol); }
.cmp-row .name { color: var(--star); overflow: hidden; text-overflow: ellipsis; }
.cmp-row .detail { color: var(--muted); font-size: 12.5px; }
.cmp-restore { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.cmp-restore form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.cmp-restore select { background: var(--deep); border: 1px solid var(--line); border-radius: 7px; color: var(--ink); padding: 4px 8px; font: inherit; font-size: 12.5px; }
.cmp-restore .hint-s { flex-basis: 100%; }
.diff-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.diff-bar .tool-group { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.diff-bar .tool-group button { border: 0; background: transparent; color: var(--muted); padding: 4px 12px; border-radius: 6px; font-size: 12.5px; }
.diff-bar .tool-group button[aria-pressed="true"] { background: var(--panel-2); color: var(--star); }
.prose-diff { font-family: var(--prose); font-size: 17px; line-height: 1.75; color: #ece7dc; white-space: pre-wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; max-width: 820px; }
.prose-diff del { color: var(--p-fore); background: rgba(228,127,157,.12); text-decoration-thickness: 1px; }
.prose-diff ins { color: var(--p-theme); background: rgba(110,201,214,.12); text-decoration: none; border-bottom: 1px solid var(--p-theme); }
.diff-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.diff-side .prose-diff { max-width: none; font-size: 16px; }
@media (max-width: 900px) { .diff-side { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Tiến độ ---------- */
.prog-page { max-width: 1400px; }
.prog-top { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; margin-bottom: 20px; align-items: start; }
@media (max-width: 900px) { .prog-top { grid-template-columns: minmax(0, 1fr); } }
.prog-total { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: grid; gap: 8px; }
.prog-total b { font-family: var(--display); font-size: 64px; line-height: 1; color: var(--lamp); font-weight: 600; }
.prog-total > span { color: var(--muted); }
.prog-metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.pm { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; cursor: help; }
.pm-head { display: flex; justify-content: space-between; }
.pm-head b { color: var(--star); font-weight: 600; }
.pm small { color: var(--muted); font-size: 12px; }
.prog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
@media (max-width: 900px) { .prog-grid { grid-template-columns: minmax(0, 1fr); } }
.chart { width: 100%; height: 110px; display: block; background: var(--deep); border-radius: 8px; }
.chart.small { height: 70px; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); }
.audit { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.audit b { font-weight: 600; font-size: 12.5px; }
.audit.k-highlight b { color: var(--p-symbol); } .audit.k-stale b { color: var(--warn); } .audit.k-absent b { color: var(--p-fore); }
.audit.k-tension b { color: var(--p-theme); } .audit.k-idea_tp b { color: var(--muted); }
@media (max-width: 620px) { .audit { grid-template-columns: minmax(0, 1fr); } }
.weights { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .weights { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Xuất bản ---------- */
.exp-page { max-width: 1400px; }
.exp-grid { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 960px) { .exp-grid { grid-template-columns: minmax(0, 1fr); } }
.fmt-picks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.job { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.job b { color: var(--star); font-weight: 600; display: block; }
.job small { color: var(--muted); font-size: 12px; }
.job .acts { display: flex; gap: 4px; align-items: center; }
.job .acts form { margin: 0; }
.job.st-done .chip { color: var(--good); } .job.st-failed .chip { color: var(--warn); } .job.pending .chip { color: var(--p-theme); }
.side-links { display: flex; gap: 14px; flex-wrap: wrap; }

/* ---------- Sơ đồ quan hệ ---------- */
.rel-page { max-width: 1600px; }
.rel-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.rel-bar input[type=range] { flex: 1; min-width: 200px; max-width: 600px; accent-color: var(--lamp); }
.rel-bar output { color: var(--star); }
.rel-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
@media (max-width: 900px) { .rel-wrap { grid-template-columns: minmax(0, 1fr); } }
.cy { height: min(70vh, 720px); min-height: 420px; background: radial-gradient(120% 90% at 30% 20%, #2a3760 0%, var(--deep) 60%, var(--void) 100%); border: 1px solid var(--line); border-radius: 12px; }
.rel-info ul { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }

/* ---------- Độ phủ nội dung ---------- */
.f-text { color: var(--good); } .f-outline { color: var(--lamp); } .f-empty { color: var(--p-fore); }
.cov { margin-bottom: 18px; }
.cov-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cov-bar { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; }
.cov-bar .seg { flex: 1; min-width: 3px; }
.cov-bar .seg.f-text { background: var(--good); } .cov-bar .seg.f-outline { background: var(--lamp); opacity: .85; }
.cov-bar .seg.f-empty { background: var(--p-fore); opacity: .55; }
.cov-bar .seg:hover { opacity: 1; outline: 2px solid var(--star); outline-offset: -2px; }
.cov-sum { margin: 0; font-size: 13px; }
.gaps { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 10px; }
.gap { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--deep); }
.gap-ends { font-size: 13px; margin-bottom: 6px; }
.gap ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.gap li { display: flex; gap: 6px; align-items: baseline; font-size: 13px; flex-wrap: wrap; }
.gap li .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; align-self: center; }
.gap li a { color: var(--star); }
.gap li small { color: var(--muted); font-size: 11.5px; width: 100%; padding-left: 30px; }

/* Bảng quản lý chương: bảng bên trái, xem trước trình tự kể bên phải (màn hình rộng) */
.chapters-page { max-width: 1640px; }
.ch-lead { max-width: 900px; margin: 4px 0 22px; }
.ch-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 28px; align-items: start; }
@media (max-width: 1100px) { .ch-layout { grid-template-columns: 1fr; } }
.ch-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ch-table th { text-align: left; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 600; padding: 0 8px 8px; border-bottom: 1px solid var(--line); }
.ch-table td { padding: 7px 8px; border-bottom: 1px solid rgba(57,72,110,.55); vertical-align: middle; }
.ch-table tr.bad td { background: rgba(240,146,74,.07); }
.ch-table .num { text-align: right; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-table input, .ch-table select { width: 100%; min-width: 0; background: var(--deep); border: 1px solid var(--line); border-radius: 7px; color: var(--ink); padding: 7px 9px; font: inherit; font-size: 13px; }
.ch-table input:focus, .ch-table select:focus { border-color: var(--lamp); outline: none; }
.ch-table td:nth-child(2) { width: 26%; }
.ch-table td:nth-child(3), .ch-table td:nth-child(4) { width: 25%; }
.ch-no { white-space: nowrap; font-weight: 600; color: var(--star); }
.ch-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.ch-err { color: var(--warn); font-size: 12.5px; margin: 8px 0 0; }
.ch-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.ch-actions .spacer { flex: 1; }
.ch-actions form { margin: 0; }
.ch-gap { font-size: 12.5px; color: #e47f9d; }
.ch-order { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; position: sticky; top: 16px; max-height: calc(100vh - var(--topbar) - 40px); overflow: auto; }
.ch-order h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.ch-order h2 .faint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.ch-list { list-style: none; margin: 0; padding: 0; display: grid; }
.ch-list li { display: grid; grid-template-columns: 64px 52px minmax(0, 1fr); column-gap: 8px; align-items: baseline; padding: 5px 8px; border-left: 3px solid var(--c, transparent); font-size: 13px; border-radius: 0 6px 6px 0; }
.ch-list li.start { margin-top: 8px; border-top: 1px dashed rgba(126,136,168,.4); }
.ch-list li.none { border-left: 3px dashed rgba(228,127,157,.6); }
.ch-list li.hl { background: rgba(232,182,90,.08); }
.ch-list .ch-tag { font-size: 11px; font-weight: 600; color: var(--c, #e47f9d); }
.ch-list .rk { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.ch-list .t { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-list .k { grid-column: 3; font-size: 11.5px; color: var(--faint); }
.ch-list li.tp .t { font-family: var(--display); font-size: 16px; font-weight: 600; color: var(--star); }

/* Trang Tiến độ: cảnh đang viết dở */
.now-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 8px 14px; }
.now-list li { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--deep); }
.now-list li a { color: var(--ink); font-weight: 500; }
.now-list .now-bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.now-list .now-bar i { display: block; height: 100%; background: var(--lamp); }
.now-list li > small:last-child { grid-column: 1 / -1; }

/* ---------- Dựng khung cùng AI ---------- */
.page.ol-page { max-width: 1480px; }
.ol-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 18px; align-items: start; margin-top: 18px; }
.ol-col { display: grid; gap: 18px; min-width: 0; }
@media (max-width: 1500px) { .ol-grid { grid-template-columns: minmax(0, 1fr); } }
.ol-brief { min-height: 300px; }
.ol-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ol-tp { border-top: 1px solid var(--line); padding-top: 8px; display: grid; gap: 8px; }
.ol-tp:first-child { border-top: 0; padding-top: 0; }
.ol-tp-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.ol-tp-head b { font-weight: 600; color: var(--star); }
.ol-tp-head small { display: block; color: var(--muted); font-size: 12px; }
.ol-tp-head .btn { flex: none; }
.ol-sec { margin: 8px 0 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ol-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.ol-item input[type="checkbox"] { align-self: start; margin-top: 9px; accent-color: var(--lamp); }
.ol-item > div { display: grid; gap: 4px; min-width: 0; }
.ol-item input[type="text"], .ol-item textarea { width: 100%; background: var(--deep); border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink); padding: 5px 8px; font: inherit; font-size: 13px; }
.ol-item input[type="text"] { color: var(--star); font-weight: 600; }
.ol-item textarea { resize: vertical; line-height: 1.5; }
.ol-item small { color: var(--muted); font-size: 12px; line-height: 1.45; }
.ol-item:has(input[type="checkbox"]:not(:checked)) > div { opacity: .45; }
.ol-beats { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.ol-tp-head small .st-chip { margin-left: 4px; }
.ol-tp-sum { margin: 0; color: var(--ink); font-size: 13px; line-height: 1.55; }
.ol-scenes { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: grid; gap: 8px; }
.ol-scenes li { display: grid; gap: 2px; }
.ol-sc-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.ol-sc-head a { color: var(--star); font-weight: 500; text-decoration: none; }
.ol-sc-head a:hover { color: var(--lamp); text-decoration: underline; }
.ol-sc-head .num, .ol-tp-head b .num { font-size: 11px; font-weight: 400; }
.ol-scenes p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.ol-scenes small { color: var(--faint); font-size: 11.5px; }
.ol-tp .edit, .ol-chars .edit { padding: 0 6px; font-size: 11.5px; }
.ol-chars { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ol-chars li { display: grid; grid-template-columns: auto auto 1fr; align-items: baseline; gap: 2px 8px; }
.ol-chars i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.ol-chars b { font-weight: 600; color: var(--star); font-size: 13px; }
.ol-chars .edit { justify-self: start; }
.ol-chars small { grid-column: 2 / -1; color: var(--muted); font-size: 12px; }
#ol-total, #ol-char-count { font: 13px var(--ui); margin-left: 4px; }
