/* ============================================================
   Learning Log — EDITORIAL (Magazine × Swiss)

   COLOR THEMES ARE DATA. They live in data/themes.json and are injected as
   `html[data-theme="<id>"] { --token: … }` rules at runtime by src/ui/themes.js.
   The single `html[data-theme="press"]` block below is only a no-JS / first-paint
   FALLBACK — the canonical, editable source of every theme is data/themes.json.
   ============================================================ */

:root {
  --font-serif: "Instrument Serif", Georgia, serif;
  --font-cond: "Archivo", system-ui, sans-serif;     /* heavy condensed-ish */
  --font-body: "Schibsted Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --content-max: 1080px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* No-JS / first-paint fallback: default theme tokens (mirrors data/themes.json
   "press"). When JS runs, src/ui/themes.js injects all themes and overrides this. */
html[data-theme="press"] {
  --bg: #f6f3ea;
  --surface: #fffdf7;
  --surface-2: #efe9da;
  --ink: #1c1813;
  --muted: #6b6358;
  --faint: #a89e8d;
  --line: #e0d9c9;
  --rule: #cdc4b1;
  --accent: #b23a20;
  --accent-ink: #fffdf7;
  --st-learning: #c2410c;
  --st-done: #15803d;
  --st-planned: #9a9488;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
::selection { background: var(--accent); color: var(--accent-ink); }
a { color: inherit; text-decoration: none; }

/* paper grain / texture via subtle gradient (press + ink) */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(1200px 700px at 100% -5%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 55%);
}
html[data-theme="mono"] body::before { background: none; }

/* ============================================================
   Masthead
   ============================================================ */
.masthead {
  position: sticky; top: 0; z-index: 40;
  background: var(--bg);
  border-bottom: 1.5px solid var(--rule);
}
.mast-row {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 18px clamp(20px, 5vw, 56px);
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.monogram {
  width: 44px; height: 44px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 17px;
  letter-spacing: -1px; flex: none;
  transition: transform 0.5s var(--ease-out);
}
.monogram:hover { transform: rotate(-6deg); }
html[data-theme="mono"] .monogram { background: var(--accent); }
.brand-text .handle { font-family: var(--font-mono); font-size: 14px; font-weight: 600; letter-spacing: -0.3px; }
.brand-text .role { font-size: 12px; color: var(--muted); }

.nav { margin-left: auto; display: flex; gap: 4px; }
.nav a {
  position: relative;
  display: flex; align-items: baseline; gap: 7px;
  padding: 9px 14px;
  font-family: var(--font-body);
  font-size: 14.5px; font-weight: 500; letter-spacing: -0.2px;
  color: var(--muted);
  transition: color 0.25s var(--ease);
}
.nav a .idx { font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); transition: color 0.25s var(--ease); }
.nav a::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 4px;
  height: 1.5px; background: var(--accent);
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.32s var(--ease-out);
}
.nav a:hover { color: var(--ink); }
.nav a:hover .idx { color: var(--accent); }
.nav a.active { color: var(--ink); }
.nav a.active .idx { color: var(--accent); }
.nav a.active::after { transform: scaleX(1); }

.mast-tools { display: flex; align-items: center; gap: 16px; }
.themes { display: flex; gap: 8px; }
.theme-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--rule); cursor: pointer; position: relative;
  transition: transform 0.3s var(--ease-out);
}
.theme-dot:hover { transform: scale(1.12); }
/* Preview background + inner accent ring are set inline from data/themes.json. */
.theme-dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 1.5px solid var(--accent); opacity: 0; transform: scale(0.7);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease-out);
}
.theme-dot.on::after { opacity: 1; transform: scale(1); }

/* dateline strip */
.dateline {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.dateline-inner {
  max-width: var(--content-max); margin: 0 auto;
  padding: 8px clamp(20px, 5vw, 56px);
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.5px;
  color: var(--muted); text-transform: uppercase;
}
.dateline .tagline { color: var(--muted); text-transform: none; font-size: 11.5px; letter-spacing: 0.3px; }
.dateline .tagline .blink {
  display: inline-block; width: 7px; height: 12px; background: var(--accent);
  margin-left: 2px; transform: translateY(1px); animation: blink 1.1s steps(2) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
.dateline .socials { display: flex; gap: 16px; }
.dateline .socials a { color: var(--muted); transition: color 0.25s var(--ease); }
.dateline .socials a:hover { color: var(--accent); }

/* ============================================================
   Main / sections
   ============================================================ */
.main { position: relative; z-index: 1; }
.section {
  display: none;
  max-width: var(--content-max); margin: 0 auto;
  padding: 60px clamp(20px, 5vw, 56px) 120px;
}
.section.show { display: block; }

.sec-head {
  display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 24px;
  padding-bottom: 30px; margin-bottom: 54px;
  border-bottom: 2px solid var(--rule);
}
.eyebrow {
  font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px;
  display: flex; align-items: center; gap: 9px;
}
.eyebrow::before { content: ""; width: 22px; height: 1.5px; background: var(--accent); }
.h1 {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(46px, 7.5vw, 82px); line-height: 0.98; letter-spacing: -0.015em;
  padding-bottom: 0.1em;
}
.h1 em { font-style: italic; color: var(--accent); }
.sec-head .lead {
  font-size: 15.5px; color: var(--muted); max-width: 300px; text-align: right;
  text-wrap: pretty; padding-bottom: 6px;
}

/* reveal */
.reveal { opacity: 1; transform: none; }
@keyframes revIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.section.animate .reveal { animation: revIn 0.7s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 55ms); }
@media (prefers-reduced-motion: reduce) { .section.animate .reveal { animation: none; } }

/* ============================================================
   Learning
   ============================================================ */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 52px; }
.filter {
  font-family: var(--font-mono); font-size: 12px;
  padding: 8px 15px; border: 1px solid var(--rule); border-radius: 0;
  color: var(--muted); cursor: pointer; background: transparent;
  display: flex; align-items: center; gap: 8px;
  transition: all 0.25s var(--ease);
}
.filter:hover { color: var(--ink); border-color: var(--ink); }
.filter.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filter .cnt { opacity: 0.65; font-size: 11px; }

.cat { margin-bottom: 54px; }
.cat-head {
  display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 18px;
  padding-bottom: 12px; margin-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.cat-head .cat-num { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.cat-head h2 {
  font-family: var(--font-cond); font-weight: 800;
  font-size: 26px; letter-spacing: -0.01em; text-transform: uppercase;
  white-space: nowrap;
}
.cat-head .cat-bar { height: 2px; background: var(--surface-2); position: relative; overflow: hidden; min-width: 30px; }
.cat-head .cat-bar > i {
  position: absolute; inset: 0 auto 0 0; background: var(--accent);
  transform-origin: left; transform: scaleX(0);
  transition: transform 1s var(--ease-out);
}
.section.animate .cat.reveal .cat-bar > i { transition-delay: 0.35s; }
.cat-head .cat-meta { font-family: var(--font-mono); font-size: 11px; color: var(--faint); white-space: nowrap; }

.topics { display: flex; flex-direction: column; }
.topic {
  display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 16px;
  padding: 14px 8px;
  border-bottom: 1px solid var(--line);
  transition: background 0.25s var(--ease), padding-left 0.25s var(--ease);
}
.topic:hover { background: var(--surface); padding-left: 16px; }
.topic.hidden { display: none; }
.topic .t-name { font-family: var(--font-cond); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.topic .t-note { font-size: 13.5px; color: var(--muted); justify-self: start; }
.t-status {
  justify-self: end;
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--faint);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; position: relative; }
.t-status.learning { color: var(--st-learning); } .t-status.learning .status-dot { background: var(--st-learning); }
.t-status.done { color: var(--st-done); } .t-status.done .status-dot { background: var(--st-done); }
.t-status.planned .status-dot { background: transparent; border: 1.5px dashed var(--st-planned); }
.t-status.learning .status-dot::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: var(--st-learning); opacity: 0.35; animation: pulse 1.9s var(--ease) infinite;
}
@keyframes pulse { 0% { transform: scale(0.7); opacity: 0.4; } 70% { transform: scale(2.4); opacity: 0; } 100% { opacity: 0; } }

/* ============================================================
   Projects
   ============================================================ */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0; border-top: 1px solid var(--line); }
.card {
  position: relative; display: flex; flex-direction: column;
  padding: 30px; min-height: 210px;
  border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  background: transparent;
  transition: background 0.3s var(--ease);
}
.card:nth-child(2n) { border-right: none; }
.card:hover { background: var(--surface); }
.card .c-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.card .c-tag { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--accent); }
.card .c-arrow {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule);
  display: grid; place-items: center; font-size: 14px;
  transition: transform 0.4s var(--ease-out), background 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease);
}
.card:hover .c-arrow { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); transform: rotate(-45deg); }
.card h3 { font-family: var(--font-serif); font-weight: 400; font-size: 30px; letter-spacing: -0.01em; margin-bottom: 8px; }
.card p { font-size: 14.5px; color: var(--muted); margin-bottom: 18px; text-wrap: pretty; }
.card .c-stack { margin-top: auto; display: flex; flex-wrap: wrap; gap: 7px; }
.chip { font-family: var(--font-mono); font-size: 11px; padding: 4px 10px; border: 1px solid var(--line); color: var(--muted); }

.card.feat { grid-column: 1 / -1; flex-direction: row; align-items: stretch; gap: 40px; min-height: 240px; border-right: none; }
.card.feat .feat-main { flex: 1; display: flex; flex-direction: column; }
.card.feat h3 { font-size: 48px; line-height: 1; margin-bottom: 14px; }
.card.feat p { font-size: 16px; max-width: 48ch; }
.card.feat .feat-side {
  width: 200px; flex: none; border-left: 1px solid var(--rule); padding-left: 30px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.card.feat .feat-side .c-arrow { margin-left: auto; }

/* ============================================================
   Writing
   ============================================================ */
.posts { border-top: 2px solid var(--rule); }
.post {
  display: grid; grid-template-columns: 120px 1fr auto; gap: 28px; align-items: baseline;
  padding: 28px 8px; border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background 0.3s var(--ease), padding 0.35s var(--ease);
}
.post:hover { background: var(--surface); padding-left: 18px; padding-right: 18px; }
.post .p-date { font-family: var(--font-mono); font-size: 12px; color: var(--accent); letter-spacing: 0.5px; }
.post .p-title { font-family: var(--font-serif); font-weight: 400; font-size: 28px; line-height: 1.1; letter-spacing: -0.01em; transition: color 0.25s var(--ease); }
.post:hover .p-title { color: var(--accent); }
.post .p-sub { font-size: 14.5px; color: var(--muted); margin-top: 6px; text-wrap: pretty; }
.post .p-read { font-family: var(--font-mono); font-size: 11px; color: var(--faint); white-space: nowrap; }

/* reader */
.reader { position: fixed; inset: 0; background: var(--bg); z-index: 80; overflow-y: auto; opacity: 0; pointer-events: none; transition: opacity 0.4s var(--ease); }
.reader.open { opacity: 1; pointer-events: auto; }
.reader-inner { max-width: 660px; margin: 0 auto; padding: 80px 28px 140px; transform: translateY(16px); transition: transform 0.5s var(--ease-out); }
.reader.open .reader-inner { transform: none; }
.reader-back {
  font-family: var(--font-mono); font-size: 13px; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 40px;
  transition: color 0.25s var(--ease), gap 0.25s var(--ease);
}
.reader-back:hover { color: var(--accent); gap: 12px; }
.reader h1 { font-family: var(--font-serif); font-weight: 400; font-size: clamp(38px, 6vw, 60px); line-height: 1.02; letter-spacing: -0.015em; margin: 14px 0 14px; }
.reader .r-meta { font-family: var(--font-mono); font-size: 12px; color: var(--accent); letter-spacing: 0.5px; margin-bottom: 44px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.reader article p { font-size: 18.5px; line-height: 1.75; margin-bottom: 24px; }
.reader article h2 { font-family: var(--font-cond); font-weight: 700; font-size: 24px; text-transform: uppercase; letter-spacing: -0.01em; margin: 46px 0 16px; }
.reader article blockquote { border-left: 2px solid var(--accent); padding-left: 24px; margin: 30px 0; font-family: var(--font-serif); font-style: italic; font-size: 26px; line-height: 1.3; color: var(--ink); }
.reader article code { font-family: var(--font-mono); font-size: 14px; background: var(--surface-2); padding: 2px 7px; }

/* ============================================================
   About
   ============================================================ */
.about-grid { max-width: 680px; border-top: 2px solid var(--rule); }
.stat-row { display: grid; grid-template-columns: 170px 1fr; gap: 24px; align-items: baseline; padding: 22px 8px; border-bottom: 1px solid var(--line); }
.stat-row .k { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--faint); }
.stat-row .v { font-size: 17px; }
.stat-row .v em { font-family: var(--font-serif); font-style: italic; font-size: 20px; color: var(--accent); }

/* ============================================================
   Mobile
   ============================================================ */
.menu-btn { display: none; }
@media (max-width: 820px) {
  .nav {
    position: fixed; inset: 0 0 auto auto; top: 0; right: 0;
    width: 80%; max-width: 300px; height: 100vh;
    flex-direction: column; gap: 2px; margin-left: 0;
    background: var(--surface); border-left: 1.5px solid var(--rule);
    padding: 80px 24px 24px; z-index: 60;
    transform: translateX(100%); transition: transform 0.4s var(--ease-out);
  }
  .nav.open { transform: none; }
  .nav a { font-size: 20px; font-family: var(--font-serif); padding: 12px 0; }
  .nav a::after { display: none; }
  .menu-btn {
    display: grid; place-items: center; position: fixed; top: 14px; right: 16px; z-index: 70;
    width: 42px; height: 42px; background: var(--ink); color: var(--bg); border: none; cursor: pointer; font-size: 16px;
  }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 59; opacity: 0; pointer-events: none; transition: opacity 0.35s var(--ease); }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .sec-head { grid-template-columns: 1fr; }
  .sec-head .lead { text-align: left; max-width: none; }
  .grid { grid-template-columns: 1fr; }
  .card { border-right: none !important; }
  .card.feat { flex-direction: column; gap: 24px; }
  .card.feat .feat-side { width: auto; border-left: none; border-top: 1px solid var(--rule); padding-left: 0; padding-top: 20px; flex-direction: row; align-items: center; }
  .card.feat .feat-side .c-arrow { margin-left: 0; order: 2; }
  .post { grid-template-columns: 1fr; gap: 8px; }
  .stat-row { grid-template-columns: 1fr; gap: 6px; }
  .article-page { padding-top: 8px; }
}

/* ============================================================
   Article page (per-post, server-rendered at /writing/<slug>)
   ============================================================ */
.article-page { max-width: 680px; margin: 0 auto; padding: 24px 0 80px; }
.reader-back {
  font-family: var(--font-mono); font-size: 13px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 8px;
  transition: color 0.25s var(--ease), gap 0.25s var(--ease);
}
.reader-back:hover { color: var(--accent); gap: 12px; }
.reader-back.bottom { margin-top: 48px; }
.article-page > h1 {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(38px, 6vw, 60px); line-height: 1.02; letter-spacing: -0.015em;
  margin: 22px 0 14px;
}
.article-page .r-meta {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent);
  letter-spacing: 0.5px; margin-bottom: 44px; padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.article-body p { font-size: 18.5px; line-height: 1.75; margin-bottom: 24px; }
.article-body h2 {
  font-family: var(--font-cond); font-weight: 700; font-size: 24px;
  text-transform: uppercase; letter-spacing: -0.01em; margin: 46px 0 16px;
}
.article-body blockquote {
  border-left: 2px solid var(--accent); padding-left: 24px; margin: 30px 0;
  font-family: var(--font-serif); font-style: italic; font-size: 26px;
  line-height: 1.3; color: var(--ink);
}
.article-body code { font-family: var(--font-mono); font-size: 14px; background: var(--surface-2); padding: 2px 7px; }
