/* Ficha del libro (diseño de la propuesta) */
  :root {
    --bg: #eef3fa;
    --surface: #ffffff;
    --ink: #1c2433;
    --ink-soft: #4b5568;
    --line: #dfe6f1;
    --radius: 18px;
    --shadow: 0 20px 50px -20px rgba(16, 38, 82, .35);

    /* Color de la estación (se sobrescribe con data-estacion) */
    --st: #8a5e3c;        /* color de marca de la estación */
    --st-ui: #8a5e3c;     /* relleno de botones e insignias */
    --st-ink: #ffffff;    /* texto sobre --st-ui */
    --st-text: #8a5e3c;   /* texto con el color de la estación sobre blanco */
  }

  /* ---------- Colores por estación (tomados del catálogo 2027) ---------- */
  [data-estacion="lilliput"] { --st: #00aeef; --st-ui: #0087c1; --st-ink: #fff; --st-text: #0077aa; }
  [data-estacion="cuentos"]  { --st: #ed1c24; --st-ui: #d9161e; --st-ink: #fff; --st-text: #c8141b; }
  [data-estacion="primera"]  { --st: #f4af34; --st-ui: #f4af34; --st-ink: #231f20; --st-text: #9a6200; }
  [data-estacion="segunda"]  { --st: #f1653c; --st-ui: #da4e25; --st-ink: #fff; --st-text: #b83c17; }
  [data-estacion="tercera"]  { --st: #b62d77; --st-ui: #b62d77; --st-ink: #fff; --st-text: #b62d77; }
  [data-estacion="cuarta"]   { --st: #2ba4a9; --st-ui: #1e8589; --st-ink: #fff; --st-text: #1b7a7e; }
  [data-estacion="quinta"]   { --st: #8a5e3c; --st-ui: #8a5e3c; --st-ink: #fff; --st-text: #8a5e3c; }
  [data-estacion="enlaces"]  { --st: #d61e78; --st-ui: #d61e78; --st-ink: #fff; --st-text: #b0145f; }
  [data-estacion="novela"]   { --st: #e1e336; --st-ui: #e1e336; --st-ink: #1a1a1a; --st-text: #c8141b; --st-tint: #e81820; }

  * { box-sizing: border-box; }
  html, body { margin: 0; }
  body {
    font-family: "Montserrat", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }

  /* ---------- Fondo inmersivo con la portada ---------- */
  .hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    overflow: clip;   /* «clip» recorta igual pero deja funcionar los elementos fijos (sticky) */
    padding: 24px 16px 120px;
    border-top: 6px solid var(--st);
  }
  .hero::before {
    content: "";
    position: absolute;
    inset: -40px;
    z-index: -3;
    background: var(--cover) center 30% / cover no-repeat;
    filter: blur(36px) saturate(1.2);
    transform: scale(1.1);
  }
  .hero::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -2;
    background: linear-gradient(180deg,
      color-mix(in srgb, var(--st-tint, var(--st-ui)) 30%, rgba(8, 18, 40, .82)) 0%,
      color-mix(in srgb, var(--st-tint, var(--st-ui)) 25%, rgba(8, 18, 40, .62)) 55%,
      var(--bg) 100%);
  }

  /* ---------- Marca de agua con la ilustración de la portadilla de cada estación ---------- */
  .wm {
    position: absolute;
    left: 0; right: 0;
    z-index: -1;
    pointer-events: none;
    background-repeat: no-repeat;
    background-size: cover;
  }
  .wm-top {
    top: 0;
    height: clamp(260px, 34vw, 560px);
    background-image: var(--wm-top);
    background-position: top center;
    mix-blend-mode: soft-light;
    opacity: .5;
    -webkit-mask-image: linear-gradient(#000 45%, transparent);
            mask-image: linear-gradient(#000 45%, transparent);
  }
  .wm-bottom {
    bottom: 0;
    height: clamp(140px, 18vw, 300px);
    background-image: var(--wm-bottom);
    background-position: bottom center;
    mix-blend-mode: multiply;
    opacity: .3;
    -webkit-mask-image: linear-gradient(transparent, #000 55%);
            mask-image: linear-gradient(transparent, #000 55%);
  }
  /* Novela gráfica: rayos y trama de puntos de cómic */
  [data-estacion="novela"] .wm-top {
    background-image:
      radial-gradient(rgba(255, 255, 255, .35) 1.3px, transparent 1.8px),
      repeating-conic-gradient(from 0deg at 85% 0%, rgba(255, 255, 255, .22) 0deg 3deg, transparent 3deg 9deg);
    background-size: 12px 12px, cover;
    background-repeat: repeat, no-repeat;
    mix-blend-mode: soft-light;
    opacity: 1;
  }

  .wrap { max-width: 1120px; margin: 0 auto; }

  .topbar { margin-bottom: 28px; }
  /* La barra con «Mis libros» y el nombre queda siempre a la vista al bajar por la ficha */
  .topbar { position: sticky; top: 12px; z-index: 30; pointer-events: none; }
  .topbar > * { pointer-events: auto; }
  .topbar .back, .topbar .user-chip { background: rgba(43, 28, 18, .62); box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
  .back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: .95rem;
    padding: 10px 16px 10px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .25);
    backdrop-filter: blur(8px);
    transition: background .2s;
  }
  .back:hover { background: rgba(255, 255, 255, .24); }
  .back svg { width: 18px; height: 18px; }

  /* ---------- Ficha ---------- */
  .book {
    display: grid;
    grid-template-columns: minmax(220px, 340px) minmax(0, 1fr);
    gap: clamp(24px, 5vw, 56px);
    align-items: start;
  }

  .cover-col { position: sticky; top: 84px; }

  /* ---------- Portada 3D animada ---------- */
  .cover-stage {
    position: relative;
    width: 100%;
    perspective: 1400px;
    padding: 6px 0 22px;
    animation: float 6s ease-in-out infinite;
  }
  /* Sombra en el "piso" que acompaña la flotación */
  .cover-stage::after {
    content: "";
    position: absolute;
    left: 12%; right: 12%; bottom: 0;
    height: 18px;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(0, 0, 0, .45), transparent);
    animation: floor 6s ease-in-out infinite;
    pointer-events: none;
  }
  .cover-enter {
    transform-style: preserve-3d;
    animation: enter 1.1s cubic-bezier(.2, .8, .2, 1) both;
  }
  .cover-3d {
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(var(--ry, 16deg)) rotateX(var(--rx, 3deg));
    transition: transform .6s cubic-bezier(.2, .8, .2, 1);
    cursor: pointer;
  }
  .cover-3d.is-tilting { transition: transform .12s linear; }

  .cover {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 3px 8px 8px 3px;
    box-shadow:
      0 30px 60px -18px rgba(0, 0, 0, .6),
      0 0 0 1px rgba(0, 0, 0, .08);
    background: rgba(255, 255, 255, .1);
  }
  /* Lomo: sombra y pliegue a la izquierda de la tapa */
  .cover-spine {
    position: absolute;
    inset: 0;
    border-radius: 3px 8px 8px 3px;
    background: linear-gradient(90deg,
      rgba(0, 0, 0, .35) 0%, rgba(255, 255, 255, .25) 1.6%,
      rgba(0, 0, 0, .18) 3.2%, transparent 7%);
    pointer-events: none;
  }
  /* Borde de las páginas (grosor del libro) */
  .cover-pages {
    position: absolute;
    top: 1.2%; bottom: 1.2%;
    left: calc(100% - 2px);
    width: 7%;
    transform-origin: left center;
    transform: rotateY(-90deg);
    background:
      linear-gradient(180deg, rgba(0, 0, 0, .12), transparent 12%, transparent 88%, rgba(0, 0, 0, .12)),
      repeating-linear-gradient(90deg, #f7f3ea 0 1.5px, #d9d2c2 1.5px 2.5px);
    border-radius: 0 3px 3px 0;
    pointer-events: none;
  }
  /* Reflejo que sigue al cursor */
  .cover-glare {
    position: absolute;
    inset: 0;
    border-radius: 3px 8px 8px 3px;
    background: radial-gradient(circle at var(--mx, 30%) var(--my, 20%),
      rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 55%);
    opacity: 0;
    transition: opacity .4s;
    pointer-events: none;
  }
  .cover-3d.is-tilting .cover-glare { opacity: 1; }
  /* Destello de luz que cruza la portada cada pocos segundos */
  .cover-shine {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 3px 8px 8px 3px;
    pointer-events: none;
  }
  .cover-shine::before {
    content: "";
    position: absolute;
    top: -20%; bottom: -20%;
    width: 35%;
    left: -60%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .55), transparent);
    transform: skewX(-18deg);
    animation: shine 7s ease-in-out 1.4s infinite;
  }

  @keyframes enter {
    from { opacity: 0; transform: translateY(30px) rotateY(-75deg) scale(.9); }
    to   { opacity: 1; transform: none; }
  }
  @keyframes float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
  }
  @keyframes floor {
    0%, 100% { transform: scale(1);   opacity: 1; }
    50%      { transform: scale(.85); opacity: .65; }
  }
  @keyframes shine {
    0%, 70% { left: -60%; }
    100%    { left: 130%; }
  }
  .read-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 20px;
    padding: 16px 20px;
    border: 0;
    border-radius: 14px;
    background: var(--st-ui);
    color: var(--st-ink);
    font: 700 1.15rem/1 "Montserrat", sans-serif;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 12px 24px -10px color-mix(in srgb, var(--st-ui) 80%, transparent);
    transition: filter .2s, transform .2s;
  }
  .read-btn:hover { filter: brightness(1.08); transform: translateY(-2px); }
  .read-btn svg { width: 22px; height: 22px; }

  .info { padding-top: 4px; }

  .brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
  }
  .brand img { width: 72px; height: auto; flex: none; }
  .brand-text { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
  .collection {
    color: #e8d199;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
  }
  .station {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px 5px 6px;
    border-radius: 999px;
    background: var(--st-ui);
    color: var(--st-ink);
    font-size: .85rem;
    font-weight: 700;
  }
  .station::before {
    content: "";
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--st-ink);
    opacity: .9;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 21s-7-6.2-7-11.5A7 7 0 0 1 19 9.5C19 14.8 12 21 12 21z'/%3E%3Ccircle cx='12' cy='9.5' r='2.5'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 21s-7-6.2-7-11.5A7 7 0 0 1 19 9.5C19 14.8 12 21 12 21z'/%3E%3Ccircle cx='12' cy='9.5' r='2.5'/%3E%3C/svg%3E") center / contain no-repeat;
  }

  h1 {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 700;
    font-size: clamp(2.1rem, 5vw, 3.6rem);
    line-height: 1.05;
    margin: 0 0 18px;
    color: #fff;
    text-wrap: balance;
  }

  .credits {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 28px;
    margin: 0 0 22px;
    color: #fff;
  }
  .credits div { display: flex; flex-direction: column; }
  .credits dt {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    opacity: .75;
  }
  .credits dd { margin: 0; font-size: 1.05rem; font-weight: 600; }

  .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
  .chip {
    font-size: .82rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    color: #fff;
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .25);
  }

  /* ---------- Botones de sección ---------- */
  .tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  .tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 14px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: var(--surface);
    color: var(--st-text);
    font: 700 .95rem "Montserrat", sans-serif;
    cursor: pointer;
    box-shadow: 0 8px 18px -10px rgba(16, 38, 82, .45);
    transition: background .2s, color .2s, transform .2s, border-color .2s;
  }
  .tab svg { width: 18px; height: 18px; flex: none; }
  .tab:hover { transform: translateY(-2px); border-color: var(--st); }
  .tab[aria-selected="true"] {
    background: var(--st-ui);
    color: var(--st-ink);
    border-color: var(--st-ui);
  }
  .tab:focus-visible, .read-btn:focus-visible, .back:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
  }

  .panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-top: 4px solid var(--st);
  }
  .tabpanel { padding: clamp(20px, 4vw, 32px); }
  .panel.panel-ancho { margin-top: clamp(20px, 3vw, 32px); scroll-margin-top: 16px; }
  .tabpanel[hidden] { display: none; }
  .tab[hidden] { display: none; }
  .tabs:has(.tab[hidden]) { grid-template-columns: repeat(2, 1fr); }

  .tabpanel h2 {
    margin: 0 0 12px;
    font-size: .8rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--st-text);
  }
  .synopsis p {
    margin: 0 0 .8em;
    font-size: 1.05rem;
    max-width: 62ch;
  }
  .synopsis p:last-child { margin-bottom: 0; }
  .synopsis p:first-child::first-letter {
    float: left;
    font-family: "Fraunces", Georgia, serif;
    font-size: 3.4em;
    line-height: .85;
    padding: 6px 10px 0 0;
    color: var(--st-text);
  }

  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    padding: 24px 0;
    color: var(--ink-soft);
  }
  .empty svg { width: 40px; height: 40px; color: var(--st-text); }

  /* ---------- Lector incrustado (libro y cartilla) ---------- */
  .frame-wrap {
    position: relative;
    background: #f3f5f9;
    overflow: hidden;
  }
  .frame-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    opacity: 0;
    transition: opacity .4s;
  }
  .frame-wrap.is-loaded iframe { opacity: 1; }
  .frame-wrap.is-loaded .frame-loading { display: none; }
  .frame-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: .9rem;
  }
  .spinner {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 4px solid color-mix(in srgb, var(--st-ui) 25%, transparent);
    border-top-color: var(--st-ui);
    animation: spin .9s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  .ghost-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--st-text);
    font: 600 .82rem "Montserrat", sans-serif;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .2s, background .2s;
  }
  .ghost-btn:hover { border-color: var(--st); }
  .ghost-btn svg { width: 16px; height: 16px; flex: none; }

  /* Lector a pantalla completa */
  .reader {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: #0b0f17;
    color: #fff;
  }
  .reader[open] { display: flex; flex-direction: column; animation: reader-in .35s ease-out; }
  .reader::backdrop { background: rgba(5, 8, 15, .7); }
  @keyframes reader-in { from { opacity: 0; transform: translateY(16px); } }
  .reader-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-top: 5px solid var(--st);
    background: #10151f;
  }
  .reader-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .reader-title strong {
    font-family: "Fraunces", Georgia, serif;
    font-size: 1.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .reader-kind {
    flex: none;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--st-ui);
    color: var(--st-ink);
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
  }
  .reader-actions { display: flex; align-items: center; gap: 8px; flex: none; }
  .reader .ghost-btn { background: transparent; color: #fff; border-color: #2c3546; }
  .return-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 6px 18px 6px 6px;
    border: 0;
    border-radius: 999px;
    background: var(--st-ui);
    color: var(--st-ink);
    font: 700 .92rem "Montserrat", sans-serif;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--st-ui) 85%, transparent);
    transition: transform .2s, filter .2s, box-shadow .2s;
  }
  .return-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
    box-shadow: 0 12px 26px -8px color-mix(in srgb, var(--st-ui) 95%, transparent);
  }
  .return-icon {
    display: grid;
    place-items: center;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--st-ink) 18%, transparent);
    transition: transform .2s;
  }
  .return-btn:hover .return-icon { transform: translateX(-3px); }
  .return-icon svg { width: 18px; height: 18px; }
  .return-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
  .frame-reader { flex: 1; background: #0b0f17; }
  .frame-reader .frame-loading { color: #c9d1de; }

  .empty strong { color: var(--ink); }

  /* ---------- Tablet ---------- */
  @media (max-width: 860px) {
    .book { grid-template-columns: 240px minmax(0, 1fr); }
  }

  /* ---------- Móvil ---------- */
  @media (max-width: 640px) {
    .hero { padding-top: 16px; }
    .topbar { margin-bottom: 20px; }
    .book { grid-template-columns: minmax(0, 1fr); gap: 24px; }
    .cover-col {
      position: static;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .cover-stage { width: min(62vw, 240px); }
    .read-btn { max-width: 340px; }
    .info { text-align: center; padding-top: 0; }
    .brand { justify-content: center; }
    .brand img { width: 50px; }
    .credits, .chips { justify-content: center; }
    .tabs { gap: 8px; }
    .tab { flex-direction: column; gap: 4px; padding: 10px 6px; font-size: .82rem; }
    .panel { text-align: left; }
    .synopsis p { font-size: 1rem; }
    .ghost-btn span { display: none; }
    .reader .ghost-btn span { display: none; }
  }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .cover-stage, .cover-stage::after, .cover-enter, .cover-shine::before { animation: none !important; }
    .cover-3d { transform: rotateY(10deg); }
  }

/* ---------- Tabla de contenido interactiva (Enlaces) ---------- */
.toc { margin-top: 26px; }
.toc h2 { margin-bottom: 4px; }
.toc-ayuda { margin: 0 0 14px; color: var(--ink-soft, #5b6070); font-size: .9rem; }
.toc-unidad { display: grid; grid-template-columns: 64px 1fr; gap: 0; margin-bottom: 12px; border-radius: 14px; overflow: hidden;
  background: color-mix(in srgb, var(--cu) 10%, #fff); box-shadow: 0 6px 18px -12px rgba(0,0,0,.35); }
.toc-num { display: grid; place-items: center; font: 900 2.6rem/1 "Baloo 2", "Montserrat", sans-serif; color: var(--cu); }
.toc-filas { list-style: none; margin: 0; padding: 0; background: #fff; }
.toc-filas li + li { border-top: 1px solid #e6e8ee; }
.toc-fila {
  display: grid; grid-template-columns: 170px 1fr auto; grid-template-areas: "sec lec pag" "sec meta pag"; align-items: center; column-gap: 12px;
  width: 100%; padding: 9px 12px; border: 0; background: none; text-align: left; cursor: pointer; font: inherit; color: inherit;
  transition: background .15s;
}
.toc-fila:hover, .toc-fila:focus-visible { background: color-mix(in srgb, var(--cu) 12%, #fff); outline: none; }
.toc-sec { grid-area: sec; font-size: .82rem; color: #5b6070; }
.toc-ed .toc-sec { color: #e8901c; } .toc-pe .toc-sec { color: #14a3a3; } .toc-ps .toc-sec { color: #e0568d; }
.toc-lec { grid-area: lec; font-style: italic; font-size: .92rem; color: #1f2433; }
.toc-meta { grid-area: meta; font-size: .74rem; color: #8a8fa0; }
.toc-pag { grid-area: pag; padding: 4px 10px; border-radius: 999px; background: var(--cu); color: #fff; font: 800 .8rem "Montserrat", sans-serif; white-space: nowrap; }
.toc-pag i { margin-left: 4px; font-style: normal; }
@media (max-width: 640px) {
  .toc-unidad { grid-template-columns: 40px 1fr; }
  .toc-num { font-size: 1.8rem; }
  .toc-fila { grid-template-columns: 1fr auto; grid-template-areas: "sec pag" "lec pag" "meta pag"; }
}
.toc:first-child, #synopsis[hidden] + .toc { margin-top: 0; }
