/* Torio V0 documentation — one shared stylesheet.
   No framework, no CDN, no runtime dependency. System fonts only. */

:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Palettes are declared once here and only assigned below, so light and dark
     cannot drift apart as values change. */
  --l-bg: #ffffff;
  --l-surface: #f8f9fb;
  --l-surface-2: #eef1f5;
  --l-text: #12151a;
  --l-muted: #58616e;
  --l-border: #e1e5eb;
  --l-border-strong: #c9d0d9;
  --l-accent: #4b47c9;
  --l-accent-contrast: #ffffff;
  --l-accent-soft: rgba(75, 71, 201, 0.08);
  --l-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 16px rgba(16, 24, 40, 0.06);

  --d-bg: #0c0e13;
  --d-surface: #14181f;
  --d-surface-2: #1c212a;
  --d-text: #e6eaf0;
  --d-muted: #98a3b3;
  --d-border: #232a35;
  --d-border-strong: #333c4a;
  --d-accent: #9aa8ff;
  /* The dark-mode accent is light, so solid accent fills need dark text. */
  --d-accent-contrast: #0c0e13;
  --d-accent-soft: rgba(154, 168, 255, 0.13);
  --d-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);

  --bg: var(--l-bg);
  --surface: var(--l-surface);
  --surface-2: var(--l-surface-2);
  --text: var(--l-text);
  --muted: var(--l-muted);
  --border: var(--l-border);
  --border-strong: var(--l-border-strong);
  --accent: var(--l-accent);
  --accent-contrast: var(--l-accent-contrast);
  --accent-soft: var(--l-accent-soft);
  --shadow: var(--l-shadow);

  /* Code is dark in both themes: commands are what readers hunt for on these
     pages, and a dark slab makes them findable at a glance. The dark theme
     uses a *lighter* slab than its page background, otherwise the block sinks
     into the page instead of sitting on it. */
  --l-code-bg: #11151c;
  --l-code-border: #262e3a;
  --d-code-bg: #171d26;
  --d-code-border: #2a323e;

  --code-bg: var(--l-code-bg);
  --code-border: var(--l-code-border);
  --code-text: #dde4ee;
  --code-muted: #7c8899;
  --tok-comment: #78879b;
  --tok-str: #9fcbff;
  --tok-ok: #7ee787;

  --page: 50rem;
  --radius: 10px;
  --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--d-bg);
    --surface: var(--d-surface);
    --surface-2: var(--d-surface-2);
    --text: var(--d-text);
    --muted: var(--d-muted);
    --border: var(--d-border);
    --border-strong: var(--d-border-strong);
    --accent: var(--d-accent);
    --accent-contrast: var(--d-accent-contrast);
    --accent-soft: var(--d-accent-soft);
    --shadow: var(--d-shadow);
    --code-bg: var(--d-code-bg);
    --code-border: var(--d-code-border);
  }
}

:root[data-theme="dark"] {
  --bg: var(--d-bg);
  --surface: var(--d-surface);
  --surface-2: var(--d-surface-2);
  --text: var(--d-text);
  --muted: var(--d-muted);
  --border: var(--d-border);
  --border-strong: var(--d-border-strong);
  --accent: var(--d-accent);
  --accent-contrast: var(--d-accent-contrast);
  --accent-soft: var(--d-accent-soft);
  --shadow: var(--d-shadow);
  --code-bg: var(--d-code-bg);
  --code-border: var(--d-code-border);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--accent-soft);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.5rem 0.9rem;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 20;
}
.skip-link:focus {
  left: 0;
}

a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  transition: text-decoration-color 0.15s ease;
}
a:hover {
  text-decoration-color: currentColor;
}

/* ---- Header + navigation ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
}
.header-inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
}
.wordmark .mark {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 5px;
  background: var(--accent);
}
.wordmark strong {
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.header-side {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.15rem;
  margin: 0;
  padding: 0;
}
.site-nav a {
  display: inline-block;
  padding: 0.3rem 0.1rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover {
  color: var(--text);
}
.site-nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.theme-toggle {
  flex: none;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  padding: 0;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.theme-icon::before {
  content: "◐";
}
.theme-toggle[data-mode="light"] .theme-icon::before {
  content: "☀";
}
.theme-toggle[data-mode="dark"] .theme-icon::before {
  content: "☾";
}

/* ---- Scope notice ---- */
.scope-notice {
  margin: 0;
  padding: 0.7rem 1rem;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}
.scope-notice strong {
  color: var(--text);
}
.wrap {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
}

/* ---- Main content ---- */
main {
  max-width: var(--page);
  margin: 0 auto;
  padding: 2.25rem 1.5rem 5rem;
}
.content {
  max-width: 100%;
}

main :is(h1, h2, h3, h4) {
  scroll-margin-top: 6rem;
}
main h1 {
  font-size: clamp(2rem, 1.5rem + 1.6vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-weight: 700;
  margin: 0 0 0.6rem;
}
main h1 + p {
  font-size: 1.14rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0 0 2.25rem;
}
main h2 {
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 650;
  margin: 3.25rem 0 0.9rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
main h1 + p + h2 {
  border-top: 0;
  padding-top: 0;
  margin-top: 2rem;
}
main h3 {
  font-size: 1.22rem;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.008em;
  margin: 2.75rem 0 0.7rem;
}
main h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 1.9rem 0 0.5rem;
}
main p {
  margin: 0 0 1.05rem;
}
main p,
main li {
  overflow-wrap: break-word;
}
main ul,
main ol {
  padding-left: 1.35rem;
  margin: 0 0 1.05rem;
}
main li {
  margin: 0.35rem 0;
}
main li::marker {
  color: var(--muted);
}
main hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}
.mode-kicker {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

/* ---- Landing hero ---- */
body[data-page="index"] .site-header {
  border-bottom-color: transparent;
}
.hero {
  margin: 0.5rem 0 2rem;
}
.hero-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1rem;
}
.hero-title {
  font-size: clamp(2.3rem, 1.5rem + 3vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 750;
  margin: 0 0 1.1rem;
  max-width: 18ch;
}
.hero-lede {
  font-size: 1.16rem;
  line-height: 1.6;
  color: var(--muted);
  max-width: 54ch;
  margin: 0 0 1.9rem;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0 0 2.5rem;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  background: color-mix(in srgb, var(--accent) 88%, #000);
}
.btn-quiet {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}
.btn-quiet:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

/* ---- Terminal showpiece ---- */
.terminal {
  margin: 0 0 3rem;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}
.terminal-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--code-border);
  background: rgba(255, 255, 255, 0.03);
}
.terminal-bar .dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #39424f;
}
.terminal-title {
  margin-left: 0.6rem;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--code-muted);
}
.terminal-body {
  margin: 0;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.75;
  color: var(--code-text);
}
.terminal-body .term-note {
  display: block;
  margin: 0.55rem 0 0.15rem;
  color: var(--code-muted);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
}
.terminal-body .tp {
  color: var(--code-muted);
  user-select: none;
  margin-right: 0.5rem;
}
.tok-ok {
  color: var(--tok-ok);
}

/* ---- Stack diagram ---- */
.stack {
  margin: 0 0 1.6rem;
}
.stack-zone {
  padding: 1rem 1.1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stack-where {
  margin: 0 0 0.8rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--muted);
}
.stack-items {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 44rem) {
  .stack-items {
    grid-template-columns: 1fr;
  }
}
.stack-item {
  padding: 0.8rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stack-item b {
  display: block;
  font-size: 0.95rem;
  font-weight: 650;
  margin-bottom: 0.3rem;
}
.stack-item span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}
.stack-item code {
  font-size: 0.85em;
}
/* The connector carries the one fact the two halves share: the tunnel. */
.stack-pipe {
  position: relative;
  margin: 0;
  padding: 1rem 0;
  text-align: center;
}
.stack-pipe::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 2px dashed var(--border-strong);
}
.stack-pipe span {
  position: relative;
  display: inline-block;
  padding: 0.25rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---- Cards ---- */
.modes {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 44rem) {
  .modes {
    grid-template-columns: 1fr;
  }
}
.modes li {
  margin: 0;
}
.mode-card {
  display: block;
  height: 100%;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.mode-card .name {
  display: block;
  font-weight: 650;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}
.mode-card .what {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}
.mode-card code {
  font-size: 0.85em;
}

/* ---- Code ---- */
code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  padding: 0.12rem 0.36rem;
  border-radius: 4px;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.code-block {
  position: relative;
  margin: 0 0 1.3rem;
}
.code-block pre {
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  /* Right padding keeps the longest line clear of the copy button. */
  padding: 0.95rem 4rem 0.95rem 1.1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.7;
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: #39424f transparent;
}
.code-block pre::-webkit-scrollbar {
  height: 8px;
}
.code-block pre::-webkit-scrollbar-thumb {
  background: #39424f;
  border-radius: 4px;
}
/* The chip styling above is for inline code only; inside any preformatted
   block the text must inherit the slab's own colours. */
pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: inherit;
  font-family: var(--font-mono);
}
.tok-comment {
  color: var(--tok-comment);
  font-style: italic;
}
.tok-str {
  color: var(--tok-str);
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.55rem;
  padding: 0.24rem 0.55rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--code-muted);
  /* Opaque, not translucent: a long command scrolls underneath this button,
     and a see-through chip would sit on top of unreadable text. */
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.code-block:hover .copy-button,
.copy-button:focus-visible,
.copy-button.is-done {
  opacity: 1;
}
.copy-button:hover {
  color: var(--code-text);
  border-color: #3a4453;
}
.copy-button.is-done {
  color: var(--tok-ok);
  border-color: color-mix(in srgb, var(--tok-ok) 45%, transparent);
}
/* Touch devices have no hover, so never hide the affordance there. */
@media (hover: none) {
  .copy-button {
    opacity: 1;
  }
}

/* ---- On-page contents (narrow screens only; see the note below) ---- */
.toc {
  margin: 0 0 2.5rem;
  padding: 1.1rem 1.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: 2rem;
}
@media (max-width: 44rem) {
  .toc ul {
    columns: 1;
  }
}
.toc li {
  margin: 0;
  break-inside: avoid;
}
.toc a {
  display: block;
  padding: 0.28rem 0;
  font-size: 0.92rem;
  color: var(--muted);
  text-decoration: none;
}
.toc a:hover {
  color: var(--accent);
}

/* ---- Tables ---- */
.table-scroll {
  overflow-x: auto;
  /* Reference tables are denser than prose, so let them reclaim the gutter the
     text column leaves free. Collapses to zero once the viewport is narrow. */
  margin: 0 calc(-1 * clamp(0rem, (100vw - var(--page)) / 2, 5rem)) 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
th,
td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  font-weight: 650;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
td code {
  white-space: nowrap;
}
td:last-child code {
  white-space: normal;
}

/* ---- Callout ---- */
.callout {
  margin: 0 0 1.5rem;
  padding: 0.85rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.94rem;
}
.callout > :first-child {
  margin-top: 0;
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout .code-block:last-child {
  margin-bottom: 0;
}

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
}
.footer-inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 1.5rem;
}
.footer-inner p {
  margin: 0;
}
.site-footer a {
  color: var(--muted);
}

@media (max-width: 34rem) {
  body {
    font-size: 16px;
  }
  main {
    padding: 1.75rem 1.1rem 3.5rem;
  }
  .header-inner,
  .wrap {
    padding-left: 1.1rem;
    padding-right: 1.1rem;
  }
  .header-side {
    width: 100%;
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .mode-card:hover,
  .btn:hover {
    transform: none;
  }
}
