:root {
  --bg: oklch(0.975 0.004 85);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.955 0.005 85);
  --text: oklch(0.22 0.01 260);
  --muted: oklch(0.5 0.012 260);
  --border: oklch(0.9 0.006 85);
  --accent: oklch(0.58 0.2 30);
  --accent-soft: oklch(0.58 0.2 30 / 0.1);
  --accent-text: oklch(0.5 0.19 30);
  --shadow: 0 1px 2px oklch(0 0 0 / 0.04), 0 4px 16px oklch(0 0 0 / 0.04);
  --glass: oklch(0.985 0.004 85 / 0.82);
  --r-ctl: 8px;
  --r-card: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(0.17 0.006 270);
    --surface: oklch(0.21 0.007 270);
    --surface-2: oklch(0.25 0.008 270);
    --text: oklch(0.94 0.004 85);
    --muted: oklch(0.7 0.01 270);
    --border: oklch(0.3 0.008 270);
    --accent: oklch(0.68 0.18 32);
    --accent-soft: oklch(0.68 0.18 32 / 0.14);
    --accent-text: oklch(0.75 0.15 35);
    --shadow: none;
    --glass: oklch(0.19 0.007 270 / 0.82);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
img { display: block; }

#app { max-width: 680px; margin: 0 auto; padding: 0 16px calc(var(--tabs-h) + var(--safe-b) + 24px); }
body.playing #app { padding-bottom: calc(var(--tabs-h) + var(--safe-b) + 96px); }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 0 8px;
  background: var(--bg);
}
.brand { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.brand::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 3px; vertical-align: 2px; }
.updated { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Topic chips */
.chips {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 62px); z-index: 4;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 4px 16px 12px; margin: 0 -16px; background: var(--bg);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 500; color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
body.no-chips .chips { display: none; }

/* Feed cards */
.feed { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow); overflow: hidden; cursor: pointer; text-align: left; width: 100%;
  transition: transform 150ms ease-out;
}
.card:active { transform: scale(0.99); }
.card-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.card-body { padding: 14px 16px 12px; }
.meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.meta .dot::before { content: "·"; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent-soft); padding: 2px 7px; border-radius: 6px;
}
.headline { font-size: 17px; line-height: 1.45; font-weight: 500; white-space: pre-line; overflow-wrap: anywhere; }
.card .headline { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-foot svg { width: 16px; height: 16px; }
.card-foot .stat { display: inline-flex; align-items: center; gap: 4px; }
.card-foot .listen { margin-left: auto; width: 40px; height: 40px; margin-right: -8px; }
.avatars { display: inline-flex; }
.av {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--bg); background: var(--muted);
  border: 2px solid var(--surface); margin-left: -6px;
}
.av:first-child { margin-left: 0; }
.multi { color: var(--accent-text); font-weight: 600; }
.more { display: block; margin: 16px auto; height: 44px; padding: 0 20px; border-radius: var(--r-ctl); border: 1px solid var(--border); background: var(--surface); font-weight: 500; }

/* States */
.skeleton { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; }
.sk { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s ease-in-out infinite; margin: 8px 0; }
@keyframes sh { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 18px; }
.btn {
  height: 44px; padding: 0 18px; border-radius: var(--r-ctl); font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: oklch(0.99 0 0); }
.btn.on { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border-top: 1px solid var(--border);
}
.tabs a {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 11px; font-weight: 500; color: var(--muted);
}
.tabs a[aria-current="page"] { color: var(--accent-text); }
.tabs a[aria-current="page"] svg { stroke-width: 2.2; }

/* Mini player */
.player {
  position: fixed; z-index: 19; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + var(--safe-b) + 8px);
  width: min(648px, calc(100% - 16px));
  display: flex; align-items: center; gap: 4px; padding: 8px 8px 10px 10px;
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: 0 8px 24px oklch(0 0 0 / 0.12);
}
.pl-img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.pl-info { flex: 1; min-width: 0; padding: 0 6px; cursor: pointer; }
.pl-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-progress { position: absolute; left: 12px; right: 12px; bottom: 4px; height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; }
.pl-progress div { height: 100%; width: 0; background: var(--accent); transition: width 250ms linear; }

/* Panel (story detail / reader) */
.panel {
  position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  animation: slide-in 220ms ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.panel-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  background: var(--glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.panel-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-actions { display: flex; }
.panel-body { max-width: 680px; margin: 0 auto; padding: 16px 16px calc(var(--tabs-h) + var(--safe-b) + 110px); }
.hero-img { width: 100%; border-radius: var(--r-card); aspect-ratio: 16/9; object-fit: cover; background: var(--surface-2); margin-bottom: 14px; }
.story-h { font-size: 22px; line-height: 1.35; font-weight: 600; letter-spacing: -0.01em; white-space: pre-line; overflow-wrap: anywhere; margin: 6px 0 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.section { margin-top: 28px; }
.section h2 { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.section h2 svg { width: 16px; height: 16px; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.row { display: flex; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--border); text-decoration: none; width: 100%; text-align: left; }
.row:first-child { border-top: 0; }
button.row:hover, a.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; line-height: 1.4; font-weight: 500; overflow-wrap: anywhere; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.row-desc { font-size: 14px; color: var(--muted); margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-thumb { width: 72px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; }
.src-name { font-weight: 600; color: var(--text); }

.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding: 6px 0 14px; cursor: pointer; }
.tl-item::before { content: ""; position: absolute; left: -19px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.tl-item.now::before { background: var(--accent); border-color: var(--accent); }
.tl-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-text { font-size: 15px; line-height: 1.45; white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.tl-item.now .tl-text { font-weight: 600; }

.wiki { display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 14px; }
.wiki img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex: none; }
.wiki p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.wiki + .wiki { margin-top: 8px; }

.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.video { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; text-align: left; }
.video img, .video iframe { width: 100%; aspect-ratio: 16/9; object-fit: cover; border: 0; display: block; }
.video .v-t { padding: 8px 10px 10px; font-size: 14px; font-weight: 500; line-height: 1.35; }
.video .v-s { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }

.keys { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.key { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); }
.key[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.search { display: flex; gap: 8px; margin-bottom: 10px; }
.search input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctl);
}

/* Reader */
.reader { font-size: 18px; line-height: 1.65; }
.reader h1 { font-size: 26px; line-height: 1.25; letter-spacing: -0.015em; margin: 4px 0 8px; }
.reader .byline { font-size: 14px; color: var(--muted); margin-bottom: 20px; }
.reader img, .reader figure { max-width: 100%; height: auto; border-radius: 8px; margin: 12px 0; }
.reader figcaption { font-size: 13px; color: var(--muted); }
.reader a { color: var(--accent-text); }
.reader blockquote { margin: 16px 0; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.notice { background: var(--surface-2); border-radius: var(--r-card); padding: 14px 16px; font-size: 15px; color: var(--muted); margin: 12px 0; }

/* Listen tab */
.card-plain { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; margin-bottom: 12px; }
.card-plain h3 { margin: 0 0 4px; font-size: 17px; }
.card-plain p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r-ctl); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { height: 36px; padding: 0 12px; border-radius: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 10px 0; }
.bar div { height: 100%; background: var(--accent); width: 0; transition: width 200ms; }
.queue .row { cursor: pointer; }
.queue .row.cur .row-title { color: var(--accent-text); }
.page-h { font-size: 22px; font-weight: 700; margin: 4px 0 12px; letter-spacing: -0.01em; }

/* Story mode */
.storymode { position: fixed; inset: 0; z-index: 40; background: radial-gradient(120% 80% at 20% 10%, oklch(0.35 0.09 30), #111 70%); color: #fafafa; overflow: hidden; }
.sm-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.9; }
.sm-shade { position: absolute; inset: 0; background: linear-gradient(180deg, oklch(0 0 0 / 0.55) 0%, oklch(0 0 0 / 0) 25%, oklch(0 0 0 / 0.35) 50%, oklch(0 0 0 / 0.9) 100%); }
.sm-bars { position: absolute; z-index: 3; top: calc(env(safe-area-inset-top, 0px) + 10px); left: 12px; right: 12px; display: flex; gap: 4px; }
.sm-bars span { flex: 1; height: 3px; border-radius: 2px; background: oklch(1 0 0 / 0.3); overflow: hidden; }
.sm-bars span i { display: block; height: 100%; width: 0; background: #fff; }
.sm-bars span.done i { width: 100%; }
.sm-text { position: absolute; z-index: 2; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); padding: 0 24px; max-width: 680px; margin: 0 auto; }
.sm-meta { font-size: 14px; opacity: 0.85; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.sm-meta .badge { color: #fff; background: var(--accent); }
.sm-headline { font-size: clamp(24px, 6vw, 34px); line-height: 1.25; font-weight: 700; letter-spacing: -0.015em; white-space: pre-line; text-shadow: 0 1px 12px oklch(0 0 0 / 0.4); display: -webkit-box; -webkit-line-clamp: 9; -webkit-box-orient: vertical; overflow: hidden; }
.sm-zone { position: absolute; z-index: 1; top: 0; bottom: 0; width: 35%; }
.sm-left { left: 0; } .sm-right { right: 0; }
.sm-controls { position: absolute; z-index: 3; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); display: flex; justify-content: center; gap: 24px; }
.icon-btn.light { color: #fff; background: oklch(1 0 0 / 0.14); }
.icon-btn.big { width: 56px; height: 56px; }

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 90px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 200ms ease-out, transform 200ms ease-out; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 900px) {
  .headline { font-size: 18px; }
}
