/* Tipografías alojadas en la app (sin conexión y sin llamadas a Google) */
@font-face { font-family: 'Cormorant Garamond'; src: url('/fonts/cormorant-500Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url('/fonts/cormorant-500Medium_Italic.woff2') format('woff2'); font-weight: 500; font-style: italic; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url('/fonts/cormorant-600SemiBold.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('/fonts/manrope-400Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('/fonts/manrope-500Medium.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('/fonts/manrope-600SemiBold.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('/fonts/manrope-700Bold.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Manrope'; src: url('/fonts/manrope-800ExtraBold.woff2') format('woff2'); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('/fonts/spectral-400Regular.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('/fonts/spectral-400Regular_Italic.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('/fonts/spectral-600SemiBold.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('/fonts/spectral-600SemiBold_Italic.woff2') format('woff2'); font-weight: 600; font-style: italic; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('/fonts/spectral-800ExtraBold.woff2') format('woff2'); font-weight: 800; font-style: normal; font-display: swap; }

/* Layout: app de una pantalla; barra superior + vista (escribir | escaleta | wiki | progreso | ajustes); en móvil, barra de pestañas inferior y paneles en hoja inferior. */
:root {
  --bg: #eef0ec; --surface: #f8f9f6; --paper: #fdfdfb; --line: #d5dad4; --line-soft: #e4e8e2;
  --fg: #1c231f; --muted: #4f5c55; --faint: #646d67;
  --accent: #86671e; --accent-soft: rgba(138,106,31,.12); --on-accent: #fffaf0;
  --ok: #3c774e; --warn: #8f6316; --bad: #b0453a; --idle: #8b978f;
  --ins: rgba(63,125,82,.14); --del: rgba(176,69,58,.13);
  --mark: rgba(196,163,90,.28); --ph: rgba(74,116,181,.13); --ph-fg: #3a5f99;
  --shadow: 0 10px 30px rgba(20,30,25,.14);
  --f-display: "Cormorant Garamond", "Cormorant", Garamond, "Times New Roman", serif;
  --f-text: "Spectral", Georgia, "Times New Roman", serif;
  --f-ui: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --ed-size: 19px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #1a1f1c; --surface: #242b27; --paper: #202622; --line: #3a4540; --line-soft: #2e3732;
  --fg: #e6ebe8; --muted: #9aaba2; --faint: #87958e;
  --accent: #c4a35a; --accent-soft: rgba(196,163,90,.14); --on-accent: #1a1f1c;
  --ok: #6fb17f; --warn: #d6a04a; --bad: #e07a6c; --idle: #6f7f77;
  --ins: rgba(111,177,127,.16); --del: rgba(224,122,108,.16);
  --mark: rgba(196,163,90,.3); --ph: rgba(110,150,214,.16); --ph-fg: #9cbcf0;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #1a1f1c; --surface: #242b27; --paper: #202622; --line: #3a4540; --line-soft: #2e3732;
  --fg: #e6ebe8; --muted: #9aaba2; --faint: #87958e;
  --accent: #c4a35a; --accent-soft: rgba(196,163,90,.14); --on-accent: #1a1f1c;
  --ok: #6fb17f; --warn: #d6a04a; --bad: #e07a6c; --idle: #6f7f77;
  --ins: rgba(111,177,127,.16); --del: rgba(224,122,108,.16);
  --mark: rgba(196,163,90,.3); --ph: rgba(110,150,214,.16); --ph-fg: #9cbcf0;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}
/* hermandades */
:root { --h-rojo: #c0533f; --h-naranja: #d0843a; --h-amarillo: #c9a83a; --h-verde: #4f8a5b; --h-azul: #4a74b5; --h-indigo: #5a5fb0; --h-violeta: #8a63b0; --h-rosa: #c46a93; --h-marron: #8a6445; --h-gris: #8b978f; }

html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--f-ui); font-size: 14px; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }

/* ---- barra superior ---- */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface); min-width: 0; }
.brand { font-family: var(--f-display); font-weight: 600; font-size: 24px; letter-spacing: .04em; color: var(--accent); line-height: 1; white-space: nowrap; }
.brand small { font-family: var(--f-ui); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-left: 6px; font-weight: 600; }
.nav { display: flex; gap: 2px; margin-left: 12px; }
.nav button { border: 0; background: none; padding: 7px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13px; }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--fg); }
.nav button:hover { color: var(--fg); }
.top .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--st, var(--idle)); flex: none; }
.pill[data-st="ok"] { --st: var(--ok); } .pill[data-st="pend"] { --st: var(--warn); } .pill[data-st="err"] { --st: var(--bad); } .pill[data-st="sync"] { --st: var(--accent); }
.pill[data-st="sync"]::before { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .25; } }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 7px 12px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { border-color: transparent; background: none; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main { min-height: 0; position: relative; }
.view { height: 100%; min-height: 0; }
.view[hidden] { display: none !important; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---- escribir ---- */
#v-escribir { display: grid; grid-template-columns: 260px minmax(0, 1fr) 290px; }
.chapters { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.chapters .head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; gap: 8px; }
.eyebrow { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; color: var(--faint); }
.chlist { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; min-height: 0; flex: 1; }
.chlist li button { width: 100%; text-align: left; border: 0; background: none; border-radius: 8px; padding: 8px 10px; display: grid; grid-template-columns: var(--numw, 34px) 1fr auto; gap: 2px 8px; align-items: baseline; }
.chlist li button:hover { background: var(--line-soft); }
.chlist li button[aria-current="true"] { background: var(--accent-soft); }
.chlist .num { font-family: var(--f-display); font-size: 19px; font-weight: 600; color: var(--accent); grid-row: span 2; line-height: 1.1; white-space: nowrap; }
.chlist .t { font-weight: 600; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chlist .m { font-size: 11.5px; color: var(--muted); grid-column: 2 / 4; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chlist .flags { display: flex; gap: 4px; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); display: inline-block; flex: none; }
.dot.escrito { background: var(--ok); } .dot.esbozo { background: var(--warn); } .dot.sin-esbozo { background: var(--idle); }
.dot.dirty { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.dot.conf { background: var(--bad); }

.editor-col { display: grid; grid-template-rows: auto auto 1fr auto; min-height: 0; min-width: 0; background: var(--paper); }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--line-soft); overflow-x: auto; scrollbar-width: none; background: var(--paper); }
.toolbar::-webkit-scrollbar { display: none; }
.tb { border: 0; background: none; min-width: 34px; height: 34px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; padding: 0 8px; flex: none; }
.tb:hover, .tb[aria-pressed="true"] { background: var(--line-soft); color: var(--fg); }
.tb.b { font-family: var(--f-text); font-weight: 800; font-size: 16px; } .tb.i { font-family: var(--f-text); font-style: italic; font-size: 16px; }
.tb.txt { font-size: 12.5px; font-weight: 600; gap: 6px; }
.tsep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; flex: none; }
.chtitle { border: 0; background: none; font-family: var(--f-display); font-size: 21px; font-weight: 600; padding: 0 8px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; flex: none; }
.chtitle .icon { color: var(--faint); }
.selchip { margin-left: auto; flex: none; }
.banners { display: flex; flex-direction: column; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 9px 16px; font-size: 13px; border-bottom: 1px solid var(--line-soft); }
.banner.bad { background: var(--del); } .banner.warn { background: var(--accent-soft); }
.banner p { margin: 0; flex: 1 1 240px; }
.findbar { display: flex; gap: 6px; align-items: center; padding: 6px 16px; border-bottom: 1px solid var(--line-soft); }
.findbar input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 6px 10px; }
.findbar .cnt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; text-align: center; }

.ed-scroll { overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
#ed { max-width: 68ch; margin: 0 auto; padding: 40px 28px 40vh; font-family: var(--f-text); font-size: var(--ed-size); line-height: 1.7; outline: none; caret-color: var(--accent); word-wrap: break-word; hyphens: manual; }
#ed p { margin: 0 0 .85em; }
#ed p:first-child { text-align: center; margin-bottom: 2em; line-height: 1.5; }
#ed p:first-child strong:first-child { font-family: var(--f-display); font-size: 1.5em; letter-spacing: .02em; font-weight: 600; }
#ed p:first-child strong:not(:first-child) { font-weight: 400; font-style: italic; color: var(--muted); font-size: .92em; }
#ed p.gap { margin: 0; height: .85em; overflow: hidden; }
#ed p.sep { text-align: center; letter-spacing: .6em; color: var(--faint); margin: 1.4em 0; }
#ed mark.ph { background: var(--ph); color: var(--ph-fg); border-radius: 3px; padding: 0 2px; font-family: var(--f-ui); font-size: .82em; }
#ed:empty::before { content: "Empieza a escribir…"; color: var(--faint); }
::highlight(kw-find) { background-color: var(--mark); }
::highlight(kw-find-cur) { background-color: var(--accent); color: var(--on-accent); }
.statusbar { display: flex; align-items: center; gap: 14px; padding: 6px 16px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.goal { display: inline-flex; align-items: center; gap: 6px; }
.goal .bar { width: 70px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.goal .bar i { display: block; height: 100%; background: var(--ok); }
.statusbar .warnh { color: var(--warn); overflow: hidden; text-overflow: ellipsis; }

.context { border-left: 1px solid var(--line); background: var(--surface); min-height: 0; overflow-y: auto; padding: 14px 14px 30px; display: flex; flex-direction: column; gap: 18px; }
.ctx-sec { display: flex; flex-direction: column; gap: 8px; }
.ctx-sec h3 { margin: 0; }
.mentions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.mentions button { width: 100%; border: 0; background: none; text-align: left; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; }
.mentions button:hover { background: var(--line-soft); }
.mentions .n { margin-left: auto; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.mentions .cat { font-size: 10.5px; color: var(--faint); }
.hdot { width: 9px; height: 9px; border-radius: 50%; background: var(--hc, transparent); border: 1px solid var(--hc, var(--line)); flex: none; }
.sugg { border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; background: var(--paper); display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.sugg .diff { font-family: var(--f-text); font-size: 14px; line-height: 1.45; }
.sugg del { background: var(--del); text-decoration: line-through; border-radius: 3px; }
.sugg ins { background: var(--ins); text-decoration: none; border-radius: 3px; }
.sugg .why { color: var(--muted); font-size: 12px; }
.sugg .acts { display: flex; gap: 6px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.empty { color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---- vistas de página ---- */
.page { max-width: 1080px; margin: 0 auto; padding-block: 22px 60px; padding-inline: 20px; display: flex; flex-direction: column; gap: 18px; }
h1.vt { font-family: var(--f-display); font-weight: 600; font-size: 34px; margin: 0; line-height: 1.1; text-wrap: balance; }
h2.st { font-family: var(--f-display); font-weight: 600; font-size: 24px; margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; font-weight: 600; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.chip[aria-pressed="true"] { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.chip .c { font-weight: 500; opacity: .7; font-variant-numeric: tabular-nums; }
input.field, select.field, textarea.field { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 8px 11px; min-width: 0; }
textarea.field { width: 100%; resize: vertical; line-height: 1.5; }
.search { flex: 1 1 220px; }

/* mapa del libro */
.bookmap { display: grid; grid-template-columns: repeat(var(--n, 33), minmax(0, 1fr)); gap: 3px; }
.bookmap button { height: 30px; border: 0; border-radius: 4px; background: var(--idle); opacity: .35; padding: 0; font-size: 9.5px; font-weight: 700; color: var(--bg); }
.bookmap button.escrito { background: var(--ok); opacity: 1; } .bookmap button.esbozo { background: var(--warn); opacity: .85; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

.esc-list { display: flex; flex-direction: column; }
.esc-date { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--faint); padding: 16px 0 6px 64px; }
.esc-card { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 4px 12px; padding: 14px 0; border-top: 1px solid var(--line-soft); scroll-margin-top: 20px; }
.esc-card .rom { font-family: var(--f-display); font-size: 30px; font-weight: 600; color: var(--accent); line-height: 1; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.esc-card .rom .dot { width: 9px; height: 9px; }
.esc-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.esc-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); font-weight: 600; align-items: center; }
.esc-frase { font-family: var(--f-text); font-style: italic; font-size: 18px; line-height: 1.35; }
.esc-res { font-family: var(--f-text); font-size: 15px; line-height: 1.55; color: var(--muted); max-width: 72ch; }
.esc-warn { font-size: 12px; color: var(--warn); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.esc-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.esc-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.esc-form label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; font-weight: 700; color: var(--muted); }
.esc-form .full { grid-column: 1 / -1; }
.state { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--muted); text-transform: lowercase; }
.state.escrito { background: var(--ins); color: var(--ok); } .state.esbozo { background: var(--accent-soft); color: var(--warn); }

/* wiki */
.wiki { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
.wlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; max-height: calc(100vh - 260px); overflow-y: auto; position: sticky; top: 0; }
.wlist button { width: 100%; text-align: left; border: 0; background: none; border-radius: 8px; padding: 8px 10px; display: grid; grid-template-columns: auto 1fr auto; gap: 1px 8px; align-items: center; }
.wlist button:hover { background: var(--line-soft); }
.wlist button[aria-current="true"] { background: var(--accent-soft); }
.wlist .t { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wlist .s { grid-column: 2 / 4; font-size: 11.5px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wlist .n { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.ficha { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.ficha-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; justify-content: space-between; }
.ficha-head h2 { font-family: var(--f-display); font-size: 36px; font-weight: 600; margin: 0; line-height: 1; }
.md { font-family: var(--f-text); font-size: 15.5px; line-height: 1.6; max-width: 72ch; min-width: 0; }
.md h1 { display: none; }
.md h2 { font-family: var(--f-ui); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin: 1.8em 0 .5em; }
.md h3 { font-family: var(--f-ui); font-size: 13.5px; margin: 1.2em 0 .3em; color: var(--accent); }
.md ul, .md ol { padding-left: 1.2em; margin: .3em 0; } .md li { margin: .15em 0; }
.md p { margin: .4em 0; }
.md code { font-size: .88em; background: var(--line-soft); padding: 1px 4px; border-radius: 4px; }
.md blockquote { margin: .5em 0; padding-left: 12px; border-left: 2px solid var(--line); color: var(--muted); }
.tbl { overflow-x: auto; } .md table { border-collapse: collapse; font-family: var(--f-ui); font-size: 13px; } .md td, .md th { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.appears { display: flex; flex-wrap: wrap; gap: 5px; }
.appears button { border: 1px solid var(--line); background: var(--paper); border-radius: 6px; padding: 3px 8px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.appears button span { color: var(--faint); font-weight: 500; margin-left: 4px; }
.hits { display: flex; flex-direction: column; gap: 2px; }
.hits button { border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 7px; font-size: 13px; line-height: 1.45; }
.hits button:hover { background: var(--line-soft); }
.hits b { color: var(--accent); font-weight: 700; font-size: 11.5px; display: block; }
.hits mark { background: var(--mark); color: inherit; border-radius: 2px; }
.ask { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 12px; }
.ask form { display: flex; gap: 8px; }
.ask .answer { font-family: var(--f-text); font-size: 15px; line-height: 1.55; }

/* progreso */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-family: var(--f-display); font-size: 32px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 3px; }
.bars .r { display: grid; grid-template-columns: 70px minmax(0, 1fr) 60px; gap: 8px; align-items: center; font-size: 12px; font-variant-numeric: tabular-nums; }
.bars .r button { border: 0; background: none; padding: 0; text-align: left; font-weight: 600; color: var(--muted); }
.bars .track { height: 10px; background: var(--line-soft); border-radius: 3px; overflow: hidden; }
.bars .track i { display: block; height: 100%; background: var(--idle); border-radius: 3px; }
.bars .track i.escrito { background: var(--ok); } .bars .track i.esbozo { background: var(--warn); }
.bars .r .v { text-align: right; color: var(--muted); }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 14px; }
.spark div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; font-size: 9.5px; color: var(--faint); }
.spark i { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; opacity: .85; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.log li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 13px; align-items: baseline; flex-wrap: wrap; }
.log time { color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; min-width: 90px; }
.log p { margin: 0; flex: 1 1 240px; }
.card { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
pre.raw { white-space: pre-wrap; word-break: break-word; font-size: 11.5px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto; margin: 0; }

/* ---- hoja / modal ---- */
.scrim { position: fixed; inset: 0; background: rgba(10,14,12,.42); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: min(720px, 100%); max-height: 86vh; border-radius: 16px 16px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
@media (min-width: 900px) { .scrim { align-items: center; } .sheet { border-radius: 16px; max-height: 82vh; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line-soft); }
.sheet-head h2 { font-family: var(--f-display); font-size: 24px; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 14px 16px 20px; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px 14px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.difflines { font-family: var(--f-text); font-size: 13.5px; line-height: 1.45; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.difflines div { padding: 2px 10px; white-space: pre-wrap; word-break: break-word; }
.difflines .a { background: var(--ins); } .difflines .d { background: var(--del); } .difflines .h { color: var(--faint); font-family: var(--f-ui); font-size: 11px; background: var(--line-soft); }
.chk { display: flex; gap: 10px; align-items: flex-start; }
.chk input { margin-top: 3px; }
.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.welcome { max-width: 520px; margin: 12vh auto 0; padding: 0 20px; display: flex; flex-direction: column; gap: 14px; text-align: left; font-family: var(--f-text); font-size: 16px; line-height: 1.6; }
.welcome h2 { font-family: var(--f-display); font-size: 40px; margin: 0; font-weight: 600; color: var(--accent); }

/* ---- barra de pestañas móvil ---- */
.tabbar { display: none; }
.only-mobile { display: none !important; }

@media (max-width: 1180px) { #v-escribir { grid-template-columns: 240px minmax(0, 1fr); } #v-escribir .context { display: none; } .only-narrow { display: inline-flex !important; } }
@media (min-width: 1181px) { .only-narrow { display: none !important; } }
@media (max-width: 860px) {
  .nav { display: none; }
  .brand small { display: none; }
  #v-escribir { grid-template-columns: minmax(0, 1fr); }
  #v-escribir .chapters { display: none; }
  .only-mobile { display: inline-flex !important; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .tabbar button { border: 0; background: none; padding: 8px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700; color: var(--faint); }
  .tabbar button[aria-current="page"] { color: var(--accent); }
  .tabbar .icon { width: 21px; height: 21px; }
  #ed { padding: 26px 18px 45vh; }
  .wiki { grid-template-columns: minmax(0, 1fr); }
  .wiki.detail .wlist-wrap { display: none; }
  .wiki:not(.detail) .ficha { display: none; }
  .wlist { max-height: none; position: static; }
  .esc-card { grid-template-columns: 40px minmax(0, 1fr); }
  .esc-card .rom { font-size: 24px; }
  .esc-date { padding-left: 52px; }
  .bookmap button { height: 24px; font-size: 0; }
  h1.vt { font-size: 28px; }
  .page { padding-inline: 16px; }
  body.kb .tabbar { display: none; }
}
#app.focus .top, #app.focus .tabbar, #app.focus .chapters, #app.focus .context { display: none !important; }
#app.focus #v-escribir { grid-template-columns: minmax(0, 1fr); }
#app.focus { grid-template-rows: minmax(0, 1fr); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---- escritorio: html base, login, proyectos, admin ---- */
html, body { margin: 0; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { padding-top: env(safe-area-inset-top, 0px); }
.projbtn { border: 0; background: none; display: inline-flex; align-items: center; gap: 6px; padding: 0; cursor: pointer; max-width: 40vw; }
.projbtn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projbtn .icon { color: var(--faint); width: 14px; height: 14px; }
.login { height: 100%; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at top, var(--surface), var(--bg) 60%); }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.login-mark { width: 64px; height: 64px; }
.login h1 { font-family: var(--f-display); font-weight: 600; font-size: 44px; margin: 0; line-height: 1; }
.login-sub { font-family: var(--f-text); font-size: 17px; line-height: 1.5; color: var(--muted); margin: 0 0 8px; }
#login-msg { color: var(--bad); min-height: 1.2em; }
.adm-table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.adm-table th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); font-weight: 700; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.adm-table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.adm-table tr[data-act] { cursor: pointer; }
.adm-table tr[data-act]:hover td { background: var(--line-soft); }
fieldset.card { margin: 0; }
fieldset.card legend { padding: 0 4px; }
@media (max-width: 860px) { .tabbar { grid-template-columns: repeat(5, 1fr); } }

/* ---- panel de acceso (/admin) ---- */
.nav a.navlink { padding: 7px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13px; text-decoration: none; }
.nav a.navlink:hover { color: var(--fg); }
body.modo-admin .nav, body.modo-admin .tabbar, body.modo-admin #pill, body.modo-admin #btn-sync, body.modo-admin #btn-project .icon { display: none !important; }
body.modo-admin #btn-project { pointer-events: none; }
body.modo-admin #app { grid-template-rows: auto 1fr 0; }
.admin-volver { display: none; }
body.modo-admin .admin-volver { display: inline-flex; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--on-accent, #fff); }
#adm-signup { min-width: 300px; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; background: var(--hc); cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch[aria-pressed="true"] { border-color: var(--fg); }
.swatch.none { background: transparent; box-shadow: inset 0 0 0 1px var(--line, #ccc); position: relative; }
.swatch.none::after { content: ''; position: absolute; left: 3px; right: 3px; top: 50%; height: 1.5px; background: var(--muted); transform: rotate(-45deg); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend button { display: inline-flex; align-items: center; gap: 6px; }
.legend .chip { font-size: 12px; padding: 3px 9px; }
.colorpick { padding: 8px 10px; border: 1px solid var(--line, rgba(0,0,0,.1)); border-radius: 10px; }
