:root {
  --ink: #15110d;
  --ink-2: #221b14;
  --paper: #eedfbf;
  --paper-dim: #c9b38a;
  --gold: #c9a14a;
  --gold-hi: #e6c46d;
  --red: #a3362a;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); font-family: var(--sans); overflow: hidden; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 4px; }
::selection { background: var(--gold); color: var(--ink); }
input { caret-color: var(--gold-hi); }
* { scrollbar-width: thin; scrollbar-color: #9a7b43 transparent; }
[hidden] { display: none !important; }

/* ---------- Botones ---------- */
.btn { border: 1px solid transparent; border-radius: 999px; padding: .55rem 1.1rem; font-size: .85rem; letter-spacing: .02em; transition: background .2s, border-color .2s, color .2s; }
.btn-gold { background: var(--gold); color: var(--ink); font-weight: 600; }
.btn-gold:hover { background: var(--gold-hi); }
.btn-ghost { background: rgba(21,17,13,.55); color: var(--paper); border-color: rgba(238,223,191,.25); backdrop-filter: blur(6px); }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold-hi); }

/* ---------- Intro ---------- */
#intro { position: fixed; inset: 0; z-index: 50; background: radial-gradient(ellipse at 50% 40%, #2a2017 0%, var(--ink) 70%); }
#intro-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.intro-title { position: absolute; top: 9vh; left: 0; right: 0; text-align: center; pointer-events: none; }
.intro-title .kicker { margin: 0 0 .6rem; font-size: .78rem; letter-spacing: .32em; text-transform: uppercase; color: var(--gold); }
.intro-title h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: clamp(2.4rem, 6vw, 4.8rem); line-height: 1; color: var(--paper); text-shadow: 0 4px 30px rgba(0,0,0,.6); }
.intro-caption { position: absolute; bottom: 16vh; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0; }
.intro-caption .cap-year { display: block; font-family: var(--serif); font-size: clamp(2rem, 4vw, 3.2rem); font-weight: 700; color: var(--gold-hi); }
.intro-caption .cap-text { display: block; font-family: var(--serif); font-style: italic; font-size: clamp(1.1rem, 2vw, 1.5rem); color: var(--paper); }
.intro-actions { position: absolute; bottom: 5vh; left: 0; right: 0; display: flex; gap: .8rem; justify-content: center; }

/* ---------- Visor ---------- */
#viewer { position: fixed; inset: 0; background: var(--ink); }

/* ---------- Barra superior ---------- */
#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 1rem; padding: .9rem 1.4rem 2.2rem; background: linear-gradient(to bottom, rgba(21,17,13,.92), rgba(21,17,13,0)); pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; }
.brand-title { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.brand-sub { font-size: .7rem; letter-spacing: .2em; text-transform: uppercase; color: var(--paper-dim); }
.hud { text-align: center; min-width: 14rem; }
.hud-year { font-family: var(--serif); font-size: 2.3rem; font-weight: 700; line-height: 1; color: var(--gold-hi); font-variant-numeric: tabular-nums; text-shadow: 0 2px 16px rgba(0,0,0,.7); }
.hud-am { font-size: .7rem; letter-spacing: .18em; text-transform: uppercase; color: var(--paper-dim); min-height: 1em; margin-top: .25rem; }
.tools { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; }
.search { position: relative; }
.search input { width: 19rem; max-width: 34vw; padding: .55rem .9rem; border-radius: 999px; border: 1px solid rgba(238,223,191,.25); background: rgba(21,17,13,.65); color: var(--paper); font-size: .85rem; outline: none; backdrop-filter: blur(6px); }
.search input:focus { border-color: var(--gold); }
.search input::placeholder { color: var(--paper-dim); opacity: 1; }
#btn-home { display: grid; place-items: center; min-height: 38px; padding: .55rem .7rem; }
#search-results { position: absolute; top: calc(100% + .4rem); right: 0; width: 100%; min-width: 19rem; margin: 0; padding: .35rem; list-style: none; background: rgba(28,22,16,.97); border: 1px solid rgba(201,161,74,.35); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
#search-results li { padding: .55rem .7rem; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: .8rem; }
#search-results li:hover, #search-results li.active { background: rgba(201,161,74,.16); }
#search-results .r-title { font-family: var(--serif); font-size: 1.05rem; }
#search-results .r-year { font-size: .75rem; color: var(--paper-dim); white-space: nowrap; align-self: center; }

/* ---------- Biblioteca de exploración ---------- */
#tours-menu { position: fixed; top: 5.5rem; right: 1.4rem; bottom: 5.5rem; z-index: 13; width: min(460px, calc(100vw - 2.8rem)); display: flex; flex-direction: column; padding: 1.6rem; background: #221b14; border-radius: 5px; box-shadow: 0 16px 60px rgba(0,0,0,.5); }
.explore-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.explore-heading h2 { margin: 0; font: 600 2rem/1.05 var(--serif); text-wrap: balance; }
.explore-heading p { margin: .6rem 0 1.3rem; color: var(--paper-dim); font-size: .75rem; line-height: 1.5; }
.icon-button { border: 0; background: transparent; color: var(--paper-dim); font-size: 1.7rem; min-width: 40px; min-height: 40px; margin: -.5rem -.5rem 0 0; }
.icon-button:hover { color: var(--gold-hi); }
.explore-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; flex-shrink: 0; }
.explore-tabs button { min-height: 42px; padding: .65rem .6rem; border: 1px solid #735e40; border-radius: 3px; background: none; color: var(--paper); text-align: left; font-size: .78rem; }
.explore-tabs button:hover { background: #30261a; border-color: var(--gold); }
.explore-tabs button[aria-pressed="true"] { color: var(--ink); background: var(--paper); border-color: var(--paper); font-weight: 600; }
#saved-count { font-variant-numeric: tabular-nums; }
.collection-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); gap: .7rem; margin: 1rem 0; flex-shrink: 0; }
.collection-controls label { display: flex; flex-direction: column; gap: .4rem; min-width: 0; color: var(--paper-dim); font-size: .7rem; }
.collection-controls input, .collection-controls select { width: 100%; min-width: 0; min-height: 42px; border: 1px solid #735e40; border-radius: 3px; padding: .6rem; background: #19140f; color: var(--paper); font: inherit; font-size: .8rem; color-scheme: dark; }
.collection-controls input::placeholder { color: var(--paper-dim); opacity: 1; }
.collection-controls select { cursor: pointer; }
.collection-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--paper-dim); font-size: .7rem; padding-bottom: .8rem; }
.collection-toolbar button { border: 0; padding: .2rem 0; background: none; color: var(--gold-hi); font-size: .7rem; text-decoration: underline; text-underline-offset: 3px; }
.collection-toolbar > div { display: flex; gap: .8rem; }
.collection-toolbar button[aria-pressed="true"] { color: var(--paper); font-weight: 600; }
#explore-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: .5rem; }
.collection-entry { display: flex; flex-direction: column; width: 100%; gap: .4rem; text-align: left; border: 0; border-top: 1px solid #4b3c2b; background: none; padding: 1.1rem .5rem; color: var(--paper); transition: background .18s; }
.collection-entry:hover, .collection-entry:focus-visible { background: #30261a; }
.entry-meta { font-size: .7rem; line-height: 1.5; color: var(--paper-dim); }
.entry-title { font: 600 1.5rem/1.1 var(--serif); text-wrap: balance; }
.entry-description { font-size: .77rem; line-height: 1.6; color: var(--paper-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-status { font-size: .7rem; color: var(--gold-hi); margin-top: .2rem; }
.entry-action { font-size: .75rem; color: var(--gold-hi); margin-top: .3rem; text-decoration: underline; text-underline-offset: 3px; }
.collection-group { margin: 1.4rem .5rem .5rem; font: 600 1.2rem/1.3 var(--serif); color: var(--gold-hi); }
.collection-group:first-child { margin-top: .5rem; }
.collection-empty { font: 500 1.25rem/1.5 var(--serif); padding: 1rem .5rem; color: var(--paper-dim); }
.editorial-note { margin: .9rem 0 0; font-size: .7rem; line-height: 1.6; color: var(--paper-dim); }
.editorial-note a { color: var(--paper); text-underline-offset: 3px; }
.editorial-note { flex-shrink: 0; }
.editorial-note summary { cursor: pointer; padding: .4rem 0; }
.editorial-note p { margin: .4rem 0 0; max-height: 7rem; overflow-y: auto; }

/* ---------- Línea de tiempo ---------- */
#timeline { position: fixed; left: 1.4rem; right: 1.4rem; bottom: 2rem; z-index: 10; }
.tl-track { position: relative; height: 34px; border-radius: 8px; overflow: hidden; background: rgba(21,17,13,.7); border: 1px solid rgba(238,223,191,.18); backdrop-filter: blur(6px); cursor: pointer; }
.tl-eras { position: absolute; inset: 0; }
.tl-era { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; font-size: .66rem; letter-spacing: .06em; color: var(--paper-dim); border-left: 1px solid rgba(238,223,191,.12); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 .3rem; transition: color .2s, background .2s; }
.tl-era:hover { color: var(--paper); background: rgba(201,161,74,.1); }
.tl-window { position: absolute; top: 2px; bottom: 2px; border: 1.5px solid var(--gold); border-radius: 5px; background: rgba(201,161,74,.14); pointer-events: none; min-width: 4px; }

/* ---------- Hotspots ---------- */
.hs { position: relative; width: 26px; height: 26px; cursor: pointer; border: 0; padding: 0; background: transparent; }
.hs::before, .hs::after { content: ""; position: absolute; inset: 0; border-radius: 50%; }
.hs::before { background: radial-gradient(circle, var(--gold-hi) 0 28%, rgba(201,161,74,.35) 30% 60%, transparent 62%); }
.hs::after { border: 1.5px solid var(--gold-hi); }
.hs.active::after { animation: pulse 2.4s ease-out infinite; }
.hs:hover::before { background: radial-gradient(circle, #fff3cf 0 32%, rgba(230,196,109,.55) 34% 64%, transparent 66%); }
.hs-label { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%) translateY(4px); white-space: nowrap; padding: .3rem .6rem; border-radius: 6px; background: rgba(21,17,13,.92); border: 1px solid rgba(201,161,74,.4); font-family: var(--serif); font-size: 1rem; color: var(--paper); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.hs:hover .hs-label, .hs:focus-visible .hs-label, .hs.active .hs-label { opacity: 1; transform: translateX(-50%) translateY(0); }
.hs.active::before { background: radial-gradient(circle, #fff3cf 0 34%, rgba(163,54,42,.6) 36% 66%, transparent 68%); }
@keyframes pulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(2.2); opacity: 0; } }
body.zoomed-out .hs { width: 16px; height: 16px; }

/* ---------- Ficha ---------- */
#ficha { position: fixed; top: 5.5rem; right: 1.4rem; bottom: 5.5rem; z-index: 12; width: min(400px, 90vw); padding: 2rem 1.8rem; overflow-y: auto; background: linear-gradient(160deg, #f3e6c8 0%, #e6d2a6 100%); color: var(--ink); border-radius: 4px; box-shadow: 0 20px 60px rgba(0,0,0,.55), inset 0 0 60px rgba(120,80,30,.18); transform: translateX(120%); visibility: hidden; }
.ficha-close { position: absolute; top: .6rem; right: .8rem; background: none; border: 0; font-size: 1.6rem; color: #6b5536; }
.ficha-year { margin: 0; font-size: .75rem; letter-spacing: .22em; text-transform: uppercase; color: var(--red); font-weight: 600; }
.ficha-title { margin: .3rem 0 .2rem; font-family: var(--serif); font-size: 2.1rem; line-height: 1.05; font-weight: 700; }
.ficha-ref { margin: 0; font-family: var(--serif); font-style: italic; font-size: 1.1rem; color: #6b5536; }
.ficha-rule { height: 2px; margin: 1.1rem 0; background: linear-gradient(to right, var(--red), transparent); }
.ficha-text { margin: 0; font-family: var(--serif); font-size: 1.22rem; line-height: 1.5; }
.context-note { font-size: .72rem; line-height: 1.5; font-style: italic; color: #6b5536; }
.ficha-back { display: block; padding: .3rem 0; margin: 0 1.5rem 1.1rem 0; color: #60401e; border: 0; background: none; font-size: .75rem; text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.ficha-passages { margin: 1.4rem 0; }
.ficha-passages h3 { font: 600 1.35rem/1.2 var(--serif); margin: 0 0 .6rem; }
.ficha-passages details { padding: .8rem 0; border-top: 1px solid #b69b6f; }
.ficha-passages summary { cursor: pointer; font-size: .8rem; line-height: 1.6; color: #60401e; }
.ficha-passages p { font: 500 1.1rem/1.5 var(--serif); margin: .65rem 0; }
.ficha-passages a, .ficha-source { color: #60401e; font-size: .75rem; line-height: 1.6; text-underline-offset: 3px; }
.ficha-source { display: inline-block; margin: .6rem 0; }
.ficha-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin: 1.2rem 0; }
.ficha-tags button { background: transparent; color: #6b4827; border: 1px solid #a88b60; padding: .45rem .65rem; border-radius: 999px; font-size: .7rem; }
.ficha-tags button:hover { background: rgba(120,80,30,.1); }
.save-point { width: 100%; border: 1px solid #7b6035; color: var(--ink); border-radius: 3px; padding: .75rem; background: transparent; font-size: .78rem; }
.save-point:hover, .save-point[aria-pressed="true"] { background: #d9bf8a; }
.ficha-related { margin-top: 1.8rem; }
.ficha-related h3 { font: 600 1.35rem/1.2 var(--serif); margin: 0 0 .65rem; }
.ficha-related button { display: block; width: 100%; border: 0; border-top: 1px solid #b69b6f; background: transparent; text-align: left; color: #60401e; font-size: .78rem; line-height: 1.5; padding: .8rem .2rem; }
.ficha-related button:hover { color: var(--red); background: rgba(120,80,30,.06); }
#ficha :focus-visible { outline-color: #7b4223; }

/* ---------- Recorrido ---------- */
#tourbar { position: fixed; left: 1.4rem; bottom: 5.2rem; z-index: 12; width: min(620px, calc(100vw - 470px)); padding: 1rem 1.2rem; background: rgba(21,17,13,.96); border: 1px solid rgba(201,161,74,.4); border-radius: 5px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.tour-info { display: flex; justify-content: space-between; font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.tour-name { padding-right: 1rem; line-height: 1.6; }
#tour-step { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.tour-progress { display: flex; gap: .4rem; margin-top: .5rem; }
.tour-progress button { position: relative; flex: 1; height: 24px; padding: 0; background: none; border: 0; }
.tour-progress button::before { content: ''; display: block; height: 3px; background: #655336; border-radius: 2px; }
.tour-progress button.passed::before { background: var(--gold); }
.tour-progress button[aria-current]::before, .tour-progress button:hover::before { background: var(--gold-hi); height: 5px; }
.tour-caption { margin: .4rem 0 .8rem; font-family: var(--serif); font-size: 1.35rem; font-style: italic; }
.tour-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* ---------- Varios ---------- */
#toast { position: fixed; left: 50%; top: 5.5rem; transform: translateX(-50%); z-index: 60; padding: .6rem 1rem; border-radius: 10px; background: var(--gold); color: var(--ink); font-size: .85rem; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
#credits { position: fixed; left: 0; right: 0; bottom: .45rem; z-index: 9; text-align: center; font-size: .66rem; color: rgba(238,223,191,.5); }
#credits a { color: inherit; }
body.editing #viewer { cursor: crosshair; }

@media (max-width: 820px) {
  #topbar { grid-template-columns: 1fr auto; gap: .8rem; padding: .8rem 1rem 2rem; }
  .brand { display: flex; min-width: 0; }
  .brand-title { font-size: 1rem; }
  .brand-sub { font-size: .69rem; letter-spacing: .03em; margin-top: .2rem; }
  .hud { min-width: 0; text-align: right; }
  .hud-year { font-size: 1.6rem; }
  .hud-am { font-size: .69rem; letter-spacing: 0; }
  .tools { grid-column: 1 / -1; }
  .search { flex: 1; min-width: 0; }
  .search input { width: 100%; max-width: none; min-height: 42px; font-size: 16px; }
  .tools .btn { min-height: 42px; }
  #search-results { min-width: 0; width: calc(100vw - 2rem); left: 0; right: auto; }
  #search-results .r-title { min-width: 0; }
  #search-results .r-year { font-size: .65rem; }
  #tours-menu { top: 8rem; bottom: 5.5rem; left: 1rem; right: 1rem; width: auto; padding: 1.3rem; }
  .explore-heading h2 { font-size: 1.7rem; }
  .explore-heading p { margin-bottom: 1rem; }
  .explore-tabs button { font-size: .75rem; padding: .6rem .5rem; }
  .collection-controls input, .collection-controls select { font-size: 16px; }
  #ficha { top: 8rem; bottom: 5.5rem; right: 1rem; width: min(400px, calc(100vw - 2rem)); padding: 1.8rem 1.4rem; }
  body.tour-active #ficha { top: auto; bottom: calc(6.3rem + var(--tour-height, 190px)); max-height: min(40dvh, calc(100dvh - 14.3rem - var(--tour-height, 190px))); }
  #tourbar { left: 1rem; right: 1rem; width: auto; bottom: 5.3rem; padding: .85rem 1rem; }
  .tour-info { font-size: .7rem; letter-spacing: .03em; }
  .tour-caption { font-size: 1.15rem; line-height: 1.25; margin: .25rem 0 .6rem; }
  .tour-actions .btn { min-height: 40px; }
  #timeline { left: 1rem; right: 1rem; }
  .tl-era { font-size: 0; }
  #credits { padding: 0 1rem; font-size: .69rem; line-height: 1.3; }
  #toast { top: 8rem; width: max-content; max-width: calc(100vw - 2rem); text-align: center; }
}

@media (min-width: 821px) and (max-width: 1150px) {
  .brand-title { font-size: 1.05rem; }
  .brand-sub { font-size: .6rem; }
  .hud { min-width: 10rem; }
  .search input { width: 12rem; }
}

@media (max-height: 650px) and (max-width: 820px) {
  #tours-menu { overflow-y: auto; }
  #explore-list { flex: none; overflow: visible; }
  body.tour-active #ficha { bottom: calc(5.7rem + var(--tour-height, 190px)); max-height: min(40dvh, calc(100dvh - 13.7rem - var(--tour-height, 190px))); }
  body.tour-active .ficha-title { font-size: 1.6rem; }
  #tourbar { bottom: 4.7rem; }
  .tour-caption { font-size: 1rem; }
  #timeline { bottom: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
