@font-face {
  font-family: "Marston";
  src: url("./assets/fonts/Marston.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #080808;
  --panel: rgba(12, 12, 12, .82);
  --line: rgba(255, 255, 255, .16);
  --line-strong: rgba(255, 255, 255, .34);
  --text: #f1f1ed;
  --muted: rgba(241, 241, 237, .58);
  --paper-shadow: 0 30px 80px rgba(0, 0, 0, .62), 0 6px 22px rgba(0, 0, 0, .48);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 43%, rgba(255,255,255,.045), transparent 38%),
    linear-gradient(180deg, #0b0b0b 0%, #050505 100%);
  font-family: "Marston", Georgia, "Times New Roman", serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.lore-viewer {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 480px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  isolation: isolate;
}

.lore-viewer::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .23;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255,255,255,.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.012) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, #000, transparent 78%);
}

.lore-header {
  min-height: 72px;
  padding: max(18px, env(safe-area-inset-top)) clamp(18px, 3vw, 44px) 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  z-index: 20;
}

.lore-brand { min-width: 0; }
.lore-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font: 600 10px/1.1 system-ui, sans-serif;
  letter-spacing: .3em;
}
.lore-brand h1 {
  margin: 0;
  font-size: clamp(17px, 2vw, 25px);
  font-weight: 400;
  letter-spacing: .065em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button, .nav-button {
  appearance: none;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.035);
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease, opacity .18s ease;
}
.icon-button:hover, .nav-button:hover {
  border-color: var(--line-strong);
  background: rgba(255,255,255,.08);
}
.icon-button:active, .nav-button:active { transform: scale(.96); }
.icon-button:focus-visible, .nav-button:focus-visible, .page-jump input:focus-visible {
  outline: 1px solid rgba(255,255,255,.78);
  outline-offset: 3px;
}
.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
}
.icon-button svg, .nav-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.book-stage {
  position: relative;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 0 clamp(8px, 1.5vw, 20px) 4px;
  overflow: hidden;
}

.book-shell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  flex: 0 0 auto;
  filter: drop-shadow(0 26px 48px rgba(0,0,0,.48));
}
.book {
  width: 100%;
  height: 100%;
  margin: auto;
}

.page {
  position: relative;
  background: #151515;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.09);
}
.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 22px rgba(0,0,0,.08);
}

.stf__parent {
  margin: auto !important;
  width: 100% !important;
  max-width: none !important;
}
.stf__wrapper {
  box-shadow: var(--paper-shadow);
}
.stf__wrapper.--landscape::after {
  content: "";
  position: absolute;
  z-index: 20;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,.16), rgba(0,0,0,.5) 50%, rgba(0,0,0,.16));
  box-shadow: -7px 0 15px rgba(0,0,0,.16), 7px 0 15px rgba(0,0,0,.11);
}
.stf__item { background: #101010; }

.loading {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 44px));
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: 54px 1fr;
  grid-template-rows: auto auto;
  gap: 15px 18px;
  padding: 21px;
  border: 1px solid var(--line);
  background: rgba(7,7,7,.9);
  backdrop-filter: blur(12px);
  z-index: 30;
}
.loading[hidden] { display: none; }
.loading-mark {
  grid-row: 1 / 3;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  font-size: 22px;
  letter-spacing: .06em;
}
.loading-copy { min-width: 0; }
.loading-copy strong {
  display: block;
  margin-bottom: 5px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: .05em;
}
.loading-copy span {
  display: block;
  color: var(--muted);
  font: 500 11px/1.4 system-ui, sans-serif;
  letter-spacing: .03em;
}
.loading-track {
  height: 2px;
  align-self: end;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.loading-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: rgba(255,255,255,.82);
  transition: width .16s ease;
}

.fatal-error {
  width: min(520px, calc(100vw - 40px));
  padding: 22px;
  border: 1px solid rgba(255,255,255,.24);
  background: rgba(10,10,10,.92);
}
.fatal-error strong { font-size: 20px; font-weight: 400; }
.fatal-error p {
  margin: 9px 0 0;
  color: var(--muted);
  font: 13px/1.55 system-ui, sans-serif;
}

.book-controls {
  justify-self: center;
  align-self: end;
  margin: 0 12px max(18px, env(safe-area-inset-bottom));
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  z-index: 25;
}
.book-controls[hidden] { display: none; }
.nav-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-color: transparent;
}
.nav-button:disabled { opacity: .25; cursor: default; }
.page-jump {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  color: var(--muted);
  font: 600 11px/1 system-ui, sans-serif;
  letter-spacing: .08em;
}
.page-jump input {
  width: 40px;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  text-align: right;
  font: inherit;
  appearance: textfield;
}
.page-jump input::-webkit-inner-spin-button,
.page-jump input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.reading-hint {
  position: absolute;
  left: 50%;
  bottom: 79px;
  transform: translateX(-50%);
  padding: 7px 10px;
  color: rgba(255,255,255,.55);
  background: rgba(0,0,0,.48);
  font: 500 10px/1.2 system-ui, sans-serif;
  letter-spacing: .04em;
  pointer-events: none;
  animation: hintOut .6s ease 4.5s forwards;
  z-index: 18;
}
.reading-hint[hidden] { display: none; }
@keyframes hintOut { to { opacity: 0; transform: translate(-50%, 6px); } }


/* Modo integrado dentro de /lore.php. El lector conserva toda su lógica,
   pero cede la cabecera a la web principal para evitar títulos duplicados. */
html.is-embedded .lore-viewer {
  grid-template-rows: 1fr auto;
}
html.is-embedded .lore-header {
  position: absolute;
  top: 14px;
  right: 14px;
  min-height: 0;
  padding: 0;
  z-index: 40;
}
html.is-embedded .lore-brand {
  display: none;
}
html.is-embedded .book-stage {
  padding-top: 14px;
}
html.is-embedded .book-controls {
  margin-bottom: 14px;
}
html.is-embedded .reading-hint {
  bottom: 72px;
}

@media (max-width: 700px) {
  .lore-viewer { grid-template-rows: 58px 1fr auto; }
  .lore-header {
    min-height: 58px;
    padding: max(12px, env(safe-area-inset-top)) 13px 4px;
    align-items: center;
  }
  .lore-kicker { display: none; }
  .lore-brand h1 { font-size: 14px; letter-spacing: .055em; }
  .icon-button { width: 38px; height: 38px; flex-basis: 38px; }
  .book-stage { padding-left: 3px; padding-right: 3px; }
  .book-controls { margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .reading-hint { bottom: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .loading-track span, .icon-button, .nav-button { transition: none !important; }
}
