:root {
  color-scheme: light;
  /* Color */
  --bg: #f7f5f0;
  --surface: #fffdf9;
  --surface-2: #f1eee7;
  --ink: #221f2a;
  --ink-2: #3b3745;
  --muted: #5c5667;
  --line: #e5e0d6;
  --line-strong: #cdc6b8;
  --purple: #6656db;
  --purple-strong: #4f3fc2;
  --purple-soft: #ecebfb;
  --purple-ink: #fff;
  --yellow: #f3cd64;
  --yellow-soft: #fdf3d4;
  --ok: #1d6b45;
  --err: #8c2f2f;
  /* Type */
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.0625rem;
  /* Space (4/8 grid) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;
  /* Shape */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(34, 31, 42, 0.05);
  --shadow-2: 0 1px 2px rgba(34, 31, 42, 0.06), 0 10px 24px -14px rgba(34, 31, 42, 0.22);
  --content: 1120px;
  --gutter: 16px;
}

@font-face {
  font-family: "Noto Sans Math";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/NotoSansMath-Regular.ttf") format("truetype");
  unicode-range: U+2100-214F, U+1D400-1D7FF;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: var(--fs-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }

a { color: var(--purple-strong); }

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  top: var(--s2);
  left: var(--s2);
  z-index: 30;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--s2) 14px;
  border-radius: var(--r-pill);
  background: var(--purple);
  color: var(--purple-ink);
  font-family: var(--ui);
  text-decoration: none;
  white-space: nowrap;
}

/* Header: one row on wide screens */
.site-header,
.site-footer {
  display: flex;
  align-items: center;
  gap: var(--s3) var(--s5);
  padding: var(--s3) max(var(--gutter), calc((100% - var(--content)) / 2 + var(--gutter)));
}

.site-header {
  flex-wrap: nowrap;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.brand img,
.brand svg { width: 32px; height: 32px; display: block; }

.site-nav {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  gap: 2px;
  min-width: 0;
}

.site-nav a {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s3);
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.site-nav a:hover { background: var(--surface-2); color: var(--ink); }

.site-nav a[aria-current="page"],
.site-nav a.is-current {
  background: var(--purple-soft);
  color: var(--purple-strong);
  font-weight: 650;
}

.page-content {
  width: min(var(--content), 100%);
  margin-inline: auto;
  padding: var(--s7) var(--gutter) var(--s8);
}

/* Intro */
.page-intro { max-width: 54rem; margin: 0 0 var(--s6); }

.page-intro h1 {
  margin: 0 0 var(--s3);
  font-size: clamp(1.75rem, 1.1rem + 2vw, 2.6rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.page-intro p {
  max-width: 52rem;
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-lg);
  line-height: 1.55;
  text-wrap: pretty;
}

.page-intro p + p {
  margin-top: var(--s2);
  font-size: var(--fs-sm);
}

/* Long-form content below the tool */
.page-body {
  max-width: 72ch;
  margin-top: var(--s8);
  padding-top: var(--s6);
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  line-height: 1.65;
}

.page-intro + .page-body { margin-top: 0; padding-top: 0; border-top: 0; }

.page-body section + section { margin-top: var(--s6); }

.page-body h2 {
  margin: 0 0 var(--s3);
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 750;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.page-body h3 {
  margin: var(--s5) 0 var(--s1);
  color: var(--ink);
  font-size: var(--fs-lg);
  font-weight: 650;
  line-height: 1.3;
}

.page-body p { margin: 0 0 var(--s3); }

.page-body ul { margin: 0; padding-inline-start: 1.25rem; }

.page-body li + li { margin-top: var(--s1); }

/* Footer */
.site-footer {
  flex-wrap: wrap;
  justify-content: space-between;
  padding-block: var(--s5);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.site-footer > p { flex: 1 1 18rem; margin: 0; }

.site-footer nav { display: flex; flex-wrap: wrap; gap: 2px var(--s1); }

.site-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  color: inherit;
  text-decoration: none;
}

.site-footer nav a:hover { background: var(--surface-2); color: var(--ink); }

.workbench-wrapper,
.examples-section {
  direction: ltr;
  text-align: start;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lang-switch {
  position: relative;
  display: inline-block;
}

.lang-switch summary {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 0.95rem;
}

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

.lang-switch summary:hover { background: var(--surface-2); }

.lang-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.lang-list {
  position: absolute;
  bottom: calc(100% + var(--s2));
  right: 0;
  min-width: 190px;
  max-height: 280px;
  overflow-y: auto;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  z-index: 100;
  text-align: left;
}

[dir="rtl"] .lang-list {
  right: auto;
  left: 0;
  text-align: right;
}

.site-footer .lang-list a {
  display: block;
  min-height: 0;
  padding: var(--s2) var(--s4);
  border-radius: 0;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.88rem;
  white-space: nowrap;
}

.site-footer .lang-list a:hover { background: var(--surface-2); }

.site-footer .lang-list a[aria-current="true"] {
  font-weight: 600;
  color: var(--purple-strong);
}

/* Header: brand + language on row one, scrollable tab strip on row two */
@media (max-width: 960px) {
  html, body { overflow-x: clip; }

  .site-header {
    flex-wrap: wrap;
    gap: 0 var(--s3);
    padding-block: 6px 0;
  }

  .brand { order: 1; font-size: 1.125rem; }

  .site-nav {
    order: 3;
    flex: 1 0 100%;
    gap: 0;
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: calc(var(--gutter) - var(--s3));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-padding-inline: var(--gutter);
    scrollbar-width: none;
  }

  .site-nav::-webkit-scrollbar { display: none; }

  .site-nav a,
  .site-nav a:hover {
    border-radius: 0;
    background: none;
  }

  .site-nav a[aria-current="page"],
  .site-nav a.is-current {
    background: none;
    box-shadow: inset 0 -3px 0 var(--purple);
  }
}

@media (max-width: 800px) {
  :root { --gutter: 12px; }

  .page-content { padding-block: var(--s5) var(--s7); }

  .page-intro { margin-bottom: var(--s4); }

  .page-intro h1 { margin-bottom: var(--s2); font-size: 1.6rem; }

  .page-intro p { font-size: 0.95rem; line-height: 1.45; }

  .page-intro p + p { font-size: 0.8125rem; }

  .page-body { margin-top: var(--s7); }

  .page-body h2 { font-size: 1.25rem; }
}

/* Touch targets: footer language menu items reach 44px on phones/touch. */
@media (max-width: 800px), (pointer: coarse) {
  .site-footer .lang-list a { display: flex; align-items: center; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
