:root {
  --bg: #0c0d10;
  --panel: #16181e;
  --panel-2: #1c1f27;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f2f0ea;
  --muted: #9a9ba3;
  --accent: #f6821f;
  --accent-soft: rgba(246, 130, 31, 0.15);
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  background:
    radial-gradient(700px 380px at 50% -180px, rgba(246, 130, 31, 0.13), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Masthead ── */
.masthead {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.1rem 0;
  text-align: center;
}
.masthead-top {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.refresh {
  background: none; border: 1px solid var(--line); color: var(--muted);
  width: 34px; height: 34px; border-radius: 50%; font-size: 0.95rem; cursor: pointer;
  transition: transform 0.3s ease, color 0.2s, border-color 0.2s;
}
.refresh:hover { color: var(--text); border-color: var(--accent); }
.refresh:active { transform: rotate(180deg) scale(0.9); }
.refresh.spin { animation: spin 0.8s linear infinite; }
.wordmark { font-family: var(--serif); font-size: clamp(2.4rem, 12vw, 3.6rem); letter-spacing: -0.02em; margin-top: 0.3rem; }
.tagline { color: var(--muted); font-style: italic; font-family: var(--serif); font-size: 0.92rem; }

/* ── Topic chips ── */
.chips {
  position: sticky; top: 0; z-index: 20;
  background: rgba(12, 13, 16, 0.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: 0.6rem;
}
.chips-scroll {
  max-width: 1100px; margin: 0 auto;
  display: flex; gap: 0.5rem; overflow-x: auto;
  padding: 0.35rem 1.1rem 0.7rem; scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.9rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  font-size: 0.85rem; white-space: nowrap; user-select: none;
  transition: transform 0.15s ease, background 0.2s, color 0.2s, border-color 0.2s;
}
.chip:active { transform: scale(0.93); }
.chip.on { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
.chip .em { font-size: 0.95rem; }

/* ── Main ── */
main { max-width: 1100px; width: 100%; margin: 0 auto; padding: 1.4rem 1.1rem 3rem; flex: 1; }
.feed.dim { opacity: 0.4; transition: opacity 0.2s; pointer-events: none; }

.glance {
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.6rem;
  animation: rise 0.5s ease both;
}
.glance-label { font-size: 0.66rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.intro { font-family: var(--serif); font-size: 1.12rem; line-height: 1.5; margin-top: 0.4rem; }

/* ── Feed grid ── */
.feed { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 620px) { .feed { grid-template-columns: 1fr 1fr; } }
@media (min-width: 940px) { .feed { grid-template-columns: 1fr 1fr 1fr; } }

.cat-row { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 0.6rem; margin: 1.1rem 0 0.1rem; }
.cat-row h2 { font-family: var(--serif); font-size: 1.35rem; }
.cat-row .count { font-size: 0.66rem; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }

/* Card */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  animation: rise 0.5s ease both;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-4px); border-color: rgba(246, 130, 31, 0.55); box-shadow: 0 14px 30px rgba(0,0,0,0.4); }
.card:active { transform: scale(0.985); }
.card.featured { grid-column: 1 / -1; }

.thumb { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: var(--panel-2); }
.card.featured .thumb { aspect-ratio: 16 / 8; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.6s ease; }
.card:hover .thumb img { transform: scale(1.06); }
/* gradient placeholder when no image */
.thumb.ph { display: flex; align-items: center; justify-content: center; }
.thumb.ph.g0 { background: linear-gradient(135deg, #f6821f, #b23c00); }
.thumb.ph.g1 { background: linear-gradient(135deg, #2b6cff, #123a8a); }
.thumb.ph.g2 { background: linear-gradient(135deg, #12b981, #065f46); }
.thumb.ph.g3 { background: linear-gradient(135deg, #a855f7, #5b21b6); }
.thumb.ph span { font-family: var(--serif); font-size: 2.4rem; color: rgba(255,255,255,0.85); }

.card-body { padding: 0.9rem 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.card h3 { font-size: 1.02rem; line-height: 1.32; }
.card.featured h3 { font-size: 1.35rem; }
.card .blurb { color: var(--muted); font-size: 0.88rem; }
.card .meta { margin-top: auto; display: flex; gap: 0.5rem; align-items: center; font-size: 0.7rem; color: var(--muted); }

.badge { background: var(--accent-soft); color: var(--accent); padding: 0.15rem 0.55rem; border-radius: 999px; font-weight: 600; letter-spacing: 0.03em; font-size: 0.7rem; }
.badge.ghost { background: rgba(255,255,255,0.06); color: var(--muted); }

/* ── Loading / spinner ── */
.loading { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 3rem 0; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.error { grid-column: 1 / -1; background: var(--panel); border: 1px solid rgba(255,90,90,0.4); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: #ffb4b4; }

/* ── Overlay / sheet ── */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; visibility: hidden; }
.overlay.open { visibility: visible; }
.overlay-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); opacity: 0; backdrop-filter: blur(3px); transition: opacity 0.3s ease; }
.overlay.open .overlay-backdrop { opacity: 1; }

.sheet {
  position: relative; z-index: 1; width: 100%; max-width: 760px;
  max-height: 94dvh; background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(100%); transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.overlay.open .sheet { transform: translateY(0); }
.sheet-grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 0.6rem auto 0; flex: none; }
.sheet-close { position: absolute; top: 0.7rem; right: 0.8rem; z-index: 3; width: 34px; height: 34px; border-radius: 50%; border: none; background: rgba(0,0,0,0.5); color: #fff; font-size: 0.85rem; cursor: pointer; }

.nav { position: absolute; top: 40%; z-index: 3; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: rgba(0,0,0,0.55); color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer; display: none; transition: background 0.2s, transform 0.2s; }
.nav:hover { background: var(--accent); }
.nav:active { transform: scale(0.9); }
.nav.prev { left: 0.6rem; } .nav.next { right: 0.6rem; }
@media (min-width: 720px) { .nav { display: block; } }

.sheet-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.hero { position: relative; aspect-ratio: 16 / 9; background: var(--panel-2); overflow: hidden; }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.hero.ph { display: flex; align-items: center; justify-content: center; }
.hero.ph span { font-family: var(--serif); font-size: 3.5rem; color: rgba(255,255,255,0.85); }

.sheet-body { padding: 1.1rem 1.3rem 1.5rem; }
.sheet-meta { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.sheet-meta .time { font-size: 0.72rem; color: var(--muted); }
.sheet-title { font-family: var(--serif); font-size: 1.5rem; line-height: 1.25; margin: 0.7rem 0 0.9rem; }

/* content crossfade on swap */
.detail { animation: fade 0.3s ease both; }
.detail .summary { font-size: 1rem; line-height: 1.65; }
.detail h4 { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin: 1.1rem 0 0.5rem; }
.detail ul { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.detail li { position: relative; padding-left: 1.1rem; color: var(--text); font-size: 0.94rem; }
.detail li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }
.detail .why { margin-top: 1rem; padding: 0.8rem 1rem; background: var(--accent-soft); border-radius: 12px; font-size: 0.94rem; }

.read-btn { display: inline-block; margin-top: 1.3rem; text-decoration: none; color: #1a1205; font-weight: 700; padding: 0.7rem 1.3rem; border-radius: 12px; background: linear-gradient(90deg, var(--accent), #faae40); transition: transform 0.15s ease; }
.read-btn:active { transform: scale(0.96); }

/* skeleton shimmer */
.sk { border-radius: 8px; background: linear-gradient(90deg, var(--panel-2) 25%, #262a33 37%, var(--panel-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; }
.sk.line { height: 0.85rem; margin: 0.5rem 0; }
.sk.w80 { width: 80%; } .sk.w60 { width: 60%; } .sk.w90 { width: 90%; }

/* thumbnail rail */
.rail { display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.6rem 0.8rem calc(0.7rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex: none; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail-item { flex: none; width: 56px; height: 40px; border-radius: 8px; overflow: hidden; cursor: pointer; opacity: 0.55; border: 2px solid transparent; transition: opacity 0.2s, border-color 0.2s; background: var(--panel-2); }
.rail-item:hover { opacity: 0.85; }
.rail-item.active { opacity: 1; border-color: var(--accent); }
.rail-item img { width: 100%; height: 100%; object-fit: cover; }
.rail-item.ph { display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,0.8); font-family: var(--serif); }

/* ── Footer ── */
footer { border-top: 1px solid var(--line); padding: 1rem; text-align: center; color: var(--muted); font-size: 0.78rem; display: flex; justify-content: center; gap: 0.5rem; }
.dot { opacity: 0.5; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -400% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
