/* svw mainpage — TokyoNight-inspired palette, auto light/dark */

:root {
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
    sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --radius: 10px;
  --maxw: 1080px;
}

/* Dark (TokyoNight Moon) — default when the OS prefers dark */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1b26;
  --bg-soft: #1f2235;
  --bg-card: #22243a;
  --fg: #c0caf5;
  --fg-dim: #9aa5ce;
  --fg-faint: #565f89;
  --border: #2f354d;
  --accent: #7aa2f7;
  --accent2: #bb9af7;
  --green: #9ece6a;
  --cyan: #7dcfff;
  --orange: #ff9e64;
  --red: #f7768e;
  --code-bg: #15161f;
  --shadow: rgba(0, 0, 0, 0.45);
}

/* Light (TokyoNight Day) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #e9ebf2;
    --bg-soft: #e1e3ec;
    --bg-card: #f4f5fa;
    --fg: #3760bf;
    --fg-dim: #6172b0;
    --fg-faint: #a8aecb;
    --border: #c8cbf0;
    --accent: #2e7de9;
    --accent2: #9854f1;
    --green: #587539;
    --cyan: #007197;
    --orange: #b15c00;
    --red: #f52a65;
    --code-bg: #d8daf0;
    --shadow: rgba(50, 60, 120, 0.18);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e9ebf2;
  --bg-soft: #e1e3ec;
  --bg-card: #f4f5fa;
  --fg: #3760bf;
  --fg-dim: #6172b0;
  --fg-faint: #a8aecb;
  --border: #c8cbf0;
  --accent: #2e7de9;
  --accent2: #9854f1;
  --green: #587539;
  --cyan: #007197;
  --orange: #b15c00;
  --red: #f52a65;
  --code-bg: #d8daf0;
  --shadow: rgba(50, 60, 120, 0.18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.65;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1.2rem;
  padding: 0.7rem 1.4rem;
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.nav .brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  white-space: nowrap;
}
.nav .brand:hover { text-decoration: none; }
.nav .brand .logo { color: var(--accent2); }
.nav .links {
  display: flex;
  gap: 0.4rem 1.1rem;
  flex-wrap: wrap;
  margin-left: auto;
  margin-right: 0.8rem;
  align-items: center;
}
/* the switcher sits outside .links so narrow screens never push it off:
   links wrap onto a second row, the pill stays pinned top-right */
.nav .switcher { flex: none; }
.nav .links a { color: var(--fg-dim); font-size: 0.95rem; }
.nav .links a.active { color: var(--accent); font-weight: 600; }
.nav .links a:hover { color: var(--accent); text-decoration: none; }

/* theme + language folded into one segmented control */
.switcher {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  overflow: hidden;
}
.theme-toggle, .lang-toggle {
  border: none;
  background: none;
  color: var(--fg-dim);
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}
.theme-toggle { border-right: 1px solid var(--border); }
.theme-toggle:hover, .lang-toggle:hover { color: var(--accent); }
.switcher:hover { border-color: var(--accent); }

/* ---------- hero ---------- */
.hero {
  text-align: center;
  padding: 4.5rem 1.5rem 3rem;
  max-width: var(--maxw);
  margin: 0 auto;
}
/* ---------- hero wordmark ----------
   "Simple Virtual Wave" — drawn on canvas by assets/main.js with the same
   3x5 block glyphs as the svw empty-screen splash (src/render/render.cpp), with an
   animated left-to-right wave gradient. Without canvas/JS the <h1> below is
   the fallback, set in the splash-style pixel font (Press Start 2P, OFL). */
@font-face {
  font-family: "Press Start 2P";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/press-start-2p-latin.woff2") format("woff2");
}
.hero h1.wordmark-text .initial {
  /* word-initial letters: bigger, and only the vermilion stroke blinks */
  font-size: 1.4em;
  -webkit-text-stroke: 2px var(--red);
  animation: initial-stroke-blink 2.2s ease-in-out infinite;
}
@keyframes initial-stroke-blink {
  0%, 100% { -webkit-text-stroke-color: var(--red); }
  50%      { -webkit-text-stroke-color: transparent; }
}

.hero h1.wordmark-text {
  margin: 0 0 0.5rem;
  font-family: "Press Start 2P", var(--font-mono);
  font-size: clamp(0.95rem, 3.2vw, 2.1rem);
  letter-spacing: 0.01em;
  line-height: 1.5;
  background: linear-gradient(90deg,
      var(--accent) 0%, var(--cyan) 25%, var(--green) 50%,
      var(--accent2) 75%, var(--accent) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: wordmark-wave 6s linear infinite;
}
.wordmark-rule {
  display: block;
  height: 3px;
  width: min(38rem, 85%);
  margin: 0 auto;
  border-radius: 2px;
  background: linear-gradient(90deg,
      var(--accent), var(--accent2), var(--accent));
  background-size: 200% 100%;
  animation: wordmark-wave 6s linear infinite;
}
@keyframes wordmark-wave {
  from { background-position: 0% 0; }
  to   { background-position: -200% 0; }  /* flows left to right */
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .wordmark-text, .wordmark-rule { animation: none; }
  .install-jump { animation: none; transition: none; }
}

.hero .tagline {
  color: var(--fg-dim);
  font-size: 1.15rem;
  max-width: 46rem;
  margin: 0 auto 2rem;
}

.install-jump {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0 auto 1.8rem;
  padding: 0.9rem 1.6rem;
  color: #fff;
  background:
    linear-gradient(135deg, var(--accent), var(--accent2)) padding-box,
    linear-gradient(90deg, var(--red), var(--orange), var(--green),
      var(--cyan), var(--accent), var(--accent2), var(--red)) border-box;
  background-size: 100% 100%, 300% 100%;
  border: 2px solid transparent;
  border-radius: 14px;
  box-shadow: 0 12px 36px color-mix(in srgb, var(--accent) 35%, transparent);
  text-align: left;
  transition: transform 150ms ease, box-shadow 150ms ease;
  animation: install-border-wave 2.2s linear infinite,
    install-border-flash 3.2s ease-in-out infinite;
}
.install-jump:hover {
  color: #fff;
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 10px 30px var(--shadow);
}
.install-jump svg {
  width: 2rem;
  height: 2rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.install-jump-copy { display: flex; flex-direction: column; line-height: 1.25; }
.install-jump-copy strong { font-size: 1.25rem; letter-spacing: 0.01em; }
.install-jump-copy small {
  margin-top: 0.18rem;
  color: rgba(255, 255, 255, 0.82);
}
@keyframes install-border-wave {
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 0, -300% 0; }
}
@keyframes install-border-flash {
  0%, 100% {
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 24%, transparent);
  }
  50% {
    box-shadow: 0 0 22px color-mix(in srgb, var(--accent2) 62%, transparent);
  }
}

#download { scroll-margin-top: 5rem; }

.install-cmd {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 52rem;
  margin: 0 auto 1.6rem;
  padding: 0.7rem 0.9rem 0.7rem 1.1rem;
  background: var(--code-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px var(--shadow);
  text-align: left;
}
.install-cmd code {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--green);
  overflow-x: auto;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.install-platforms {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 0.1rem;
  padding-right: 0.8rem;
  border-right: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.25;
  white-space: nowrap;
}
.install-platforms strong {
  color: var(--accent);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
}
.install-cmd .prompt { color: var(--fg-faint); user-select: none; }
.copy-btn {
  flex: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-dim);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  cursor: pointer;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

.hero-cta { display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }
.btn {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--fg);
  background: var(--bg-card);
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.btn.primary:hover { filter: brightness(1.1); }

/* ---------- generic sections ---------- */
.section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2.6rem 1.5rem;
}
.section h2 {
  font-size: 1.7rem;
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
}
.section > p.lead { color: var(--fg-dim); margin-top: 0; max-width: 52rem; }
.section h3 { font-size: 1.2rem; margin: 1.8rem 0 0.4rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1.4rem;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.card:hover { border-color: var(--accent); }
.card .icon { font-size: 1.3rem; }
.card h3 { margin: 0.4rem 0 0.3rem; font-size: 1.05rem; }
.card p { margin: 0; color: var(--fg-dim); font-size: 0.92rem; }

/* ---------- code blocks ---------- */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
}
code { font-family: var(--font-mono); }
p code, li code, td code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.9em;
}
pre code { background: none; padding: 0; }

/* Terminal-style command highlighting. The same semantic palette adapts to
   both page themes through the existing color variables. */
pre.terminal-code,
.install-cmd.terminal-code {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  box-shadow:
    inset 3px 0 0 color-mix(in srgb, var(--accent) 75%, transparent),
    inset 0 1px 0 color-mix(in srgb, var(--fg) 8%, transparent),
    0 10px 28px color-mix(in srgb, var(--shadow) 34%, transparent);
}
.terminal-command { color: var(--fg-dim); }
.terminal-command .tok-prompt {
  color: var(--green);
  font-weight: 800;
  user-select: none;
}
.terminal-command .tok-command {
  color: var(--cyan);
  font-weight: 700;
}
.terminal-command .tok-keyword {
  color: var(--accent);
  font-weight: 650;
}
.terminal-command .tok-option { color: var(--accent2); }
.terminal-command .tok-string { color: var(--green); }
.terminal-command .tok-path { color: var(--cyan); }
.terminal-command .tok-number { color: var(--orange); }
.terminal-command .tok-variable { color: var(--accent2); }
.terminal-command .tok-operator {
  color: var(--red);
  font-weight: 700;
}
.terminal-command .tok-comment {
  color: var(--fg-faint);
  font-style: italic;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  margin: 1rem 0;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  text-align: left;
}
th { background: var(--bg-card); font-family: var(--font-mono); font-weight: 600; }
td { color: var(--fg-dim); }
td:first-child { color: var(--fg); }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding: 1.6rem 1.5rem 2.4rem;
  text-align: center;
  color: var(--fg-faint);
  font-size: 0.88rem;
}

/* ---------- docs page ---------- */
.docs-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 2rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
/* grid/flex children default to min-width:auto — a nowrap sidebar entry would
   otherwise force the whole page wider than a phone viewport */
.docs-nav, .docs-content { min-width: 0; }
.docs-nav {
  position: sticky;
  top: 4.2rem;
  align-self: start;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  font-size: 0.88rem;
  border-right: 1px solid var(--border);
  padding-right: 1rem;
}
.docs-nav .nav-section { margin-bottom: 0.8rem; }
.docs-nav .nav-section > a {
  font-weight: 700;
  color: var(--fg);
}
.docs-nav .nav-count { color: var(--fg-faint); font-size: 0.8rem; }
.docs-nav .nav-cmd {
  display: block;
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.06rem 0 0.06rem 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.docs-nav a:hover { color: var(--accent); text-decoration: none; }

.docs-content h1 { margin-top: 0; }
.docs-content h2 {
  margin-top: 2.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.doc-entry { margin-bottom: 2rem; }
.doc-entry h3 { font-family: var(--font-mono); font-size: 1.15rem; }
.doc-entry .usage {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--cyan);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.doc-entry .try-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin: 0.7rem 0 0.3rem;
}

/* ---------- asciinema cast demos ---------- */
/* Docs demos are collapsed by default; opening one mounts the same inline,
   width-fitted, auto-playing player as the homepage hero. */
.cast-details {
  margin: 0.7rem 0 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
}
.cast-details > summary {
  cursor: pointer;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
  user-select: none;
}
.cast-details > summary:hover { color: var(--accent); }
.cast-details[open] > summary { border-bottom: 1px solid var(--border); }
.cast-details .cast { border: none; border-radius: 0; aspect-ratio: auto; }

.cast {
  /* asciinema player mount point; recordings are truecolor dark frames */
  background: #1a1b26;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  /* reserve space so lazy-mounted players do not jump the layout */
  aspect-ratio: 100 / 30;
}
.cast.mounted {
  /* once the player exists it computes its own height from the
     terminal geometry and font metrics — a fixed ratio would clip it */
  aspect-ratio: auto;
}
.cast .asciinema-player-wrapper { max-width: 100%; }

.hero .cast {
  box-shadow: 0 16px 50px var(--shadow);
}
/* cast sits at the very top of the hero; the wordmark follows below */
.hero .wordmark-text { margin-top: 2.6rem; }

/* ---------- diagonal duo (hero): For humans / For AI, in parallel ----------
   One frame split along the diagonal: top-left triangle plays the TUI tour
   (red gradient), bottom-right plays the pi agent session (blue gradient).
   Both loop simultaneously; clicking a corner expands that half to full
   frame with a diagonal clip-path wipe. A glowing seam softens the split. */
.duo { margin: 0 auto; max-width: 64rem; }
.duo-frame {
  position: relative;
  border-radius: var(--radius);
  padding: 3px;
  background: linear-gradient(135deg,
      #f7768e 0%, #ff9e64 30%, #1a1b26 50%, #7aa2f7 75%, #bb9af7 100%);
  box-shadow: 0 18px 44px var(--shadow);
}
.duo-stage {
  position: relative;
  aspect-ratio: 10 / 5.4;
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  background: #1a1b26;
}
.duo-layer {
  position: absolute;
  inset: 0;
  transition: clip-path 0.8s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.duo-layer .asciinema-player-wrapper,
.duo-layer .asciinema-player,
.duo-layer .asciinema-player .ap-player { height: 100%; }
/* split state: TL triangle = human, BR triangle = pi agent (3-point
   polygons: the expand target is the same triangle stretched past the far
   corner, so the wipe sweeps along the diagonal) */
.duo-tl { clip-path: polygon(0 0, 100% 0, 0 100%); z-index: 1; }
.duo-br { clip-path: polygon(100% 0, 100% 100%, 0 100%); z-index: 1; }
/* expanded state: the triangle stretched 3x past the far corner covers all */
.duo-layer.full.duo-tl { clip-path: polygon(0 0, 300% 0, 0 300%); z-index: 3; }
.duo-layer.full.duo-br { clip-path: polygon(100% -200%, 100% 100%, -200% 100%); z-index: 3; }
.duo-layer.hidden-peer { opacity: 0; transition: opacity 0.5s ease; }
.duo-layer { transition: clip-path 0.8s cubic-bezier(0.22, 0.8, 0.3, 1),
                         opacity 0.5s ease; }

/* diagonal seam: a crisp SVG hairline with the wordmark's wave gradient */
.duo-seam-svg {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.duo.expanded .duo-seam-svg { opacity: 0; }

/* corner tabs: pinned to the frame corners, filled gradient pills */
.duo-corner {
  position: absolute;
  z-index: 5;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  padding: 0.55rem 0.9rem;
  color: #1a1b26;
}
.duo-corner:hover { filter: brightness(1.12) saturate(1.2); }
.duo-corner-tl {
  top: 0; left: 0;
  border-radius: calc(var(--radius) - 2px) 0 var(--radius) 0;
  background: linear-gradient(135deg, #ff6e7e, #ff9e64);
}
.duo-corner-br {
  bottom: 0; right: 0;
  border-radius: var(--radius) 0 calc(var(--radius) - 2px) 0;
  background: linear-gradient(315deg, #6ea8ff, #bb9af7);
}
.duo.expanded .duo-corner { opacity: 0.4; }
.duo.expanded .duo-corner.is-on { opacity: 1; }

/* corner pills: the wave gradient rides on the fill itself */
.duo-corner-tl {
  background: linear-gradient(90deg,
      #ff6e7e 0%, #ff9e64 25%, #ffc777 50%, #ff6e7e 75%, #ff9e64 100%);
  background-size: 200% 100%;
  animation: duo-wave 5s linear infinite;
}
.duo-corner-br {
  background: linear-gradient(90deg,
      #6ea8ff 0%, #39c5cf 25%, #4fd6be 50%, #6ea8ff 75%, #39c5cf 100%);
  background-size: 200% 100%;
  animation: duo-wave 5s linear infinite;
}
@keyframes duo-wave {
  from { background-position: 0% 0; }
  to   { background-position: -200% 0; }
}
/* active corner: a slow, bright, saturated glow pulses like an activated
   border (hue follows the corner: red TL / blue BR) */
.duo-corner.is-on.duo-corner-tl {
  animation: duo-glow-tl 2.6s ease-in-out infinite;
}
.duo-corner.is-on.duo-corner-br {
  animation: duo-glow-br 2.6s ease-in-out infinite;
}
@keyframes duo-glow-tl {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 110, 126, 0); }
  50%      { box-shadow: 0 0 18px 4px rgba(255, 110, 126, 0.95); }
}
@keyframes duo-glow-br {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110, 168, 255, 0); }
  50%      { box-shadow: 0 0 18px 4px rgba(110, 168, 255, 0.95); }
}
@media (prefers-reduced-motion: reduce) {
  .duo-corner span, .duo-corner.is-on { animation: none; }
}
@media (max-width: 900px) {
  .duo-stage { aspect-ratio: 10 / 6.4; }
}

.cast-caption {
  color: var(--fg-faint);
  font-size: 0.85rem;
  margin: 0.6rem 0 0;
}
.doc-entry .cast-details { margin: 0.7rem 0 0.4rem; }

@media (max-width: 900px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-nav {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
  }
}
