/* Storyteller web reader — the one stylesheet every page shares.
   Spec: docs/superpowers/specs/2026-09-23-web-reader-ui-redesign-design.md
   Budget: <= 6KB gzipped (test/styles.test.mjs). System fonts only.
   Contrast of every token pair is checked by test/styles.test.mjs. */

:root {
  --bg: #f6fbf7;
  --surface: #ffffff;
  --surface-2: #eef6f1;
  --text: #17392a;
  --muted: #5b7a6a;
  --border: #d5e8dc;
  --brand: #257148;
  --brand-strong: #1f6b47;
  --brand-soft: #e6f4ec;
  --on-brand-soft: #1f6b47;
  --accent: #f28c28;
  --accent-strong: #b8500a;
  --promo-bg: #fff4e8;
  --hero-from: #257148;
  --hero-to: #174f35;
  --level-a1: #2e7d32;
  --level-a2: #00796b;
  --level-b1: #1565c0;
  --level-b2: #6b3fa0;
  --level-c1: #b8500a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(23, 57, 42, .08);
  --shadow-lift: 0 8px 22px rgba(23, 57, 42, .14);
  --wrap: 1120px;
  --reader-scale: 1;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101a15;
    --surface: #18241e;
    --surface-2: #1e2c25;
    --text: #e8f1ec;
    --muted: #8fb5a2;
    --border: #2a3b32;
    --brand: #7fd1a4;
    --brand-soft: #1e3a2c;
    --on-brand-soft: #a5d6b8;
    --promo-bg: #2b2217;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
    --shadow-lift: 0 8px 22px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #101a15;
  --surface: #18241e;
  --surface-2: #1e2c25;
  --text: #e8f1ec;
  --muted: #8fb5a2;
  --border: #2a3b32;
  --brand: #7fd1a4;
  --brand-soft: #1e3a2c;
  --on-brand-soft: #a5d6b8;
  --promo-bg: #2b2217;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-lift: 0 8px 22px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.hero :focus-visible, .site-footer :focus-visible { outline-color: #fff; }
[hidden] { display: none !important; }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; padding: 8px 14px; border-radius: var(--radius-sm); background: var(--surface); }
.skip-link:focus { top: 8px; }

/* ---------- Buttons & chips ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; min-height: 44px; padding: .5em 1.2em; border: 2px solid transparent; border-radius: 999px; font-weight: 700; line-height: 1.2; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }
.btn-accent { background: var(--accent-strong); color: #fff; }
.btn-primary { background: var(--brand-strong); color: #fff; }
.btn-ghost { background: transparent; border-color: currentColor; color: var(--brand); }
.btn-on-dark { color: #fff; }
.link-btn { min-height: 44px; padding: 0; border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; }
.chip { display: inline-block; padding: .1em .6em; border-radius: 999px; background: var(--brand-soft); color: var(--on-brand-soft); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.level-A1 { --level: var(--level-a1); }
.level-A2 { --level: var(--level-a2); }
.level-B1 { --level: var(--level-b1); }
.level-B2 { --level: var(--level-b2); }
.level-C1 { --level: var(--level-c1); }
.chip[class*="level-"] { background: var(--level); color: #fff; }

/* ---------- Header ---------- */
.site-header { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; gap: 8px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; color: var(--text); font-size: 1.15rem; font-weight: 800; text-decoration: none; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.main-nav { display: flex; align-items: center; gap: 2px; }
.main-nav > a, .dropdown > summary { display: flex; align-items: center; min-height: 44px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--brand); font-weight: 600; text-decoration: none; cursor: pointer; list-style: none; white-space: nowrap; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after { content: "▾"; margin-left: 4px; font-size: .8em; }
.main-nav > a:hover, .dropdown > summary:hover { background: var(--brand-soft); }
.dropdown { position: relative; }
.dropdown-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px; max-height: 70vh; overflow: auto; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
.main-nav .dropdown-list { left: 0; right: auto; }
.dropdown-list a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
.dropdown-list a:hover, .dropdown-list a[aria-current] { background: var(--brand-soft); }
.count { color: var(--muted); font-size: .85em; font-weight: 500; }
.nav-toggle-label { display: none; }
.nav-toggle { display: none; }
.get-app { white-space: nowrap; }
@media (max-width: 860px) {
  .nav-toggle-label { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: var(--radius-sm); color: var(--brand); font-size: 1.4rem; cursor: pointer; }
  .nav-toggle { display: block; }
  .main-nav { display: none; position: absolute; left: 0; right: 0; top: 100%; flex-direction: column; align-items: stretch; padding: 8px 16px 16px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-lift); }
  .nav-toggle:checked ~ .main-nav { display: flex; }
  .nav-toggle:focus-visible + .nav-toggle-label { outline: 3px solid var(--brand); }
  .main-nav .dropdown-list { position: static; box-shadow: none; border: 0; padding: 0 0 0 12px; }
  .get-app { display: none; }
}

/* ---------- Footer ---------- */
.site-footer { margin-top: 56px; padding: 32px 0 20px; background: #17392a; color: #cfe5d8; font-size: .92rem; }
.site-footer a { color: #fff; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 24px; }
.footer-grid h2 { font-size: 1rem; color: #fff; }
.footer-grid ul { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.footer-brand { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: #fff; font-weight: 800; font-size: 1.1rem; }
.footer-brand img { border-radius: 8px; }
.footer-bottom { margin-top: 24px; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .15); font-size: .85rem; }
@media (max-width: 720px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-about { grid-column: 1 / -1; }
}

/* ---------- Sections & hero ---------- */
.section { padding: 28px 0 4px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-title { margin: 0; font-size: 1.35rem; }
.section-link { margin-left: auto; font-weight: 600; white-space: nowrap; }
.hero { background: linear-gradient(135deg, var(--hero-from), var(--hero-to)); color: #fff; }
.hero-inner { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; padding-top: 40px; padding-bottom: 40px; }
.hero-title { margin: 0 0 .4em; font-size: clamp(1.8rem, 4vw, 2.8rem); }
.hero-sub { max-width: 36em; margin: 0 0 1.2em; font-size: 1.1rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 24px 0 0; padding: 0; list-style: none; }
.hero-stats strong { display: block; font-size: 1.5rem; }
.hero-mascot { width: 220px; height: 220px; border-radius: 40px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
@media (max-width: 720px) {
  .hero-inner { grid-template-columns: 1fr; padding-top: 28px; padding-bottom: 28px; text-align: center; }
  .hero-mascot { grid-row: 1; width: 128px; height: 128px; margin: 0 auto; border-radius: 28px; }
  .hero-actions, .hero-stats { justify-content: center; }
}
.lang-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-picker a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; text-decoration: none; }

/* ---------- Level tiles, genre chips ---------- */
.level-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.level-tile { display: block; padding: 16px; border-radius: var(--radius); background: var(--level); color: #fff; text-decoration: none; box-shadow: var(--shadow); transition: transform .15s; }
.level-tile:hover { transform: translateY(-3px); }
.level-code { display: block; font-size: 1.8rem; font-weight: 800; line-height: 1; }
.level-name { display: block; margin-top: 4px; font-weight: 600; }
.level-count { font-size: .85rem; }
.genre-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.genre-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; text-decoration: none; }
.genre-chip:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- Story cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); color: var(--text); text-decoration: none; transition: transform .15s, box-shadow .15s; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.card-cover { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); }
.card-title { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: .95rem; font-weight: 700; line-height: 1.3; }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: auto; }
.card-mins { color: var(--muted); font-size: .8rem; }

/* ---------- Featured card, app promo ---------- */
.featured { display: grid; grid-template-columns: minmax(140px, 240px) 1fr; gap: 20px; padding: 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.featured-cover { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); }
.featured-body h2, .featured-body h3 { margin: 0 0 .3em; font-size: 1.5rem; }
.featured-body h2 a, .featured-body h3 a { color: var(--text); text-decoration: none; }
.featured-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 .6em; color: var(--muted); }
.featured-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; }
@media (max-width: 560px) { .featured { grid-template-columns: 1fr; } }
.app-promo { display: flex; align-items: center; gap: 20px; padding: 20px; border-radius: var(--radius); background: var(--promo-bg); }
.promo-logo { width: 72px; height: 72px; border-radius: 18px; }
.app-promo-body { flex: 1; }
.app-promo h2 { margin: 0 0 .3em; font-size: 1.25rem; }
.app-promo ul { margin: .4em 0 0; padding-left: 1.2em; }
.about { margin: .8em 0 0; font-size: .92rem; }
.play-badge img { width: 155px; height: 60px; }
.play-badge-text { display: inline-flex; align-items: center; gap: .4em; }
@media (max-width: 640px) {
  .app-promo { flex-direction: column; text-align: center; }
  .app-promo ul { display: inline-block; text-align: left; }
}

/* ---------- Page head, breadcrumb, listing ---------- */
.page-head { padding: 20px 0 4px; }
.page-head h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); }
.page-head p { margin: 0; color: var(--muted); }
.breadcrumb ol { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; color: var(--muted); font-size: .88rem; }
.breadcrumb li + li::before { content: "›"; margin-right: 6px; }
.breadcrumb a { color: var(--muted); }
.filters { display: grid; gap: 10px; margin: 16px 0; padding: 14px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filter-label { min-width: 72px; color: var(--muted); font-size: .9rem; font-weight: 700; }
.filter-more { margin: 0; font-weight: 600; }
.chip-link { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--brand); font-size: .9rem; font-weight: 600; text-decoration: none; cursor: pointer; }
.chip-link.is-active { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
@media (pointer: coarse) { .chip-link { min-height: 44px; } }
.search-input { flex: 1; min-width: 0; min-height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--text); }
.sort-select { min-height: 44px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); }
.result-bar { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; color: var(--muted); }
.result-count { margin: 0; }
.clear-filters { min-height: 44px; margin-left: auto; border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; }
.load-more { display: flex; justify-content: center; margin: 24px 0 8px; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 20px 0; }
.pagination a, .pagination span { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); text-decoration: none; }
.pagination [aria-current] { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
.pagination .gap { min-width: auto; min-height: auto; padding: 0 4px; border: none; background: none; }
.empty-state { padding: 32px 0; color: var(--muted); text-align: center; }

/* ---------- Story page ---------- */
.read-progress { position: fixed; top: 0; left: 0; right: 0; z-index: 70; height: 3px; pointer-events: none; }
.read-progress span { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: 0 50%; }
.story-head { display: grid; grid-template-columns: minmax(160px, 280px) 1fr; gap: 24px; align-items: start; padding: 12px 0 8px; }
.story-cover { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); box-shadow: var(--shadow-lift); }
.story-title { margin: 0 0 .2em; font-size: clamp(1.7rem, 4vw, 2.5rem); }
.story-byline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 .6em; color: var(--muted); }
.summary, .description { margin: .5em 0; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; margin: .8em 0; font-size: .92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; }
.story-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.player { display: flex; align-items: center; gap: 12px; max-width: 460px; margin-top: 12px; padding: 6px 16px 6px 6px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); }
.player-btn { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--brand-strong); color: #fff; font-size: 1.1rem; cursor: pointer; }
.player-label { font-size: .85rem; font-weight: 600; white-space: nowrap; }
.player-track { flex: 1; height: 6px; overflow: hidden; border-radius: 3px; background: var(--surface-2); }
.player-fill { display: block; width: 0; height: 100%; background: var(--brand-strong); }
.player-time { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.player-end, .player-error { margin: .6em 0 0; padding: 10px 14px; border-radius: var(--radius-sm); font-weight: 600; }
.player-end { background: var(--brand-soft); color: var(--on-brand-soft); }
.player-end a { color: inherit; }
/* Reuses the promo section's warm tone (already AA-checked in both themes,
   see styles.test.mjs's text/promo-bg pairs) for a visually distinct
   warning, without inventing a new color pair. */
.player-error { background: var(--promo-bg); color: var(--text); }
@media (max-width: 640px) {
  .story-head { grid-template-columns: 1fr; }
  .story-cover { max-width: 280px; margin: 0 auto; }
  .player-label { display: none; }
}
.reader-tools { position: sticky; top: 64px; z-index: 40; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 16px 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.seg, .seg-spacer { margin-right: auto; }
.seg { display: inline-flex; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.seg button, .tool-btn { min-height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--brand); font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--brand-strong); color: #fff; }
.tool-btn { min-width: 44px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.story-text { max-width: 65ch; margin: 0 auto; font-size: calc(1.125rem * var(--reader-scale)); line-height: 1.75; }
.story-text .en { margin: 0 0 1.1em; }
.story-text .en:has(+ .tr) { margin-bottom: .35em; }
.story-text .tr { margin: 0 0 1.2em; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); font-size: .9em; }
.story-text.hide-translation .tr { display: none; }
.story-text.hide-translation .en { margin-bottom: 1.1em; }
.chapter + .chapter { margin-top: 2em; }
.chapter-title { font-size: 1.2rem; }
.quiz { max-width: 760px; margin: 32px auto 0; padding: 20px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.quiz h2 { font-size: 1.25rem; }
.quiz-list { display: grid; gap: 18px; margin: 0; padding-left: 1.2em; }
.quiz-question { margin: 0 0 8px; font-weight: 700; }
.quiz-options { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.quiz-option { min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); text-align: left; cursor: pointer; }
.quiz-option:disabled { cursor: default; }
.quiz-option.is-correct { border-color: var(--level-a1); background: var(--brand-soft); color: var(--on-brand-soft); font-weight: 700; }
.quiz-option.is-wrong { border-color: #c62828; text-decoration: line-through; }
.quiz-feedback { margin: 8px 0 0; font-weight: 700; }
.quiz-feedback:empty { display: none; }
.quiz-reveal { margin-top: 8px; color: var(--muted); }
.quiz-reveal summary { min-height: 32px; color: var(--brand); font-weight: 600; cursor: pointer; }
.story-cta, .related { margin-top: 32px; }

/* ---------- 404 ---------- */
.not-found { padding: 40px 16px 8px; text-align: center; }
.not-found img { width: 140px; height: 140px; margin: 0 auto 16px; border-radius: 32px; }
.not-found .hero-actions { justify-content: center; margin-top: 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
