@view-transition {
  navigation: auto;
}

:root {
  --bg: #181715;
  --fg: #f1eee7;
  --muted: rgba(241, 238, 231, 0.60);
  --faint: rgba(241, 238, 231, 0.36);
  --underline: rgba(241, 238, 231, 0.35);
  --media-bg: rgba(241, 238, 231, 0.06);
  --caption-bg: rgba(24, 23, 21, 0.72);
  --pill-bg: rgba(0, 0, 0, 0.58);
  --pill-bg-hover: rgba(0, 0, 0, 0.80);
  --pill-fg: #f1eee7;
  --mobile-pill: rgba(241, 238, 231, 0.09);
  --card-bg: color-mix(in srgb, #181715 93%, #f1eee7);
  --card-border: rgba(241, 238, 231, 0.09);
  --card-divider: rgba(241, 238, 231, 0.07);
  --card-shadow: inset 0 1px 0 rgba(241, 238, 231, 0.06), 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px -12px rgba(0, 0, 0, 0.6);
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f5f4f1;
  --fg: #1a1917;
  --muted: rgba(26, 25, 23, 0.62);
  --faint: rgba(26, 25, 23, 0.38);
  --underline: rgba(26, 25, 23, 0.34);
  --media-bg: rgba(26, 25, 23, 0.06);
  --caption-bg: rgba(245, 244, 241, 0.78);
  --pill-bg: rgba(20, 19, 18, 0.62);
  --pill-bg-hover: rgba(20, 19, 18, 0.82);
  --pill-fg: #f5f4f1;
  --mobile-pill: rgba(26, 25, 23, 0.08);
  --card-bg: color-mix(in srgb, #f5f4f1 45%, #ffffff);
  --card-border: rgba(26, 25, 23, 0.11);
  --card-divider: rgba(26, 25, 23, 0.08);
  --card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 2px rgba(38, 37, 35, 0.06), 0 12px 32px -12px rgba(38, 37, 35, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    --bg: #f5f4f1;
    --fg: #1a1917;
    --muted: rgba(26, 25, 23, 0.62);
    --faint: rgba(26, 25, 23, 0.38);
    --underline: rgba(26, 25, 23, 0.34);
    --media-bg: rgba(26, 25, 23, 0.06);
    --caption-bg: rgba(245, 244, 241, 0.78);
    --pill-bg: rgba(20, 19, 18, 0.62);
    --pill-bg-hover: rgba(20, 19, 18, 0.82);
    --pill-fg: #f5f4f1;
    --mobile-pill: rgba(26, 25, 23, 0.08);
    --card-bg: color-mix(in srgb, #f5f4f1 45%, #ffffff);
    --card-border: rgba(26, 25, 23, 0.11);
    --card-divider: rgba(26, 25, 23, 0.08);
    --card-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 2px rgba(38, 37, 35, 0.06), 0 12px 32px -12px rgba(38, 37, 35, 0.18);
    color-scheme: light;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Lock full viewport on Home and desktop Projects (daoho.dev exact feel) */
body[data-page="home"] {
  height: 100dvh;
  overflow: hidden;
}

@media (min-width: 769px) and (min-height: 520px) {
  body[data-page="projects"] {
    height: 100dvh;
    overflow: hidden;
  }
}

/* Continuous full-viewport ASCII Lorenz butterfly canvas */
#sim-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  image-rendering: pixelated;
}

.site-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body[data-page="home"] .site-shell {
  height: 100%;
  min-height: 0;
}

@media (min-width: 769px) and (min-height: 520px) {
  body[data-page="projects"] .site-shell {
    height: 100%;
    min-height: 0;
  }
}

a {
  color: inherit;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: opacity 0.15s ease, text-decoration-color 0.15s ease, color 0.15s ease;
}

a:hover {
  text-decoration-color: var(--fg);
}

/* —— Fixed Centered Lowercase Mono Nav (daoho.dev exact) —— */
.site-nav {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding-top: 2rem;
  font-family: var(--font-mono);
  font-size: 13px;
  text-transform: lowercase;
  color: var(--fg);
  view-transition-name: site-nav;
}

.site-nav a {
  text-decoration: none;
  opacity: 0.56;
}

.site-nav a:hover {
  opacity: 1;
}

.site-nav a[aria-current="page"] {
  opacity: 1;
}

.site-nav a:focus-visible,
.theme-toggle:focus-visible {
  opacity: 1;
  outline: 2px solid var(--fg);
  outline-offset: 4px;
  border-radius: 3px;
}

.theme-toggle {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0.35rem;
  margin: -0.35rem;
  color: var(--fg);
  opacity: 0.56;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, transform 0.18s ease;
}

.theme-toggle:hover {
  opacity: 1;
}

.theme-toggle:active {
  transform: scale(0.92);
}

.theme-toggle .icon-moon {
  display: none;
}
.theme-toggle .icon-sun {
  display: block;
}
html[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}
html[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

/* —— Home (daoho.dev bottom-anchored prose + wide-open jellyfish canvas above) —— */
main.page-home {
  position: relative;
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 6rem clamp(1.5rem, 18vw, 20vw) clamp(3.25rem, 11vh, 7.5rem);
}

.home-content {
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
  max-width: 44rem;
}

.home-quote {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  text-transform: lowercase;
  line-height: 1.65;
  letter-spacing: 0.02em;
  color: var(--fg);
  opacity: 0.62;
}

.cursor-blink {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 0.35em;
  transform: translateY(0.15em);
  background-color: var(--fg);
  animation: cursor-blink 1.1s steps(1, end) infinite;
}

@keyframes cursor-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.home-prose {
  max-width: 44rem;
  font-family: var(--font-mono);
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--fg);
}

.home-prose h1 {
  margin: 0 0 0.55rem;
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
}

.home-prose p {
  margin: 0 0 0.5rem;
  color: var(--fg);
}

.home-links {
  margin: 1.15rem 0 0 !important;
  font-size: 13.5px;
}

.home-links a {
  opacity: 0.62;
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-underline-offset: 5px;
}

.home-links a:hover,
.home-links a:focus-visible {
  opacity: 1;
  text-decoration-color: var(--fg);
}

.home-links .sep {
  opacity: 0.4;
  user-select: none;
  margin: 0 0.15rem;
}

/* —— Inline citation link + hover card (daoho.dev style) —— */
.cite {
  position: relative;
  display: inline;
  text-decoration: none;
  white-space: nowrap;
}

/* underline spans the logo + name (text-decoration skips images) */
.cite::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--cite-underline-bottom, -2px);
  height: 1px;
  background: var(--underline);
  pointer-events: none;
  transition: background-color 0.15s ease;
}

.cite:hover::after,
.cite:focus-visible::after {
  background: var(--fg);
}

.cite:focus-visible::after {
  height: 2px;
}

.cite-logo {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 5px;
  vertical-align: -2px;
  user-select: none;
}

.cite:focus-visible {
  outline: none;
}

.cite-card {
  position: absolute;
  left: 0;
  bottom: 100%;
  z-index: 50;
  width: 300px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  color: var(--fg);
  font-family: var(--font-mono);
  white-space: normal;
  text-align: left;
  transform-origin: bottom left;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px) scale(0.98);
  /* close quickly, open after a short hover intent delay */
  transition: opacity 0.08s ease-in, transform 0.08s ease-in, visibility 0s linear 0.11s;
}

/* invisible bridge so the pointer can travel from the link into the card */
.cite-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 12px;
}

.cite:hover .cite-card,
.cite:focus-visible .cite-card {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: opacity 0.12s ease-out 0.055s, transform 0.12s ease-out 0.055s, visibility 0s linear 0.055s;
}

.cite-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 0;
  font-size: 12px;
  line-height: 1;
}

.cite-card-logo {
  width: 16px;
  height: 16px;
  flex: none;
}

.cite-card-name {
  opacity: 0.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cite-dates {
  margin-left: auto;
  padding-left: 0.5rem;
  flex: none;
  opacity: 0.4;
  font-variant-numeric: tabular-nums;
}

.cite-role {
  padding: 10px 14px 0;
  font-size: 13px;
  line-height: 18px;
}

.cite-summary {
  padding: 6px 14px 12px;
  font-size: 12px;
  line-height: 18px;
  opacity: 0.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cite-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--card-divider);
  font-size: 11px;
  line-height: 1;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.cite-card:hover .cite-foot {
  opacity: 0.7;
}

/* touch / narrow screens: just the logo + link, no hover card */
@media (hover: none), (max-width: 768px) {
  .cite-card {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cite-card,
  .cite:hover .cite-card,
  .cite:focus-visible .cite-card {
    transform: none;
    transition: visibility 0s;
  }
}

/* —— Projects (daoho.dev exact horizontal left-right rail on desktop) —— */
main.page-projects {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 3rem;
  min-height: 0;
}

.projects-rail {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-inline: max(1.5rem, calc((100% - 56rem) / 2));
  scroll-padding-inline: max(1.5rem, calc((100% - 56rem) / 2));
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
}

.projects-rail::-webkit-scrollbar {
  display: none;
}

.projects-rail:focus-visible {
  outline: 2px solid var(--faint);
  outline-offset: -2px;
}

.projects-rail.is-dragging,
.projects-rail.is-wheeling {
  scroll-snap-type: none;
}

.projects-rail.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.project-card {
  flex: 0 0 auto;
  width: min(76vw, calc(min(60dvh, 38rem) * 1.5));
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
}

.project-media-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--media-bg);
}

.project-media-link {
  display: block;
  width: 100%;
  height: 100%;
}

.project-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.project-card:hover .project-media,
.project-card:focus-within .project-media {
  transform: scale(1.03);
}

.project-overlay-actions {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  display: flex;
  gap: 0.45rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.project-card:hover .project-overlay-actions,
.project-card:focus-within .project-overlay-actions {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.overlay-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.38rem 0.78rem;
  border-radius: 999px;
  background: var(--pill-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--pill-fg);
  font-family: var(--font-mono);
  font-size: 12px;
  text-decoration: none;
  transition: background 0.16s ease;
}

.overlay-pill:hover {
  background: var(--pill-bg-hover);
  text-decoration: none;
}

.project-caption {
  margin-top: 0.55rem;
  padding: 0.6rem 0.8rem 0.65rem;
  border-radius: 6px;
  background: var(--caption-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background-color 0.3s ease;
}

.project-caption-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.project-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 16.5px;
  line-height: 1.3;
  color: var(--fg);
}

.project-title a {
  text-decoration: none;
}

.project-title a:hover {
  text-decoration: underline;
  text-decoration-color: var(--underline);
}

.project-stat {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.project-tagline {
  margin: 0.25rem 0 0;
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1.48;
  color: var(--muted);
  max-width: 34rem;
}

/* —— Now Page (reesechong.com/now minimal) —— */
main.page-now {
  width: 100%;
  max-width: 38rem;
  margin: 0 auto;
  padding: 7.5rem 1.5rem 5rem;
}

.now-article h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.85rem, 3.6vw, 2.25rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--fg);
}

.now-date {
  margin: 0.55rem 0 2rem;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.now-article p {
  margin: 0 0 1.15rem;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--muted);
}

.now-footnote {
  margin-top: 2.5rem !important;
  font-family: var(--font-mono) !important;
  font-size: 12px !important;
  color: var(--faint) !important;
}

.now-footnote a {
  color: var(--muted);
}

/* Touch devices show overlay pills cleanly */
@media (hover: none) {
  .project-overlay-actions {
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }
}

/* Obscured CS webring — quiet corner, pops a little on hover/focus */
.webring {
  position: fixed;
  right: max(0.7rem, env(safe-area-inset-right));
  bottom: max(0.55rem, env(safe-area-inset-bottom));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  opacity: 0.26;
  transition: opacity 0.18s ease;
}

.webring:hover,
.webring:focus-within {
  opacity: 0.72;
}

.webring a {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  min-height: 1.35rem;
  line-height: 1;
}

.webring-nav {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.85;
}

.webring-home {
  padding: 0.1rem;
}

.webring-mark {
  width: 16px;
  height: 16px;
  display: block;
  opacity: 0.9;
}

.webring-mark-on-light {
  display: none;
}

html[data-theme="light"] .webring-mark-on-dark {
  display: none;
}

html[data-theme="light"] .webring-mark-on-light {
  display: block;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .webring-mark-on-dark {
    display: none;
  }
  html:not([data-theme="dark"]) .webring-mark-on-light {
    display: block;
  }
}

/* Mobile (daoho.dev clean mobile stack for /projects/ + comfortable home padding) */
@media (max-width: 768px) {
  /* Home must scroll on short phones — locked 100dvh clips bio/links */
  body[data-page="home"] {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body[data-page="home"] .site-shell {
    height: auto;
    min-height: 100dvh;
  }

  .site-nav {
    gap: 1.25rem;
    padding-top: calc(1.1rem + env(safe-area-inset-top, 0px));
    padding-inline: 0.75rem;
  }

  .site-nav a,
  .theme-toggle {
    min-height: 2.5rem;
    padding-inline: 0.2rem;
    display: inline-flex;
    align-items: center;
  }

  main.page-home {
    height: auto;
    min-height: 100dvh;
    /* Keep a pond band above the copy; safe-area for notched phones */
    padding:
      max(36vh, calc(4.5rem + env(safe-area-inset-top, 0px)))
      1.25rem
      max(2.75rem, calc(1.25rem + env(safe-area-inset-bottom, 0px)));
  }

  .home-content {
    gap: 1.35rem;
    max-width: 100%;
    /* Soft scrim so quote/bio stay readable over busy koi on small screens */
    margin-inline: -0.35rem;
    padding: 0.9rem 0.55rem 0.35rem;
    border-radius: 10px;
    background: linear-gradient(
      to top,
      color-mix(in srgb, var(--bg) 96%, transparent) 0%,
      color-mix(in srgb, var(--bg) 88%, transparent) 48%,
      color-mix(in srgb, var(--bg) 55%, transparent) 78%,
      color-mix(in srgb, var(--bg) 12%, transparent) 100%
    );
  }

  .home-quote {
    font-size: 13px;
    line-height: 1.55;
  }

  .home-prose {
    font-size: 13.5px;
    line-height: 1.65;
  }

  .home-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0;
    padding-bottom: 0.15rem;
  }

  main.page-projects {
    justify-content: flex-start;
    padding:
      calc(5.25rem + env(safe-area-inset-top, 0px))
      1.15rem
      max(4rem, calc(2.5rem + env(safe-area-inset-bottom, 0px)));
  }

  .projects-rail {
    flex-direction: column;
    overflow-x: visible;
    padding-inline: 0;
    scroll-padding-inline: 0;
    gap: 2.75rem;
    cursor: default;
  }

  .project-card {
    width: 100%;
  }

  .project-media-frame {
    border-radius: 12px;
  }

  .project-overlay-actions {
    opacity: 1;
    pointer-events: auto;
    transform: none;
    left: 0.75rem;
    bottom: 0.75rem;
    gap: 0.35rem;
  }

  .overlay-pill {
    padding: 0.42rem 0.72rem;
    font-size: 11.5px;
  }

  .project-caption {
    padding: 0.55rem 0.7rem 0.6rem;
  }

  .project-tagline {
    font-size: 14px;
    max-width: none;
  }

  main.page-now {
    padding:
      calc(6.5rem + env(safe-area-inset-top, 0px))
      1.25rem
      max(4rem, calc(2.5rem + env(safe-area-inset-bottom, 0px)));
  }

  .now-article p {
    font-size: 1.05rem;
    line-height: 1.65;
  }

  .webring {
    opacity: 0.2;
    right: max(0.55rem, env(safe-area-inset-right));
    bottom: max(0.45rem, env(safe-area-inset-bottom));
  }

  .webring a {
    min-width: 1.6rem;
    min-height: 1.6rem;
  }
}

/* Extra-short phones: still more pond room, slightly tighter type */
@media (max-width: 768px) and (max-height: 700px) {
  main.page-home {
    padding-top: max(30vh, calc(4.1rem + env(safe-area-inset-top, 0px)));
    padding-bottom: max(2.25rem, calc(1rem + env(safe-area-inset-bottom, 0px)));
  }

  .home-content {
    gap: 1.05rem;
    padding-top: 0.75rem;
    background: linear-gradient(
      to top,
      color-mix(in srgb, var(--bg) 97%, transparent) 0%,
      color-mix(in srgb, var(--bg) 92%, transparent) 55%,
      color-mix(in srgb, var(--bg) 70%, transparent) 85%,
      color-mix(in srgb, var(--bg) 20%, transparent) 100%
    );
  }

  .home-prose h1 {
    margin-bottom: 0.4rem;
  }

  .home-links {
    margin-top: 0.85rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .project-media {
    transition: none;
  }
  .cursor-blink {
    animation: none;
  }
}
