/* ── Theme tokens ────────────────────────────────────────────────────── */
:root {
  --bg:        #fdfdfc;
  --fg:        #1a1a1a;
  --muted:     #6b6b6b;
  --link:      #1c5d99;
  --link-hover:#0f3d6b;
  --border:    #e6e4de;
  --code-bg:   #f4f3ef;
  --sel:       #d7e6f4;
  --measure:   40rem;
  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, "Times New Roman", serif;
  --display: "Fraunces", Charter, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Dark: follow system when data-theme=auto, or forced via data-theme=dark */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #16181c; --fg: #e6e6e3; --muted: #9a9a95;
    --link: #7cb4e6; --link-hover: #a9cef0; --border: #2c2f36;
    --code-bg: #21242b; --sel: #2a3f57;
  }
}
:root[data-theme="dark"] {
  --bg: #16181c; --fg: #e6e6e3; --muted: #9a9a95;
  --link: #7cb4e6; --link-hover: #a9cef0; --border: #2c2f36;
  --code-bg: #21242b; --sel: #2a3f57;
}

/* ── Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--sel); }

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 2px; }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 2px; }

/* ── Animated WebGL water header ─────────────────────────────────────── */
.header-image {
  position: relative;
  width: 100%;
  height: 150px;
  overflow: hidden;
}
.header-image canvas { display: block; width: 100%; height: 100%; }
@media (max-width: 800px) {
  .header-image { height: 100px; }
}

/* ── Header ──────────────────────────────────────────────────────────── */
.site-head {
  max-width: 46rem;
  margin: 0 auto;
  padding: 2.2rem 1.25rem 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
}
.site-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.site-brand:hover { text-decoration: none; }
.site-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex: none;
}
.site-name {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.site-brand:hover .site-name { color: var(--link); }
.site-nav {
  font-family: var(--sans);
  font-size: 0.95rem;
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.site-nav a { color: var(--muted); }
.site-nav a:hover { color: var(--fg); text-decoration: none; }
.site-nav a.active { color: var(--fg); font-weight: 600; }
.theme-toggle {
  margin-left: 0.3rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--muted); }

/* ── Main column ─────────────────────────────────────────────────────── */
.content {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.4rem 1.25rem 1rem;
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; }
h1 { font-size: 2rem; line-height: 1.12; letter-spacing: -0.02em; margin: 0 0 1rem; }
h2 { font-size: 1.42rem; line-height: 1.2; letter-spacing: -0.015em; margin: 2.2rem 0 0.8rem; }
h3 { font-size: 1.15rem; margin: 1.8rem 0 0.6rem; }
p { margin: 0 0 1.1rem; }

.intro h1 {
  font-size: clamp(2.4rem, 6vw, 3.2rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 0.7rem;
}
.intro p { color: var(--muted); font-size: 1.08rem; }
.section-label {
  font-family: var(--sans); font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); font-weight: 600;
  margin-top: 2.6rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;
}

/* ── Prose ───────────────────────────────────────────────────────────── */
.prose { max-width: 34rem; }
.prose.page { max-width: 36rem; }
.prose img { max-width: 100%; height: auto; border-radius: 4px; }
.prose blockquote {
  margin: 1.4rem 0; padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 3px solid var(--border); color: var(--muted); font-style: italic;
}
.prose code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--code-bg); padding: 0.12em 0.38em; border-radius: 4px;
}
.prose pre {
  background: var(--code-bg); padding: 1rem 1.1rem; border-radius: 6px;
  overflow-x: auto; font-size: 0.86rem; line-height: 1.5;
}
.prose pre code { background: none; padding: 0; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2.4rem 0; }
.prose ul, .prose ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }
.prose li { margin-bottom: 0.3rem; }
.prose table { border-collapse: collapse; width: 100%; margin: 1.2rem 0; font-size: 0.95rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.45rem 0.7rem; text-align: left; }

/* ── Post list ───────────────────────────────────────────────────────── */
.post-list { list-style: none; padding: 0; margin: 1.2rem 0 0; }
.post-item { margin: 0 0 1.8rem; }
.post-item-link {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; color: var(--fg);
}
.post-item-link:hover { text-decoration: none; }
.post-item-link:hover .post-item-title { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.post-item-title { font-family: var(--display); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.015em; }
.post-item-date {
  font-family: var(--sans); font-size: 0.82rem; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.post-item-desc { color: var(--muted); margin: 0.3rem 0 0; font-size: 0.98rem; }
.more-link { font-family: var(--sans); font-size: 0.95rem; margin-top: 2rem; }

/* ── What I learned this year ────────────────────────────────────────── */
.learn-intro { color: var(--muted); max-width: 34rem; }
.learn-list { display: flex; flex-direction: column; gap: 3rem; margin-top: 2rem; }
.learn-card { margin: 0; }
.learn-media {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
  line-height: 0;
}
.learn-media img, .learn-media video {
  display: block; width: 100%; height: auto;
}
.learn-title {
  font-family: var(--display); font-size: 1.3rem; font-weight: 600;
  letter-spacing: -0.015em; margin: 1rem 0 0.2rem;
}
.learn-date {
  font-family: var(--sans); font-size: 0.82rem; color: var(--muted);
  margin: 0 0 0.6rem; font-variant-numeric: tabular-nums;
}
.learn-card .prose { max-width: 34rem; }
.learn-empty { color: var(--muted); margin-top: 1.6rem; }

/* ── Recommendations ─────────────────────────────────────────────────── */
.rec-intro { color: var(--muted); max-width: 34rem; }
.rec-groups { margin-top: 2rem; }
.rec-group { margin-bottom: 2.4rem; }
.rec-heading {
  font-size: 0.82rem; font-family: var(--sans); text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border); padding-bottom: 0.45rem; margin: 0 0 1rem;
}
.rec-list { list-style: none; padding: 0; margin: 0; }
.rec-item { margin: 0 0 1.1rem; }
.rec-title { font-family: var(--display); font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; }
.rec-by { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); }
.rec-note { color: var(--muted); font-size: 0.98rem; margin-top: 0.15rem; }
.rec-note p { margin: 0; }
.rec-empty { color: var(--muted); margin-top: 1.6rem; }

/* ── Projects ────────────────────────────────────────────────────────── */
.projects-intro { color: var(--muted); max-width: 30rem; }
.projects-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem; margin: 2rem 0 1.1rem;
}
.project-card {
  display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--fg); background: var(--bg);
  transition: border-color .18s ease, transform .18s ease;
}
.project-card:hover {
  color: var(--fg); text-decoration: none; border-color: var(--muted);
  transform: translateY(-3px);
}
.project-card:focus-visible { outline-offset: 4px; }
.project-art {
  position: relative; height: 210px; overflow: hidden; isolation: isolate;
}
.project-art-label {
  position: absolute; top: 1rem; left: 0; width: 100%; text-align: center;
  font-family: var(--sans); font-size: .65rem; letter-spacing: .06em;
}
.project-art-rewind { background: #e5ebdb; color: #485e4b; }
.project-art-rewind img {
  position: absolute; width: 200px; height: auto; max-width: none;
  left: 50%; top: 18px; margin-left: -100px; transform: rotate(-12deg);
  filter: drop-shadow(0 12px 10px #33463426);
}
.project-art-blackjack { background: #153e38; color: #c9ded2; }
.project-playing-card {
  position: absolute; width: 99px; height: 139px; top: 65px;
  border-radius: 7px; background: #f8f4e9; color: #193f38;
  box-shadow: 0 8px 18px #071e2845; font-family: Georgia, serif;
}
.project-playing-card > span {
  position: absolute; top: 10px; left: 11px; font-size: 19px; line-height: 1;
}
.project-playing-card > strong {
  display: grid; place-items: center; height: 100%; font-size: 56px; font-weight: 400;
}
.project-playing-card-ace { left: calc(50% - 85px); transform: rotate(-17deg); }
.project-playing-card-king { left: calc(50% - 13px); transform: rotate(13deg); color: #b34432; }
.project-info { padding: 1.2rem; flex: 1; display: flex; flex-direction: column; }
.project-category {
  font-family: var(--sans); font-size: .65rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 .55rem;
}
.project-info h2 { font-size: 1.3rem; margin: 0 0 .7rem; line-height: 1.2; }
.project-description { font-size: .95rem; line-height: 1.55; color: var(--muted); margin: 0 0 1.2rem; }
.project-open {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-top: auto; font-family: var(--sans); font-size: .82rem; font-weight: 500;
  color: var(--link);
}
.project-card:hover .project-open { color: var(--link-hover); }
.projects-note { font-family: var(--sans); font-size: .78rem; color: var(--muted); }
.project-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (max-width: 560px) {
  .projects-grid { grid-template-columns: minmax(0, 1fr); gap: 1.4rem; }
  .project-info { padding: 1.3rem; }
  .project-info h2 { font-size: 1.5rem; }
}

/* ── Videos ──────────────────────────────────────────────────────────── */
.video-intro { color: var(--muted); max-width: 34rem; }
.video-grid {
  list-style: none; padding: 0; margin: 2rem 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 2.2rem 1.6rem;
}
.video-card { margin: 0; }
.video-thumb {
  display: block; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; background: var(--code-bg); line-height: 0;
  aspect-ratio: 16 / 9;
}
.video-thumb:hover { border-color: var(--muted); text-decoration: none; }
.video-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.video-thumb-empty { display: block; width: 100%; height: 100%; }
.video-title {
  display: block; font-family: var(--display); font-size: 1.15rem;
  font-weight: 600; letter-spacing: -0.015em; margin: 0.7rem 0 0.15rem; color: var(--fg);
}
a.video-title:hover { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.video-date {
  font-family: var(--sans); font-size: 0.8rem; color: var(--muted);
  margin: 0 0 0.4rem; font-variant-numeric: tabular-nums;
}
.video-note { color: var(--muted); font-size: 0.95rem; }
.video-note p { margin: 0 0 0.5rem; }
.video-note p:last-child { margin-bottom: 0; }
.video-empty { color: var(--muted); margin-top: 1.6rem; }

/* ── Single post ─────────────────────────────────────────────────────── */
.post-head { margin-bottom: 1.8rem; }
.post-title { margin-bottom: 0.4rem; }
.post-meta {
  font-family: var(--sans); font-size: 0.85rem; color: var(--muted); margin: 0;
  font-variant-numeric: tabular-nums;
}
.post-back { margin-top: 2.6rem; font-family: var(--sans); font-size: 0.9rem; }

/* ── Archive ─────────────────────────────────────────────────────────── */
.archive-year { margin-bottom: 1.8rem; }
.archive-year h2 {
  font-size: 1rem; font-family: var(--sans); color: var(--muted);
  margin: 1.8rem 0 0.6rem; font-weight: 600;
}
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-item {
  display: flex; gap: 1rem; align-items: baseline; padding: 0.28rem 0;
}
.archive-item time {
  font-family: var(--sans); font-size: 0.82rem; color: var(--muted);
  width: 4.2rem; flex: none; font-variant-numeric: tabular-nums;
}
.archive-columns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem 2.4rem;
  margin-top: 1.4rem;
}
.archive-col h2 {
  font-size: 1rem; font-family: var(--sans); color: var(--muted);
  margin: 0 0 0.6rem; font-weight: 600;
}
@media (max-width: 560px) {
  .archive-columns { grid-template-columns: 1fr; gap: 0.6rem 0; }
}

/* ── Footer ──────────────────────────────────────────────────────────── */
.site-foot {
  max-width: var(--measure);
  margin: 3rem auto 0;
  padding: 1.4rem 1.25rem 3rem;
  border-top: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
}
.site-foot a { color: var(--muted); }
.site-foot a:hover { color: var(--fg); }
.foot-social { margin: 0 0 0.4rem; }
.foot-social a { color: var(--fg); }
.foot-meta { margin: 0; }

@media (max-width: 480px) {
  body { font-size: 18px; }
  .theme-toggle { margin-left: 0; order: 3; }
  .post-item-link { flex-direction: column; gap: 0.15rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
