/* ===========================================================================
   Anuario COCHILCO — visor unificado
   Paleta institucional (ver PROMPT_MAESTRO del proyecto):
   azul #2E6CA4 · azul oscuro #194467 · cobre #B4611F · verde #6E8B3D
   teal #2E8B8B · crema #F2EFE7 · papel #FCFBF8 · borde tarjeta #D8D4C8
   =========================================================================== */

:root {
  --azul: #2E6CA4;
  --azul-oscuro: #194467;
  --cobre: #B4611F;
  --rojo: #C1272D;
  --rojo-oscuro: #9C1F24;
  --verde: #6E8B3D;
  --teal: #2E8B8B;
  --oro: #8C6D1F;
  --crema: #F2EFE7;
  --papel: #FCFBF8;
  --borde: #D8D4C8;
  --texto: #23303C;
  --texto-suave: #5B6672;
  --sombra: 0 18px 45px -18px rgba(20, 35, 55, 0.45);
  --radio: 10px;
  --font: "Segoe UI", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font);
  color: var(--texto);
  background: linear-gradient(180deg, #101c29 0%, #16283b 45%, #1b3049 100%);
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------------------------------------------------------------------- */
/* Pantalla de carga                                                      */
/* ---------------------------------------------------------------------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(160deg, #143253 0%, #0e2136 100%);
  color: #eef3f8;
  transition: opacity .5s ease, visibility .5s ease;
}
#loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-mark {
  font-size: 13px;
  letter-spacing: .35em;
  text-transform: uppercase;
  color: #a9c3dc;
}
.loading-spinner {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.18);
  border-top-color: var(--cobre);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-progress { font-size: 13px; color: #cfe0ef; min-height: 18px; }
.loading-error {
  max-width: 560px;
  text-align: center;
  background: rgba(180, 60, 40, .15);
  border: 1px solid rgba(220, 100, 80, .5);
  color: #ffd9cf;
  padding: 14px 18px;
  border-radius: var(--radio);
  font-size: 13px;
  line-height: 1.5;
  display: none;
}
.loading-error.show { display: block; }

/* ---------------------------------------------------------------------- */
/* Layout general                                                         */
/* ---------------------------------------------------------------------- */
#app {
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  display: grid;
  grid-template-rows: 5px auto minmax(0, 1fr) auto;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-areas:
    "ribbon ribbon"
    "topbar topbar"
    "sidebar stage"
    "sidebar toolbar";
}
#app.toc-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}
#app.toc-collapsed #sidebar {
  overflow: hidden;
  visibility: hidden;
  border: 0;
  padding: 0;
}

/* ---- Franja institucional (azul/rojo en diagonal, guiño al distintivo
   de gobierno que la diseñadora agregó al Anuario impreso) ---- */
#gov-ribbon {
  grid-area: ribbon;
  background: repeating-linear-gradient(-45deg,
    var(--azul) 0 14px,
    var(--rojo) 14px 28px);
}

/* ---- Barra superior ---- */
#topbar {
  grid-area: topbar;
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  min-height: 60px;
  padding: 8px 20px;
  background: var(--azul-oscuro);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand-mark {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--azul) 0%, var(--azul) 48%, var(--rojo) 52%, var(--rojo) 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; color: #fff;
  letter-spacing: -.5px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.brand-mark span { text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.brand-text { line-height: 1.15; min-width: 0; }
.brand-text strong {
  display: block;
  font-size: 14.5px;
  letter-spacing: .06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-text span { display: block; font-size: 11px; color: #b9cbdd; }
#topbar .actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
}
.btn {
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06);
  color: #eef3f8;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: background .15s ease, transform .1s ease;
}
a.btn { text-decoration: none; }
.btn:hover { background: rgba(255,255,255,.16); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--rojo);
  border-color: var(--rojo);
  color: #fff;
}
.btn-primary:hover { background: var(--rojo-oscuro); }
.btn-ghost { background: transparent; }
.btn .caret { font-size: 10px; opacity: .9; }

.download-menu { position: relative; }
.download-submenu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 196px;
  padding: 6px;
  background: var(--papel);
  border: 1px solid var(--borde);
  border-radius: 10px;
  box-shadow: 0 16px 36px -16px rgba(15, 28, 43, .55);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.download-submenu[hidden] { display: none; }
.download-submenu button,
.download-submenu a {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--texto);
  text-align: left;
  text-decoration: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
}
.download-submenu button:hover,
.download-submenu a:hover { background: rgba(193, 39, 45, .1); color: var(--rojo-oscuro); }
.download-submenu button:disabled { opacity: .55; cursor: default; }

/* ---- Sidebar / indice ---- */
#sidebar {
  grid-area: sidebar;
  background: var(--papel);
  border-right: 1px solid var(--borde);
  overflow-y: auto;
  padding: 16px 0 24px;
  min-width: 0;
}
.sidebar-title {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--texto-suave);
  padding: 0 18px 10px;
}
.toc-chapter { margin-bottom: 4px; }
.toc-chapter-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  background: transparent;
  border: none;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--texto);
}
.toc-chapter-head:hover { background: rgba(46,108,164,.07); }
.toc-chapter-head.active { background: rgba(46,108,164,.12); color: var(--azul-oscuro); }
.chip {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}
.toc-chapter-head .arrow { margin-left: auto; font-size: 10px; color: var(--texto-suave); transition: transform .15s ease; }
.toc-chapter.open .toc-chapter-head .arrow { transform: rotate(90deg); }
.toc-sections { display: none; padding: 2px 0 8px 0; }
.toc-chapter.open .toc-sections { display: block; }
.toc-group-label {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 18px 3px 34px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  color: var(--cobre);
  opacity: .85;
}
.toc-group-label:hover { opacity: 1; background: rgba(46,108,164,.06); }
.toc-group-label.active { color: var(--azul-oscuro); opacity: 1; }
.toc-section {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 18px 6px 34px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 12.5px;
  color: var(--texto-suave);
  line-height: 1.35;
}
.toc-section:hover { background: rgba(46,108,164,.08); color: var(--texto); }
.toc-section.active { background: rgba(46,108,164,.14); color: var(--azul-oscuro); font-weight: 700; }
.toc-section .pg { font-variant-numeric: tabular-nums; color: #93a0ab; font-size: 11px; }
.toc-section.active .pg { color: var(--azul-oscuro); }
.toc-fixed {
  padding: 6px 18px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--texto);
  display: flex;
  align-items: center;
  gap: 8px;
}
.toc-fixed:hover { background: rgba(46,108,164,.08); }
.toc-fixed.active { background: rgba(46,108,164,.14); color: var(--azul-oscuro); }
.toc-sep { height: 1px; background: var(--borde); margin: 8px 18px 10px; }

/* ---- Escenario del libro ---- */
#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  padding: 24px;
}
#book-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
#book-viewport.is-zoomed { cursor: grab; }
#book-viewport.is-panning { cursor: grabbing; }
#book-viewport.is-marquee { cursor: crosshair; }
#book-viewport.is-marquee.is-panning { cursor: crosshair; }
#book {
  /* Scroll continuo: #book apila TODAS las hojas verticalmente (no una sola
     hoja a la vez). El ancho/alto exactos de cada hoja los fija app.js
     (sizeAllSheets), a partir del ancho disponible, manteniendo siempre la
     proporcion real de la pagina (215:280); el alto total de #book es
     simplemente la suma de todas las hojas + los espacios entre ellas. */
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 26px 0 90px;
  transform-origin: top center;
}

/* recuadro de seleccion para "zoom de area" */
#marquee-box {
  position: fixed;
  border: 2px dashed var(--cobre);
  background: rgba(180, 97, 31, .16);
  pointer-events: none;
  display: none;
  z-index: 50;
  border-radius: 2px;
}
#marquee-box.active { display: block; }
.sheet {
  position: relative;
  flex-shrink: 0;
  background: var(--papel);
  border-radius: 3px;
  box-shadow: var(--sombra);
  overflow: hidden;
}
.sheet.placeholder {
  background: linear-gradient(100deg, #f4f1e8 30%, #ece7da 50%, #f4f1e8 70%);
  background-size: 200% 100%;
  animation: sheet-shimmer 1.6s ease-in-out infinite;
}
@keyframes sheet-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.sheet canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity .22s ease; }
.sheet.is-loaded canvas { opacity: 1; }
.sheet .page-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--texto-suave); font-size: 13px; text-align: center; padding: 30px;
}

.stage-nav {
  position: absolute;
  top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 28, 43, .35);
  color: #fff;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity .2s ease, background .2s ease;
  z-index: 20;
}
#stage:hover .stage-nav { opacity: 1; }
.stage-nav:hover { background: rgba(15, 28, 43, .6); }
.stage-nav:disabled { opacity: 0 !important; pointer-events: none; }
#nav-prev { left: 10px; }
#nav-next { right: 10px; }

/* hotspot clicable sobre "serie completa" */
.hotspot {
  position: absolute;
  border: 1.5px dashed transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.hotspot:hover, .hotspot:focus-visible {
  background: rgba(193, 39, 45, .12);
  border-color: var(--rojo);
  outline: none;
}
.hotspot::after {
  content: "⬇ Descargar base de datos completa (Excel)";
  position: absolute;
  left: 50%; bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: var(--rojo);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.hotspot:hover::after, .hotspot:focus-visible::after { opacity: 1; }

/* ---- Barra inferior ---- */
#toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  min-width: 0;
  min-height: 54px;
  background: var(--papel);
  border-top: 1px solid var(--borde);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--texto-suave);
}
#toolbar .goto { display: flex; align-items: center; gap: 6px; }
#toolbar input[type="number"] {
  width: 56px;
  padding: 5px 6px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
}
#toolbar .sep { width: 1px; height: 20px; background: var(--borde); }
#zoom-hint { color: #99a3ac; font-size: 11.5px; }

.zoom-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.tbtn {
  border: 1px solid var(--borde);
  background: #fff;
  color: var(--texto);
  width: 27px;
  height: 27px;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.tbtn:hover { background: rgba(46,108,164,.08); border-color: var(--azul); }
.tbtn.wide { width: auto; padding: 0 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tbtn.active { background: var(--cobre); border-color: var(--cobre); color: #fff; }
#zoom-level {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
  color: var(--texto);
}

/* ===========================================================================
   Contenido HTML de portada e indice (renderizado dentro de .sheet)
   =========================================================================== */
.cover-page {
  position: relative;
  width: 100%; height: 100%;
  background: radial-gradient(circle at 85% 12%, #234f78 0%, var(--azul-oscuro) 45%, #0e2136 100%);
  color: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6.2% 7% 5.4%;
}
.cover-page .texture {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(115deg, rgba(255,255,255,.05) 0 2px, transparent 2px 34px);
  mix-blend-mode: screen;
}
.cover-page .eyebrow {
  position: relative;
  font-size: .62em;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: #bcd0e3;
  display: flex; align-items: center; gap: 10px;
}
.cover-page .eyebrow::before { content: ""; width: 28px; height: 2px; background: var(--cobre); display: inline-block; }
.cover-title { position: relative; }
.cover-title .kicker {
  font-size: .78em; font-weight: 700; letter-spacing: .18em; color: var(--cobre); text-transform: uppercase;
  margin-bottom: .35em;
}
.cover-title h1 {
  margin: 0;
  font-size: 2.55em;
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -.01em;
}
.cover-title h2 {
  margin: .5em 0 0;
  font-size: 1.18em;
  font-weight: 500;
  color: #d9e5f0;
  max-width: 80%;
  line-height: 1.3;
}
.cover-badge {
  margin-top: 1.1em;
  display: inline-flex;
  align-items: center;
  gap: .5em;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.22);
  padding: .5em 1.1em;
  border-radius: 999px;
  font-size: .82em;
  font-weight: 700;
  letter-spacing: .04em;
  width: fit-content;
}
.cover-badge b { color: var(--cobre); font-size: 1.1em; }
.cover-art {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 46%;
  opacity: .9;
}
.cover-chips {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5em .9em;
  font-size: .62em;
}
.cover-chip { display: flex; align-items: center; gap: .55em; color: #d9e5f0; }
.cover-chip i { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.cover-footer {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: .62em;
  color: #9fb6cb;
  border-top: 1px solid rgba(255,255,255,.18);
  padding-top: .9em;
}
.cover-footer strong { color: #fff; letter-spacing: .06em; }

/* ---- Indice ---- */
.index-page {
  width: 100%; height: 100%;
  background: var(--papel);
  padding: 6% 6.5%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.index-page .idx-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--azul-oscuro);
  padding-bottom: .5em;
  margin-bottom: .9em;
}
.index-page .idx-head h1 {
  margin: 0;
  font-size: 1.5em;
  color: var(--azul-oscuro);
  letter-spacing: .01em;
}
.index-page .idx-head span {
  font-size: .68em;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.idx-columns {
  flex: 1;
  columns: 2;
  column-gap: 5%;
}
.idx-chapter { break-inside: avoid; margin-bottom: 1.1em; }
.idx-chapter-title {
  display: flex;
  align-items: center;
  gap: .5em;
  font-size: .78em;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .5em;
  color: var(--texto);
}
.idx-chapter-title i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.idx-row {
  display: flex;
  align-items: baseline;
  gap: .4em;
  font-size: .68em;
  padding: .28em 0;
  border-bottom: 1px dotted var(--borde);
  color: var(--texto);
}
.idx-row .dots { flex: 1; border-bottom: 1px dotted var(--borde); margin: 0 .3em; transform: translateY(-3px); }
.idx-row .pg { font-variant-numeric: tabular-nums; color: var(--azul-oscuro); font-weight: 700; }
.index-page .idx-foot {
  margin-top: .8em;
  padding-top: .6em;
  border-top: 1px solid var(--borde);
  font-size: .6em;
  color: var(--texto-suave);
  display: flex;
  justify-content: space-between;
}

/* ===========================================================================
   Modal Excel
   =========================================================================== */
#excel-modal {
  position: fixed; inset: 0;
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 18, 28, .58);
  backdrop-filter: blur(2px);
}
#excel-modal.open { display: flex; }
.excel-panel {
  width: min(94vw, 1180px);
  height: min(90vh, 760px);
  background: var(--papel);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.55);
}
.excel-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--azul-oscuro);
  color: #fff;
}
.excel-panel-head .title { display: flex; flex-direction: column; gap: 2px; }
.excel-panel-head .title strong { font-size: 14.5px; }
.excel-panel-head .title span { font-size: 11.5px; color: #b9cbdd; }
.excel-panel-head .actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.icon-btn:hover { background: rgba(255,255,255,.16); }

.btn-download-xlsx {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px 9px 15px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--cobre), #d97f3f);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .1px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 8px 18px -6px rgba(180, 97, 31, .6);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.btn-download-xlsx .dl-icon { font-size: 15px; line-height: 1; }
.btn-download-xlsx:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 10px 22px -6px rgba(180, 97, 31, .7); }
.btn-download-xlsx:active { transform: translateY(0); filter: brightness(.98); }

.excel-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px 0;
  background: #EDEAE0;
  overflow-x: auto;
}
.excel-tab {
  border: 1px solid var(--borde);
  border-bottom: none;
  background: #E4E0D3;
  color: var(--texto-suave);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
}
.excel-tab.active { background: var(--papel); color: var(--texto); }

.excel-body {
  flex: 1;
  overflow: auto;
  background: var(--papel);
  position: relative;
}
.excel-status {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--texto-suave); font-size: 13px; gap: 10px; flex-direction: column;
}
.excel-preview-wrap {
  padding: 22px 26px 40px;
  background: #fff;
  min-height: 100%;
}
table.excel-preview-table {
  border-collapse: collapse;
  font-size: 12.5px;
  color: var(--texto);
  background: #fff;
}
table.excel-preview-table td {
  border: 1px solid #ECE8DC;
  padding: 5px 10px;
  vertical-align: middle;
  white-space: pre-line;
  text-align: left;
}
table.excel-preview-table td.excel-chart-cell {
  padding: 8px;
  vertical-align: top;
}
.excel-chart-canvas {
  display: block;
  width: 100%;
  height: 230px;
}

.excel-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--crema);
  border-top: 1px solid var(--borde);
  font-size: 11.5px;
  color: var(--texto-suave);
}

/* ===========================================================================
   Utilidades
   =========================================================================== */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

@media (max-width: 1100px) {
  #app,
  #app.toc-collapsed {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "ribbon"
      "topbar"
      "stage"
      "toolbar";
  }
  #toc-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 18, 28, .48);
    z-index: 44;
  }
  #toc-backdrop[hidden] { display: none; }
  #app.toc-open #toc-backdrop { display: block; }
  #sidebar,
  #app.toc-collapsed #sidebar {
    visibility: visible;
    position: fixed;
    z-index: 45;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    padding: 16px 0 24px;
    border-right: 1px solid var(--borde);
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  #app.toc-open #sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 30px rgba(0, 0, 0, .28);
  }
  #topbar {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 8px 12px 10px;
  }
  .brand { width: 100%; flex: 1 1 100%; }
  .brand-text strong {
    white-space: normal;
    text-overflow: unset;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 13px;
    letter-spacing: .02em;
    line-height: 1.25;
  }
  #topbar .actions {
    width: 100%;
    flex-shrink: 1;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  #btn-fullscreen .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #stage { padding: 8px 4px; }
  #book { gap: 12px; padding: 8px 0 40px; }
  .stage-nav { opacity: .92; width: 34px; height: 34px; font-size: 20px; }
  #nav-prev { left: 2px; }
  #nav-next { right: 2px; }
  #toolbar {
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }
  #zoom-hint,
  #toolbar .sep { display: none; }
  .goto label { font-size: 12px; }
  .excel-panel {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .excel-panel-head { flex-wrap: wrap; align-items: flex-start; gap: 8px; }
  .excel-panel-head .actions { flex-wrap: wrap; }
  .excel-preview-wrap { padding: 12px; }
  .excel-panel-foot { flex-direction: column; align-items: flex-start; gap: 6px; }
  .loading-mark { letter-spacing: .12em; text-align: center; padding: 0 16px; }
  .loading-error { margin: 0 16px; }
  .hotspot::after { white-space: normal; max-width: 70vw; text-align: center; }
}

@media (max-width: 420px) {
  .tbtn.wide { padding: 0 8px; }
}
