/* Every colour token holds light-dark(light, dark). Dark uses the GitHub Dark Dimmed palette. */
:root {
  --d-bg: #22272e; --d-bg-2: #1c2128; --d-surface: #2d333b; --d-surface-2: #323942;
  --d-ink: #cdd9e5; --d-ink-2: #adbac7; --d-muted: #768390; --d-rule: #444c56;
  --d-wash: #3a2f26; --d-edge: rgb(205 217 229 / 0.07);
}
:root {
  color-scheme: light dark;

  --bg: light-dark(#f6f6f4, var(--d-bg));
  --bg-2: light-dark(#efefec, var(--d-bg-2));
  --surface: light-dark(#ffffff, var(--d-surface));
  --surface-2: light-dark(#fffaf6, var(--d-surface-2));
  --ink: light-dark(#17181b, var(--d-ink));
  --ink-2: light-dark(#3f4247, var(--d-ink-2));
  --muted: light-dark(#73767c, var(--d-muted));
  --rule: light-dark(#e3e1dc, var(--d-rule));
  --accent: light-dark(#ff6600, #ff7a1f);
  --accent-2: light-dark(#ffb27a, #ffb27a);
  --accent-ink: light-dark(#b34700, #ffa264);
  --on-accent: #ffffff;
  --wash: light-dark(#fff0e5, var(--d-wash));
  --glass: light-dark(rgb(255 255 255 / 0.62), color-mix(in srgb, var(--d-surface) 60%, transparent));
  --glass-edge: light-dark(rgb(255 255 255 / 0.8), rgb(255 255 255 / 0.08));
  --shadow: 0 1px 2px light-dark(rgb(23 24 27 / 0.05), rgb(0 0 0 / 0.4)), 0 10px 30px -8px light-dark(rgb(23 24 27 / 0.10), rgb(0 0 0 / 0.5));
  --shadow-hi: 0 2px 4px light-dark(rgb(23 24 27 / 0.06), rgb(0 0 0 / 0.45)), 0 24px 46px -18px light-dark(rgb(255 102 0 / 0.30), rgb(0 0 0 / 0.75)), 0 10px 22px -12px light-dark(rgb(23 24 27 / 0.14), rgb(255 122 31 / 0.10));

  --radius: 18px;
  --card-border: light-dark(rgb(23 24 27 / 0.06), var(--d-edge));
  --card-blur: 0px;
  --gap: 14px;

  --display: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
  --read: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --num: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --title-size: 1.3rem;
  --title-weight: 700;
  --title-lh: 1.25;
  --title-track: -0.02em;
  --title-style: normal;
  --read-size: 1.02rem;
  --read-lh: 1.62;
  --read-ws: 0.06em;
  --read-ls: 0.004em;
  --read-weight: 420;

  --sheen: 0.6;
  --lift: -3px;
  --rail-w: 280px;
  --ease-spring: cubic-bezier(.2, .9, .25, 1.15);
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 400 0.95rem/1.5 var(--read);
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s ease, color .4s ease;
}

button { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Brand mark: a little extruded 3D tile ---------- */
.mark {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, var(--accent-2), var(--accent) 55%, color-mix(in oklab, var(--accent), #000 18%));
  box-shadow:
    inset 0 1.5px 0 rgb(255 255 255 / 0.45),
    inset 0 -2px 0 rgb(0 0 0 / 0.18),
    0 3px 0 color-mix(in oklab, var(--accent), #000 35%),
    0 8px 18px -4px color-mix(in oklab, var(--accent), transparent 40%);
  transform: rotate(-6deg);
  transition: transform .5s var(--ease-spring);
}
.brand:hover .mark { transform: rotate(6deg) scale(1.06); }
.mark svg { width: 58%; height: 58%; fill: #fff; filter: drop-shadow(0 1px 0 rgb(0 0 0 / 0.2)); }
.mark-lg { width: 64px; height: 64px; border-radius: 18px; }

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 22px;
  padding: 26px 20px 20px 24px;
  background: color-mix(in oklab, var(--bg-2), transparent 30%);
  backdrop-filter: blur(18px) saturate(1.2);
  border-right: 1px solid var(--rule);
}

.rail-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.wordmark { font: 700 1.25rem/1 var(--display); letter-spacing: -0.02em; }

/* Theme toggle: a sun that sets into a moon; half-and-half means "match my device". */
.theme-toggle {
  width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--surface);
  color: var(--ink); cursor: pointer; box-shadow: var(--shadow);
  transition: transform .4s var(--ease-spring), background-color .3s;
}
.theme-toggle:hover { transform: rotate(-12deg) scale(1.06); }
.theme-toggle:active { transform: scale(.92); }
.theme-toggle svg { width: 22px; height: 22px; overflow: visible; }
.theme-toggle .core { fill: currentColor; transition: transform .5s var(--ease-spring); transform-origin: center; }
.theme-toggle .cut { transition: transform .5s var(--ease-spring); transform: translate(8px, -8px); }
.theme-toggle .rays path { stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; fill: none; }
.theme-toggle .rays { transform-origin: 12px 12px; transition: transform .5s var(--ease-spring), opacity .3s; }
.theme-toggle .half { fill: var(--surface); stroke: currentColor; stroke-width: 0; opacity: 0; transition: opacity .3s; }
.theme-toggle[data-mode='light'] { color: #f59e0b; }
.theme-toggle[data-mode='dark'] { color: #a5b4fc; }
.theme-toggle[data-mode='dark'] .cut { transform: none; }
.theme-toggle[data-mode='dark'] .core { transform: scale(1.35); }
.theme-toggle[data-mode='dark'] .rays { transform: rotate(-90deg) scale(.4); opacity: 0; }
.theme-toggle[data-mode='system'] .rays { transform: rotate(45deg) scale(.75); opacity: .5; }
.theme-toggle[data-mode='system'] .half { opacity: 1; }
.theme-toggle[data-mode='system'] .core { stroke: currentColor; stroke-width: 1.6; }

.refresh {
  margin: -8px 0 0; display: flex; align-items: center; gap: 8px;
  font: 500 0.74rem/1.3 var(--num); color: var(--muted); letter-spacing: 0.01em;
}
.live { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgb(34 197 94 / 0.6); animation: pulse 2.4s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgb(34 197 94 / 0); } 100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); } }

.sync {
  display: flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none;
  font-size: 0.8rem; color: var(--muted); text-align: left; cursor: pointer; margin-top: -8px;
}
.sync u { color: var(--accent-ink); text-underline-offset: 3px; }
.sync-dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--muted); vertical-align: 1px; }
.sync-dot.ok { background: #22c55e; }

.rail-label {
  margin: 0 0 10px; font: 600 0.7rem/1 var(--num); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}
.topics { display: flex; flex-direction: column; gap: 2px; }
.topic {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 12px; background: none;
  font-size: 0.9rem; text-align: left; cursor: pointer; color: var(--ink-2);
  transition: background-color .2s, transform .25s var(--ease-spring), color .2s;
}
.topic:hover { background: var(--surface); transform: translateX(3px); color: var(--ink); }
.topic[aria-pressed='true'] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px light-dark(rgb(23 24 27 / 0.06), rgb(0 0 0 / 0.4)), 0 10px 22px -10px light-dark(rgb(255 102 0 / 0.45), rgb(255 122 31 / 0.25)); }
.topic:hover { box-shadow: 0 8px 18px -12px light-dark(rgb(23 24 27 / 0.35), rgb(0 0 0 / 0.8)); }
.topic .emoji { font-size: 1.05rem; filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.15)); transition: transform .3s var(--ease-spring); }
.topic:hover .emoji { transform: scale(1.25) rotate(-8deg); }
.topic .n { margin-left: auto; font: 500 0.74rem/1 var(--num); color: var(--muted); }
/* Archive sits at the foot of the sidebar, apart from the topics */
.archive-tab { margin-top: auto; flex: none; padding-top: 10px; padding-bottom: 10px; border-top: 1px solid var(--rule); border-radius: 0 0 12px 12px; }
.archive-tab[aria-pressed='true'] { border-radius: 12px; border-top-color: transparent; }

/* ---------- Feed ---------- */
.feed {
  width: 100%; max-width: 920px; margin: 0 auto;
  padding: 44px max(28px, env(safe-area-inset-right, 0px)) 120px max(28px, env(safe-area-inset-left, 0px));
}
.feed-head { margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; font: 600 0.72rem/1 var(--num); letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-ink); }
.feed-head h1 {
  margin: 0; font: 600 clamp(1.6rem, 3vw, 2.1rem)/1.15 var(--display);
  letter-spacing: -0.02em; text-wrap: balance; color: var(--ink);
}
.feed-head p:last-child { margin: 10px 0 0; color: var(--muted); max-width: 60ch; }

.stories { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--gap); }

.story {
  --mx: 50%; --my: 50%;
  position: relative; isolation: isolate;
  display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 4px 20px;
  padding: 22px 24px 18px 18px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(var(--card-blur)) saturate(1.3);
  transition: transform .35s cubic-bezier(.2, .8, .3, 1), box-shadow .35s ease, background-color .35s, border-color .3s;
  overflow: hidden;
}
.story:hover { box-shadow: var(--shadow-hi); transform: translateY(var(--lift)); }
.sheen {
  position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: 0;
  background: radial-gradient(420px circle at var(--mx) var(--my), light-dark(rgb(255 255 255 / 0.9), rgb(255 255 255 / 0.10)), transparent 60%);
  transition: opacity .3s;
}
.story:hover .sheen { opacity: var(--sheen); }

.stories.intro .story { animation: rise .6s cubic-bezier(.2, .8, .3, 1) backwards; animation-delay: calc(var(--i) * 45ms); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } }

.score { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding-top: 3px; }
.rank { font: 600 0.68rem/1 var(--num); color: var(--muted); letter-spacing: 0.06em; margin-bottom: 6px; }
.pts { font: 650 1.22rem/1 var(--num); color: var(--accent-ink); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.pts-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.meter { display: block; width: 100%; height: 4px; margin-top: 8px; border-radius: 4px; background: var(--rule); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transform-origin: left; animation: grow 1s var(--ease-spring) both; animation-delay: calc(var(--i) * 45ms + 150ms); }
@keyframes grow { from { transform: scaleX(0); } }

.story-body { min-width: 0; }
.kicker {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin: 0 0 6px;
  font: 500 0.76rem/1.3 var(--num); color: var(--muted); letter-spacing: 0.01em;
}
.kicker > * + *::before { content: '·'; display: inline-block; margin: 0 8px; opacity: 0.6; }
.kicker .domain { color: var(--ink-2); }
.author { text-decoration: underline 1px transparent; text-underline-offset: 3px; transition: color .2s, text-decoration-color .2s; }
.author:hover { color: var(--accent-ink); text-decoration-color: currentColor; }

.title {
  margin: 0; font-family: var(--display); font-size: var(--title-size); font-weight: var(--title-weight);
  font-style: var(--title-style); line-height: var(--title-lh); letter-spacing: var(--title-track); text-wrap: balance;
}
.title a { text-decoration: none; background: linear-gradient(var(--accent), var(--accent)) 0 100% / 0 2px no-repeat; transition: background-size .35s ease; }
.title a:hover { background-size: 100% 2px; }
.title a:visited { color: var(--ink-2); }
.lead .title { font-size: calc(var(--title-size) * 1.35); }

.summary {
  margin: 10px 0 0; max-width: 66ch;
  font-family: var(--read); font-size: var(--read-size); font-weight: var(--read-weight);
  line-height: var(--read-lh); word-spacing: var(--read-ws); letter-spacing: var(--read-ls);
  color: var(--ink-2); text-wrap: pretty;
}
.lead .summary { font-size: calc(var(--read-size) * 1.06); }
.summary.pending { color: var(--muted); font-style: italic; }
.note { color: var(--muted); font-size: 0.85em; }

.thread {
  display: flex; gap: 10px; align-items: baseline; margin-top: 12px; padding: 10px 14px;
  border-radius: calc(var(--radius) * 0.6); background: var(--wash);
}
.thread-label { flex: none; font: 600 0.66rem/1.6 var(--num); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-ink); }
.thread p { margin: 0; font-size: 0.92rem; line-height: 1.55; word-spacing: var(--read-ws); color: var(--ink-2); }

.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.action {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 9px;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--surface);
  font-size: 0.82rem; font-weight: 600; cursor: pointer; color: var(--ink-2);
  transition: transform .3s var(--ease-spring), background-color .2s, color .2s, border-color .2s, box-shadow .2s;
}
.action svg { width: 16px; height: 16px; transition: transform .35s var(--ease-spring); }
.action:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); transform: translateY(-1px); box-shadow: 0 6px 16px -6px var(--accent); }
.action:hover svg { transform: translateY(1px) rotate(-8deg); }
.action:active { transform: scale(.94); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600;
  color: light-dark(hsl(var(--hue) 60% 32%), hsl(var(--hue) 80% 78%));
  background: light-dark(hsl(var(--hue) 90% 95%), hsl(var(--hue) 40% 18% / 0.8));
}
.tag .emoji { font-size: 0.85rem; }
.comments {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  font: 500 0.78rem/1 var(--num); color: var(--muted); text-decoration: none; transition: color .2s;
}
.comments svg { width: 16px; height: 16px; }
.comments:hover { color: var(--accent-ink); }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 72px 20px; text-align: center;
  background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--rule);
}
.empty-art { font-size: 3rem; animation: bob 2.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(6deg); } }
.empty strong { font: 700 1.5rem/1.2 var(--display); }
.empty span:last-child { color: var(--muted); }

.colophon { margin-top: 40px; font-size: 0.8rem; color: var(--muted); }

/* ---------- Glass surfaces: toast and welcome ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  display: flex; align-items: center; gap: 16px; padding: 10px 10px 10px 18px; overflow: hidden;
  border-radius: 999px; background: var(--glass); color: var(--ink);
  border: 1px solid var(--glass-edge);
  backdrop-filter: blur(20px) saturate(1.6); -webkit-backdrop-filter: blur(20px) saturate(1.6);
  box-shadow: var(--shadow-hi); font-size: 0.9rem; font-weight: 500;
  transform: translate(-50%, 140%) scale(.9); opacity: 0;
  transition: transform .45s var(--ease-spring), opacity .25s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 2px; width: 100%;
  background: var(--accent); transform-origin: left; transform: scaleX(0);
}
.toast.show::after { animation: countdown 3s linear forwards; }
@keyframes countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.toast button {
  padding: 6px 14px; border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-weight: 700; cursor: pointer; transition: transform .25s var(--ease-spring);
}
.toast button:hover { transform: scale(1.06); }


.welcome { border: 0; padding: 0; background: none; color: var(--ink); max-width: calc(100vw - 32px); }
.welcome::backdrop { background: light-dark(rgb(20 20 25 / 0.25), rgb(0 0 0 / 0.55)); backdrop-filter: blur(6px); }
.welcome[open] .welcome-card { animation: pop .5s var(--ease-spring); }
.welcome-card {
  width: min(420px, calc(100vw - 32px)); display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 32px 28px 22px; border-radius: 28px; text-align: center;
  background: var(--glass); border: 1px solid var(--glass-edge);
  backdrop-filter: blur(26px) saturate(1.6); -webkit-backdrop-filter: blur(26px) saturate(1.6);
  box-shadow: var(--shadow-hi);
}
.welcome-card h2 { margin: 8px 0 0; font: 650 1.6rem/1.15 var(--display); letter-spacing: -0.02em; }
.welcome-card > p { margin: 0; color: var(--ink-2); line-height: 1.55; word-spacing: var(--read-ws); }
.segmented { display: flex; padding: 4px; margin-top: 6px; border-radius: 999px; background: var(--bg-2); width: 100%; }
.segmented button { flex: 1; padding: 8px; border: 0; border-radius: 999px; background: none; font-weight: 600; cursor: pointer; color: var(--muted); transition: background-color .25s, color .25s, box-shadow .25s; }
.segmented button[aria-selected='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.welcome-card input {
  width: 100%; padding: 13px 16px; border: 1px solid var(--rule); border-radius: 14px;
  background: var(--surface); color: var(--ink); font: 500 1rem var(--read); text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
.welcome-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent), transparent 80%); }
.primary {
  width: 100%; padding: 13px; border: 0; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent-2), var(--accent) 60%); color: var(--on-accent);
  font-weight: 700; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35), 0 10px 24px -10px var(--accent);
  transition: transform .3s var(--ease-spring), filter .2s;
}
.primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.primary:disabled { opacity: .6; cursor: progress; }
.welcome-error { min-height: 1.2em; margin: 0; font-size: 0.85rem; color: light-dark(#c2410c, #fb923c); }
.link { border: 0; background: none; color: var(--muted); font-size: 0.85rem; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* View transition for theme swaps */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .45s; }

/* ---------- Phones and narrow windows ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: static; height: auto; overflow: visible; gap: 14px; min-width: 0;
    padding: 18px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
    border-right: 0; border-bottom: 1px solid var(--rule);
  }
  .refresh { margin: 0; }
  .sync { margin-top: 0; }
  .rail-label { display: none; }
  .topics { flex-direction: row; overflow-x: auto; gap: 6px; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
  .topic { width: auto; flex: none; border: 1px solid var(--rule); border-radius: 999px; padding: 6px 12px; }
  .topic:hover { transform: none; }
  .archive-tab { margin-top: 0; width: auto; align-self: flex-start; border: 1px solid var(--rule); border-radius: 999px; padding: 6px 12px; }
  .feed { padding: 22px max(16px, env(safe-area-inset-right, 0px)) 120px max(16px, env(safe-area-inset-left, 0px)); }
  .story { grid-template-columns: 1fr; padding: 18px 18px 16px; }
  .score { flex-direction: row; align-items: baseline; gap: 6px; }
  .rank { margin: 0 6px 0 0; }
  .meter { display: none; }
}
@media (max-width: 480px) {
  .comments-word { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
