/* ============================================================
   Legs — Porthole Dossier
   Dark by default. System-aware. No framework.
   ============================================================ */

:root {
  --ink: #0A1628;
  --ink-2: #0F1E33;
  --ink-3: #14263F;
  --paper: #F0EAD6;
  --mute: #8594A8;
  --rule: rgba(240, 234, 214, 0.08);
  --rule-strong: rgba(240, 234, 214, 0.16);

  --shell: #E8590C;
  --bubble: #7FB8D4;
  --lamp: #E9B872;

  --bg: var(--ink);
  --bg-2: var(--ink-2);
  --fg: var(--paper);
  --fg-mute: var(--mute);

  --measure: 68ch;
  --col: 720px;

  --step-0: 0.875rem;
  --step-1: 1.0625rem;
  --step-2: 1.25rem;
  --step-3: 1.625rem;
  --step-4: 2.25rem;
  --step-5: 3.25rem;
  --step-6: 4.75rem;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease-out: cubic-bezier(.2, .9, .3, 1);

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--paper);
    --bg-2: #E9E1C8;
    --fg: var(--ink);
    --fg-mute: #5A6878;
    --rule: rgba(10, 22, 40, 0.10);
    --rule-strong: rgba(10, 22, 40, 0.22);
    color-scheme: light;
  }
}

/* Cross-document view transitions */
@view-transition { navigation: auto; }

::selection { background: var(--shell); color: var(--paper); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: var(--step-1);
  line-height: 1.65;
  color: var(--fg);
  background: var(--bg);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient background: slow, low-contrast gradient drift */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -1;
  background:
    radial-gradient(1200px 800px at 15% -10%, rgba(127, 184, 212, 0.08), transparent 60%),
    radial-gradient(900px 700px at 110% 20%, rgba(233, 184, 114, 0.05), transparent 65%),
    radial-gradient(1000px 900px at 50% 110%, rgba(232, 89, 12, 0.04), transparent 60%);
  animation: drift 32s var(--ease) infinite alternate;
  pointer-events: none;
}

@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  100% { transform: translate3d(2%, -1%, 0) scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   Type
   ============================================================ */

.display {
  font-family: "Winky Rough", "Fraunces", Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.05;
}

h1, h2, h3, h4 {
  font-family: "Inter", sans-serif;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 2.25rem 0 0.75rem;
  color: var(--fg);
}

h1 { font-size: var(--step-4); font-weight: 700; letter-spacing: -0.025em; }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p { margin: 0 0 1rem; }

a {
  color: var(--fg);
  text-decoration: none;
  background-image: linear-gradient(90deg, var(--bubble), var(--shell));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 1px;
  transition: background-size 220ms var(--ease-out), color 220ms var(--ease);
  padding-bottom: 2px;
}

a:hover { background-size: 100% 1px; color: var(--fg); }

a.plain { background: none; padding: 0; }
a.plain:hover { color: var(--shell); }

hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2.5rem 0;
}

small, .meta { font-size: var(--step-0); color: var(--fg-mute); }

code, pre, .mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:not(pre) > code {
  font-size: 0.92em;
  background: var(--bg-2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--rule);
}

pre {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  padding: 1rem 1.15rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.55;
}

pre code { background: transparent; padding: 0; border: 0; font-size: inherit; }

blockquote {
  border-left: 2px solid var(--shell);
  margin: 1.5rem 0;
  padding: 0.1rem 0 0.1rem 1.25rem;
  color: var(--fg-mute);
  font-style: italic;
}

/* ============================================================
   Layout
   ============================================================ */

.wrap {
  max-width: var(--col);
  margin: 0 auto;
  padding: 0 1.5rem;
}

main.wrap { padding-top: 2rem; padding-bottom: 5rem; }

/* ============================================================
   Header
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  background: color-mix(in oklab, var(--bg) 72%, transparent);
  border-bottom: 1px solid var(--rule);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 1rem;
}

.site-title {
  font-family: "Winky Rough", serif;
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--fg);
  background: none;
  padding: 0;
}

.site-title:hover { color: var(--shell); background: none; }

.nav-categories {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.nav-categories a {
  display: inline-flex;
  align-items: center;
  padding: 0;
  background: none;
  border-radius: 999px;
}

.nav-categories a[aria-current="page"] .porthole {
  box-shadow: 0 0 0 2px var(--shell);
}

/* ============================================================
   Porthole — the signature component
   ============================================================ */

.porthole {
  position: relative;
  display: inline-block;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--ink-2);
  isolation: isolate;
  transition: transform 280ms var(--ease-out);
}

.porthole img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Rotating conic ring revealed on hover — the "subtle flash" */
.porthole::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    var(--bubble),
    var(--lamp),
    var(--shell),
    var(--bubble)
  );
  opacity: 0;
  transition: opacity 320ms var(--ease);
  z-index: -1;
  animation: spin 6s linear infinite;
  animation-play-state: paused;
}

.porthole:hover::before,
a:hover .porthole::before {
  opacity: 1;
  animation-play-state: running;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Sizes */
.porthole.sm { width: 24px; height: 24px; }
.porthole.md { width: 36px; height: 36px; }
.porthole.lg { width: 64px; height: 64px; }
.porthole.xl { width: 160px; height: 160px; }
.porthole.hero { width: clamp(180px, 28vw, 260px); height: clamp(180px, 28vw, 260px); }

.porthole.hero::before { inset: -3px; }

/* ============================================================
   Home
   ============================================================ */

.home-hero {
  padding: 3.5rem 0 2.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
}

.home-hero h1 {
  font-family: "Winky Rough", serif;
  font-size: clamp(3rem, 9vw, var(--step-6));
  font-weight: 500;
  letter-spacing: -0.03em;
  margin: 0 0 1rem;
  line-height: 0.95;
  background: linear-gradient(100deg, var(--paper) 20%, var(--bubble) 55%, var(--paper) 85%);
  background-size: 200% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  animation: sheen 14s var(--ease) infinite;
}

@keyframes sheen {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

.home-hero p {
  font-size: var(--step-2);
  color: var(--fg-mute);
  max-width: 52ch;
  line-height: 1.5;
  margin: 0;
}

.section-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-mute);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  font-weight: 500;
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Post list — no boxes, hairlines */
.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  border-bottom: 1px solid var(--rule);
}

.post-list li:first-child { border-top: 1px solid var(--rule); }

.post-list a {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1.1rem 0;
  background: none;
  color: var(--fg);
  transition: transform 220ms var(--ease-out), color 220ms var(--ease);
}

.post-list a:hover {
  background: none;
  transform: translateX(4px);
  color: var(--fg);
}

.post-list .title {
  font-size: var(--step-2);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.post-list time {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--fg-mute);
  letter-spacing: 0.02em;
}

.empty {
  color: var(--fg-mute);
  font-style: italic;
  padding: 1rem 0;
}

/* ============================================================
   Post
   ============================================================ */

.post { padding-top: 1rem; }

.post-header {
  padding: 2.5rem 0 1.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.5rem;
  align-items: start;
}

.post-header .porthole.hero {
  view-transition-name: post-porthole;
}

.post-header-text { min-width: 0; }

.post-header h1 {
  font-family: "Winky Rough", serif;
  font-size: clamp(2rem, 5vw, var(--step-5));
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 0.25rem 0 1rem;
  line-height: 1.02;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  color: var(--fg-mute);
  font-size: var(--step-0);
  margin: 0;
}

.post-meta time {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg);
  background: none;
  padding: 0;
}

.tag {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--fg-mute);
  padding: 0.18rem 0.55rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
}

.draft-badge {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  color: var(--lamp);
  border: 1px solid var(--lamp);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.post-body {
  max-width: var(--measure);
}

.post-body > * + * { margin-top: 1.05rem; }

.post-body h2 { margin-top: 2.5rem; }
.post-body h3 { margin-top: 2rem; }

.post-body a {
  color: var(--fg);
  background-image: linear-gradient(90deg, var(--bubble), var(--shell));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
}

.post-body a:hover { color: var(--bubble); }

/* ============================================================
   Accordion — uses native <details> + modern height animation
   ============================================================ */

details.accordion {
  border-top: 1px solid var(--rule);
  padding: 0;
  margin: 1.25rem 0;
  interpolate-size: allow-keywords;
}

details.accordion:last-of-type { border-bottom: 1px solid var(--rule); }

details.accordion summary {
  cursor: pointer;
  list-style: none;
  padding: 0.9rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  font-size: var(--step-1);
  color: var(--fg);
  user-select: none;
  transition: color 180ms var(--ease);
}

details.accordion summary::-webkit-details-marker { display: none; }

details.accordion summary::before {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 1.5px solid var(--bubble);
  border-bottom: 1.5px solid var(--bubble);
  transform: rotate(-45deg);
  transition: transform 240ms var(--ease-out);
  flex-shrink: 0;
}

details.accordion[open] > summary::before {
  transform: rotate(45deg);
}

details.accordion summary:hover { color: var(--bubble); }

/* Modern height animation for <details> content */
details.accordion::details-content {
  overflow: hidden;
  block-size: 0;
  transition: block-size 320ms var(--ease-out), content-visibility 320ms allow-discrete;
}

details.accordion[open]::details-content {
  block-size: auto;
}

details.accordion > *:not(summary) { margin-left: 1.6rem; }
details.accordion[open] > *:not(summary):last-child { padding-bottom: 1rem; }

/* ============================================================
   Mermaid — dark theme + draw-in animation
   ============================================================ */

pre.mermaid {
  background: transparent;
  border: 0;
  padding: 1.5rem 0;
  text-align: center;
  overflow: visible;
}

pre.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Draw-in animation: set via JS when in viewport */
pre.mermaid.draw svg .edgePath path,
pre.mermaid.draw svg .flowchart-link {
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  animation: draw 900ms var(--ease-out) forwards;
}

pre.mermaid.draw svg .node,
pre.mermaid.draw svg .cluster {
  opacity: 0;
  animation: node-in 500ms var(--ease-out) forwards;
}

pre.mermaid.draw svg .edgeLabel,
pre.mermaid.draw svg .label {
  opacity: 0;
  animation: node-in 400ms var(--ease-out) forwards;
  animation-delay: 600ms;
}

@keyframes draw  { to { stroke-dashoffset: 0; } }
@keyframes node-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Footer
   ============================================================ */

.site-footer {
  border-top: 1px solid var(--rule);
  margin-top: 4rem;
  padding: 1.75rem 0 2.5rem;
  font-size: var(--step-0);
  color: var(--fg-mute);
}

.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ============================================================
   View Transitions — morph the porthole between pages
   ============================================================ */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 260ms;
  animation-timing-function: var(--ease-out);
}

::view-transition-old(post-porthole),
::view-transition-new(post-porthole) {
  animation-duration: 380ms;
  animation-timing-function: var(--ease-out);
}

/* ============================================================
   Scroll reveal (JS adds .inview)
   ============================================================ */

.reveal {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 500ms var(--ease-out), transform 500ms var(--ease-out);
}

.reveal.inview {
  opacity: 1;
  transform: none;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 640px) {
  .site-header .wrap { height: 52px; }
  .nav-categories { gap: 0.25rem; }
  .porthole.sm { width: 22px; height: 22px; }

  .home-hero { padding: 2.5rem 0 2rem; }

  .post-header {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .post-list a {
    grid-template-columns: 28px 1fr;
    gap: 0.8rem;
  }
  .post-list time { grid-column: 2; margin-top: 0.15rem; }
}
