/* Counterpoint — restrained editorial reading brief. Mobile-first, dark by
   default, light via prefers-color-scheme. One file, no reset framework. */

/* The hidden attribute must beat our own display rules (#tabbar is flex). */
[hidden] { display: none !important; }

:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232732;
  --text: #e8e6e1;
  --muted: #9aa0ab;
  --line: #2b2f3a;
  --accent: #d8a657;      /* muted gold — brand + Listen */
  --good: #5fb98f;        /* worth knowing */
  --good-ink: #0f1115;
  --meh: #7c8391;         /* meh */
  --shadow: 0 10px 30px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.35);
  --radius: 18px;
  --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f3ee;
    --surface: #ffffff;
    --surface-2: #ecebe4;
    --text: #1b1d23;
    --muted: #5b616c;
    --line: #e0ded6;
    --accent: #a9781c;
    --good: #2f8f63;
    --good-ink: #ffffff;
    --meh: #6b7280;
    --shadow: 0 8px 24px rgba(30,30,40,.12), 0 2px 6px rgba(30,30,40,.08);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app { display: flex; flex-direction: column; min-height: 100%; }

/* ---- Top bar ---- */
#topbar {
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 18px) 10px calc(var(--safe-l) + 18px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
#brief-title { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: .2px; }
#brief-sub { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }

/* ---- Offline banner ---- */
.banner {
  margin: 10px calc(var(--safe-r) + 14px) 0 calc(var(--safe-l) + 14px);
  padding: 8px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--text); font-size: .82rem;
}

/* ---- Main view ---- */
#view {
  flex: 1 1 auto; position: relative;
  padding: 0 calc(var(--safe-r) + 14px) 0 calc(var(--safe-l) + 14px);
}

/* ============ Token gate ============ */
.gate {
  min-height: 70vh; display: flex; flex-direction: column;
  justify-content: center; gap: 14px; max-width: 420px; margin: 0 auto;
  padding: 24px 6px;
}
.gate h2 { margin: 0; font-size: 1.4rem; }
.gate p { margin: 0; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
input[type=password], input[type=text] {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font-weight: 600;
  text-align: center; text-decoration: none; display: inline-block;
}
.btn-accent { background: var(--accent); color: #17130a; border-color: transparent; }
.btn:active { transform: translateY(1px); }
.err { color: #e5766b; font-size: .85rem; margin: 0; min-height: 1em; }

/* ============ Card stack ============ */
.stack-wrap {
  /* 176px reserve = topbar + footer (‹ dots › nav row + hint) */
  position: relative; height: calc(100dvh - var(--tab-h) - var(--safe-b) - 176px);
  min-height: 420px; margin-top: 12px;
  touch-action: pan-y;
}
.card {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 20px 16px; overflow: hidden;
  will-change: transform, opacity;
}
/* peeking cards sit behind, slightly smaller + lower */
.card.behind-1 { transform: translateY(14px) scale(.965); }
.card.behind-2 { transform: translateY(28px) scale(.93); }
.card.behind-1, .card.behind-2 { box-shadow: 0 6px 18px rgba(0,0,0,.30); }
.card.top { z-index: 5; }

/* overscroll none: at the end of the body an up-drag must reach our pointer
   handlers (acknowledge), not bounce/chain as a native scroll */
.card-scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: none; }
.card h2 {
  margin: 0 0 8px; font-size: 1.28rem; line-height: 1.25; font-weight: 680;
  letter-spacing: -.2px;
}
.attr { margin: 0 0 14px; font-size: .86rem; color: var(--muted); }
.attr .who { color: var(--text); font-weight: 620; }
.attr .show { font-style: italic; }
.domain-pill {
  display: inline-block; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .6px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); margin-bottom: 12px;
}
blockquote {
  margin: 0 0 14px; padding: 2px 0 2px 16px;
  border-left: 3px solid var(--accent);
  font-size: 1.24rem; line-height: 1.42; font-weight: 420;
}
.card-body { margin: 0 0 14px; color: var(--muted); font-size: .95rem; }

/* speaker identity line ("XXX is/was AAA"), just above the why disclosure */
.speaker-blurb { margin: 0 0 6px; color: var(--muted); font-size: .82rem; }

/* why-ranked disclosure */
details.why { margin-top: 4px; font-size: .8rem; color: var(--muted); }
details.why summary { cursor: pointer; list-style: none; user-select: none; }
details.why summary::-webkit-details-marker { display: none; }
details.why summary::before { content: "▸ "; }
details.why[open] summary::before { content: "▾ "; }
.factors { display: flex; gap: 6px; margin: 8px 0 0; flex-wrap: wrap; }
.factors .f {
  flex: 1 1 auto; text-align: center; padding: 6px 4px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line); min-width: 48px;
}
.factors .f b { display: block; font-size: .95rem; color: var(--text); }
.factors .f span { font-size: .62rem; text-transform: uppercase; letter-spacing: .5px; }
.factors .f.total b { color: var(--accent); }

/* card action row */
.actions { display: flex; gap: 10px; margin-top: 14px; align-items: stretch; }
.listen {
  flex: 1 1 auto; background: transparent; color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 60%, var(--line));
  border-radius: 12px; padding: 12px; font-weight: 640; text-decoration: none;
  text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.rate { display: flex; gap: 10px; }
.rate button {
  border-radius: 12px; padding: 12px 14px; font-weight: 660; border: 1px solid transparent;
}
.rate .good { background: var(--good); color: var(--good-ink); }
.rate .meh { background: var(--surface-2); color: var(--meh); border-color: var(--line); }
.rate button:active { transform: translateY(1px); }

/* stack footer: ‹ dots › browse nav + gesture hint, below the stack.
   The buttons are the tap fallback — Safari's edge swipes (page back/forward)
   and scrolling compete with the sideways gesture. */
.stack-foot { text-align: center; }
.browse-nav { display: flex; align-items: center; justify-content: center; gap: 2px; margin: 6px 0 0; }
.browse-nav .dots, .browse-nav .dots-count { margin: 0; }
.nav-btn {
  background: none; border: none; color: var(--muted);
  font-size: 1.3rem; line-height: 1; padding: 8px 16px; border-radius: 10px;
}
.nav-btn:active { color: var(--accent); transform: translateY(1px); }
.dots { display: flex; justify-content: center; gap: 6px; margin: 12px 0 0; }
.dot {
  width: 6px; height: 6px; border-radius: 999px; background: var(--line);
  transition: width .15s ease, background .15s ease;
}
.dot.on { background: var(--accent); width: 16px; }
.dots-count { color: var(--muted); font-size: .74rem; margin: 12px 0 0; }
.swipe-hint { text-align: center; color: var(--muted); font-size: .74rem; margin: 10px 0 0; }

/* ============ Empty / all-caught-up ============ */
.empty {
  min-height: 60vh; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center; text-align: center; padding: 20px;
}
.empty .mark { font-size: 2.4rem; }
.empty h2 { margin: 0; font-size: 1.3rem; }
.empty p { margin: 0; color: var(--muted); }

/* ============ Archive ============ */
.list { list-style: none; margin: 14px 0 24px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li a, .row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px; border-radius: 14px; background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; color: var(--text);
}
.list .date { font-weight: 620; }
.list .meta { color: var(--muted); font-size: .82rem; }
.section-h { margin: 18px 2px 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.back {
  display: inline-flex; align-items: center; gap: 6px; margin: 14px 0 4px;
  background: none; border: none; color: var(--accent); font-weight: 600; padding: 6px 0;
}

/* read-only archived cards (static list, full face, no swipe) */
.ro-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 18px 14px; margin: 12px 0;
}
.ro-card.st-swiped { opacity: .72; }
.state-tag {
  float: right; font-size: .64rem; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px;
}

/* ============ Settings ============ */
.settings { margin: 14px 0 30px; display: flex; flex-direction: column; gap: 22px; }
.settings h2 { font-size: 1rem; margin: 0 0 4px; }
.settings .note { color: var(--muted); font-size: .85rem; margin: 0 0 8px; }
.radio-group { display: flex; flex-direction: column; gap: 2px; }
.radio {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.radio:first-of-type { border-radius: 12px 12px 0 0; }
.radio:last-of-type { border-radius: 0 0 12px 12px; }
.radio + .radio { border-top: none; }
.radio input { accent-color: var(--accent); width: 18px; height: 18px; }
.radio.sel { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.saved-note { color: var(--good); font-size: .82rem; min-height: 1em; margin: 4px 0 0; }
.ver { color: var(--muted); font-size: .74rem; margin-top: 8px; }

/* ============ Bottom tab bar ============ */
#tabbar {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  -webkit-backdrop-filter: saturate(1.2) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l); padding-right: var(--safe-r);
}
.tab {
  flex: 1 1 0; background: none; border: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px; height: var(--tab-h); color: var(--muted); font-size: .68rem;
}
.tab .tab-ico { font-size: 1.15rem; line-height: 1; }
.tab[aria-current="page"] { color: var(--accent); }

/* swipe-away helper class toggled by JS; pointer-events off so the card
   can't take taps mid-flight */
.card.leaving { transition: transform .28s ease-out, opacity .28s ease-out; pointer-events: none; }
.card.snapping { transition: transform .22s cubic-bezier(.2,.7,.3,1); }

@media (prefers-reduced-motion: reduce) {
  .card.leaving, .card.snapping { transition: none; }
}
