/* SAFIR · Inicio del usuario con sesión (enlazado desde WEB-INF/vistas/comunes/inicio.jsp) */
  :root {
    --indigo: #252866;
    --lav: #7775D6;
    --lav-soft: #E9E7FF;
    --warm: #FFFCF7;
    --carbon: #292936;
    --gold: #F2B84B;

    --bg: var(--warm);
    --surface: #ffffff;
    --soft: var(--lav-soft);
    --text: var(--carbon);
    --title: var(--indigo);
    --muted: #5b5b72;
    --line: #E3E0F7;
    --bar: var(--indigo);
    --btn: var(--indigo);
    --btn-text: #ffffff;
    --link: var(--indigo);
    --outline: var(--lav);
    --panel: #ffffff;

    --sans: "DM Sans", "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --serif: "Literata", "Source Serif 4", Georgia, "Times New Roman", serif;

    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  :root[data-theme="dark"] {
    --bg: #12142E;
    --surface: #1D2042;
    --soft: #181B3A;
    --text: #D9D9E8;
    --title: #F1F0FF;
    --muted: #A5A6C4;
    --line: #2C3060;
    --bar: #1D2042;
    --btn: #7775D6;
    --btn-text: #12142E;
    --link: #B9B7F5;
    --outline: #7775D6;
    --panel: #1D2042;
  }
  *, *::before, *::after { box-sizing: border-box; }
  html { height: auto; background: var(--bar); scroll-padding-top: env(safe-area-inset-top, 0px); scroll-behavior: smooth; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 1.0625rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background .3s, color .3s;
  }
  h1, h2, h3 { font-family: var(--sans); color: var(--title); font-weight: 300; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
  p { margin: 0; }
  a { color: inherit; }
  :focus-visible { outline: 3px solid var(--lav); outline-offset: 3px; border-radius: 6px; }
  .wrap { width: min(1120px, 100% - 2.5rem); margin-inline: auto; }

  /* Botones */
  .btn {
    display: inline-flex; align-items: center; justify-content: center;
    font: 500 1rem/1 var(--sans);
    padding: .95rem 1.6rem; border-radius: 999px; border: 1.5px solid transparent;
    background: var(--btn); color: var(--btn-text); cursor: pointer; text-decoration: none;
    transition: transform .15s, background .2s;
  }
  .btn:hover { transform: translateY(-1px); }
  .btn.outline { background: transparent; color: var(--link); border-color: var(--outline); }
  .btn.small { padding: .65rem 1.15rem; font-size: .95rem; }
  .btn.on-bar { background: var(--lav-soft); color: var(--indigo); }

  /* Barra de navegación */
  header.bar { background: var(--bar); color: #fff; }
  header.bar .wrap { display: flex; align-items: center; gap: 2rem; min-height: 72px; width: 100%; max-width: none; padding-inline: clamp(.9rem, 2vw, 1.5rem); }
  .brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: #fff; }
  .brand svg { width: 52px; height: 38px; }
  .brand span { font: 500 1.5rem/1 var(--sans); letter-spacing: .28em; }
  nav { display: flex; gap: 1.6rem; margin-right: auto; }
  nav a { color: #E9E7FF; text-decoration: none; font-size: .98rem; }
  nav a:hover { color: #fff; text-decoration: underline; text-underline-offset: 6px; }
  .theme-toggle {
    background: transparent; color: #E9E7FF; border: 1.5px solid rgba(233,231,255,.4);
    border-radius: 999px; padding: .5rem .95rem; font: 400 .9rem var(--sans); cursor: pointer;
  }
  .theme-toggle:hover { border-color: #fff; color: #fff; }

  /* Hero: el texto siempre va al frente; el escenario queda detrás */
  .hero { position: relative; overflow: hidden; padding: clamp(3rem, 7vw, 5.5rem) 0; }
  .hero::before { /* resplandor suave en lugar de círculos planos */
    content: ""; position: absolute; width: 820px; height: 820px; border-radius: 50%;
    background: radial-gradient(circle, var(--soft) 0%, var(--soft) 34%, transparent 68%);
    top: 50%; right: -230px; transform: translateY(-50%); z-index: 0; pointer-events: none;
  }
  .hero::after { /* anillos finos que se desvanecen */
    content: ""; position: absolute; width: 540px; height: 540px; border-radius: 50%;
    left: -210px; bottom: -280px; z-index: 0; pointer-events: none;
    background: repeating-radial-gradient(circle, transparent 0 34px, var(--line) 34px 35.5px);
    -webkit-mask-image: radial-gradient(circle, #000 22%, transparent 70%);
    mask-image: radial-gradient(circle, #000 22%, transparent 70%);
  }
  .hero .wrap { position: relative; z-index: 1; min-height: 560px; display: flex; align-items: center; }
  .hero-copy { position: relative; z-index: 3; width: 100%; }
  .hero h1 { font-size: clamp(2.7rem, 6.4vw, 4.9rem); max-width: 10em; text-shadow: 0 0 22px var(--bg), 0 0 8px var(--bg); }
  .hero .lead { margin-top: 1.5rem; font-size: 1.2rem; max-width: 30em; color: var(--text); text-shadow: 0 0 14px var(--bg); }
  .hero .actions { margin-top: 2.2rem; display: flex; flex-wrap: wrap; gap: .9rem; }
  .hero .note { margin-top: 1.4rem; font-size: .95rem; color: var(--muted); }

  /* Escenario: luna (fondo) → avión → libro abierto y pila de libros */
  .stage { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: min(560px, 52%); aspect-ratio: 1; z-index: 1; pointer-events: none; }
  .stage > * { position: absolute; }
  .stage svg { display: block; }
  .rings { inset: 0; width: 100%; height: 100%; overflow: visible; }
  .rings .r { fill: none; stroke: var(--line); stroke-width: 1.5; }
  .moon { left: 40%; top: 2%; width: 52%; aspect-ratio: 1; border-radius: 50%; z-index: 1; box-shadow: 0 0 70px 14px rgba(203,201,244,.5); }
  .moon svg { width: 100%; height: 100%; }
  .plane { left: 6%; top: 12%; width: 60%; z-index: 2; }
  .plane svg { width: 100%; height: auto; overflow: visible; }
  .openbook { left: 22%; top: 57%; width: 50%; z-index: 3; }
  .openbook svg, .stack svg { width: 100%; height: auto; overflow: visible; }
  .stack { left: 76%; top: 67%; width: 23%; z-index: 3; }

  /* Secciones */
  section { padding: clamp(3.5rem, 8vw, 6rem) 0; }
  h2 { font-size: clamp(2rem, 4.2vw, 3.1rem); max-width: 16em; }
  .sec-lead { margin-top: 1.1rem; max-width: 36em; color: var(--text); }

  /* Lectura */
  .reading { background: var(--soft); }
  .reading .wrap { display: grid; grid-template-columns: .8fr 1.2fr; gap: 3.5rem; align-items: center; }
  .reader {
    background: var(--panel); border: 1px solid var(--line); border-radius: 22px; overflow: hidden;
  }
  .reader-top {
    display: flex; align-items: center; gap: .8rem; padding: .9rem 1.3rem;
    border-bottom: 1px solid var(--line); font-size: .95rem; color: var(--muted);
  }
  .reader-top strong { color: var(--title); font-weight: 500; margin-right: auto; font-family: var(--serif); }
  .ctl { display: inline-flex; border: 1.5px solid var(--outline); border-radius: 999px; overflow: hidden; }
  .ctl button {
    background: transparent; color: var(--link); border: 0; font: 500 .95rem var(--sans);
    padding: .4rem .85rem; cursor: pointer;
  }
  .ctl button:hover { background: var(--soft); }
  .ctl button + button { border-left: 1.5px solid var(--outline); }
  .reader-body { padding: clamp(1.4rem, 4vw, 2.6rem); }
  .story { font-family: var(--serif); font-size: 1.2rem; line-height: 1.8; max-width: 34em; color: var(--text); transition: font-size .2s; }
  .story p + p { margin-top: 1.1em; }
  .story .first::first-letter { font-size: 3.1em; float: left; line-height: .85; padding: .08em .12em 0 0; color: var(--title); font-weight: 500; }

  /* Escribir */
  .write .wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 3.5rem; align-items: start; }
  .steps { list-style: none; padding: 0; margin: 2.2rem 0 0; display: grid; gap: 1.5rem; counter-reset: s; }
  .steps li { display: grid; grid-template-columns: 2.6rem 1fr; gap: 1rem; counter-increment: s; }
  .steps li::before {
    content: counter(s); width: 2.6rem; height: 2.6rem; border-radius: 50%;
    display: grid; place-items: center; background: var(--soft); color: var(--title);
    font-weight: 500; border: 1px solid var(--line);
  }
  .steps h3 { font-size: 1.2rem; font-weight: 500; letter-spacing: 0; }
  .steps p { margin-top: .2rem; color: var(--muted); }
  .demo { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 1.6rem; }
  .file {
    display: flex; align-items: center; gap: 1rem; padding: 1rem 1.1rem;
    border: 1.5px dashed var(--outline); border-radius: 14px; background: var(--bg);
  }
  .file .icon { width: 42px; height: 52px; border-radius: 6px; background: var(--lav); color: #fff; display: grid; place-items: center; font-size: .72rem; font-weight: 600; letter-spacing: .06em; flex: none; }
  .file b { display: block; font-weight: 500; color: var(--title); }
  .file small { color: var(--muted); }
  .demo .btn { margin-top: 1rem; }
  .chapters { list-style: none; padding: 0; margin: 1.3rem 0 0; display: grid; gap: .6rem; }
  .chapters li {
    display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center;
    padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
    animation: pop .35s ease both;
  }
  @keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
  .chapters input { width: 1.15rem; height: 1.15rem; accent-color: var(--lav); }
  .chapters label { cursor: pointer; font-family: var(--serif); color: var(--title); }
  .chapters span { font-size: .88rem; color: var(--muted); }
  .status { margin-top: 1rem; min-height: 1.6em; font-weight: 500; color: var(--title); }

  /* Lectores + coins */
  .reader-hub { background: var(--bg); }
  .hub { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 2.6rem; }
  .coins { background: var(--indigo); color: #fff; border-radius: 22px; padding: 2rem; display: flex; flex-direction: column; }
  :root[data-theme="dark"] .coins { background: #1D2042; border: 1px solid var(--line); }
  .coins h3 { color: #fff; font-size: 1.4rem; font-weight: 400; }
  .coins p { color: #D9D9E8; margin-top: .4rem; }
  .coin-row { display: flex; align-items: center; gap: 1rem; margin: 2rem 0 1.4rem; }
  .coin {
    width: 66px; height: 66px; border-radius: 50%; background: var(--gold); color: #B8832A;
    display: grid; place-items: center; font: 500 1.7rem var(--sans); box-shadow: inset 0 0 0 5px rgba(184,131,42,.25); flex: none;
  }
  .coin-num { font: 300 3.4rem/1 var(--sans); color: var(--gold); }
  .btn.gold { background: var(--gold); color: #3a2a06; align-self: flex-start; margin-top: auto; }
  .continue { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 2rem; }
  .continue h3 { font-size: 1.4rem; font-weight: 400; }
  .continue .row { display: grid; grid-template-columns: 112px 1fr; gap: 1.4rem; margin-top: 1.6rem; align-items: center; }
  .cover { aspect-ratio: 3/4; border-radius: 12px; background: var(--lav); display: grid; place-items: center; }
  .cover svg { width: 76%; }
  .book-title { font-family: var(--serif); font-size: 1.2rem; color: var(--title); font-weight: 500; }
  .book-sub { color: var(--muted); font-size: .95rem; margin-top: .15rem; }
  .progress { height: 8px; border-radius: 99px; background: var(--soft); margin: 1rem 0 1.2rem; overflow: hidden; }
  .progress i { display: block; height: 100%; width: 58%; background: var(--lav); border-radius: 99px; }
  .small-note { margin-top: 1.4rem; font-size: .88rem; color: var(--muted); }

  /* CTA final */
  .final { background: var(--bar); color: #fff; text-align: center; border-top: 6px solid var(--gold); }
  .final h2 { color: #fff; margin-inline: auto; max-width: 14em; }
  .final p { margin: 1.2rem auto 0; max-width: 32em; color: #D9D9E8; }
  .final .actions { margin-top: 2rem; display: flex; justify-content: center; flex-wrap: wrap; gap: .9rem; }
  .final .btn.outline { color: #fff; border-color: rgba(255,255,255,.55); }

  footer { background: var(--bar); color: #C9C8EC; padding: 2rem 0 2.4rem; font-size: .92rem; border-top: 1px solid rgba(255,255,255,.1); }
  footer .wrap { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; }
  footer .brand span { font-size: 1.15rem; }
  footer .brand svg { width: 40px; height: 30px; }

  /* ===== Animaciones e ilustraciones ===== */
  .plane .plane-float { animation: launch 1.3s cubic-bezier(.2,.8,.2,1) both, drift 7s ease-in-out 1.3s infinite; }
  @keyframes launch { from { opacity: 0; transform: translate(-55%, 45%) rotate(-14deg) scale(.7); } to { opacity: 1; transform: none; } }
  @keyframes drift { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-12px) rotate(-1.5deg); } }
  .spark { position: absolute; width: 26px; height: 26px; animation: twinkle 3s ease-in-out infinite; }
  .spark.s1 { left: 3%; top: 6%; width: 30px; height: 30px; }
  .spark.s2 { left: 91%; top: 42%; width: 20px; height: 20px; animation-delay: 1s; }
  .spark.s3 { left: 12%; top: 52%; width: 22px; height: 22px; animation-delay: 2s; }
  @keyframes twinkle { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* La luna rota y un punto orbita sus anillos */
  .moon svg { animation: spin 50s linear infinite; }
  .orbit { animation: spin 60s linear infinite; transform-origin: 370px 157px; transform-box: view-box; }

  /* Libro abierto: las páginas pasan una tras otra */
  .flip { animation: flip 6s ease-in-out infinite; animation-delay: var(--d, 0s); transform-origin: 150px 0; transform-box: view-box; }
  @keyframes flip {
    0%, 8%  { transform: scaleX(1);  opacity: 1; }
    34%     { transform: scaleX(-1); opacity: 1; }
    82%     { transform: scaleX(-1); opacity: 1; }
    92%     { transform: scaleX(-1); opacity: 0; }
    93%     { transform: scaleX(1);  opacity: 0; }
    100%    { transform: scaleX(1);  opacity: 1; }
  }

  /* Pila de libros: brinca en cadena, de abajo hacia arriba */
  .hop { animation: hop 1.8s cubic-bezier(.3,.1,.4,1) infinite; animation-delay: var(--d, 0s); }
  @keyframes hop {
    0%, 55%, 100% { transform: translateY(0); }
    15% { transform: translateY(var(--h, -14px)); }
    30% { transform: translateY(0); }
    38% { transform: translateY(calc(var(--h, -14px) * .35)); }
    46% { transform: translateY(0); }
  }
  .stack .shadow { animation: shade 1.8s ease-in-out infinite; transform-origin: 80px 140px; transform-box: view-box; }
  @keyframes shade { 0%, 55%, 100% { transform: scaleX(1); opacity: .16; } 15% { transform: scaleX(.72); opacity: .08; } }

  /* Escena del pueblo */
  .scene { display: block; width: 100%; height: auto; background: #12142E; }
  .scene .win { fill: #FFFCF7; }
  .scene.play .win { animation: lightOff .9s ease forwards; animation-delay: var(--d); }
  @keyframes lightOff { to { fill: #2B2E63; } }
  .tw { animation: twinkle 3.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
  .glow { animation: glow 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
  @keyframes glow { 0%,100% { opacity: .65; transform: scale(1); } 50% { opacity: 1; transform: scale(1.25); } }
  .fly { animation: fly 11s linear 1.5s infinite; }
  @keyframes fly { from { transform: translate(-90px, 30px); opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } to { transform: translate(680px, -40px); opacity: 0; } }

  /* Catálogo con portadas */
  .catalog { padding-bottom: 2.5rem; }
  .marquee { margin-top: 2.4rem; overflow: hidden; -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
  .track { display: flex; gap: 1.6rem; width: max-content; padding: .8rem 0 1rem; animation: slide 48s linear infinite; }
  .marquee:hover .track, .marquee:focus-within .track { animation-play-state: paused; }
  @keyframes slide { to { transform: translateX(calc(-50% - .8rem)); } }
  .book { margin: 0; width: 170px; flex: none; }
  .book svg { width: 100%; height: auto; display: block; border-radius: 12px; box-shadow: 0 12px 26px -14px rgba(37,40,102,.55); transition: transform .25s; }
  .book:hover svg { transform: translateY(-8px) rotate(-1.5deg); }
  .book figcaption { margin-top: .75rem; font-family: var(--serif); color: var(--title); font-size: 1rem; line-height: 1.3; }
  .book figcaption span { display: block; font-family: var(--sans); font-size: .85rem; color: var(--muted); margin-top: .15rem; }

  /* Entradas al hacer scroll */
  .rv { opacity: 0; transform: translateY(18px); transition: opacity .7s ease, transform .7s ease; }
  .rv.in { opacity: 1; transform: none; }
  .continue .progress i { width: 0; transition: width 1.5s cubic-bezier(.2,.7,.2,1) .3s; }
  .continue.in .progress i { width: 58%; }
  .coins.in .coin { animation: coinSpin 1.4s cubic-bezier(.2,.8,.2,1); }
  @keyframes coinSpin { from { transform: rotateY(540deg) scale(.6); } to { transform: none; } }

  @media (prefers-reduced-motion: reduce) {
    .plane .plane-float, .spark, .tw, .glow, .fly, .track, .coins.in .coin, .moon svg, .orbit, .flip, .hop, .stack .shadow { animation: none !important; }
    .scene.play .win { animation: none; }
    .fly { display: none; }
    .rv { opacity: 1; transform: none; }
    .continue .progress i { width: 58%; }
    .marquee { overflow-x: auto; -webkit-mask-image: none; mask-image: none; }
    .book[data-dup] { display: none; }
  }

  /* ===== Ventanas flotantes (iniciar sesión / registrarse) ===== */
  .btn.ghost-bar { background: transparent; color: #E9E7FF; border-color: rgba(233,231,255,.5); }
  .btn.ghost-bar:hover { border-color: #fff; color: #fff; }
  .overlay[hidden], .modal[hidden] { display: none; }
  .overlay {
    position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
    padding: max(1rem, env(safe-area-inset-top, 0px)) 1rem max(1rem, env(safe-area-inset-bottom, 0px));
    background: rgba(18,20,46,.5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    animation: fadeIn .25s ease;
  }
  .modal {
    position: relative; width: min(430px, 100%); max-height: 100%; overflow-y: auto;
    padding: 2.2rem 1.9rem 1.8rem; border-radius: 26px; color: var(--text);
    background: rgba(255,252,247,.82); -webkit-backdrop-filter: blur(18px) saturate(1.2); backdrop-filter: blur(18px) saturate(1.2);
    border: 1px solid rgba(255,255,255,.65); box-shadow: 0 30px 80px -20px rgba(18,20,46,.6);
    animation: rise .3s cubic-bezier(.2,.8,.2,1);
  }
  :root[data-theme="dark"] .modal { background: rgba(29,32,66,.82); border-color: rgba(119,117,214,.4); }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
  .modal .close {
    position: absolute; top: .9rem; right: .9rem; width: 38px; height: 38px; border-radius: 50%;
    border: 0; background: rgba(119,117,214,.15); color: var(--title); font: 400 1.5rem/1 var(--sans); cursor: pointer;
  }
  .modal .close:hover { background: rgba(119,117,214,.3); }
  .m-brand { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-bottom: 1.1rem; }
  .m-brand svg { width: 48px; height: 36px; }
  .m-brand .dk { display: none; }
  :root[data-theme="dark"] .m-brand .lt { display: none; }
  :root[data-theme="dark"] .m-brand .dk { display: block; }
  .m-brand span { font: 500 1.3rem/1 var(--sans); letter-spacing: .28em; color: var(--title); }
  .modal h2 { font-size: 1.9rem; max-width: none; text-align: center; }
  .m-sub { text-align: center; color: var(--muted); margin-top: .4rem; font-size: .98rem; }
  .modal form { margin-top: 1.2rem; }
  .modal label { display: block; margin: 1rem 0 .35rem; font-size: .92rem; font-weight: 500; color: var(--title); }
  .modal input {
    width: 100%; font: inherit; font-size: 1rem; padding: .85rem 1rem; border-radius: 12px;
    border: 1.5px solid var(--line); background: rgba(255,255,255,.75); color: var(--text);
  }
  :root[data-theme="dark"] .modal input { background: rgba(18,20,46,.6); }
  .modal input::placeholder { color: #8b8ba3; }
  .modal input:focus { outline: none; border-color: var(--lav); box-shadow: 0 0 0 3px rgba(119,117,214,.28); }
  .pw { position: relative; }
  .pw input { padding-right: 5.2rem; }
  .pw-toggle { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); border: 0; background: transparent; color: var(--link); font: 500 .88rem var(--sans); cursor: pointer; padding: .4rem .6rem; border-radius: 8px; }
  .form-msg { min-height: 1.4em; margin-top: .8rem; font-size: .92rem; color: var(--muted); }
  .form-msg.err { color: #B3261E; }
  :root[data-theme="dark"] .form-msg.err { color: #FF9C94; }
  .form-msg.ok { color: var(--title); font-weight: 500; }
  .m-submit { width: 100%; margin-top: .6rem; padding: 1rem; }
  .m-switch { margin-top: 1.3rem; text-align: center; font-size: .95rem; color: var(--muted); }
  .link { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--link); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
  .s-btn {
    display: flex; align-items: center; gap: .85rem; width: 100%; margin-top: .75rem; padding: .85rem 1.2rem;
    border-radius: 999px; border: 1.5px solid var(--outline); background: rgba(255,255,255,.55); color: var(--title);
    font: 500 1rem var(--sans); cursor: pointer; text-align: left; transition: transform .15s, background .2s;
  }
  :root[data-theme="dark"] .s-btn { background: rgba(18,20,46,.45); }
  .s-btn:hover { transform: translateY(-1px); background: rgba(233,231,255,.8); }
  :root[data-theme="dark"] .s-btn:hover { background: rgba(119,117,214,.25); }
  .s-btn.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
  .s-btn.primary:hover { background: var(--btn); }
  .s-btn svg { width: 22px; height: 22px; flex: none; }
  .m-or { display: flex; align-items: center; gap: .8rem; margin: 1.1rem 0 .1rem; color: var(--muted); font-size: .88rem; }
  .m-or::before, .m-or::after { content: ""; height: 1px; flex: 1; background: var(--line); }
  .m-legal { margin-top: 1rem; font-size: .82rem; color: var(--muted); text-align: center; }
  @media (prefers-reduced-motion: reduce) { .overlay, .modal { animation: none; } }

  .user-chip { max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Responsive */
  @media (max-width: 900px) {
    .reading .wrap, .write .wrap, .hub { grid-template-columns: 1fr; }
    .hero .wrap { flex-direction: column; min-height: 0; }
    .stage { position: relative; right: auto; top: auto; transform: none; width: min(92%, 440px); margin: 1.5rem auto 0; }
    nav { display: none; }
    header.bar .wrap { justify-content: space-between; }
    .theme-toggle { margin-left: auto; }
  }
  @media (max-width: 480px) {
    .continue .row { grid-template-columns: 90px 1fr; }
    .coin-num { font-size: 2.7rem; }
    header.bar .btn.ghost-bar { display: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    .plane-float, .chapters li { animation: none; }
    html { scroll-behavior: auto; }
    * { transition: none !important; }
  }

  /* ===== Inicio (usuario con sesión) ===== */
  .btn.user { background: transparent; color: #E9E7FF; border-color: rgba(233,231,255,.5); gap: .55rem; max-width: 20ch; }
  .btn.user:hover { border-color: #fff; color: #fff; }
  .btn.user b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--lav-soft); color: var(--indigo); display: inline-grid; place-items: center; font: 600 .85rem var(--sans); flex: none; }

  .welcome { background: var(--soft); padding: clamp(2.5rem, 6vw, 4.2rem) 0; }
  .welcome h1 { font-size: clamp(2.2rem, 5.2vw, 3.8rem); max-width: 14em; }
  .welcome .lead { margin-top: .9rem; color: var(--text); max-width: 34em; }
  .search { margin-top: 1.7rem; display: flex; gap: .7rem; max-width: 680px; }
  .search input {
    flex: 1; min-width: 0; font: inherit; padding: .95rem 1.4rem; border-radius: 999px;
    border: 1.5px solid var(--outline); background: var(--surface); color: var(--text);
  }
  .search input::placeholder { color: #8b8ba3; }
  .search input:focus { outline: none; box-shadow: 0 0 0 3px rgba(119,117,214,.28); }

  .block { padding: clamp(2.6rem, 6vw, 4rem) 0 0; }
  .block:last-of-type { padding-bottom: clamp(3rem, 7vw, 5rem); }
  .block h2 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); }
  .block .sec-lead { margin-top: .6rem; }

  .resume-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.2rem; margin-top: 1.7rem; }
  .resume { display: grid; grid-template-columns: 84px 1fr; gap: 1.1rem; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 1.1rem; }
  .resume .cv svg { width: 100%; height: auto; display: block; border-radius: 8px; }
  .resume .progress { margin: .8rem 0 .5rem; }
  .resume .progress i { width: var(--p, 0%); }
  .resume .pct { font-size: .85rem; color: var(--muted); margin-bottom: .8rem; }

  .shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.7rem 1.3rem; margin-top: 1.8rem; }
  .shelf .book { width: auto; }
  .tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
  .tab { font: 500 .95rem var(--sans); padding: .6rem 1.15rem; border-radius: 999px; border: 1.5px solid var(--outline); background: transparent; color: var(--link); cursor: pointer; }
  .tab:hover { background: var(--soft); }
  .tab[aria-selected="true"] { background: var(--btn); color: var(--btn-text); border-color: transparent; }
  .tab small { opacity: .75; margin-left: .25rem; }

  .off { display: none !important; }
  .nores { display: none; margin-top: 2.5rem; color: var(--muted); }
  .nores.on { display: block; }
  .hint { margin-top: 1.6rem; font-size: .88rem; color: var(--muted); }

  /* Menú de usuario */
  header.bar { position: relative; z-index: 50; }
  .menu-wrap { position: relative; }
  .btn.user .caret { width: 12px; height: 12px; flex: none; transition: transform .2s; }
  .btn.user[aria-expanded="true"] .caret { transform: rotate(180deg); }
  .menu {
    position: absolute; right: 0; top: calc(100% + .6rem); min-width: 240px; padding: .5rem;
    background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 24px 50px -18px rgba(18,20,46,.5); animation: rise .2s cubic-bezier(.2,.8,.2,1);
  }
  .menu[hidden] { display: none; }
  .menu-head { padding: .6rem .8rem .7rem; border-bottom: 1px solid var(--line); margin-bottom: .35rem; }
  .menu-head b { display: block; color: var(--title); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-head small { color: var(--muted); }
  .menu a { display: block; padding: .65rem .8rem; border-radius: 10px; text-decoration: none; color: var(--text); font-size: .98rem; }
  .menu a:hover, .menu a:focus-visible { background: var(--soft); color: var(--title); }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

  /* Avión de papel en la bienvenida */
  .welcome { position: relative; overflow: hidden; }
  .welcome .wrap { position: relative; }
  .welcome .wrap > *:not(.welcome-plane) { position: relative; z-index: 1; }
  .welcome-plane { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: min(340px, 34%); pointer-events: none; z-index: 0; }
  .welcome-plane svg { width: 100%; height: auto; overflow: visible; display: block; }

  /* Mis obras */
  .new-work {
    aspect-ratio: 3/4; border: 1.5px dashed var(--outline); border-radius: 12px; background: transparent;
    color: var(--link); font: 500 1rem var(--sans); cursor: pointer; padding: 1rem; text-align: center;
    display: grid; place-content: center; gap: .4rem;
  }
  .new-work:hover { background: var(--soft); }
  .new-work span { font-size: 2rem; line-height: 1; font-weight: 300; }

  @media (max-width: 760px) {
    .welcome-plane { position: relative; top: auto; right: auto; transform: none; width: 200px; margin: 1.6rem 0 0 auto; }
  }

  /* ===== Accesos rápidos y navegación entre vistas ===== */
  nav a[aria-current="page"] { color: #fff; text-decoration: underline; text-underline-offset: 6px; }
  .icon-btn {
    position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
    border-radius: 50%; color: #E9E7FF; border: 1.5px solid rgba(233,231,255,.4); text-decoration: none;
  }
  .icon-btn:hover { border-color: #fff; color: #fff; }
  .icon-btn svg { width: 20px; height: 20px; }
  .header-actions { display: flex; align-items: center; gap: .6rem; }
  .icon-btn { cursor: pointer; background: transparent; font: inherit; padding: 0; }
  .icon-btn .dot {
    position: absolute; top: 5px; right: 6px; width: 10px; height: 10px; border-radius: 50%;
    background: #E5484D; border: 2px solid var(--bar);
  }
  .icon-btn .dot[hidden] { display: none; }
  .lang-wrap { position: relative; }
  .lang-wrap .menu { min-width: 160px; }
  .menu button[role="menuitemradio"] {
    display: block; width: 100%; text-align: left; padding: .65rem .8rem; border: 0; border-radius: 10px;
    background: transparent; color: var(--text); font: inherit; font-size: .98rem; cursor: pointer;
  }
  .menu button[role="menuitemradio"]:hover, .menu button[role="menuitemradio"]:focus-visible { background: var(--soft); color: var(--title); }
  .menu button[aria-checked="true"] { color: var(--title); font-weight: 600; }
  .menu button[aria-checked="true"]::after { content: " ✓"; }
  .menu a.logout { color: #C03A3F; }
  .menu .sep { height: 1px; background: var(--line); margin: .35rem .4rem; }

  .quick { padding: clamp(2rem, 5vw, 3rem) 0 0; }
  .quick h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
  .quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; margin-top: 1.4rem; }
  .qcard {
    display: grid; gap: .35rem; align-content: start; padding: 1.2rem 1.25rem; text-decoration: none;
    background: var(--panel); border: 1px solid var(--line); border-radius: 18px; color: var(--text);
    transition: transform .15s, border-color .2s, box-shadow .2s;
  }
  .qcard:hover { transform: translateY(-3px); border-color: var(--lav); box-shadow: 0 16px 30px -22px rgba(37,40,102,.6); }
  .qcard .qi { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--soft); color: var(--title); }
  .qcard .qi svg { width: 22px; height: 22px; }
  .qcard b { margin-top: .5rem; font-weight: 500; color: var(--title); font-size: 1.05rem; }
  .qcard small { color: var(--muted); font-size: .9rem; line-height: 1.4; }

  .empty { margin-top: 1.7rem; display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.4rem;
    background: var(--panel); border: 1px dashed var(--outline); border-radius: 18px; padding: 1.3rem 1.5rem; }
  .empty p { color: var(--muted); max-width: 36em; }

  /* ===== Tarjetas de obras del inicio (Continuar leyendo / Recomendados) ===== */
  .obra-grid { margin-top: 1.4rem; display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .obra-card { display: grid; gap: .3rem; align-content: start; text-decoration: none; color: var(--text); }
  .obra-cover { aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; display: grid; place-items: center;
    background: var(--soft); border: 1px solid var(--line); transition: transform .15s, border-color .2s; }
  .obra-card:hover .obra-cover { transform: translateY(-3px); border-color: var(--lav); }
  .obra-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .obra-noimg { font-size: 2rem; color: var(--lav); }
  .obra-card b { margin-top: .4rem; font-weight: 500; color: var(--title); font-size: 1rem; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .obra-card small { color: var(--muted); font-size: .85rem; }
  .obra-bar { display: block; height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: .25rem; }
  .obra-bar i { display: block; height: 100%; background: var(--lav); border-radius: 99px; }
  .block .more { margin-top: 1.4rem; }

  footer .links { display: flex; flex-wrap: wrap; gap: .4rem 1.3rem; }
  footer .links a { color: #C9C8EC; text-decoration: none; }
  footer .links a:hover { color: #fff; text-decoration: underline; text-underline-offset: 4px; }

  /* ===== Tarjeta de perfil dentro del menú de cuenta ===== */
  #userMenu { min-width: 290px; }
  .menu a.profile-card {
    position: relative; display: block; padding: 0; margin-bottom: .4rem; overflow: hidden;
    border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  }
  .menu a.profile-card:hover, .menu a.profile-card:focus-visible { background: var(--soft); }
  .pc-cover {
    display: block; height: 86px; overflow: hidden;
    background: linear-gradient(135deg, var(--indigo) 0%, var(--lav) 100%);
  }
  .pc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .pc-avatar {
    position: absolute; left: .9rem; top: 58px; width: 56px; height: 56px; border-radius: 50%;
    display: grid; place-items: center; overflow: hidden;
    background: var(--lav-soft); color: var(--indigo); font: 600 1.4rem var(--sans);
    border: 3px solid var(--surface); box-shadow: 0 4px 12px -4px rgba(18,20,46,.45);
  }
  .pc-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
  .pc-body { display: flex; align-items: center; gap: .6rem; padding: 2.2rem .9rem .85rem; }
  .pc-names { flex: 1; min-width: 0; display: block; line-height: 1.3; }
  .pc-names b { display: block; color: var(--title); font-weight: 600; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pc-names small { display: block; color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pc-edit {
    flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--soft); color: var(--link); border: 1px solid var(--line);
    transition: background .2s, color .2s;
  }
  .pc-edit svg { width: 17px; height: 17px; }
  .menu a.profile-card:hover .pc-edit, .menu a.profile-card:focus-visible .pc-edit { background: var(--btn); color: var(--btn-text); border-color: transparent; }

  /* ===== Nivel sobre la foto de perfil: etiqueta negra "LV n" montada en el borde superior del circulo ===== */
  .nv-av { position: relative; display: inline-flex; flex: none; }
  .nv-tag {
    position: absolute; top: 0; left: 50%; transform: translate(-50%, -60%); z-index: 2;
    background: #000; color: #fff; border-radius: 3px; white-space: nowrap; pointer-events: none;
    font: 700 .58rem/1 var(--sans); letter-spacing: .04em; padding: .2rem .36rem;
    box-shadow: 0 0 0 1px rgba(255,255,255,.4);
  }
  /* Tarjeta de perfil del menu: el circulo (.pc-avatar) mide 56px y empieza en left .9rem / top 58px */
  .nv-tag-card { top: 58px; left: calc(.9rem + 28px); font-size: .72rem; padding: .26rem .55rem; border-radius: 4px; }
  .nv-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

  /* ===== TAREA 3: desglose "Catálogo" en la barra ===== */
  .cat-wrap { position: relative; display: flex; align-items: center; }
  /* Igual que los enlaces "Mi biblioteca" / "Crear obra": mismo color, tamaño y subrayado al pasar el cursor */
  .cat-btn {
    display: inline-flex; align-items: center; gap: .35rem; padding: 0; margin: 0; border: 0; background: transparent;
    color: #E9E7FF; font: inherit; font-size: .98rem; line-height: inherit; cursor: pointer;
  }
  .cat-btn:hover, .cat-btn[aria-expanded="true"] { color: #fff; text-decoration: underline; text-underline-offset: 6px; }
  .cat-btn .caret { width: 12px; height: 12px; flex: none; transition: transform .2s; }
  .cat-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }
  .cat-wrap .menu { left: 0; right: auto; min-width: 230px; max-height: 70vh; overflow-y: auto; }
  nav .menu a { display: flex; justify-content: space-between; gap: 1rem; }
  nav .menu a:hover, nav .menu a:focus-visible { text-decoration: none; }
  nav .menu a small { color: var(--muted); font-variant-numeric: tabular-nums; }
  nav .menu a.cat-todo { color: var(--title); font-weight: 600; }

  /* ===== TAREA 5: contador y desglose de mensajes / notificaciones ===== */
  .aviso-wrap { position: relative; display: flex; }
  .icon-btn .badge {
    position: absolute; top: -5px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px;
    display: inline-grid; place-items: center; border-radius: 999px; box-sizing: border-box;
    background: #E5484D; color: #fff; border: 2px solid var(--bar);
    font: 700 .68rem/1 var(--sans); font-variant-numeric: tabular-nums; letter-spacing: 0;
    animation: badge-pop .25s cubic-bezier(.2,.8,.2,1);
  }
  .icon-btn .badge[hidden] { display: none; }
  @keyframes badge-pop { from { transform: scale(.4); } to { transform: scale(1); } }

  .aviso-pop {
    position: absolute; right: -8px; top: calc(100% + .6rem); z-index: 60; width: min(340px, 88vw);
    background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 24px 50px -18px rgba(18,20,46,.5); animation: rise .2s cubic-bezier(.2,.8,.2,1);
    overflow: hidden;
  }
  .aviso-pop[hidden] { display: none; }
  /* Puente invisible para que el cursor pase del icono al panel sin cerrarlo */
  .aviso-pop::before { content: ""; position: absolute; left: 0; right: 0; top: -.7rem; height: .7rem; }
  .aviso-cab {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    padding: .85rem 1rem .7rem; border-bottom: 1px solid var(--line);
  }
  .aviso-cab b { color: var(--title); font-size: 1rem; }
  .aviso-cab span { color: var(--muted); font-size: .8rem; text-align: right; }
  .aviso-lista { list-style: none; margin: 0; padding: .35rem; max-height: 330px; overflow-y: auto; }
  .aviso-item {
    display: grid; gap: .15rem; padding: .6rem .7rem; border-radius: 10px;
    color: var(--text); text-decoration: none;
  }
  .aviso-item:hover, .aviso-item:focus-visible { background: var(--soft); outline: none; }
  .aviso-item.nueva { background: color-mix(in srgb, var(--soft) 55%, transparent); }
  .aviso-tipo {
    display: flex; align-items: center; gap: .4rem;
    font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  }
  .aviso-item.nueva .aviso-tipo { color: var(--title); font-weight: 600; }
  .aviso-punto { width: 7px; height: 7px; border-radius: 50%; background: #E5484D; flex: none; }
  .aviso-msg {
    font-size: .92rem; line-height: 1.4; color: var(--text);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .aviso-fecha { font-size: .76rem; color: var(--muted); }
  .aviso-vacio { padding: 1rem; text-align: center; color: var(--muted); font-size: .9rem; }
  .aviso-todas {
    display: block; padding: .75rem 1rem; text-align: center; border-top: 1px solid var(--line);
    color: var(--title); font-weight: 600; font-size: .9rem; text-decoration: none;
  }
  .aviso-todas:hover, .aviso-todas:focus-visible { background: var(--soft); outline: none; }
  @media (hover: none) { .aviso-pop { display: none !important; } }   /* en celular el toque va directo a la página */
  @media (prefers-reduced-motion: reduce) { .icon-btn .badge, .aviso-pop { animation: none; } }

  /* ===== TAREA 6: buscador centrado en el encabezado (todas las vistas menos el inicio) ===== */
  header.bar .wrap.con-buscador { gap: 1.4rem; }
  header.bar .wrap.con-buscador nav { margin-right: 0; }
  .hdr-search {
    position: relative; flex: 1 1 260px; max-width: 440px; margin-inline: auto; display: flex; align-items: center;
  }
  .hdr-search svg {
    position: absolute; left: .95rem; width: 18px; height: 18px; color: #C9C8EC; pointer-events: none;
  }
  .hdr-search input {
    width: 100%; min-width: 0; font: inherit; font-size: .95rem; padding: .62rem 1rem .62rem 2.6rem;
    border-radius: 999px; border: 1.5px solid rgba(233,231,255,.35); background: rgba(255,255,255,.1); color: #fff;
    transition: background .2s, border-color .2s, box-shadow .2s;
  }
  .hdr-search input::placeholder { color: #C9C8EC; opacity: 1; }
  .hdr-search input:hover { border-color: rgba(233,231,255,.6); }
  .hdr-search input:focus {
    outline: none; background: var(--surface); color: var(--text); border-color: var(--lav);
    box-shadow: 0 0 0 3px rgba(119,117,214,.35);
  }
  .hdr-search input:focus::placeholder { color: #8b8ba3; }
  .hdr-search:focus-within svg { color: var(--lav); }
  .hdr-search input::-webkit-search-cancel-button { cursor: pointer; }

  /* Con poco espacio, el buscador baja a su propia fila debajo de la barra */
  @media (max-width: 1100px) {
    header.bar .wrap.con-buscador { flex-wrap: wrap; row-gap: .2rem; }
    header.bar .wrap.con-buscador nav { margin-right: auto; }   /* la 1.ª fila vuelve a repartirse como antes */
    .hdr-search { order: 10; flex: 1 1 100%; max-width: none; margin: 0 0 .8rem; }
  }

  /* ===== TAREA 7: desglose de sugerencias (obras y autores) bajo el buscador ===== */
  .sug-panel {
    position: absolute; left: 0; right: 0; top: calc(100% + .5rem); z-index: 70;
    max-height: min(70vh, 460px); overflow-y: auto; padding: .4rem;
    background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 24px 50px -18px rgba(18,20,46,.5); animation: rise .18s cubic-bezier(.2,.8,.2,1);
  }
  .sug-panel[hidden] { display: none; }
  .sug-tit {
    padding: .55rem .7rem .3rem; font-size: .72rem; font-weight: 600; letter-spacing: .07em;
    text-transform: uppercase; color: var(--muted);
  }
  .sug-op {
    display: flex; align-items: center; gap: .75rem; padding: .5rem .6rem; border-radius: 10px;
    color: var(--text); text-decoration: none; cursor: pointer;
  }
  .sug-op.activa, .sug-op:focus-visible { background: var(--soft); outline: none; }
  .sug-img {
    flex: none; width: 34px; height: 46px; border-radius: 6px; overflow: hidden; display: grid; place-items: center;
    background: linear-gradient(160deg, var(--indigo), var(--lav)); color: #fff; font-weight: 600; font-size: .95rem;
  }
  .sug-img.redonda { width: 38px; height: 38px; border-radius: 50%; background: var(--lav-soft); color: var(--indigo); }
  .sug-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .sug-txt { min-width: 0; display: grid; line-height: 1.3; }
  .sug-txt b { font-weight: 500; color: var(--title); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sug-txt small { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sug-txt mark { background: rgba(119,117,214,.25); color: inherit; border-radius: 3px; padding: 0 1px; }
  .sug-op.todo { margin-top: .3rem; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; padding-top: .7rem; }
  .sug-op.todo b { font-weight: 600; color: var(--link); }
  .sug-lupa { flex: none; width: 34px; text-align: center; font-size: 1.2rem; color: var(--lav); }
  .sug-vacio { padding: .9rem .7rem .4rem; color: var(--muted); font-size: .9rem; }
  @media (prefers-reduced-motion: reduce) { .sug-panel { animation: none; } }