/* ============= Tokens ============= */
:root {
  --bg: #fafaf7;
  --ink: #0a0a0a;
  --ink-soft: #555;
  --ink-softer: #888;
  --rule: #d8d8d2;
  --accent: #9eff1f;
  --serif: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sidebar-w: 260px;
  --content-max: 640px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(transparent 60%, var(--accent) 60%);
  background-size: 0% 100%;
  background-repeat: no-repeat;
  transition: background-size 0.35s ease, color 0.2s ease;
  padding: 0 2px;
  margin: 0 -2px;
}
a:hover {
  background-size: 100% 100%;
}
a.plain {
  background: none;
  padding: 0;
  margin: 0;
  color: var(--ink-soft);
  border-bottom: 1px solid currentColor;
  transition: color 0.2s ease;
}
a.plain:hover {
  color: var(--ink);
  background: none;
}

/* ============= Layout ============= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 60px 48px 80px;
  gap: 80px;
}

.app[data-sidebar="top"] {
  grid-template-columns: 1fr;
  max-width: 760px;
  gap: 40px;
}

/* ============= Sidebar ============= */
.sidebar {
  position: sticky;
  top: 60px;
  align-self: start;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}
.app[data-sidebar="top"] .sidebar {
  position: static;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 20px;
}

.brand {
  margin-bottom: 28px;
}
.brand .name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0 0 2px;
}
.brand .clock {
  font-family: var(--mono);
  font-style: italic;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.app[data-sidebar="top"] .brand { margin-bottom: 0; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.app[data-sidebar="top"] .nav {
  flex-direction: row;
  gap: 18px;
}
.nav a {
  display: inline-block;
  width: fit-content;
  background: none;
  padding: 2px 0;
  margin: 0;
  color: var(--ink);
  position: relative;
}
.nav a::before {
  content: "";
  display: inline-block;
  width: 0;
  overflow: hidden;
  transition: width 0.25s ease;
  white-space: pre;
}
.nav a:hover::before {
  content: "→ ";
  width: 1.4em;
}
.nav a.active {
  color: var(--ink);
}
.nav a.active::before {
  content: "→ ";
  width: 1.4em;
}
.nav a:hover {
  background: none;
  color: var(--ink);
}

.sidebar .meta {
  margin-top: 32px;
  color: var(--ink-softer);
  font-size: 12px;
}
.app[data-sidebar="top"] .sidebar .meta { display: none; }

/* ============= Main column ============= */
main {
  max-width: var(--content-max);
  width: 100%;
}

.page {
  display: none;
}
.page.active {
  display: block;
}

.page-title {
  font-family: var(--mono);
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin: 0 0 28px;
  font-weight: 500;
}

/* ============= Home ============= */
.hero-photo {
  width: 100%;
  aspect-ratio: 4/3;
  background: #eee url("assets/maitree.jpg") center/cover no-repeat;
  filter: grayscale(100%) contrast(1.05);
  margin-bottom: 12px;
}
.photo-credit {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-softer);
  margin-bottom: 28px;
}
.bio p {
  margin: 0 0 1em;
  text-wrap: pretty;
}
.bio em {
  font-style: italic;
}

.section-h {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 19px;
  margin: 36px 0 12px;
  color: var(--ink);
}

.list-arrow {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.list-arrow li {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.list-arrow li::before {
  content: "↗";
  color: var(--ink-softer);
  font-family: var(--mono);
  font-size: 13px;
  flex-shrink: 0;
}

/* ============= Musings ============= */
.essay-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
.essay-list li {
  border-bottom: 1px solid var(--rule);
  padding: 22px 0;
}
.essay-list li:first-child { border-top: 1px solid var(--rule); }
.essay-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.essay-row .meta {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-softer);
}
.essay-row .title {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.3;
  font-weight: 400;
}
.essay-row .title a {
  background: none;
  padding: 0;
  margin: 0;
}
.essay-row .title a:hover {
  font-style: italic;
}
.essay-row .excerpt {
  color: var(--ink-soft);
  font-size: 16px;
  margin-top: 4px;
}

/* ============= Projects ============= */
.proj-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 48px;
}
.proj {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.proj-media {
  width: 100%;
  aspect-ratio: 16/10;
  background: #eee;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--rule);
}
.proj-media-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.proj-media .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-softer);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background:
    repeating-linear-gradient(135deg,
      transparent 0 11px,
      rgba(0,0,0,0.04) 11px 12px);
}
.proj-title {
  font-family: var(--serif);
  font-size: 18px;
  font-style: italic;
}
.proj-title::before {
  content: "↳ ";
  color: var(--ink-softer);
  font-style: normal;
}
.proj-desc {
  color: var(--ink-soft);
  font-size: 15px;
}

/* animated placeholders for project media */
.anim-pulse {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 40%, rgba(158,255,31,0.18), transparent 50%),
              radial-gradient(ellipse at 70% 60%, rgba(0,0,0,0.04), transparent 60%);
  animation: pulse 6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.08); opacity: 1; }
}
.anim-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 24px 24px;
  animation: drift 8s linear infinite;
}
@keyframes drift {
  from { background-position: 0 0; }
  to { background-position: 24px 24px; }
}
.anim-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 20px;
}
.anim-bars span {
  flex: 1;
  background: var(--ink);
  height: 30%;
  animation: bar 1.6s ease-in-out infinite;
}
.anim-bars span:nth-child(2) { animation-delay: 0.1s; }
.anim-bars span:nth-child(3) { animation-delay: 0.2s; }
.anim-bars span:nth-child(4) { animation-delay: 0.3s; }
.anim-bars span:nth-child(5) { animation-delay: 0.4s; }
.anim-bars span:nth-child(6) { animation-delay: 0.5s; }
.anim-bars span:nth-child(7) { animation-delay: 0.6s; }
@keyframes bar {
  0%, 100% { height: 20%; }
  50% { height: 80%; }
}

/* ============= Contact ============= */
.contact-list {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-family: var(--serif);
  font-size: 19px;
}
.contact-list li {
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.contact-list .label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-softer);
  width: 90px;
  flex-shrink: 0;
}

/* ============= Essay reader ============= */
.essay-reader {
  max-width: 640px;
}
.essay-back {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 36px;
  display: inline-block;
  background: none;
  padding: 0;
}
.essay-back::before { content: "← "; }
.essay-h1 {
  font-family: var(--serif);
  font-size: 36px;
  line-height: 1.15;
  font-weight: 400;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.essay-meta {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 28px;
  font-size: 15px;
}
.essay-body p {
  margin: 0 0 1em;
  text-wrap: pretty;
}
.essay-body h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 22px;
  margin: 36px 0 8px;
}
.essay-body blockquote {
  border-left: 2px solid var(--accent);
  margin: 24px 0;
  padding: 4px 0 4px 18px;
  color: var(--ink-soft);
  font-style: italic;
}

/* ============= Reveal animations ============= */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.9s ease, transform 0.9s cubic-bezier(.2,.7,.2,1);
}
.reveal.in {
  opacity: 1;
  transform: none;
}

/* Intro animation: stack */
.intro-stack > * {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(.2,.7,.2,1);
}
.intro-stack.run > *:nth-child(1) { transition-delay: 0.05s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(2) { transition-delay: 0.18s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(3) { transition-delay: 0.32s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(4) { transition-delay: 0.46s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(5) { transition-delay: 0.60s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(6) { transition-delay: 0.74s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(7) { transition-delay: 0.88s; opacity: 1; transform: none; }
.intro-stack.run > *:nth-child(n+8) { transition-delay: 1s; opacity: 1; transform: none; }

/* Intro animation: fade-up (whole page) */
.intro-fade {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1s ease, transform 1s cubic-bezier(.2,.7,.2,1);
}
.intro-fade.run {
  opacity: 1;
  transform: none;
}

/* Intro animation: typewriter (clock + name) */
.intro-typer .name,
.intro-typer .clock {
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  vertical-align: bottom;
  border-right: 2px solid transparent;
}
.intro-typer.run .name {
  animation: typing 0.8s steps(20, end) forwards, caret 0.8s ease forwards;
}
.intro-typer.run .clock {
  animation: typing 0.7s steps(8, end) 0.85s forwards, caret 0.7s ease 0.85s forwards;
  width: 0;
}
.intro-typer .name { width: 0; }
@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}
@keyframes caret {
  from { border-right-color: var(--ink); }
  90%  { border-right-color: var(--ink); }
  to   { border-right-color: transparent; }
}
.intro-typer .body-after {
  opacity: 0;
  transition: opacity 0.8s ease 1.7s;
}
.intro-typer.run .body-after { opacity: 1; }

/* ============= Tweaks panel position override (smaller) ============= */
.tweaks-mini {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 50;
}

/* ============= Responsive ============= */
@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
    padding: 32px 24px 60px;
    gap: 32px;
  }
  .sidebar {
    position: static;
  }
  .essay-h1 { font-size: 28px; }
}

/* selection */
::selection {
  background: var(--accent);
  color: var(--ink);
}

/* ============= Home — typewriter name + cycling roles ============= */
.home-page { width: 100%; }
.home-hero {
  min-height: calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 16px 100px;
  position: relative;
}
.home-hero-inner {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Typewriter name */
.home-name {
  font-family: var(--serif);
  font-size: clamp(36px, 6.5vw, 76px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  font-weight: 400;
  margin: 0;
  display: inline-block;
  position: relative;
  white-space: nowrap;
}
/* Invisible ghost reserves the full name's width */
.home-name-ghost {
  visibility: hidden;
  white-space: nowrap;
  display: inline-block;
}
/* Visible layer absolutely positioned, left-anchored — grows letter by letter */
.home-name-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: baseline;
  white-space: nowrap;
}
.home-name-typed {
  white-space: pre;
}
.home-name-caret {
  display: inline-block;
  width: 2px;
  height: 0.85em;
  background: var(--ink);
  margin-left: 4px;
  align-self: center;
  animation: home-caret 0.85s steps(2) infinite;
}
.home-page[data-phase="done"] .home-name-caret {
  display: none;
}
@keyframes home-caret {
  50% { opacity: 0; }
}

/* Roles line */
.home-roles {
  margin-top: 56px;
  font-family: var(--serif);
  font-size: clamp(20px, 2.6vw, 30px);
  line-height: 1.3;
  font-weight: 400;
  color: var(--ink);
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 0.35em;
  flex-wrap: nowrap;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.7s ease 0s, transform 0.7s cubic-bezier(.2,.7,.2,1) 0s;
}
.home-page[data-phase="done"] .home-roles {
  opacity: 1;
  transform: none;
  transition-delay: 0.1s;
}
.home-roles-label {
  color: var(--ink-soft);
}
.home-roles-dot {
  color: var(--ink-soft);
  margin-left: -0.15em;
}

/* Cycling word slot */
.home-cycle {
  position: relative;
  display: inline-block;
  font-style: italic;
  font-weight: 400;
  vertical-align: baseline;
}
.home-cycle-spacer {
  visibility: hidden;
  display: inline-block;
  font-style: italic;
  padding: 0 6px;
}
.home-cycle-word {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.45s ease, transform 0.55s cubic-bezier(.2,.7,.2,1);
  background: linear-gradient(transparent 62%, var(--accent) 62%, var(--accent) 92%, transparent 92%);
  background-repeat: no-repeat;
  padding: 0 6px;
  font-style: italic;
}
.home-cycle-word.on {
  opacity: 1;
  transform: translateY(0);
}

/* Scroll hint */
.home-scroll-hint {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-softer);
  opacity: 0;
  transition: opacity 0.6s ease 1.6s;
}
.home-page[data-phase="done"] .home-scroll-hint {
  opacity: 1;
  animation: bounce 2.4s ease-in-out 1.6s infinite;
}
.home-scroll-line {
  width: 1px;
  height: 36px;
  background: var(--ink-softer);
}
@keyframes bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.6; }
  50% { transform: translateX(-50%) translateY(6px); opacity: 1; }
}

/* Home below-fold sections */
.home-sec {
  max-width: 640px;
  margin: 64px auto 0;
  padding: 0 8px;
}
.home-sec-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-softer);
  margin-bottom: 18px;
  border-top: 1px solid var(--rule);
  padding-top: 24px;
}
.home-sec-body {
  font-size: 17px;
  line-height: 1.6;
  margin: 0 0 1em;
  text-wrap: pretty;
}
.home-essay-list { list-style: none; padding: 0; margin: 0; }
.home-essay-list li { border-bottom: 1px solid var(--rule); }
.home-essay-list li:first-child { border-top: 1px solid var(--rule); }
.home-essay-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 18px 0;
  background: none;
  margin: 0;
  gap: 24px;
}
.home-essay-list a:hover { background: none; }
.home-essay-list a:hover .home-essay-title { font-style: italic; }
.home-essay-title {
  font-family: var(--serif);
  font-size: 19px;
  transition: font-style 0.2s ease;
}
.home-essay-meta {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-softer);
  flex-shrink: 0;
}
.home-elsewhere {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  font-family: var(--mono);
  font-size: 13px;
}

@media (max-width: 700px) {
  .home-roles { white-space: normal; }
}


/* ============= Home full-bleed layout (no sidebar) ============= */
.app.home-app {
  display: block;
  max-width: none;
  padding: 0;
  margin: 0;
  min-height: 100vh;
}
.app.home-app > main {
  max-width: none;
  width: 100%;
  display: block;
}
.app.home-app .home-page { width: 100%; }

/* Non-home pages: centered max-width column with top padding to clear floating nav */
.app.home-app > main > .page:not(.home-page) {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 120px 32px 120px;
}
@media (max-width: 600px) {
  .app.home-app > main > .page:not(.home-page) {
    padding: 84px 20px 80px;
  }
}

/* Make hero full viewport on home */
.app.home-app .home-hero {
  min-height: 100vh;
  padding: 60px 24px 100px;
}

/* Below-fold sections need their own container on home (no sidebar) */
.app.home-app .home-page > section:not(.home-hero) {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 24px;
  padding-right: 24px;
}
.app.home-app .home-page > section:last-child {
  padding-bottom: 120px;
}

/* ============= Top-center nav ============= */
.nav-shell {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  opacity: 0;
  pointer-events: none;
  outline: none;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(.2,.7,.2,1);
}
.nav-shell.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ----- Expanded variant (home): nav always visible, no dot ----- */
.nav-shell.expanded .float-nav {
  position: static;
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

/* ----- Compact variant (subpages): dot collapses into links on hover ----- */
.nav-shell.compact {
  min-width: 14px;
  min-height: 14px;
}
.nav-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(.2,.7,.2,1);
  box-shadow: 0 0 0 1px rgba(20,20,18,0.06);
}
.nav-shell.compact:hover .nav-dot,
.nav-shell.compact:focus-within .nav-dot {
  opacity: 0;
  transform: scale(0.4);
}

.nav-shell.compact .float-nav {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(.2,.7,.2,1);
}
.nav-shell.compact:hover .float-nav,
.nav-shell.compact:focus-within .float-nav {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
  transition-delay: 0.05s;
}

/* ----- Shared nav styling ----- */
.float-nav {
  display: flex;
  gap: 28px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.float-nav a {
  color: var(--ink);
  padding: 0 4px;
  margin: 0;
  position: relative;
  background-image: linear-gradient(transparent 55%, var(--accent) 55%, var(--accent) 92%, transparent 92%);
  background-size: 0% 100%;
  background-repeat: no-repeat;
  background-position: 0 0;
  transition: background-size 0.25s cubic-bezier(.2,.7,.2,1);
}
.float-nav a:hover,
.float-nav a.active {
  background-size: 100% 100%;
}

@media (max-width: 600px) {
  .nav-shell { top: 14px; }
  .float-nav { gap: 16px; font-size: 11px; }
}

/* Hide scroll hint when not on home (defensive) */
.app:not(.home-app) .home-scroll-hint { display: none; }
