/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #fbfbf9;
  --surface: #ffffff;
  --surface-2: #f3f3f0;
  --line: #e4e3de;
  --line-soft: #eeede9;
  --text: #19191b;
  --text-2: #36373b;
  --muted: #73757b;
  --accent: #2f5bd3;
  --accent-soft: #e9effc;
  --dot: rgba(25, 25, 27, 0.07);
  --code-bg: #16181d;
  --shadow: 0 16px 40px rgba(20, 20, 24, 0.07);
  --danger: #b42323;
  --add-bg: #edfbef; --add-text: #1a5c2e;
  --remove-bg: #fff0f0; --remove-text: #902020;
  --tone-data: #6b4fd8;
  --tone-football: #2f7d3e;
  --tone-math: #2f5bd3;
  --tone-build: #8a4fc9;
  --tone-essay: #a86a00;
  --tone-reflection: #4c5d99;
  --tone-note: #73757b;
  --tone-briefing: #1f7a72;
  --radius: 10px;
  --max: 1120px;
  --article: 680px;
  --font: "Pretendard Variable", Pretendard, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121314; --surface: #18191b; --surface-2: #202124; --line: #2e2f33; --line-soft: #242528;
    --text: #ececea; --text-2: #cfd0cc; --muted: #9a9ca1; --accent: #8fb0ff; --accent-soft: rgba(143, 176, 255, 0.13);
    --dot: rgba(236, 236, 234, 0.06); --code-bg: #0c0d0f; --shadow: 0 16px 40px rgba(0, 0, 0, 0.35); --danger: #ff8b8b;
    --add-bg: rgba(60, 180, 90, 0.14); --add-text: #8fe0a5; --remove-bg: rgba(220, 70, 70, 0.14); --remove-text: #ffa3a3;
    --tone-data: #a996ff; --tone-football: #7fcf8a; --tone-math: #8fb0ff; --tone-build: #c99dff; --tone-essay: #e6b45c; --tone-reflection: #a5b4e8; --tone-note: #9a9ca1; --tone-briefing: #5ccfc3;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121314; --surface: #18191b; --surface-2: #202124; --line: #2e2f33; --line-soft: #242528;
  --text: #ececea; --text-2: #cfd0cc; --muted: #9a9ca1; --accent: #8fb0ff; --accent-soft: rgba(143, 176, 255, 0.13);
  --dot: rgba(236, 236, 234, 0.06); --code-bg: #0c0d0f; --shadow: 0 16px 40px rgba(0, 0, 0, 0.35); --danger: #ff8b8b;
  --add-bg: rgba(60, 180, 90, 0.14); --add-text: #8fe0a5; --remove-bg: rgba(220, 70, 70, 0.14); --remove-text: #ffa3a3;
  --tone-data: #a996ff; --tone-football: #7fcf8a; --tone-math: #8fb0ff; --tone-build: #c99dff; --tone-essay: #e6b45c; --tone-reflection: #a5b4e8; --tone-note: #9a9ca1; --tone-briefing: #5ccfc3;
}

.tone-data, .visual-data-science { --tone: var(--tone-data); }
.tone-football, .visual-football-tactics { --tone: var(--tone-football); }
.tone-math, .visual-statistics-math { --tone: var(--tone-math); }
.tone-build, .visual-projects { --tone: var(--tone-build); }
.tone-essay, .visual-notes { --tone: var(--tone-essay); }
.tone-reflection, .visual-daily-reflections { --tone: var(--tone-reflection); }
.tone-note { --tone: var(--tone-note); }
.tone-briefing, .visual-daily-briefing { --tone: var(--tone-briefing); }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-padding-top: 80px; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin-top: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }
.page { width: min(100% - 48px, var(--max)); margin: 0 auto; }
main.page { flex: 1; min-height: 60vh; }
main.page:focus { outline: none; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.nav { display: flex; min-height: 60px; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: baseline; gap: 4px; text-decoration: none; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.brand-subtitle { color: var(--muted); font-size: 17px; font-weight: 500; }
.nav-links { display: flex; flex: 1; align-items: center; justify-content: flex-end; gap: 20px; white-space: nowrap; }
.nav-links a { color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: none; transition: color 140ms ease; }
.nav-links a:hover, .text-link:hover { color: var(--text); }
.nav-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; }
.theme-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.theme-button:hover { border-color: var(--muted); }

/* ---------- Buttons ---------- */
.auth-button, .button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.auth-button { min-height: 34px; padding: 0 12px; font-size: 13px; }
.button:hover, .auth-button:hover { border-color: var(--muted); }
.button.primary { border-color: var(--text); background: var(--text); color: var(--bg); }
.button.primary:hover { opacity: 0.88; }
.button.ghost { background: transparent; }
.button.danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.button:disabled { cursor: not-allowed; opacity: 0.6; }
.auth-status {
  display: inline-flex;
  max-width: 180px;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}
.auth-status[hidden] { display: none; }
.auth-avatar {
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 760;
}
.auth-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-role { color: var(--tone-football); font-size: 11px; font-weight: 760; }

/* ---------- Shared bits ---------- */
.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.cat-label { color: var(--tone, var(--muted)); font-weight: 700; text-decoration: none; }
.chip-dot { display: inline-block; width: 8px; height: 8px; flex: 0 0 auto; border-radius: 999px; background: var(--tone, var(--muted)); }
.entry-no { color: var(--muted); font-family: var(--mono); font-size: 12px; letter-spacing: 0.02em; opacity: 0.8; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tone, var(--accent)) 13%, transparent);
  color: var(--tone, var(--accent));
  font-size: 11px;
  font-weight: 760;
}
.badge.muted { --tone: var(--muted); }
.text-link { color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: none; }
.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  line-height: 1.62;
}
.back-link {
  display: inline-flex;
  margin-bottom: 28px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.back-link:hover { color: var(--text); }
.eyebrow { margin: 0 0 10px; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.04em; }

/* ---------- Home: intro ---------- */
.intro { position: relative; padding: 72px 0 44px; }
.intro::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  background-size: 18px 18px;
  content: "";
  -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 92%);
  mask-image: linear-gradient(180deg, #000 0%, transparent 92%);
  pointer-events: none;
}
.intro-kicker { display: inline-flex; align-items: center; gap: 9px; margin-bottom: 18px; color: var(--muted); font-size: 13px; font-weight: 650; }
.intro-dot { width: 7px; height: 7px; border-radius: 999px; background: #28b94c; box-shadow: 0 0 0 4px rgba(40, 185, 76, 0.15); }
.intro h1 {
  max-width: 16em;
  margin-bottom: 16px;
  font-size: clamp(32px, 4.6vw, 46px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.18;
  word-break: keep-all;
}
.intro-lead { max-width: 34em; margin-bottom: 0; color: var(--muted); font-size: 18px; line-height: 1.65; word-break: keep-all; }
.topic-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease;
}
.chip em { color: var(--muted); font-family: var(--mono); font-size: 12px; font-style: normal; }
.chip:hover { border-color: var(--tone); background: color-mix(in srgb, var(--tone) 8%, var(--surface)); }

/* ---------- Home: layout ---------- */
.home-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 64px; padding-top: 8px; }
.main-column { min-width: 0; }
.home-section { margin-bottom: 48px; scroll-margin-top: 80px; }
.home-section > .section-label { margin-bottom: 16px; }
.featured-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.post-card {
  display: flex;
  overflow: hidden;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.post-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--muted) 50%, var(--line)); box-shadow: var(--shadow); }
.post-card-body { display: flex; flex: 1; flex-direction: column; gap: 8px; padding: 14px 16px 16px; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }
.post-card-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.4; word-break: keep-all; }
.post-card-excerpt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.post-card-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 6px; color: var(--muted); font-family: var(--mono); font-size: 12px; }

.post-visual {
  display: block;
  width: 100%;
  background-color: color-mix(in srgb, var(--tone, var(--muted)) 12%, var(--surface));
  background-position: center;
  background-size: cover;
}
.post-visual.featured { position: relative; overflow: hidden; aspect-ratio: 16 / 8; border-bottom: 1px solid var(--line-soft); }
.post-visual > span { position: absolute; border-radius: 999px; background: var(--tone, var(--muted)); opacity: 0.32; }
.post-visual > span:nth-child(1) { top: 32%; left: 12%; width: 34%; height: 3px; }
.post-visual > span:nth-child(2) { top: 48%; left: 12%; width: 52%; height: 3px; opacity: 0.22; }
.post-visual > span:nth-child(3) { top: 64%; left: 12%; width: 24%; height: 3px; opacity: 0.18; }
.post-visual > span:nth-child(4) { top: 30%; right: 12%; width: 22px; height: 22px; opacity: 0.25; }
.post-visual.has-cover > span { display: none; }

/* Text-first post list */
.post-list { margin: 0; padding: 0; list-style: none; }
.post-row { border-top: 1px solid var(--line-soft); }
.post-row:first-child { border-top: 0; }
.post-row[hidden] { display: none; }
.post-row > a {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr) auto;
  gap: 6px 24px;
  align-items: start;
  padding: 22px 0;
  color: inherit;
  text-decoration: none;
}
.post-row-side { display: grid; gap: 4px; padding-top: 2px; color: var(--muted); font-size: 13px; }
.post-row-main { display: grid; min-width: 0; gap: 6px; }
.post-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font-size: 12.5px; }
.post-row-tag { opacity: 0.85; }
.post-row-title {
  color: var(--text);
  font-size: 18.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.42;
  word-break: keep-all;
  overflow-wrap: anywhere;
  transition: color 140ms ease;
}
.post-row > a:hover .post-row-title { color: var(--accent); }
.post-row-excerpt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
  word-break: keep-all;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.post-row-thumb {
  width: 112px;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background-color: var(--surface-2);
  background-position: center;
  background-size: cover;
}
.show-more {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
}
.show-more:hover { border-color: var(--muted); background: var(--surface); }

.search-bar { display: flex; align-items: center; gap: 8px; margin: 0; }
.search-bar input {
  width: min(220px, 100%);
  min-height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface) no-repeat 12px 50% / 14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2373757b' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  font-size: 14px;
}
.search-clear { color: var(--muted); font-size: 13px; font-weight: 600; }
.filter-note { margin: 0 0 8px; color: var(--muted); font-size: 14px; }

/* ---------- Sidebar ---------- */
.sidebar { display: grid; align-content: start; gap: 32px; padding-top: 2px; }
.side-card { min-width: 0; }
.side-title { margin: 0 0 12px; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.about-person { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.about-person strong { display: block; font-size: 15px; }
.about-person small { color: var(--muted); font-size: 13px; }
.avatar {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 800;
}
.about-card p { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.7; word-break: keep-all; }
.reflection-card a {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--tone-reflection);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
}
.reflection-card strong { font-family: var(--mono); font-size: 16px; letter-spacing: 0.02em; }
.reflection-card span { display: -webkit-box; overflow: hidden; color: var(--text-2); font-size: 14px; line-height: 1.6; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.reflection-card small { color: var(--muted); font-size: 12.5px; }
.reflection-card a:hover { border-color: var(--muted); border-left-color: var(--tone-reflection); }
.side-list { display: grid; gap: 2px; }
.side-list a {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 0 -8px;
  padding: 7px 8px;
  border-radius: 6px;
  text-decoration: none;
}
.side-list a:hover { background: var(--surface-2); }
.side-list strong { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.side-list em { color: var(--muted); font-family: var(--mono); font-size: 12px; font-style: normal; }
.series-mark { color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Projects ---------- */
.projects-section { margin-top: 24px; padding-top: 32px; border-top: 1px solid var(--line-soft); scroll-margin-top: 80px; }
.projects-section .section-heading { margin-bottom: 16px; }
.project-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.project-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 140ms ease;
}
.project-card:hover { border-color: var(--muted); }
.project-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 9px; font-size: 14px; font-weight: 820; }
.project-flowlog { background: #dcd5ff; color: #5540d9; }
.project-aperture { background: #5c941d; color: #fff; }
.project-vocabulary { background: #ffd229; color: #111827; }
.project-site { background: #19191b; color: #fff; }
.project-card strong { display: block; margin-bottom: 3px; font-size: 14.5px; }
.project-card small { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; }

/* ---------- Listing pages ---------- */
.listing-hero { padding: 48px 0 28px; }
.listing-hero h1 { margin-bottom: 10px; font-size: clamp(30px, 4.4vw, 42px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; }
.listing-hero p { max-width: 36em; margin-bottom: 10px; color: var(--muted); font-size: 17px; line-height: 1.6; }
.listing-hero small { color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.listing-kicker { margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.list-tools, .actions, .row-actions, .editor-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.list-tools { margin-bottom: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 40px; }
.tag {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
button.tag { cursor: pointer; }
button.tag:hover { border-color: var(--muted); }
.tag.active { border-color: var(--text); background: var(--text); color: var(--bg); }

/* ---------- State ---------- */
.state-block { padding: 80px 0; }
.state-block h1 { margin-bottom: 12px; font-size: clamp(26px, 4vw, 36px); letter-spacing: -0.02em; }
.state-block p { margin-bottom: 20px; color: var(--muted); }
.state-block.loading h1 { color: var(--muted); font-size: 16px; font-weight: 600; letter-spacing: 0; }
.loader {
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-bottom: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--text);
  border-radius: 999px;
  animation: spin 820ms linear infinite;
}
.loader[hidden] { display: none; }
@keyframes spin { to { transform: rotate(1turn); } }

/* ---------- Article ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  width: 100%;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}
.article-layout { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }
.article-shell { width: 100%; max-width: var(--article); min-width: 0; padding-top: 48px; }
.article-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; font-size: 14px; }
.article-header h1 {
  margin-bottom: 14px;
  font-size: clamp(30px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.article-subtitle { margin-bottom: 0; color: var(--muted); font-size: 19px; line-height: 1.55; word-break: keep-all; }
.article-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin-top: 18px; color: var(--muted); font-size: 14px; }
.article-meta > * + *::before { margin: 0 10px; content: "·"; opacity: 0.7; }
.article-meta a { color: var(--text-2); text-decoration: none; }
.article-meta a:hover { color: var(--accent); }
.cover-image { display: block; width: 100%; margin: 32px 0 0; border: 1px solid var(--line-soft); border-radius: 12px; }
.article-header { padding-bottom: 32px; border-bottom: 1px solid var(--line-soft); }

.markdown-body {
  margin-top: 36px;
  color: var(--text-2);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: -0.003em;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body p { margin: 0 0 1.4em; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  color: var(--text);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.35;
  scroll-margin-top: 84px;
}
.markdown-body h1 { margin: 2.2em 0 0.7em; font-size: 1.75em; }
.markdown-body h2 { margin: 2.2em 0 0.7em; font-size: 1.5em; }
.markdown-body h3 { margin: 1.9em 0 0.6em; font-size: 1.24em; }
.markdown-body h4 { margin: 1.6em 0 0.5em; font-size: 1.06em; }
.markdown-body strong { color: var(--text); font-weight: 700; }
.markdown-body a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 1.4em; padding-left: 1.4em; }
.markdown-body li { margin: 0.3em 0; }
.markdown-body li::marker { color: var(--muted); }
.markdown-body blockquote {
  margin: 1.8em 0;
  padding: 0.2em 0 0.2em 1.1em;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
.markdown-body blockquote > :last-child { margin-bottom: 0; }
.markdown-body hr { height: 0; margin: 3em 0; border: 0; border-top: 1px solid var(--line); }
.markdown-body pre {
  overflow-x: auto;
  margin: 1.6em 0;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: #e8eaf0;
  font-size: 14px;
  line-height: 1.65;
  word-break: normal;
}
.markdown-body code { padding: 0.15em 0.38em; border-radius: 5px; background: var(--surface-2); color: var(--text); font-family: var(--mono); font-size: 0.86em; }
.markdown-body pre code { padding: 0; background: transparent; color: inherit; font-size: inherit; }
.markdown-body pre code.hljs { padding: 0; background: transparent; }
.markdown-body table { display: block; overflow-x: auto; width: 100%; margin: 1.6em 0; border-collapse: collapse; font-size: 15px; line-height: 1.6; word-break: normal; }
.markdown-body th, .markdown-body td { padding: 9px 12px; border: 1px solid var(--line); }
.markdown-body th { background: var(--surface-2); color: var(--text); text-align: left; }
.markdown-body img { display: block; max-width: 100%; height: auto; margin: 1.8em auto; border-radius: var(--radius); }
.markdown-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.markdown-body .latex-source { font-family: var(--mono); }

/* Daily Reflections: posts from the same day */
.day-thoughts {
  margin-top: 56px;
  padding: 22px 24px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.day-thoughts-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin-bottom: 6px; }
.day-thoughts-head h2 { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: -0.01em; }
.day-thoughts-head time { color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
.day-thoughts-list { margin: 0; padding: 0; list-style: none; counter-reset: thought; }
.day-thoughts-list li { border-top: 1px solid var(--line-soft); }
.day-thoughts-list li:first-child { border-top: 0; }
.day-thoughts-list a {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 12px 0 12px 22px;
  text-decoration: none;
}
.day-thoughts-list a::before {
  position: absolute;
  top: 21px;
  left: 2px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--tone-reflection);
  content: "";
}
.day-thought-title { color: var(--text); font-size: 15.5px; font-weight: 650; line-height: 1.5; word-break: keep-all; overflow-wrap: anywhere; }
.day-thought-link { overflow: hidden; color: var(--muted); font-family: var(--mono); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.day-thoughts-list a:hover .day-thought-title { color: var(--accent); }
.day-thoughts-empty { margin: 4px 0 14px; color: var(--muted); font-size: 14px; }
.day-reflection-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 48px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--tone-reflection);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}
.day-reflection-link strong { color: var(--text); font-family: var(--mono); font-size: 14.5px; }
.day-reflection-link:hover { border-color: var(--muted); border-left-color: var(--tone-reflection); }

/* Table of contents (wide screens only) */
.toc { display: none; }
@media (min-width: 1240px) {
  .article-layout { grid-template-columns: minmax(0, 1fr) minmax(0, var(--article)) minmax(0, 1fr); }
  .article-shell { grid-column: 2; }
  .toc:not([hidden]) {
    position: sticky;
    top: 96px;
    display: block;
    grid-column: 3;
    align-self: start;
    justify-self: start;
    width: 220px;
    max-height: calc(100vh - 128px);
    overflow-y: auto;
    margin: 48px 0 0 56px;
    font-size: 13px;
  }
}
.toc-title { margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.toc ol { margin: 0; padding: 0; border-left: 1px solid var(--line); list-style: none; }
.toc a {
  display: block;
  margin-left: -1px;
  padding: 5px 0 5px 12px;
  border-left: 1px solid transparent;
  color: var(--muted);
  line-height: 1.45;
  text-decoration: none;
  word-break: keep-all;
}
.toc .toc-h3 a { padding-left: 24px; font-size: 12.5px; }
.toc a:hover { color: var(--text); }
.toc a.active { border-left-color: var(--accent); color: var(--text); font-weight: 600; }

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: var(--article);
  margin: 64px auto 0;
}
.post-nav a {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 140ms ease;
}
.post-nav a:hover { border-color: var(--muted); }
.post-nav span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.post-nav strong { font-size: 15px; line-height: 1.45; word-break: keep-all; overflow-wrap: anywhere; }
.post-nav-next { text-align: right; }
.related { width: 100%; max-width: var(--article); margin: 64px auto 0; }
.related .section-label { margin-bottom: 4px; }
.related .post-row > a { grid-template-columns: minmax(0, 1fr) auto; }
.related .post-row-side { display: none; }

/* ---------- Forms ---------- */
input, textarea, select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.65; }
label { display: grid; min-width: 0; grid-template-columns: minmax(0, 1fr); gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 700; }
label small { color: var(--muted); font-weight: 400; }

/* ---------- Admin ---------- */
.admin-hero, .access-gate { padding: 48px 0 28px; }
.admin-hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.admin-hero h1, .access-gate h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 38px); letter-spacing: -0.03em; }
.admin-hero p, .access-gate p { max-width: 36em; margin-bottom: 0; color: var(--muted); line-height: 1.6; }
.access-gate .actions { margin-top: 24px; }
.admin-table { display: grid; gap: 10px; margin-bottom: 48px; }
.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.recent-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.recent-title-row h3 { margin: 0; font-size: 16px; }
.admin-row p { margin-bottom: 6px; color: var(--muted); font-size: 14px; }
.admin-row small { color: var(--muted); }

/* ---------- Editor ---------- */
.editor-shell { margin: 32px 0 48px; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.editor-shell [hidden] { display: none !important; }
.editor-head { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.editor-head h1 { margin-bottom: 0; font-size: clamp(28px, 4vw, 38px); letter-spacing: -0.03em; }
.editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.editor-help { color: var(--muted); font-size: 13px; font-weight: 400; line-height: 1.6; }
.source-area, .writing-area { min-width: 0; }
.source-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.source-actions .button { min-height: 34px; padding: 0 12px; font-size: 13px; }
.writing-area > .markdown-body { width: 100%; max-width: var(--article); margin: 28px auto 0; }
.source-area .preview-head, .writing-area .preview-head { flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.source-area .preview-head h2, .writing-area .preview-head h2 { flex-shrink: 0; margin-bottom: 0; }
.source-area textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 320px;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
}
.writing-area { padding-top: 8px; }
.metadata-details { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); }
summary { cursor: pointer; font-weight: 650; }
details[open] > summary { margin-bottom: 16px; }
.image-picker { position: relative; overflow: hidden; cursor: pointer; }
.image-picker input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cover-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.cover-choice { width: 100px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
.cover-choice img { width: 90px; height: 65px; object-fit: cover; }
.correction { display: flex; align-items: center; gap: 10px; padding: 12px 0; }
.correction input { width: auto; }
.correction small { display: block; margin-top: 4px; font-weight: normal; }
.correction del { color: var(--remove-text); }
.correction ins { color: var(--add-text); text-decoration: none; }
.editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.editor-actions .editor-help { flex: 1; }
.wide, .markdown-input, .preview-pane, .editor-actions, .switch-row, .ai-bar { grid-column: 1 / -1; }
.switch-row { display: flex; flex-wrap: wrap; gap: 18px; }
.switch-row label { display: inline-flex; width: auto; align-items: center; gap: 8px; }
.switch-row input { width: auto; }
.preview-pane { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.preview-head h2 { margin: 0; font-size: 17px; }
.ai-bar { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.ai-bar-inner { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ai-bar-actions { display: flex; align-items: center; gap: 8px; }
.ai-status { color: var(--muted); font-size: 12px; font-weight: 720; letter-spacing: 0.04em; text-transform: uppercase; }
.ai-key-row { display: flex; align-items: center; gap: 8px; }
.ai-key-row input { flex: 1; margin: 0; }
.ai-changes { padding-top: 10px; border-top: 1px solid var(--line-soft); }
.ai-changes h3 { font-size: 15px; }
.ai-changes-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ai-changes-title { color: var(--muted); font-size: 12px; font-weight: 720; letter-spacing: 0.04em; text-transform: uppercase; }
.diff-code { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; font-family: var(--mono); font-size: 12px; line-height: 1.65; }
.diff-line { display: flex; gap: 8px; padding: 1px 10px; white-space: pre-wrap; word-break: break-all; }
.diff-add { background: var(--add-bg); color: var(--add-text); }
.diff-remove { background: var(--remove-bg); color: var(--remove-text); }
.diff-same { color: var(--muted); }
.diff-skip { padding: 3px 10px; background: var(--surface-2); color: var(--muted); font-style: italic; }
.diff-sign { flex: 0 0 12px; font-weight: 760; user-select: none; }
.diff-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.diff-meta:last-of-type { margin-bottom: 8px; }
.diff-meta-label { flex: 0 0 auto; color: var(--muted); font-size: 11px; font-weight: 720; text-transform: uppercase; }
.diff-meta del { color: var(--remove-text); text-decoration: line-through; }
.diff-meta ins { color: var(--add-text); text-decoration: none; }
.diff-none { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.ai-chat { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.ai-chat-messages { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.chat-msg { max-width: 86%; padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.52; }
.chat-msg-user { align-self: flex-end; border-radius: 8px 8px 2px 8px; background: var(--text); color: var(--bg); }
.chat-msg-assistant { align-self: flex-start; border-radius: 8px 8px 8px 2px; background: var(--surface-2); color: var(--text); }
.ai-chat-input-row { display: flex; gap: 8px; }
.ai-chat-input-row input { flex: 1; min-height: 40px; margin: 0; padding: 8px 12px; }

/* ---------- Toast & footer ---------- */
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast[hidden] { display: none; }
.site-footer { margin-top: 96px; border-top: 1px solid var(--line-soft); }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px 24px; padding: 28px 0 36px; color: var(--muted); font-size: 13px; }
.site-version { margin-left: 8px; font-family: var(--mono); font-size: 11px; opacity: 0.75; }
.footer-links { display: flex; align-items: center; gap: 24px; }
.footer-links a { color: var(--muted); font-weight: 600; text-decoration: none; }
.footer-links a:hover { color: var(--text); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .home-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 40px; padding-top: 32px; border-top: 1px solid var(--line-soft); }
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .editor-grid { grid-template-columns: minmax(0, 1fr); }
  .editor-actions .editor-help { flex-basis: 100%; }
  .ai-bar-inner { flex-direction: column; align-items: stretch; }
  .ai-bar-actions { flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .page { width: calc(100% - 32px); }
  .nav { flex-wrap: wrap; gap: 0 12px; padding: 10px 0 0; }
  .brand { order: 1; min-height: 38px; align-items: center; }
  .nav-actions { order: 2; margin-left: auto; gap: 8px; }
  .auth-name, .auth-role { display: none; }
  .nav-links {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
    justify-content: flex-start;
    gap: 18px;
    margin-top: 4px;
    padding: 6px 0 10px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .intro { padding: 44px 0 32px; }
  .intro-lead { font-size: 16.5px; }
  .section-heading { flex-wrap: wrap; }
  .search-bar, .search-bar input { width: 100%; }
  .sidebar, .project-grid, .editor-grid, .admin-row, .post-nav { grid-template-columns: minmax(0, 1fr); }
  .post-row > a { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; padding: 18px 0; }
  .post-row-side { display: flex; grid-column: 1 / -1; gap: 10px; padding: 0; font-size: 12.5px; }
  .post-row-thumb { width: 76px; }
  .post-row-title { font-size: 17px; }
  .post-row-excerpt { font-size: 14.5px; }
  .admin-hero, .editor-head, .footer-inner { align-items: flex-start; flex-direction: column; }
  .editor-shell { margin: 16px 0 32px; padding: 16px; }
  .article-shell { padding-top: 28px; }
  .markdown-body { font-size: 16.5px; line-height: 1.8; }
  .markdown-body pre { margin-right: -16px; margin-left: -16px; border-radius: 0; }
  .day-thoughts { padding: 18px 18px 8px; }
  .post-nav-next { text-align: left; }
}
