:root {
  --bg: #07070a;
  --bg-2: #0e0d13;
  --ink: #f2efe9;
  --muted: #8d8a96;
  --line: rgba(242, 239, 233, 0.1);
  --accent: #ff6a3d;
  --accent-2: #8f7bff;
  --ok: #2bd9a8;
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Inter Tight", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --gutter: clamp(16px, 4vw, 56px);
  --ease: cubic-bezier(0.2, 0.7, 0.1, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--bg); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { max-width: 100%; display: block; }
.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.muted { color: var(--muted); }
.serif { font-family: var(--serif); font-weight: 400; }

/* Film grain over everything */
body::after {
  content: "";
  position: fixed; inset: -50%;
  pointer-events: none; z-index: 100;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: 0.07;
  animation: grain 1s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

/* ---------- Cursor ---------- */
.cursor, .cursor-ring { position: fixed; top: 0; left: 0; pointer-events: none; z-index: 200; border-radius: 50%; mix-blend-mode: difference; }
.cursor { width: 8px; height: 8px; background: #fff; margin: -4px 0 0 -4px; }
.cursor-ring { width: 40px; height: 40px; border: 1px solid #fff; margin: -20px 0 0 -20px; transition: width .3s var(--ease), height .3s var(--ease), margin .3s var(--ease), background .3s; }
.cursor-ring.hover { width: 72px; height: 72px; margin: -36px 0 0 -36px; background: #fff; }
@media (hover: none), (pointer: coarse) { .cursor, .cursor-ring { display: none; } }

/* ---------- Nav ---------- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px var(--gutter);
  mix-blend-mode: difference;
}
.logo { font-family: var(--serif); font-size: 26px; font-style: italic; letter-spacing: -0.02em; }
.nav-links { display: flex; gap: 28px; }
.nav-links a, .nav-right { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.nav-right { display: flex; align-items: center; gap: 18px; }
.kbd-btn { border: 1px solid currentColor; border-radius: 99px; padding: 6px 12px; }
@media (max-width: 760px) { .nav-links, .clock { display: none; } }

/* ---------- Hero ---------- */
.hero { position: relative; height: 100svh; min-height: 560px; overflow: hidden; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-inner {
  position: relative; z-index: 2; height: 100%;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 0 var(--gutter) clamp(32px, 7vh, 80px);
  pointer-events: none;
}
.hero-kicker { margin-bottom: 18px; display: flex; gap: 12px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 12px var(--ok); animation: pulse 2s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .35; } }
.hero h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(72px, 17vw, 260px); line-height: 0.82; letter-spacing: -0.04em;
}
.hero h1 .line { display: block; overflow: hidden; padding-bottom: .06em; }
.hero h1 .line:nth-child(2) { font-style: italic; padding-left: 0.6em; }
.hero h1 .ch { display: inline-block; transform: translateY(110%); animation: rise 1.2s var(--ease) forwards; }
@keyframes rise { to { transform: translateY(0); } }
.hero-sub {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap;
  margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line);
  opacity: 0; animation: fade 1s 0.9s forwards;
}
.hero-sub p { max-width: 520px; font-size: clamp(17px, 1.6vw, 21px); }
.rotator { color: var(--accent); font-family: var(--serif); font-style: italic; font-size: 1.25em; }
@keyframes fade { to { opacity: 1; } }

/* ---------- Marquee ---------- */
.marquee { border-block: 1px solid var(--line); overflow: hidden; padding: 18px 0; white-space: nowrap; }
.marquee-track { display: inline-flex; gap: 48px; animation: scroll-x 40s linear infinite; }
.marquee span { font-family: var(--serif); font-size: clamp(28px, 4vw, 48px); font-style: italic; }
.marquee span::after { content: "✦"; font-style: normal; color: var(--accent); margin-left: 48px; font-size: .5em; vertical-align: middle; }
@keyframes scroll-x { to { transform: translateX(-50%); } }

/* ---------- Sections ---------- */
section { padding: clamp(80px, 14vh, 160px) var(--gutter); position: relative; }
.sec-head { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 24px; margin-bottom: clamp(40px, 6vh, 72px); }
.sec-head h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(48px, 8vw, 120px); line-height: .9; letter-spacing: -0.03em; }
.sec-head h2 em { color: var(--accent); }
.sec-num { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.about-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: clamp(32px, 6vw, 96px); }
.about-lead { font-family: var(--serif); font-size: clamp(28px, 3.4vw, 48px); line-height: 1.12; letter-spacing: -0.01em; }
.about-lead em { color: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); align-self: start; }
.stat { background: var(--bg); padding: 22px; }
.stat b { display: block; font-family: var(--serif); font-weight: 400; font-size: 48px; line-height: 1; }
@media (max-width: 860px) { .about-grid { grid-template-columns: 1fr; } }

/* ---------- Works ---------- */
.works { list-style: none; border-top: 1px solid var(--line); }
.work {
  display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 24px;
  padding: clamp(22px, 3.5vw, 40px) 0; border-bottom: 1px solid var(--line);
  cursor: pointer; position: relative;
  transition: padding .5s var(--ease), color .3s;
}
.work::before { content: ""; position: absolute; inset: 0; background: var(--c, var(--accent)); transform: scaleY(0); transform-origin: bottom; transition: transform .5s var(--ease); z-index: -1; opacity: .08; }
.work:hover::before, .work:focus-visible::before { transform: scaleY(1); }
.work:hover { padding-left: 16px; }
.work-title { font-family: var(--serif); font-size: clamp(36px, 6vw, 88px); line-height: 1; letter-spacing: -0.02em; }
.work:hover .work-title { font-style: italic; }
.work-meta { text-align: right; }
.work-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); white-space: nowrap; }
@media (max-width: 640px) {
  .work { grid-template-columns: 36px 1fr; }
  .work-meta { grid-column: 2; text-align: left; }
}
.preview {
  position: fixed; top: 0; left: 0; width: 320px; height: 220px; z-index: 40;
  pointer-events: none; border-radius: 14px; overflow: hidden;
  opacity: 0; transform: scale(.85) rotate(-4deg);
  transition: opacity .3s, transform .4s var(--ease);
  display: flex; flex-direction: column; justify-content: space-between; padding: 20px;
  color: #0b0a0f;
}
.preview.show { opacity: 1; transform: scale(1) rotate(-2deg); }
.preview .pv-title { font-family: var(--serif); font-size: 44px; line-height: .95; font-style: italic; }
@media (hover: none) { .preview { display: none; } }

/* ---------- Dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(5, 5, 8, .7); backdrop-filter: blur(8px); }
.drawer {
  position: fixed; inset: 0 0 0 auto; height: 100%; width: min(640px, 100%);
  margin: 0 0 0 auto; background: var(--bg-2); border-left: 1px solid var(--line);
  padding: clamp(24px, 4vw, 48px); overflow-y: auto;
}
.drawer[open] { animation: slide-in .5s var(--ease); }
@keyframes slide-in { from { transform: translateX(100%); } }
.drawer h3 { font-family: var(--serif); font-weight: 400; font-size: clamp(48px, 7vw, 80px); line-height: .95; margin: 24px 0 8px; }
.drawer ul { margin: 20px 0; padding-left: 0; list-style: none; }
.drawer li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.drawer li::before { content: "→ "; color: var(--accent); }
.close { position: absolute; top: 20px; right: 20px; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; font-size: 18px; }
.swatch { height: 160px; border-radius: 12px; margin-top: 28px; }

/* ---------- AI Pulse ---------- */
.pulse { background: var(--bg-2); border-block: 1px solid var(--line); }
.digest {
  font-family: var(--serif); font-size: clamp(22px, 2.4vw, 32px); line-height: 1.25;
  max-width: 980px; margin-bottom: 40px; min-height: 1em;
}
.digest .label { font-family: var(--mono); font-size: 12px; color: var(--accent); display: block; margin-bottom: 12px; letter-spacing: .06em; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 28px; align-items: center; }
.filter { font-family: var(--mono); font-size: 12px; text-transform: uppercase; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; transition: background .2s, color .2s; }
.filter[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.news-status { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.news {
  background: var(--bg-2); padding: 24px; display: flex; flex-direction: column; gap: 12px; min-height: 220px;
  transition: background .3s;
  animation: fade .6s both;
}
.news:hover { background: #15131c; }
.news h4 { font-weight: 500; font-size: 19px; line-height: 1.3; letter-spacing: -0.01em; }
.news:hover h4 { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.news p { color: var(--muted); font-size: 15px; }
.news .top { display: flex; justify-content: space-between; gap: 8px; }
.news .bottom { margin-top: auto; }
.skeleton { background: linear-gradient(90deg, var(--bg-2), #17151e, var(--bg-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Journal ---------- */
.posts { list-style: none; border-top: 1px solid var(--line); }
.post-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 24px; padding: 28px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.post-row h3 { font-family: var(--serif); font-weight: 400; font-size: clamp(28px, 3.2vw, 44px); line-height: 1.05; transition: color .3s; }
.post-row:hover h3 { color: var(--accent); font-style: italic; }
.post-row p { color: var(--muted); margin-top: 6px; }
@media (max-width: 640px) { .post-row { grid-template-columns: 1fr; gap: 6px; } }

/* ---------- Ask ---------- */
.ask-wrap { display: grid; grid-template-columns: 1fr 1.3fr; gap: clamp(32px, 5vw, 80px); }
@media (max-width: 860px) { .ask-wrap { grid-template-columns: 1fr; } }
.chat { border: 1px solid var(--line); border-radius: 18px; background: var(--bg-2); display: flex; flex-direction: column; height: 520px; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 85%; padding: 12px 16px; border-radius: 16px; font-size: 16px; white-space: pre-wrap; animation: fade .4s both; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--bg); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #17151e; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.typing::after { content: "…"; animation: pulse 1s infinite; }
.chat form { display: flex; border-top: 1px solid var(--line); }
.chat input { flex: 1; background: none; border: 0; color: var(--ink); font: inherit; padding: 18px 20px; outline: none; min-width: 0; }
.chat button[type="submit"] { padding: 0 22px; color: var(--accent); font-family: var(--mono); font-size: 12px; text-transform: uppercase; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.suggest button { font-size: 14px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; text-align: left; transition: border-color .2s; }
.suggest button:hover { border-color: var(--accent); }

/* ---------- Footer ---------- */
footer { padding: clamp(80px, 14vh, 160px) var(--gutter) 32px; border-top: 1px solid var(--line); }
.big-cta { font-family: var(--serif); font-size: clamp(56px, 12vw, 200px); line-height: .88; letter-spacing: -0.04em; display: inline-block; }
.big-cta em { color: var(--accent); }
.big-cta:hover em { font-style: normal; }
.foot-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--line); }
.foot-row a:hover { color: var(--accent); }
.socials { display: flex; gap: 24px; }

/* ---------- Command palette ---------- */
.palette { margin: 12vh auto 0; width: min(620px, calc(100% - 32px)); background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 40px 120px rgba(0,0,0,.6); }
.palette input { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--ink); font: inherit; font-size: 18px; padding: 20px 22px; outline: none; }
.palette ul { list-style: none; max-height: 50vh; overflow-y: auto; padding: 8px; }
.palette li { padding: 12px 14px; border-radius: 10px; display: flex; justify-content: space-between; gap: 12px; cursor: pointer; }
.palette li[aria-selected="true"] { background: #1b1924; }
.palette li .mono { color: var(--muted); }

/* ---------- Reveal ---------- */
.reveal { opacity: 0; transform: translateY(40px); transition: opacity 1s var(--ease), transform 1s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- Post page ---------- */
.post-hero { padding: 160px var(--gutter) 48px; border-bottom: 1px solid var(--line); }
.post-hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(48px, 8vw, 120px); line-height: .92; letter-spacing: -0.03em; max-width: 1100px; margin-top: 20px; }
.prose { max-width: 700px; margin: 0 auto; padding: 64px var(--gutter) 120px; font-size: 19px; line-height: 1.7; }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { font-family: var(--serif); font-weight: 400; font-size: 40px; line-height: 1.1; margin-top: 1.6em; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose blockquote { border-left: 2px solid var(--accent); padding-left: 20px; font-family: var(--serif); font-style: italic; font-size: 26px; line-height: 1.3; }
.prose code { font-family: var(--mono); font-size: .85em; background: #17151e; padding: 2px 6px; border-radius: 4px; }
.prose pre { background: #111017; border: 1px solid var(--line); padding: 20px; border-radius: 12px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose img { border-radius: 12px; }
.back { display: inline-block; margin-top: 8px; }
.back:hover { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .hero h1 .ch { transform: none; }
  html { scroll-behavior: auto; }
}

/* ---------- About: portrait ---------- */
#about .about-grid { grid-template-columns: minmax(260px, 0.8fr) 1.2fr; align-items: start; }
.portrait { position: relative; margin: 0; border-radius: 20px; overflow: hidden; aspect-ratio: 4 / 5; background: var(--bg-2); }
.portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 55% 55%; filter: grayscale(1) contrast(1.05) brightness(.9); transform: scale(1.04); transition: filter 1.2s var(--ease), transform 1.6s var(--ease); }
.portrait::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 50%, rgba(7,7,10,.75)), var(--accent); mix-blend-mode: multiply; opacity: .35; transition: opacity 1s var(--ease); pointer-events: none; }
.portrait:hover img { filter: none; transform: scale(1); }
.portrait:hover::after { opacity: 0; }
.portrait figcaption { position: absolute; left: 18px; bottom: 16px; z-index: 2; color: var(--ink); }
.about-lead { margin: 16px 0 24px; }
.about-body { color: var(--muted); max-width: 680px; margin-bottom: 32px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat b { font-size: clamp(32px, 3.4vw, 48px); }
.langs { margin-top: 28px; }
.langs .work-tags { margin-top: 10px; }

/* ---------- Experience timeline ---------- */
.timeline { list-style: none; border-top: 1px solid var(--line); }
.role { display: grid; grid-template-columns: 200px 1fr; gap: 24px; padding: 32px 0; border-bottom: 1px solid var(--line); }
.role summary { list-style: none; cursor: pointer; }
.role summary::-webkit-details-marker { display: none; }
.role h3 { font-family: var(--serif); font-weight: 400; font-size: clamp(28px, 3.4vw, 46px); line-height: 1.05; letter-spacing: -0.01em; transition: color .3s; }
.role summary:hover h3 { color: var(--accent); }
.role h3::after { content: " +"; color: var(--muted); font-size: .6em; }
.role details[open] h3::after { content: " −"; }
.role-co { display: block; margin-top: 6px; color: var(--muted); }
.role ul { list-style: none; margin-top: 18px; display: grid; gap: 10px; max-width: 820px; }
.role li { padding-left: 22px; position: relative; }
.role li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }
.role .chip { display: inline-block; margin-top: 8px; }
@media (max-width: 760px) { .role { grid-template-columns: 1fr; gap: 8px; } }

/* ---------- Credentials ---------- */
.cred-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.cred { background: var(--bg); padding: 28px; }
.cred-item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.cred-item:last-child { border-bottom: 0; }
.cred-item h4 { font-family: var(--serif); font-weight: 400; font-size: 24px; line-height: 1.15; }
.cred-item p { color: var(--muted); font-size: 15px; margin-top: 4px; }
.skill-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 28px; margin-top: 48px; }
.skill-grid .work-tags { margin-top: 12px; }
.skill-grid .chip { white-space: normal; }
@media (max-width: 900px) { .cred-grid { grid-template-columns: 1fr; } }

/* ---------- Medium ---------- */
.medium-head { display: flex; justify-content: space-between; margin: 48px 0 20px; }
.medium-head a:hover { color: var(--accent); }
.medium-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 20px; }
.mcard { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--bg-2); display: flex; flex-direction: column; transition: transform .5s var(--ease), border-color .3s; }
.mcard:hover { transform: translateY(-6px); border-color: var(--accent); }
.mimg { aspect-ratio: 16 / 9; background: linear-gradient(135deg, var(--accent), var(--accent-2)); overflow: hidden; }
.mimg img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(.6); transition: filter .6s, transform .8s var(--ease); }
.mcard:hover .mimg img { filter: none; transform: scale(1.04); }
.mbody { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.mbody h4 { font-family: var(--serif); font-weight: 400; font-size: 26px; line-height: 1.1; }
.mbody p { color: var(--muted); font-size: 15px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.post-cover { display: block; width: min(1000px, calc(100% - 2 * var(--gutter))); margin: 48px auto 0; border-radius: 16px; }
.custom-prose { margin: 0; padding: 0; max-width: 760px; }
.seeking { font-family: var(--serif); font-style: italic; color: var(--accent); font-size: clamp(20px, 2vw, 26px); line-height: 1.25; margin-bottom: 24px; max-width: 640px; }
@media (max-width: 860px) {
  #about .about-grid { grid-template-columns: 1fr; }
  .portrait { max-width: 480px; }
}
