/* ============================================================
   NewsWave — editorial news reader with TTS
   Palette: warm paper + ink, crimson masthead accent
   ============================================================ */

:root,
[data-theme='light'] {
  --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --color-bg: #faf7f1;
  --color-surface: #fffefb;
  --color-surface-2: #f5efe4;
  --color-surface-offset: #efe8db;
  --color-border: #e3ddcf;
  --color-divider: #ece6d9;

  --color-text: #1c1a17;
  --color-text-muted: #6b655b;
  --color-text-faint: #a8a195;
  --color-text-inverse: #fbf8f1;

  --color-accent: #b21e35;
  --color-accent-hover: #8f1729;
  --color-accent-soft: #f4e2e6;
  --color-teal: #0f766e;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(28, 26, 23, 0.06);
  --shadow-md: 0 6px 20px rgba(28, 26, 23, 0.09);
  --shadow-lg: 0 18px 48px rgba(28, 26, 23, 0.16);

  --player-h: 116px;
  --topbar-h: 116px;

  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.0625rem);
  --text-lg: clamp(1.2rem, 1.05rem + 0.7vw, 1.5rem);
  --text-xl: clamp(1.6rem, 1.2rem + 1.8vw, 2.1rem);
}

[data-theme='dark'] {
  --color-bg: #131210;
  --color-surface: #1c1a16;
  --color-surface-2: #211e18;
  --color-surface-offset: #27231c;
  --color-border: #322e25;
  --color-divider: #2a261f;

  --color-text: #ece6d8;
  --color-text-muted: #9c9484;
  --color-text-faint: #6a6357;
  --color-text-inverse: #1c1a17;

  --color-accent: #e0454f;
  --color-accent-hover: #f15a64;
  --color-accent-soft: #34211f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #131210;
    --color-surface: #1c1a16;
    --color-text: #ece6d8;
    --color-accent: #e0454f;
  }
}

/* base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: none; text-size-adjust: none; scroll-behavior: smooth; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  min-height: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
a { color: var(--color-accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.15; text-wrap: balance; }
p { text-wrap: pretty; max-width: 72ch; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--color-accent); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius-md) 0; }
.skip-link:focus { left: 0; }

/* ---------- topbar ---------- */
.topbar {
  flex-shrink: 0; z-index: 40;
  background: color-mix(in oklab, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(14px, 3vw, 28px) 6px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--color-text); flex-shrink: 0; }
.brand-mark { width: 38px; height: 38px; color: var(--color-accent); display: grid; place-items: center; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-family: var(--font-display); font-weight: 600; font-size: 1.18rem; letter-spacing: -0.01em; }
.brand-text small { font-size: var(--text-xs); color: var(--color-text-muted); letter-spacing: 0.04em; text-transform: uppercase; }

.filters { display: flex; gap: 2px; margin-left: auto; background: var(--color-surface-2); padding: 4px; border-radius: var(--radius-full); border: 1px solid var(--color-border); }
.filter { padding: 7px 14px; border-radius: var(--radius-full); font-size: var(--text-sm); font-weight: 500; color: var(--color-text-muted); transition: all 180ms cubic-bezier(.16,1,.3,1); }
.filter:hover { color: var(--color-text); }
.filter.active { background: var(--color-accent); color: #fff; box-shadow: var(--shadow-sm); }

.topbar-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn { width: 40px; height: 40px; border-radius: var(--radius-full); display: grid; place-items: center; color: var(--color-text-muted); transition: all 180ms cubic-bezier(.16,1,.3,1); }
.icon-btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.icon-btn svg { width: 20px; height: 20px; }

.meta-bar { max-width: 1320px; margin: 0 auto; padding: 4px clamp(14px, 3vw, 28px) 12px; display: flex; align-items: center; gap: 14px; }
.meta-updated { font-size: var(--text-xs); color: var(--color-text-muted); }
.link-btn { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--color-text-muted); margin-left: auto; padding: 4px 8px; border-radius: var(--radius-sm); transition: color 180ms; }
.link-btn:hover { color: var(--color-accent); }
.link-btn svg { width: 13px; height: 13px; }

@media (max-width: 680px) {
  .brand-text small { display: none; }
  .filter { padding: 6px 11px; font-size: var(--text-xs); }
  .filters { margin-left: 8px; }
}

/* ---------- layout ---------- */
.layout {
  max-width: 1320px; margin: 0 auto;
  display: grid; grid-template-columns: 400px 1fr;
  gap: 1px; background: var(--color-border);
  min-height: calc(100dvh - var(--topbar-h) - var(--player-h));
}
.list-pane { background: var(--color-bg); padding: 22px clamp(14px, 2vw, 24px) calc(var(--player-h) + 24px); overflow-y: auto; }
.reader-pane { background: var(--color-surface); position: relative; min-height: 70vh; }

.list-head { margin-bottom: 18px; }
.list-head h1 { font-family: var(--font-display); font-weight: 600; font-size: var(--text-xl); letter-spacing: -0.02em; }
.list-date { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 4px; }

.headline-list { display: flex; flex-direction: column; gap: 2px; }
.source-group-head { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.source-group-head h2 { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); }
.source-dot { width: 9px; height: 9px; border-radius: 50%; }
.src-reuters { background: #ff8000; }
.src-cnn { background: #cc0000; }
.src-pbs { background: #0066b2; }
.source-group-head .rule { flex: 1; height: 1px; background: var(--color-divider); }

.headline-card {
  display: block; width: 100%; text-align: left;
  padding: 13px 12px; border-radius: var(--radius-md);
  transition: background 160ms, transform 160ms;
}
.headline-card:hover { background: var(--color-surface-2); }
.headline-card.active { background: var(--color-accent-soft); box-shadow: inset 3px 0 0 var(--color-accent); }
.headline-card .hl-title { font-family: var(--font-display); font-weight: 500; font-size: 1.06rem; line-height: 1.3; color: var(--color-text); }
.headline-card .hl-summary { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.headline-card .hl-meta { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: 7px; display: flex; gap: 6px; align-items: center; }

/* skeleton */
.skeleton-card { height: 92px; border-radius: var(--radius-md); background: linear-gradient(100deg, var(--color-surface-2) 30%, var(--color-surface-offset) 50%, var(--color-surface-2) 70%); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin-bottom: 4px; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .reader-pane { display: none; }
  body.article-open .list-pane { display: none; }
  body.article-open .reader-pane { display: block; }
  .list-pane { max-height: none; }
  .reader-back { display: inline-flex !important; }
}

/* ---------- reader ---------- */
.reader-empty { height: 100%; min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 40px 24px; color: var(--color-text-muted); }
.reader-empty-icon { width: 64px; height: 64px; color: var(--color-text-faint); }
.reader-empty-icon svg { width: 100%; height: 100%; }
.reader-empty h2 { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); color: var(--color-text); }
.reader-empty p { max-width: 38ch; font-size: var(--text-sm); }

.reader-back { display: none; align-items: center; gap: 6px; color: var(--color-accent); font-weight: 500; font-size: var(--text-sm); margin-bottom: 16px; }
.reader-content { max-width: 720px; margin: 0 auto; padding: 44px clamp(20px, 4vw, 56px) 64px; }
.reader-top { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 14px; }
.source-badge { font-weight: 700; }
.article-title { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.7rem, 1.2rem + 2vw, 2.4rem); line-height: 1.12; letter-spacing: -0.02em; }
.article-byline { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 12px; font-style: italic; }
.article-body { margin-top: 28px; font-family: var(--font-display); font-size: 1.16rem; line-height: 1.72; }
.article-body p { margin-bottom: 1.1em; }
.article-body p.reading-active { background: var(--color-accent-soft); border-radius: 4px; box-shadow: 0 0 0 4px var(--color-accent-soft); }
.original-link { display: inline-block; margin-top: 28px; font-size: var(--text-sm); font-weight: 500; }

.reader-loading { position: absolute; inset: 0; display: flex; align-items: flex-start; justify-content: center; gap: 10px; padding-top: 80px; color: var(--color-text-muted); font-size: var(--text-sm); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--color-border); border-top-color: var(--color-accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- player bar ---------- */
.player {
  flex-shrink: 0; z-index: 50;
  background: color-mix(in oklab, var(--color-surface) 94%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-border);
  padding: 10px clamp(14px, 3vw, 28px) 14px;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.06);
}
.player-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.progress-track { flex: 1; height: 4px; background: var(--color-border); border-radius: var(--radius-full); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--color-accent); border-radius: var(--radius-full); transition: width 300ms linear; }
.progress-time { font-size: var(--text-xs); color: var(--color-text-muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.player-main { display: flex; align-items: center; gap: 14px; }
.now-playing { flex: 1; min-width: 0; }
.np-source { font-size: var(--text-xs); color: var(--color-accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.np-title { display: block; font-size: var(--text-sm); color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; align-items: center; gap: 8px; }
.ctrl { width: 42px; height: 42px; border-radius: var(--radius-full); display: grid; place-items: center; color: var(--color-text); transition: all 160ms; }
.ctrl svg { width: 22px; height: 22px; }
.ctrl:hover { background: var(--color-surface-2); }
.ctrl.play { width: 50px; height: 50px; background: var(--color-accent); color: #fff; box-shadow: var(--shadow-md); }
.ctrl.play:hover { background: var(--color-accent-hover); transform: scale(1.04); }
.ctrl.play .ico-pause { display: none; }
.ctrl.play.playing .ico-play { display: none; }
.ctrl.play.playing .ico-pause { display: block; }
.rate-pill { width: auto; min-width: 52px; padding: 0 12px; font-weight: 600; font-size: var(--text-sm); border: 1px solid var(--color-border); background: var(--color-surface-2); }

@media (max-width: 540px) {
  .now-playing { display: none; }
  .ctrl { width: 46px; height: 46px; }
  .ctrl.play { width: 54px; height: 54px; }
  .controls { gap: 6px; }
}

/* ---------- settings drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 60; opacity: 0; animation: fade 200ms forwards; }
@keyframes fade { to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(420px, 100vw); background: var(--color-surface);
  border-left: 1px solid var(--color-border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 280ms cubic-bezier(.16,1,.3,1);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--color-divider); }
.drawer-head h2 { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 20px 20px; }
.setting { padding: 18px 0; border-bottom: 1px solid var(--color-divider); }
.setting:last-child { border-bottom: none; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.setting label { font-weight: 600; font-size: var(--text-sm); }
.setting-value { font-variant-numeric: tabular-nums; color: var(--color-accent); font-weight: 700; font-size: var(--text-sm); }
input[type=range] { width: 100%; accent-color: var(--color-accent); height: 6px; }
.range-ticks { display: flex; justify-content: space-between; margin-top: 6px; font-size: var(--text-xs); color: var(--color-text-faint); }
.rate-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.preset { padding: 6px 12px; border-radius: var(--radius-full); border: 1px solid var(--color-border); font-size: var(--text-xs); color: var(--color-text-muted); transition: all 160ms; }
.preset:hover { border-color: var(--color-accent); color: var(--color-accent); }
.preset.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
select { width: 100%; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--color-border); background: var(--color-surface-2); color: var(--color-text); font-size: var(--text-sm); }
.setting-row { display: flex; justify-content: space-between; align-items: center; }
.drawer-foot { padding: 16px 20px; border-top: 1px solid var(--color-divider); }
.hint { font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.5; }
kbd { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: 4px; padding: 1px 5px; font-size: 0.8em; font-family: var(--font-body); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: calc(var(--player-h) + 16px); left: 50%; transform: translateX(-50%); z-index: 70; background: var(--color-text); color: var(--color-text-inverse); padding: 10px 18px; border-radius: var(--radius-full); font-size: var(--text-sm); box-shadow: var(--shadow-lg); opacity: 0; transition: opacity 200ms, transform 200ms; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
