  :root {
    --bg: #0f1115;
    --fg: #e8e8ea;
    --dim: #8a8f99;
    --accent: #ff5a5f;
    --panel: #161922;
    --line: #222632;
    --good: #6fcf97;
  }
  * { box-sizing: border-box; -webkit-user-select: none; user-select: none; }
  html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
    height: 100dvh; overflow: hidden; overscroll-behavior: none;
    touch-action: none;
  }
  #stage {
    position: fixed; inset: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--bg);
    z-index: 1;
  }
  header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    font-variant-numeric: tabular-nums;
    font-size: 15px;
    color: var(--dim);
  }
  header .stats { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
  header .stats b { color: var(--fg); font-weight: 600; }
  header .ver { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; opacity: 0.7; }
  header .right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
  #btn-mode { border-color: var(--accent); }
  header button {
    background: transparent; border: 1px solid var(--line); color: var(--fg);
    padding: 6px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
  }
  header button.active { border-color: var(--accent); color: var(--accent); }

  #word {
    display: flex; align-items: center; justify-content: center;
    font-family: "SF Mono", "Menlo", "Consolas", ui-monospace, monospace;
    font-weight: 500;
    font-size: clamp(56px, 13vw, 160px);
    letter-spacing: -0.01em;
    line-height: 1;
    position: relative;
  }
  #word .w {
    display: inline-block;
    white-space: nowrap;
    transform: translateX(var(--orp-shift, 0px));
  }
  #word .w .pivot { color: var(--accent); }
  #word.paused::after {
    content: "paused — tap or press space";
    position: absolute; bottom: 18%;
    font-family: inherit; font-size: 15px; color: var(--dim);
    letter-spacing: 0.04em;
  }
  #pivotline {
    position: absolute; left: 30%; top: 0; bottom: 0;
    width: 1px; background: rgba(255,90,95,0.18);
    pointer-events: none;
  }

  /* Sentence-sweep / fixation training layout: the whole sentence is shown
     and a highlight is walked across it to train eye movement. */
  #sweepview {
    display: flex; align-items: center; justify-content: center;
    padding: 6vh 8vw; position: relative; cursor: pointer;
  }
  #sweepview .sweep-inner {
    max-width: 30em;
    font-family: "Georgia", "Iowan Old Style", "Times New Roman", serif;
    font-size: clamp(22px, 3.4vw, 40px);
    line-height: 1.7;
    color: var(--dim);
    text-align: left;
    letter-spacing: 0.01em;
  }
  #sweepview .sp-word { transition: color 0.08s linear, opacity 0.18s ease; }
  #sweepview .sp-on {
    color: var(--fg);
    background: rgba(255,90,95,0.12);
    border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(255,90,95,0.12);
  }
  #sweepview .sp-orp { color: var(--accent); font-weight: 700; }
  #sweepview .sp-done { opacity: 0.28; }
  /* keywords mode: content words stay legible (the dwell map); their ORP
     letter is already red via .sp-orp. Function words sit a touch dimmer. */
  #sweepview .sp-key { color: var(--fg); }
  #sweepview.km .sp-word:not(.sp-key):not(.sp-on) { opacity: 0.62; }
  #sweepview.paused::after {
    content: "paused — tap or press space";
    position: absolute; bottom: 6%; left: 0; right: 0; text-align: center;
    font-family: -apple-system, system-ui, sans-serif;
    font-size: 14px; color: var(--dim); letter-spacing: 0.04em;
  }
  #settings select {
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--line); border-radius: 8px;
    padding: 7px 10px; font-size: 15px; font-family: inherit; width: 100%;
  }
  #completion {
    display: none;
    flex-direction: column; align-items: center; justify-content: center;
    padding: 24px; text-align: center;
    font-family: -apple-system, system-ui, sans-serif;
    gap: 14px;
  }
  #completion.show { display: flex; }
  #completion .check { font-size: 36px; color: var(--good); }
  #completion h2 { margin: 0; font-size: 22px; font-weight: 600; color: var(--fg); }
  #completion .sub { color: var(--dim); font-size: 15px; }
  #completion .stats-row { display: flex; gap: 24px; color: var(--dim); font-size: 15px; font-variant-numeric: tabular-nums; }
  #completion .stats-row b { color: var(--fg); font-weight: 600; }
  #completion .next-block { margin-top: 6px; }
  #completion .next-label { color: var(--dim); font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 8px; }
  #completion .next-grid { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 640px; }
  #completion .next-card {
    background: var(--panel); border: 1px solid var(--line); color: var(--fg);
    padding: 10px 14px; border-radius: 10px; cursor: pointer; font-size: 15px;
    max-width: 200px; text-align: left;
  }
  #completion .next-card:hover { border-color: var(--accent); }
  #completion .next-card .nc-trad { color: var(--dim); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
  #completion .next-card .nc-title { font-weight: 600; line-height: 1.25; }

  footer {
    padding: 10px 14px 16px;
    border-top: 1px solid var(--line);
    background: var(--panel);
    display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center;
    font-size: 14px; color: var(--dim);
  }
  footer .hint { text-align: center; font-size: 13px; letter-spacing: 0.04em; }
  footer .ctrls { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
  footer .ctrls button {
    background: transparent; border: 1px solid var(--line); color: var(--fg);
    padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer;
    min-width: 44px;
  }
  footer .ctrls button.primary { border-color: var(--accent); color: var(--accent); }
  footer .meta { font-size: 13px; }

  /* Library overlay */
  #library {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    display: none;
    z-index: 12;
  }
  #library.open { display: block; }
  #library .panel {
    position: absolute; top: 0; right: 0; bottom: 0;
    width: min(460px, 100%);
    background: var(--panel); border-left: 1px solid var(--line);
    display: flex; flex-direction: column;
    transform: translateX(0);
    box-shadow: -8px 0 24px rgba(0,0,0,0.5);
  }
  #library header.lib-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }
  #library h2 { margin: 0; font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); font-weight: 600; }
  #library .lib-stats { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 4px; }
  #library .lib-scroll { flex: 1; overflow-y: auto; padding: 14px 18px 20px; -webkit-overflow-scrolling: touch; }
  #library .lib-pick {
    border: 1px solid rgba(255,90,95,0.4); border-radius: 12px;
    padding: 14px; margin-bottom: 18px;
    background: rgba(255,90,95,0.05);
    cursor: pointer;
  }
  #library .lib-pick:hover { background: rgba(255,90,95,0.08); }
  #library .lib-pick .pl { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
  #library .lib-pick .pt { font-weight: 600; font-size: 17px; color: var(--fg); margin-bottom: 4px; }
  #library .lib-pick .pa { font-size: 14px; color: var(--dim); margin-bottom: 6px; }
  #library .lib-pick .pd { font-size: 14px; color: var(--dim); line-height: 1.45; }

  #library .lib-group { margin-bottom: 18px; }
  #library .lib-group-h {
    font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim);
    padding: 6px 0; border-bottom: 1px solid var(--line); margin-bottom: 6px;
  }
  #library .lib-row {
    display: grid; grid-template-columns: 1fr auto; gap: 8px;
    padding: 10px 6px; border-bottom: 1px solid rgba(34,38,50,0.5);
    cursor: pointer; align-items: center;
  }
  #library .lib-row:hover { background: rgba(255,255,255,0.02); }
  #library .lib-row.current { background: rgba(255,90,95,0.06); }
  #library .lib-row .lr-main { min-width: 0; }
  #library .lib-row .lr-title { font-size: 15px; color: var(--fg); font-weight: 500; line-height: 1.3; }
  #library .lib-row .lr-title.read { color: var(--dim); }
  #library .lib-row .lr-meta { font-size: 13px; color: var(--dim); margin-top: 2px; font-variant-numeric: tabular-nums; }
  #library .lib-row .lr-meta .check { color: var(--good); margin-right: 4px; }
  #library .lib-row .lr-meta .views { color: var(--dim); margin-left: 6px; }
  #library .lib-row .lr-actions { display: flex; gap: 4px; align-items: center; }
  #library .lib-row .lr-del {
    background: transparent; border: 1px solid var(--line); color: var(--dim);
    padding: 4px 8px; border-radius: 6px; font-size: 13px; cursor: pointer;
  }
  #library .lib-row .lr-del:hover { color: var(--accent); border-color: var(--accent); }
  #library .lib-foot {
    padding: 10px 18px; border-top: 1px solid var(--line);
    display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap;
  }
  #library .lib-foot button {
    background: transparent; border: 1px solid var(--line); color: var(--fg);
    padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
  }

  #settings {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: none; align-items: center; justify-content: center;
    z-index: 10;
  }
  #settings.open { display: flex; }
  #settings .panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; padding: 18px 20px;
    min-width: min(420px, 92vw);
    font-size: 15px;
  }
  #settings h2 { margin: 0 0 14px; font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
  #settings .row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
  #settings .row:last-of-type { border-bottom: none; }
  #settings input[type="number"] {
    width: 80px; background: var(--bg); color: var(--fg);
    border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
    font-family: inherit; font-size: 15px;
    font-variant-numeric: tabular-nums; text-align: right;
  }
  #settings input[type="checkbox"] { transform: scale(1.2); }
  #settings .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
  #settings .actions button {
    background: transparent; border: 1px solid var(--line); color: var(--fg);
    padding: 8px 14px; border-radius: 8px; font-size: 15px; cursor: pointer;
  }
  #settings .actions button.primary { border-color: var(--accent); color: var(--accent); }

  #flash {
    position: fixed; left: 50%; top: 56px; transform: translateX(-50%);
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 12px; font-size: 14px; color: var(--fg);
    opacity: 0; transition: opacity 0.2s ease;
    pointer-events: none; z-index: 20;
    font-variant-numeric: tabular-nums;
  }
  #flash.show { opacity: 1; }

  /* SEO content — visible to crawlers and JS-disabled visitors;
     the reader UI #stage (position:fixed) overlays it for sighted visitors. */
  .seo-article {
    position: relative; z-index: 0;
    padding: 32px 24px 64px;
    color: var(--fg); background: var(--bg);
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
    font-size: 18px; line-height: 1.65;
    max-width: 720px; margin: 0 auto;
  }
  .seo-article h1 { font-size: 32px; margin: 0 0 8px; line-height: 1.25; }
  .seo-article h2 { font-size: 14px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); margin: 28px 0 8px; font-weight: 600; }
  .seo-article .byline { color: var(--dim); font-size: 15px; margin: 0 0 28px; }
  .seo-article .live-stats {
    color: var(--accent); font-size: 13px; letter-spacing: 0.04em;
    margin: -12px 0 24px; padding: 6px 10px;
    background: rgba(245, 158, 11, 0.07);
    border-left: 2px solid var(--accent);
    border-radius: 2px;
  }
  .seo-article p { margin: 0 0 16px; }
  .seo-article a { color: var(--accent); text-decoration: none; }
  .seo-article a:hover { text-decoration: underline; }
  .seo-article ul { padding-left: 0; list-style: none; }
  .seo-article li { margin: 6px 0; }
  .seo-article li .meta { color: var(--dim); font-size: 15px; }
  .seo-article nav { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--dim); font-size: 15px; }
  .seo-article kbd { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 14px; }

  /* Dialogue passages: hanging-indent layout so the speaker label is visually anchored. */
  .seo-article .dialogue { margin: 16px 0 24px; }
  .seo-article .dialogue p {
    padding-left: 7.5em;
    text-indent: -7.5em;
    margin: 0 0 14px;
  }
  .seo-article .dialogue .speaker {
    display: inline-block;
    min-width: 7em;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.04em;
    font-size: 13px;
    text-transform: uppercase;
    vertical-align: baseline;
    margin-right: 0.5em;
  }
  @media (max-width: 520px) {
    .seo-article .dialogue p { padding-left: 0; text-indent: 0; }
    .seo-article .dialogue .speaker { display: block; min-width: 0; margin-bottom: 2px; }
  }
