/* ============================================================================
   NOTICIAS EN ESPAÑOL — DESIGN SYSTEM
   ----------------------------------------------------------------------------
   Aesthetic   "Newsprint editorial." Warm paper, near-black ink, one restrained
               brick-red accent, hairline rules. Calm, credible, premium.
               Restraint over decoration — every value derives from a token.

   TYPE        DM Serif Display — brand wordmark only
               Spectral         — headings + long-form reading (transcript)
               IBM Plex Sans    — labels, UI, meta, numerals
               Scale       ~1.2 minor third on a 17px root:
                 --t-2xs .68 · --t-xs .76 · --t-sm .88 · --t-1 1 · --t-2 1.2
                 --t-3 1.45 · --t-4 1.8 · --t-display clamp(2.1–3rem)
               Numerals    tabular-nums on all times/dates/durations.

   SPACING     8px base, used everywhere (no magic numbers):
                 --s-1 4 · --s-2 8 · --s-3 12 · --s-4 16
                 --s-5 24 · --s-6 32 · --s-7 48 · --s-8 64

   COLOR       Semantic roles (light values; dark-mode parity at file end):
                 --surface    page (paper)        --ink        primary text
                 --well       raised/active row   --ink-soft   upcoming reading
                 --hair       1px rules           --muted      labels / meta (AA)
                 --accent     brick-red (sparse)  --faint      already-read text
                 --accent-soft read-along wash    --on-accent  text on ink/accent

   FORM        --r-1 3 · --r-2 6 · --r-pill 999 · --hair-w 1px
               --ease cubic-bezier(.2,.65,.2,1) · --measure 36rem (reading width)

   COMPONENTS  .masthead/.folio/.dateline · .label · .editions (segmented)
               .levels (level list) · .player + .play-shell (conic ring) · .seek
               .narrator · .transcript (.tx-para > .seg > .w words) · .eq
               .tip (word translation) · .sheet (language settings) · .sk · footer

   STATE       Driven by JS via classes (see app.js):
                 body.loading → skeleton + reveals hidden
                 body.ready   → staggered reveal plays (--i stagger index)
                 body.empty   → no edition (offline/first run)
                 body.offline → folio "Sin conexión" badge
                 body.playing → active level row shows .eq, hides its meta
                 #player --p (0–100)   → conic progress ring fill
                 .seek background-size → scrubber fill
                 .seg → upcoming · .seg.done → read (dim) · .seg.active → spoken
                 .levels/.editions button.active → current selection

   A11Y        ≥44px targets · AA contrast · :focus-visible · safe-area insets
               · full prefers-reduced-motion fallbacks.
   ============================================================================ */

:root {
  /* — spacing (8px base) — */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* — type families — */
  --display: "DM Serif Display", Georgia, serif;            /* brand wordmark */
  --serif:   "Spectral", Georgia, "Times New Roman", serif; /* headings + reading */
  --sans:    "IBM Plex Sans", system-ui, -apple-system, sans-serif; /* labels + UI */

  /* — type scale (root 17px · ~1.2 minor third) — */
  --t-2xs: 0.68rem; --t-xs: 0.76rem; --t-sm: 0.88rem;
  --t-1: 1rem; --t-2: 1.2rem; --t-3: 1.45rem; --t-4: 1.8rem;
  --t-display: clamp(2.1rem, 10vw, 3rem);

  /* — color tokens — */
  --surface:   #f3eee2;   /* warm newsprint */
  --well:      #eae3d1;   /* raised surface */
  --ink:       #1b1916;   /* near-black, warm */
  --ink-soft:  #3c372e;   /* upcoming reading text */
  --muted:     #6e6553;   /* labels / meta (AA on surface) */
  --faint:     #9a907b;   /* read (past) text, decoration */
  --hair:      #d4cab3;   /* hairline rule */
  --accent:    #9a2f25;   /* editorial brick-red */
  --accent-soft:#f1ddd2;  /* read-along wash */
  --on-accent: #f6f1e6;

  /* — form — */
  --r-1: 3px; --r-2: 6px; --r-pill: 999px;
  --hair-w: 1px;
  --ease: cubic-bezier(.2, .65, .2, 1);
  --measure: 36rem;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }   /* beat component display rules */

/* ---------------- loading splash ---------------- */
.splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; background: var(--surface);
  transition: opacity .35s ease, visibility .35s ease;
}
body:not(.loading) .splash { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-mark { border-radius: 16px; opacity: 0.96; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--hair); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.splash-text {
  font-family: var(--sans); font-size: var(--t-2xs); font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted);
}

/* ---------------- pull-to-refresh ---------------- */
/* circular indicator chip that follows the finger, then eases on release */
.ptr {
  position: fixed; top: 0; left: 50%; z-index: 40;
  width: 38px; height: 38px; margin-left: -19px;
  display: grid; place-items: center;
  background: var(--surface);
  border: var(--hair-w) solid var(--hair); border-radius: 50%;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.28);
  transform: translateY(-52px); opacity: 0; pointer-events: none;
  transition: transform .32s var(--ease), opacity .32s var(--ease);
}
.ptr.dragging { transition: none; }              /* 1:1 follow while pulling */
.ptr.armed { border-color: var(--accent); }
.ptr-spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--hair); border-top-color: var(--accent);
  transition: transform .1s linear;
}
.ptr.spinning .ptr-spin { animation: spin .8s linear infinite; }


html { scroll-padding-top: 96px; }   /* keep content clear of the sticky player */
html, body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;   /* avoid jarring pull-to-refresh mid-read */
}

/* faint print grain */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: 0.5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

.wrap {
  position: relative; z-index: 1;
  max-width: 680px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + var(--s-6)) var(--s-5)
           calc(env(safe-area-inset-bottom) + var(--s-7));
  min-height: 100vh;
}

/* helper tokens */
.label {
  display: block;
  font-family: var(--sans);
  font-size: var(--t-2xs); font-weight: 700;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--muted); margin-bottom: var(--s-3);
}

/* ---------------- masthead ---------------- */
.masthead { text-align: center; }
.folio {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--sans);
  font-size: var(--t-2xs); font-weight: 600;
  letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--muted);
  padding-bottom: var(--s-2);
  border-bottom: var(--hair-w) solid var(--ink);
}
.folio-l, .folio-r { display: inline-flex; align-items: center; gap: var(--s-2); }
.issue { color: var(--accent); font-weight: 700; }
.issue::before { content: "·"; margin-right: var(--s-2); color: var(--hair); }
.netstate {
  display: none;
  color: var(--on-accent); background: var(--accent);
  padding: 2px 7px; border-radius: var(--r-pill);
  font-size: 0.6rem; letter-spacing: 0.1em;
}
body.offline .netstate { display: inline-block; }

.nameplate {
  margin: var(--s-4) 0 0;
  font-size: var(--t-display);
  line-height: 0.96; letter-spacing: -0.01em;
  text-wrap: balance;
}
.nameplate .brand {
  font-family: var(--display);
  font-weight: 400;          /* DM Serif Display ships a single weight */
}
.nameplate .np-sub {
  display: block; font-weight: 400; font-style: italic;
  font-size: 0.36em; letter-spacing: 0; color: var(--ink-soft);
  margin-top: 0.4em;
}
.dateline {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: var(--s-4);
  padding: var(--s-2) 0;
  border-top: var(--hair-w) solid var(--hair);
  border-bottom: 3px double var(--hair);
  font-family: var(--sans);
  font-size: var(--t-xs); font-weight: 500;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.dl-src { color: var(--ink-soft); font-weight: 600; }

.status {
  font-family: var(--sans);
  font-size: var(--t-sm); color: var(--muted);
  text-align: center; margin: var(--s-5) 0 0;
}
.status:empty { display: none; }   /* no gap when there's no message */

.block { margin-top: var(--s-6); }

/* ---------------- edition toggle ---------------- */
.editions {
  display: inline-flex;
  border: var(--hair-w) solid var(--ink); border-radius: var(--r-1);
  overflow: hidden;
}
.editions button {
  appearance: none; border: none; background: transparent;
  font-family: var(--sans);
  font-size: var(--t-1); font-weight: 600; letter-spacing: 0.03em;
  color: var(--ink-soft);
  min-height: 44px; padding: 0 var(--s-5);
  cursor: pointer; transition: background .18s var(--ease), color .18s var(--ease);
}
.editions button + button { border-left: var(--hair-w) solid var(--ink); }
.editions button.active { background: var(--ink); color: var(--on-accent); }

/* ---------------- level list ---------------- */
.levels { border-top: var(--hair-w) solid var(--hair); }
.levels button {
  position: relative;
  display: grid; grid-template-columns: 1fr auto;
  align-items: baseline; column-gap: var(--s-4);
  width: 100%; min-height: 56px; text-align: left;
  appearance: none; border: none; background: transparent;
  border-bottom: var(--hair-w) solid var(--hair);
  border-left: 2px solid transparent;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  cursor: pointer;
  font-family: var(--serif);
  font-size: var(--t-2); font-weight: 600; color: var(--ink);
  transition: background .15s var(--ease), border-color .15s var(--ease);
}

.levels button .sub {
  display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
  font-family: var(--sans);
  letter-spacing: 0.05em; text-transform: uppercase;
  transition: opacity .2s var(--ease);
}
.levels button .sub .dur {
  font-size: var(--t-xs); font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--ink-soft);
}
.levels button .sub .spd { font-size: var(--t-2xs); font-weight: 500; color: var(--muted); }
.levels button:active { background: var(--well); }
.levels button.active { background: var(--well); border-left-color: var(--accent); }
.levels button.active .sub .dur { color: var(--ink); }

/* now-playing equalizer (replaces the meta on the active, playing row) */
.eq {
  position: absolute; right: var(--s-3); top: 50%;
  transform: translateY(-50%);
  display: none; align-items: flex-end; gap: 2px; height: 15px;
}
.eq i { width: 3px; height: 100%; background: var(--accent); transform-origin: bottom; }
.eq i:nth-child(1) { animation: eq .9s ease-in-out infinite; }
.eq i:nth-child(2) { animation: eq .9s ease-in-out infinite .25s; }
.eq i:nth-child(3) { animation: eq .9s ease-in-out infinite .5s; }
@keyframes eq { 0%,100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
body.playing .levels button.active .sub { opacity: 0; }
body.playing .levels button.active .eq { display: flex; }

/* ---------------- player ---------------- */
.player {
  display: flex; align-items: center; gap: var(--s-4);
  margin-top: var(--s-6); padding: var(--s-3) var(--s-1);
  border-top: var(--hair-w) solid var(--ink);
  border-bottom: var(--hair-w) solid var(--ink);
  /* stays put while the page scrolls, so controls are always reachable */
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
}
.play-shell {
  flex: 0 0 auto; position: relative;
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
}
.play-shell::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p, 0) * 1%), var(--hair) 0);
  transition: background .15s linear;
}
.playpause {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  border: none; background: var(--ink); color: var(--on-accent);
  font-size: var(--t-1); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 0 0 3px var(--surface);
  transition: transform .1s var(--ease), opacity .2s var(--ease);
}
.playpause:active { transform: scale(0.94); }
.player.playing .playpause { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: 1 } 50% { opacity: 0.8 } }

.bar-wrap { flex: 1; min-width: 0; }
.seek {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 3px; background: var(--hair);
  background-image: linear-gradient(var(--ink), var(--ink));
  background-repeat: no-repeat; background-size: 0% 100%;
  outline: none; cursor: pointer;
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%; background: var(--ink);
}
.seek::-moz-range-thumb { width: 14px; height: 14px; border: none; border-radius: 50%; background: var(--ink); }
.times {
  display: flex; justify-content: space-between;
  font-family: var(--sans); font-variant-numeric: tabular-nums;
  font-size: var(--t-xs); letter-spacing: 0.04em; color: var(--muted);
  margin-top: var(--s-3);
}

.narrator {
  margin: var(--s-3) 2px 0;
  font-family: var(--sans);
  font-size: var(--t-2xs); font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}

/* ---------------- transcript / read-along ---------------- */
.transcript-wrap { margin-top: var(--s-6); }
.transcript-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: var(--hair-w) solid var(--ink);
  padding-bottom: var(--s-2); margin-bottom: var(--s-4);
}
.transcript-head .label { margin: 0; }
.ghost {
  background: none; border: none;
  font-family: var(--sans);
  font-size: var(--t-2xs); font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent); cursor: pointer;
  padding: var(--s-2) var(--s-1); margin: calc(-1 * var(--s-2)) 0;
}
.transcript {
  /* flows in the normal page scroll (no nested scroll container) */
  max-width: var(--measure); margin-inline: auto;
  font-size: var(--t-2); line-height: 1.85; color: var(--ink-soft);
  hanging-punctuation: first;
}
.tx-para { margin: 0 0 1em; }
.tx-para:last-child { margin-bottom: 0; }

.seg {                       /* upcoming text — fully readable */
  cursor: pointer; color: var(--ink-soft);
  transition: color .25s var(--ease), background .25s var(--ease);
}
.seg.done { color: var(--faint); }            /* already read — dimmed */
.seg:hover { color: var(--ink); }
.seg.active {                /* being spoken — emphasized */
  color: var(--ink); font-weight: 500;
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft);
  border-radius: 2px;
}
.seg.active::before {        /* slim accent reading tick */
  content: ""; display: inline-block;
  width: 0.16em; height: 0.95em; margin-right: 0.4em;
  background: var(--accent); border-radius: 1px;
  vertical-align: -0.06em;
}

/* tappable words */
.w { cursor: pointer; border-radius: 2px; }
@media (hover: hover) {
  .w:hover {
    text-decoration: underline; text-decoration-color: var(--accent);
    text-decoration-thickness: 1px; text-underline-offset: 3px;
  }
}
.w:active { background: var(--accent-soft); }
.hint {
  margin: var(--s-3) 0 0; font-family: var(--sans);
  font-size: var(--t-2xs); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); text-align: center;
}

/* word translation tooltip */
.tip {
  position: fixed; z-index: 50; max-width: 16rem;
  background: var(--ink); color: var(--on-accent);
  border-radius: var(--r-2); padding: var(--s-2) var(--s-3);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.55);
  font-family: var(--sans); line-height: 1.3;
  display: flex; flex-direction: column; gap: 2px;
  animation: reveal .14s var(--ease) both;
}
.tip-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.tip-save { background: none; border: none; color: var(--on-accent); font-size: 1rem; line-height: 1; cursor: pointer; padding: 0; }
.tip-w { font-weight: 700; font-size: var(--t-sm); }
.tip-t { font-size: var(--t-sm); color: color-mix(in srgb, var(--on-accent) 78%, transparent); }
.tip-play {
  margin-top: var(--s-2); align-self: flex-start;
  background: none; color: var(--on-accent);
  border: var(--hair-w) solid color-mix(in srgb, var(--on-accent) 40%, transparent);
  border-radius: var(--r-pill);
  font-family: var(--sans); font-size: var(--t-2xs); letter-spacing: 0.04em;
  padding: 3px 10px; cursor: pointer;
}

/* settings gear + language sheet */
.iconbtn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; margin: -6px -6px -6px 0;
  border: none; background: none; color: var(--muted);
  cursor: pointer; border-radius: var(--r-1);
}
.iconbtn:active { color: var(--ink); }
.sheet {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 18, 14, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 680px; background: var(--surface);
  border-radius: 14px 14px 0 0;
  padding: var(--s-5) var(--s-5) calc(env(safe-area-inset-bottom) + var(--s-6));
  box-shadow: 0 -12px 40px -12px rgba(0, 0, 0, 0.4);
  animation: sheetUp .28s var(--ease) both;
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: var(--hair-w) solid var(--ink);
  padding-bottom: var(--s-2); margin-bottom: var(--s-2);
}
.sheet-head .label { margin: 0; }
.sheet-note {
  font-family: var(--sans); font-size: var(--t-2xs); letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--faint); margin: var(--s-3) 0 0;
}
.course-list { display: flex; flex-direction: column; }
.course {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; appearance: none; background: transparent;
  border: none; border-bottom: var(--hair-w) solid var(--hair);
  border-left: 2px solid transparent;
  padding: var(--s-3) var(--s-2); min-height: 44px; cursor: pointer;
}
.course-name { font-family: var(--serif); font-size: var(--t-2); font-weight: 600; color: var(--ink); }
.course-meta {
  font-family: var(--sans); font-size: var(--t-2xs);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.course.active { background: var(--well); border-left-color: var(--accent); }
.course.soon { opacity: 0.45; cursor: default; }
.course.soon .course-meta { color: var(--accent); }

/* saved words list */
.vocab-list { display: flex; flex-direction: column; max-height: 60vh; overflow-y: auto; }
.vocab-item {
  display: flex; align-items: baseline; gap: var(--s-3);
  padding: var(--s-3) var(--s-2);
  border-bottom: var(--hair-w) solid var(--hair);
}
.vocab-w { font-family: var(--serif); font-size: var(--t-2); font-weight: 600; color: var(--ink); }
.vocab-t { flex: 1; font-family: var(--sans); font-size: var(--t-sm); color: var(--muted); }
.vocab-x {
  background: none; border: none; color: var(--faint); font-size: 1.3rem; line-height: 1;
  cursor: pointer; padding: 0 var(--s-2);
}
.vocab-empty {
  font-family: var(--sans); font-size: var(--t-sm); color: var(--muted);
  text-align: center; padding: var(--s-5) var(--s-2) var(--s-2);
}

footer {
  margin-top: var(--s-7); padding-top: var(--s-4);
  border-top: var(--hair-w) solid var(--hair);
  text-align: center;
}
.colophon, .colophon-sub {
  display: block; font-family: var(--sans);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.colophon { font-size: var(--t-2xs); font-weight: 600; color: var(--muted); }
.colophon-sub { font-size: 0.6rem; font-weight: 500; color: var(--faint); margin-top: var(--s-1); }

/* ---------------- skeleton (loading) ---------------- */
.sk {
  background: linear-gradient(90deg, var(--well), #efe8d6, var(--well));
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-1);
}
.sk-row { display: block; height: 56px; border-bottom: var(--hair-w) solid var(--hair); border-radius: 0; }
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }
body.ready .sk, body.empty .sk { display: none; }
body:not(.ready) .levels { border-top: var(--hair-w) solid var(--hair); }

/* ---------------- motion: staggered reveal ---------------- */
body.loading .reveal { opacity: 0; transform: translateY(10px); }
body.ready .reveal { animation: reveal .55s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes reveal { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------- focus / accessibility ---------------- */
.editions button:focus-visible, .levels button:focus-visible,
.playpause:focus-visible, .ghost:focus-visible,
.seek:focus-visible, .seg:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  body.ready .reveal { animation: none; }
  body.loading .reveal { opacity: 1; transform: none; }
  .player.playing .playpause, .eq i, .sk, .spinner, .ptr-spin { animation: none; }
  .transcript { scroll-behavior: auto; }
}

/* ---------------- dark mode (full parity) ---------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #15140f; --well: #211e17; --ink: #f1ebd9; --ink-soft: #d2c9b2;
    --muted: #9a9079; --faint: #6e6653; --hair: #353026;
    --accent: #d4805a; --accent-soft: #3a2c20; --on-accent: #15140f;
  }
  .grain { mix-blend-mode: screen; opacity: 0.4; }
  .sk { background: linear-gradient(90deg, var(--well), #2a261d, var(--well)); background-size: 200% 100%; }
}
