/* ==========================================================================
   JSONWorks — design tokens
   Ported from abhaydarji.com so both properties read as one body of work.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg:          #08090c;
  --bg-2:        #0b0d12;
  --surface:     #11141b;
  --surface-2:   #171b24;
  --surface-3:   #1e2330;
  --line:        rgba(255,255,255,.09);
  --line-2:      rgba(255,255,255,.16);
  --text:        #edf0f5;
  --text-dim:    #9aa3b5;
  --text-mute:   #69718a;

  --accent:      #c6f24e;   /* signal lime */
  --accent-soft: rgba(198,242,78,.14);
  --accent-line: rgba(198,242,78,.35);
  --accent-text: #c6f24e;
  --on-accent:   #0a0d04;

  --violet:      #7c6bff;
  --violet-soft: rgba(124,107,255,.16);
  --aqua:        #35e0d0;
  --aqua-soft:   rgba(53,224,208,.14);
  --rose:        #ff7a90;
  --rose-soft:   rgba(255,122,144,.14);
  --amber:       #ffc24b;
  --amber-soft:  rgba(255,194,75,.14);

  --grid-line:   rgba(255,255,255,.035);
  --glow:        0 0 0 1px rgba(198,242,78,.18), 0 18px 60px -20px rgba(198,242,78,.28);
  --shadow-lg:   0 32px 80px -32px rgba(0,0,0,.85);
  --shadow-md:   0 16px 40px -20px rgba(0,0,0,.7);

  /* Editor syntax palette (dark) */
  --syn-key:     #c6f24e;
  --syn-str:     #8fe3a8;
  --syn-num:     #ffc24b;
  --syn-bool:    #7c6bff;
  --syn-null:    #69718a;
  --syn-punct:   #9aa3b5;
  --syn-tag:     #35e0d0;
  --syn-attr:    #c6f24e;
  --syn-comment: #5b6478;

  --ff-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --ff-body:    "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ff-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --r-sm: 8px;  --r-md: 14px;  --r-lg: 20px;  --r-xl: 28px;  --r-pill: 999px;

  --pad: clamp(20px, 5vw, 48px);
  --maxw: 1200px;
  --nav-h: 68px;

  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg:          #f6f6f1;
  --bg-2:        #fefefc;
  --surface:     #ffffff;
  --surface-2:   #f2f2ec;
  --surface-3:   #e8e8e0;
  --line:        rgba(12,14,20,.11);
  --line-2:      rgba(12,14,20,.2);
  --text:        #12141a;
  --text-dim:    #4b5261;
  --text-mute:   #7c8496;

  --accent:      #b9ea3a;
  --accent-soft: rgba(122,163,10,.13);
  --accent-line: rgba(122,163,10,.4);
  --accent-text: #56760a;
  --on-accent:   #10160a;

  --violet:      #5a45e0;
  --violet-soft: rgba(90,69,224,.11);
  --aqua:        #10938a;
  --aqua-soft:   rgba(16,147,138,.12);
  --rose:        #d8425f;
  --rose-soft:   rgba(216,66,95,.12);
  --amber:       #a86a00;
  --amber-soft:  rgba(168,106,0,.12);

  --grid-line:   rgba(12,14,20,.045);
  --glow:        0 0 0 1px rgba(122,163,10,.25), 0 18px 50px -24px rgba(122,163,10,.35);
  --shadow-lg:   0 30px 70px -34px rgba(20,24,34,.35);
  --shadow-md:   0 14px 34px -20px rgba(20,24,34,.28);

  /* Editor syntax palette (light) — darkened for contrast on white */
  --syn-key:     #4a6b06;
  --syn-str:     #0f7a3d;
  --syn-num:     #9a5b00;
  --syn-bool:    #5a45e0;
  --syn-null:    #7c8496;
  --syn-punct:   #4b5261;
  --syn-tag:     #0d6f68;
  --syn-attr:    #4a6b06;
  --syn-comment: #8b93a4;
}

/* ==========================================================================
   JSONWorks — base layer: reset, layout primitives, chrome, components
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

body {
  font-family: var(--ff-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background .4s var(--ease), color .4s var(--ease);
}

/* Masked grid backdrop */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 72px 72px;
  -webkit-mask-image: radial-gradient(ellipse 120% 80% at 50% 0%, #000 20%, transparent 78%);
  mask-image: radial-gradient(ellipse 120% 80% at 50% 0%, #000 20%, transparent 78%);
  pointer-events: none; z-index: 0;
}

img, svg, video { display: block; max-width: 100%; }
svg { fill: none; }
button, input, select, textarea { font: inherit; color: inherit; background: none; border: none; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--accent); color: var(--on-accent);
  padding: 12px 20px; border-radius: 0 0 var(--r-md) 0; font-weight: 600;
}
.skip:focus { left: 0; }

.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;
}

/* ---------- Typography ---------- */

h1, h2, h3, h4, h5 {
  font-family: var(--ff-display);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -.028em;
  text-wrap: balance;
}

.h-xl { font-size: clamp(2.4rem, 6.4vw, 4.2rem); }
.h-lg { font-size: clamp(2rem, 4.6vw, 3.1rem); }
.h-md { font-size: clamp(1.5rem, 3vw, 2.1rem); }
.h-sm { font-size: clamp(1.15rem, 2vw, 1.4rem); }

.lede { font-size: clamp(1rem, 1.6vw, 1.16rem); color: var(--text-dim); max-width: 62ch; line-height: 1.75; }
.muted { color: var(--text-dim); }
.mono { font-family: var(--ff-mono); }
.accent { color: var(--accent-text); }

.eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--ff-mono); font-size: .72rem; font-weight: 500;
  letter-spacing: .18em; text-transform: uppercase; color: var(--accent-text);
}
.eyebrow::before { content: ""; width: 22px; height: 1px; background: var(--accent-line); }

/* ---------- Layout primitives ---------- */

.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--pad); position: relative; z-index: 2; }
.wrap-wide { max-width: 1440px; }
.section { padding-block: clamp(56px, 9vw, 112px); position: relative; z-index: 2; }
.section-tight { padding-block: clamp(40px, 6vw, 72px); }
main { position: relative; z-index: 2; min-height: 60vh; }

.section-head { display: flex; flex-direction: column; gap: 14px; margin-bottom: clamp(32px, 4.5vw, 56px); }
.section-head.center { align-items: center; text-align: center; }

.grid { display: grid; gap: clamp(14px, 1.8vw, 22px); }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  gap: 10px; padding: 14px 26px; border-radius: var(--r-pill);
  font-family: var(--ff-display); font-weight: 600; font-size: .95rem; letter-spacing: -.01em;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--line-2);
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease),
              background .3s var(--ease), border-color .3s var(--ease), color .3s var(--ease);
  overflow: hidden; isolation: isolate; white-space: nowrap;
}
.btn::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(115deg, transparent 20%, rgba(255,255,255,.16) 48%, transparent 72%);
  transform: translateX(-120%); transition: transform .7s var(--ease-out);
}
.btn:hover::after { transform: translateX(120%); }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); border-color: transparent; }
.btn-primary:hover { box-shadow: var(--glow); }
.btn-ghost { --btn-bg: transparent; }
.btn-ghost:hover { border-color: var(--accent-line); color: var(--accent-text); background: var(--accent-soft); }
.btn-sm { padding: 10px 18px; font-size: .85rem; }
.btn-xs { padding: 7px 14px; font-size: .78rem; gap: 7px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn .arr { width: 17px; height: 17px; transition: transform .35s var(--ease-out); }
.btn:hover .arr { transform: translateX(3px); }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: var(--r-pill); border: 1px solid var(--line);
  background: var(--surface); color: var(--text-dim);
  transition: color .3s var(--ease), border-color .3s var(--ease), background .3s var(--ease);
}
.icon-btn:hover { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-soft); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Cards ---------- */

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: clamp(18px, 2.2vw, 26px);
  transition: transform .45s var(--ease-out), border-color .35s var(--ease),
              background .35s var(--ease), box-shadow .45s var(--ease);
  overflow: hidden;
}
.card:hover { border-color: var(--line-2); }

/* Tool card used on hubs and the index */
a.tool-card { display: flex; flex-direction: column; gap: 8px; }
a.tool-card:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--shadow-md); }
a.tool-card .tc-top { display: flex; align-items: center; gap: 10px; }
a.tool-card .tc-ico {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent-text);
  font-family: var(--ff-mono); font-size: .62rem; font-weight: 600; letter-spacing: .02em;
}
a.tool-card h3 { font-size: 1rem; letter-spacing: -.02em; }
a.tool-card p { font-size: .875rem; color: var(--text-dim); line-height: 1.6; }
a.tool-card:hover h3 { color: var(--accent-text); }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface);
  font-family: var(--ff-mono); font-size: .72rem; color: var(--text-dim);
}
.pill-accent { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-text); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Nav ---------- */

.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100; height: var(--nav-h);
  display: flex; align-items: center;
  transition: background .4s var(--ease), border-color .4s var(--ease);
  border-bottom: 1px solid transparent;
}
.nav.scrolled {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom-color: var(--line);
}
.nav .wrap { display: flex; align-items: center; justify-content: space-between; gap: 20px; max-width: 1440px; }

.brand-group { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--ff-display); font-weight: 600; letter-spacing: -.02em; flex: none; }
.brand-mark { width: 28px; height: 28px; color: var(--accent); flex: none; }
.brand span { line-height: 1.15; font-size: 1.05rem; white-space: nowrap; }

.brand-div { width: 1px; height: 24px; background: var(--line-2); flex: none; }

/* Author lockup — links out to abhaydarji.com */
.by-link {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  padding: 5px 11px 5px 8px; border-radius: var(--r-pill);
  border: 1px solid transparent;
  transition: border-color .28s var(--ease), background .28s var(--ease), color .28s var(--ease);
}
.by-link:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.author-mark { width: 22px; height: 22px; color: var(--text-dim); flex: none; transition: color .28s var(--ease); }
.by-link:hover .author-mark { color: var(--accent-text); }
.by-text {
  display: flex; flex-direction: column; line-height: 1.2;
  font-family: var(--ff-display); font-size: .85rem; font-weight: 600;
  letter-spacing: -.015em; color: var(--text-dim); white-space: nowrap;
}
.by-link:hover .by-text { color: var(--text); }
.by-pre {
  font-family: var(--ff-mono); font-size: .58rem; font-weight: 400;
  letter-spacing: .12em; text-transform: uppercase; color: var(--text-mute);
}

.footer-by { margin-top: 16px; margin-left: -8px; }
.footer-by .author-mark { width: 26px; height: 26px; }
.footer-by .by-text { font-size: .95rem; }

.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a {
  padding: 8px 14px; border-radius: var(--r-pill); font-size: .89rem; color: var(--text-dim);
  transition: color .25s var(--ease), background .25s var(--ease);
}
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--text); background: var(--surface-2); }

.nav-actions { display: flex; align-items: center; gap: 9px; }
.theme-toggle .sun { display: none; }
html[data-theme="light"] .theme-toggle .sun { display: block; }
html[data-theme="light"] .theme-toggle .moon { display: none; }
.burger { display: none; }

.search-trigger {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 12px 8px 14px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-mute);
  font-size: .85rem; transition: border-color .3s var(--ease), color .3s var(--ease);
}
.search-trigger:hover { border-color: var(--accent-line); color: var(--accent-text); }
.search-trigger svg { width: 15px; height: 15px; }
.search-trigger kbd {
  font-family: var(--ff-mono); font-size: .68rem; padding: 2px 6px;
  border: 1px solid var(--line); border-radius: 5px; background: var(--surface-2); color: var(--text-mute);
}

/* Mobile drawer */
.drawer {
  position: fixed; inset: 0; z-index: 99; display: none;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  padding: calc(var(--nav-h) + 20px) var(--pad) 40px;
  flex-direction: column; gap: 4px;
  opacity: 0; transition: opacity .35s var(--ease); overflow-y: auto;
}
.drawer.open { display: flex; opacity: 1; }
.drawer a {
  font-family: var(--ff-display); font-size: 1.35rem; font-weight: 600;
  padding: 13px 0; border-bottom: 1px solid var(--line); letter-spacing: -.02em;
}
.drawer .btn { margin-top: 20px; }
.drawer .drawer-by {
  margin-top: 26px; border: 1px solid var(--line); align-self: flex-start;
  padding: 10px 16px 10px 12px; font-size: 1rem;
}
.drawer .drawer-by .by-text { display: flex; font-size: 1rem; }
.drawer .drawer-by .author-mark { width: 26px; height: 26px; }

/* ---------- Footer ---------- */

.footer { border-top: 1px solid var(--line); background: var(--bg-2); position: relative; z-index: 2; margin-top: 40px; }
.footer-grid {
  display: grid; grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: clamp(26px, 4vw, 56px); padding-block: clamp(44px, 6vw, 72px);
}
.footer-brand .brand { margin-bottom: 14px; }
.footer-brand p { font-size: .9rem; color: var(--text-dim); max-width: 34ch; line-height: 1.7; }
.footer-col h4 {
  font-family: var(--ff-mono); font-size: .7rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-mute); margin-bottom: 14px; font-weight: 500;
}
.footer-col a { display: block; padding: 5px 0; font-size: .885rem; color: var(--text-dim); transition: color .25s var(--ease); }
.footer-col a:hover { color: var(--accent-text); }
.footer-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-block: 22px; border-top: 1px solid var(--line);
  font-size: .82rem; color: var(--text-mute); font-family: var(--ff-mono);
}
.footer-bottom a:hover { color: var(--accent-text); }

/* ---------- Breadcrumbs ---------- */

.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-family: var(--ff-mono); font-size: .76rem; color: var(--text-mute); margin-bottom: 18px; }
.crumbs a { color: var(--text-dim); transition: color .25s var(--ease); }
.crumbs a:hover { color: var(--accent-text); }
.crumbs .sep { opacity: .45; }

/* ---------- Prose (tool page long-form copy) ---------- */

.prose { max-width: 74ch; }
.prose h2 { font-size: clamp(1.35rem, 2.4vw, 1.75rem); margin-top: 2.2em; margin-bottom: .6em; }
.prose h3 { font-size: clamp(1.05rem, 1.8vw, 1.22rem); margin-top: 1.7em; margin-bottom: .45em; }
.prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose p { color: var(--text-dim); margin-bottom: 1.05em; line-height: 1.78; }
.prose ul { margin: 0 0 1.2em; display: flex; flex-direction: column; gap: 10px; }
.prose ul li { position: relative; padding-left: 26px; color: var(--text-dim); line-height: 1.7; }
.prose ul li::before {
  content: ""; position: absolute; left: 6px; top: .72em; width: 7px; height: 7px;
  border-radius: 2px; background: var(--accent); opacity: .8;
}
.prose strong { color: var(--text); font-weight: 600; }
.prose code {
  font-family: var(--ff-mono); font-size: .86em; padding: 2px 6px;
  border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--accent-text);
}
.prose a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--accent-line); }
.prose a:hover { text-decoration-color: var(--accent); }

/* Worked example block */
.example { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 22px 0 28px; }
.example figure { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; min-width: 0; }
.example figcaption {
  font-family: var(--ff-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-mute); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.example pre { margin: 0; padding: 14px; overflow-x: auto; font-family: var(--ff-mono); font-size: .8rem; line-height: 1.65; color: var(--text-dim); }

/* FAQ */
.faq { display: flex; flex-direction: column; gap: 10px; max-width: 74ch; }
.faq details {
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  transition: border-color .3s var(--ease);
}
.faq details[open] { border-color: var(--line-2); }
.faq summary {
  list-style: none; cursor: pointer; padding: 16px 20px;
  font-family: var(--ff-display); font-weight: 600; font-size: .98rem; letter-spacing: -.015em;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: ""; width: 9px; height: 9px; flex: none;
  border-right: 2px solid var(--text-mute); border-bottom: 2px solid var(--text-mute);
  transform: rotate(45deg) translateY(-2px); transition: transform .3s var(--ease);
}
.faq details[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.faq .faq-body { padding: 0 20px 18px; color: var(--text-dim); line-height: 1.75; font-size: .93rem; }

/* ---------- Command palette ---------- */

.palette-backdrop {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(0,0,0,.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: clamp(60px, 12vh, 140px) 20px 20px;
}
.palette-backdrop.open { display: block; }
.palette {
  max-width: 620px; margin-inline: auto; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.palette-input { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.palette-input svg { width: 18px; height: 18px; color: var(--text-mute); flex: none; }
.palette-input input { flex: 1; font-size: 1rem; outline: none; }
.palette-input input::placeholder { color: var(--text-mute); }
.palette-results { max-height: min(52vh, 420px); overflow-y: auto; padding: 8px; }
.palette-results li a {
  display: flex; align-items: center; gap: 12px; padding: 10px 13px; border-radius: var(--r-sm);
  font-size: .92rem; transition: background .15s var(--ease);
}
.palette-results li a .pr-cat { margin-left: auto; font-family: var(--ff-mono); font-size: .68rem; color: var(--text-mute); }
.palette-results li a:hover, .palette-results li a.active { background: var(--surface-2); }
.palette-results li a.active .pr-name { color: var(--accent-text); }
.palette-empty { padding: 28px 20px; text-align: center; color: var(--text-mute); font-size: .9rem; }

/* ---------- Toast ---------- */

.toast-host { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--line-2); color: var(--text);
  font-size: .87rem; box-shadow: var(--shadow-md);
  animation: toast-in .35s var(--ease-out);
}
.toast.err { border-color: var(--rose); color: var(--rose); }
.toast.ok { border-color: var(--accent-line); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   JSONWorks — workbench: editor, toolbar, panes, tree, diff
   ========================================================================== */

.tool-hero { padding-top: calc(var(--nav-h) + clamp(26px, 4vw, 46px)); padding-bottom: clamp(18px, 2.6vw, 28px); }
.tool-hero h1 { font-size: clamp(1.9rem, 4.2vw, 2.9rem); margin-bottom: 12px; }
.tool-hero .lede { max-width: 68ch; }
.tool-hero .hero-meta { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 18px; }

/* ---------- Workbench shell ---------- */

.workbench {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow-md);
}

.wb-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.wb-toolbar .spacer { flex: 1 1 auto; }
.wb-group { display: flex; align-items: center; gap: 6px; }
.wb-sep { width: 1px; height: 22px; background: var(--line); flex: none; }

.wb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface);
  font-size: .82rem; font-weight: 500; color: var(--text-dim); white-space: nowrap;
  transition: color .22s var(--ease), border-color .22s var(--ease), background .22s var(--ease);
}
.wb-btn:hover { color: var(--text); border-color: var(--line-2); background: var(--surface-3); }
.wb-btn svg { width: 15px; height: 15px; flex: none; }
.wb-btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.wb-btn.primary:hover { box-shadow: var(--glow); color: var(--on-accent); }
.wb-btn.danger:hover { color: var(--rose); border-color: var(--rose); }
.wb-btn[disabled] { opacity: .45; pointer-events: none; }
.wb-btn.icon-only { padding: 8px; }

.wb-select {
  appearance: none; -webkit-appearance: none;
  padding: 8px 30px 8px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-dim);
  font-size: .82rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
}
.wb-select:hover { border-color: var(--line-2); color: var(--text); }
.wb-select option { background: var(--surface); color: var(--text); }

.wb-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--text-dim); cursor: pointer; user-select: none; }
.wb-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.wb-toggle .track {
  width: 34px; height: 19px; border-radius: var(--r-pill);
  background: var(--surface-3); border: 1px solid var(--line); position: relative;
  transition: background .25s var(--ease), border-color .25s var(--ease);
}
.wb-toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: var(--text-mute); transition: transform .25s var(--ease-out), background .25s var(--ease);
}
.wb-toggle input:checked + .track { background: var(--accent-soft); border-color: var(--accent-line); }
.wb-toggle input:checked + .track::after { transform: translateX(15px); background: var(--accent); }
.wb-toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Panes ---------- */

.wb-panes { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.wb-panes.single { grid-template-columns: 1fr; }
.wb-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.wb-pane + .wb-pane { border-left: 1px solid var(--line); }

.wb-pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--bg-2);
  font-family: var(--ff-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-mute);
}
.wb-pane-head .ph-actions { display: flex; gap: 4px; }
.wb-pane-head .ph-btn {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px;
  color: var(--text-mute); transition: color .2s var(--ease), background .2s var(--ease);
}
.wb-pane-head .ph-btn:hover { color: var(--accent-text); background: var(--accent-soft); }
.wb-pane-head .ph-btn svg { width: 14px; height: 14px; }
.wb-pane-head .ph-stat { font-size: .68rem; letter-spacing: .06em; text-transform: none; }

/* ---------- Editor ---------- */

.ed {
  position: relative; flex: 1; min-height: var(--ed-h, 440px); display: flex;
  font-family: var(--ff-mono); font-size: 13px; line-height: 1.6;
  background: var(--bg-2); overflow: hidden;
}
.ed-gutter {
  flex: none; padding: 12px 10px 12px 14px; text-align: right;
  color: var(--text-mute); background: var(--bg-2); border-right: 1px solid var(--line);
  user-select: none; overflow: hidden; font-variant-numeric: tabular-nums;
}
.ed-gutter span { display: block; opacity: .55; }
.ed-gutter span.err-line { color: var(--rose); opacity: 1; font-weight: 600; }
.ed-scroll { position: relative; flex: 1; overflow: auto; min-width: 0; }
.ed-layer, .ed-input {
  margin: 0; padding: 12px 16px; border: 0;
  font: inherit; line-height: inherit; letter-spacing: normal;
  white-space: pre; tab-size: 2; word-wrap: normal;
  min-width: 100%; min-height: 100%; box-sizing: border-box;
}
.ed-layer { position: absolute; inset: 0; pointer-events: none; color: var(--text); overflow: hidden; }
.ed-input {
  position: relative; display: block; width: 100%; resize: none; outline: none;
  color: transparent; background: transparent; caret-color: var(--accent);
  overflow: hidden;
}
.ed-input::selection { background: var(--accent-soft); }
.ed.wrap-on .ed-layer, .ed.wrap-on .ed-input { white-space: pre-wrap; word-break: break-word; }
.ed.readonly .ed-input { caret-color: transparent; }

/* Syntax colours */
.tk-key { color: var(--syn-key); }
.tk-str { color: var(--syn-str); }
.tk-num { color: var(--syn-num); }
.tk-bool { color: var(--syn-bool); font-weight: 500; }
.tk-null { color: var(--syn-null); font-style: italic; }
.tk-punct { color: var(--syn-punct); }
.tk-tag { color: var(--syn-tag); }
.tk-attr { color: var(--syn-attr); }
.tk-comment { color: var(--syn-comment); font-style: italic; }
.tk-err { background: var(--rose-soft); border-bottom: 2px wavy var(--rose); border-radius: 2px; }

/* ---------- Status bar ---------- */

.wb-status {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line); background: var(--surface-2);
  font-family: var(--ff-mono); font-size: .74rem; color: var(--text-mute);
}
.wb-status .st-state { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; }
.wb-status .st-state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); flex: none; }
.wb-status .st-state.ok { color: var(--accent-text); }
.wb-status .st-state.ok .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.wb-status .st-state.err { color: var(--rose); }
.wb-status .st-state.err .dot { background: var(--rose); box-shadow: 0 0 8px var(--rose); }
.wb-status .st-state.busy .dot { background: var(--amber); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.wb-status .spacer { flex: 1 1 auto; }

/* ---------- Error banner ---------- */

.wb-error {
  display: none; gap: 13px; align-items: flex-start;
  padding: 13px 16px; border-top: 1px solid var(--rose);
  background: var(--rose-soft); color: var(--text);
}
.wb-error.show { display: flex; }
.wb-error svg { width: 18px; height: 18px; color: var(--rose); flex: none; margin-top: 2px; }
.wb-error .we-body { flex: 1; min-width: 0; }
.wb-error .we-title { font-weight: 600; font-size: .9rem; margin-bottom: 3px; color: var(--rose); }
.wb-error .we-msg { font-size: .85rem; color: var(--text-dim); line-height: 1.6; }
.wb-error .we-snippet {
  margin-top: 9px; padding: 9px 12px; border-radius: var(--r-sm);
  background: var(--bg-2); border: 1px solid var(--line);
  font-family: var(--ff-mono); font-size: .76rem; color: var(--text-dim);
  white-space: pre; overflow-x: auto;
}
.wb-error .we-snippet .caret { color: var(--rose); font-weight: 700; }
.wb-error .we-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }

/* ---------- Tree view ---------- */

.tree {
  flex: 1; min-height: var(--ed-h, 440px); overflow: auto; padding: 12px 14px;
  background: var(--bg-2); font-family: var(--ff-mono); font-size: 13px; line-height: 1.75;
}
.tree-row { display: flex; align-items: flex-start; gap: 5px; white-space: pre; border-radius: 4px; padding-right: 6px; }
.tree-row:hover { background: var(--surface-2); }
.tree-row.hi { background: var(--accent-soft); }
.tree-tw {
  width: 15px; height: 21px; flex: none; display: grid; place-items: center;
  color: var(--text-mute); cursor: pointer; user-select: none;
}
.tree-tw::before {
  content: ""; width: 0; height: 0;
  border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
  transition: transform .2s var(--ease);
}
.tree-tw.open::before { transform: rotate(90deg); }
.tree-tw.leaf::before { display: none; }
.tree-tw:hover { color: var(--accent-text); }
.tree-k { color: var(--syn-key); }
.tree-c { color: var(--syn-punct); opacity: .7; }
.tree-v.s { color: var(--syn-str); }
.tree-v.n { color: var(--syn-num); }
.tree-v.b { color: var(--syn-bool); }
.tree-v.z { color: var(--syn-null); font-style: italic; }
.tree-meta { color: var(--text-mute); font-size: .84em; opacity: .75; }
.tree-copy {
  margin-left: 6px; opacity: 0; color: var(--text-mute); font-size: .78em;
  transition: opacity .2s var(--ease); cursor: pointer; flex: none;
}
.tree-row:hover .tree-copy { opacity: 1; }
.tree-copy:hover { color: var(--accent-text); }
.tree-v.link { color: var(--aqua); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Table output (CSV preview) ---------- */

.tbl-wrap { flex: 1; min-height: var(--ed-h, 440px); overflow: auto; background: var(--bg-2); }
.tbl-wrap table { font-family: var(--ff-mono); font-size: 12.5px; min-width: 100%; }
.tbl-wrap th, .tbl-wrap td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; }
.tbl-wrap th { position: sticky; top: 0; background: var(--surface-2); color: var(--accent-text); font-weight: 600; z-index: 1; }
.tbl-wrap td { color: var(--text-dim); }
.tbl-wrap tr:hover td { background: var(--surface); color: var(--text); }

/* ---------- Diff output ---------- */

.diff { flex: 1; min-height: var(--ed-h, 440px); overflow: auto; background: var(--bg-2); font-family: var(--ff-mono); font-size: 12.5px; line-height: 1.7; }
.diff-row { display: flex; white-space: pre; }
.diff-row .dn { flex: none; width: 46px; padding: 0 8px; text-align: right; color: var(--text-mute); opacity: .5; user-select: none; border-right: 1px solid var(--line); }
.diff-row .dc { flex: 1; padding: 0 12px; min-width: 0; }
.diff-row.add { background: rgba(198,242,78,.09); }
.diff-row.add .dc { color: var(--accent-text); }
.diff-row.del { background: var(--rose-soft); }
.diff-row.del .dc { color: var(--rose); }
.diff-row.ctx .dc { color: var(--text-dim); }
.diff-legend { display: flex; gap: 16px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-family: var(--ff-mono); font-size: .72rem; color: var(--text-mute); }
.diff-legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }

/* ---------- Dropzone ---------- */

.wb-drop {
  position: absolute; inset: 0; z-index: 20; display: none;
  place-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 2px dashed var(--accent-line); border-radius: var(--r-lg);
}
.workbench.dragging .wb-drop { display: grid; }
.wb-drop .wd-in { text-align: center; color: var(--accent-text); font-family: var(--ff-display); font-weight: 600; }
.wb-drop svg { width: 34px; height: 34px; margin: 0 auto 10px; }

/* ---------- Related tools ---------- */

.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
a.rel {
  display: flex; align-items: center; gap: 10px; padding: 13px 15px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
  font-size: .885rem; transition: border-color .28s var(--ease), transform .28s var(--ease-out), color .28s var(--ease);
}
a.rel:hover { border-color: var(--accent-line); color: var(--accent-text); transform: translateY(-2px); }
a.rel svg { width: 14px; height: 14px; flex: none; opacity: .55; margin-left: auto; }

/* ---------- Shortcuts table ---------- */

.keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 9px; }
.keys div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); font-size: .85rem; color: var(--text-dim); }
.keys kbd {
  font-family: var(--ff-mono); font-size: .72rem; padding: 3px 7px;
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px;
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}

/* ==========================================================================
   JSONWorks — responsive layer
   Breakpoints run large → small so later rules win.
   ========================================================================== */

/* ---------- Wide laptop ---------- */
@media (max-width: 1280px) {
  .nav .wrap { gap: 14px; }
  .nav-links a { padding: 8px 11px; font-size: .86rem; }
}

/* ---------- Small laptop ---------- */
@media (max-width: 1140px) {
  .footer-grid { grid-template-columns: 1.4fr repeat(3, 1fr); gap: 28px; }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-trigger span { display: none; }
  .search-trigger { padding: 8px 12px; }
}

/* ---------- Tablet landscape ---------- */
@media (max-width: 1024px) {
  .brand-div, .by-link .by-text { display: none; }
  .by-link { padding: 5px; }
  .nav-links a { padding: 8px 9px; font-size: .84rem; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
  .footer-brand p { max-width: 52ch; }
}

/* ---------- Tablet: drawer takes over ---------- */
@media (max-width: 900px) {
  .nav-links { display: none; }
  .burger { display: inline-grid; }
  .search-trigger kbd { display: none; }

  /* The author link belongs in the drawer at this size, not the cramped bar. */
  .nav .by-link, .nav .brand-div { display: none; }

  /* Editor panes stack; each keeps its own scroll. */
  .wb-panes { grid-template-columns: 1fr; }
  .wb-pane + .wb-pane { border-left: 0; border-top: 1px solid var(--line); }
  .ed, .tree, .tbl-wrap, .diff { min-height: 300px; }

  .example { grid-template-columns: 1fr; }
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Tablet portrait ---------- */
@media (max-width: 768px) {
  .section { padding-block: clamp(44px, 8vw, 72px); }
  .section-tight { padding-block: clamp(32px, 5vw, 52px); }
  .tool-hero { padding-top: calc(var(--nav-h) + 30px); }
  .prose { max-width: none; }
  .lede { max-width: none; }
}

/* ---------- Phone ---------- */
@media (max-width: 640px) {
  :root { --nav-h: 60px; }

  .g-2, .g-3, .g-4, .g-auto { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; gap: 26px; }
  .footer-bottom { flex-direction: column; align-items: flex-start; gap: 10px; }
  .related-grid { grid-template-columns: 1fr; }
  .keys { grid-template-columns: 1fr; }

  .brand span { font-size: .98rem; }
  .brand-mark { width: 26px; height: 26px; }

  .btn { padding: 13px 22px; font-size: .9rem; }
  body::before { background-size: 48px 48px; }

  .h-xl { font-size: clamp(2rem, 9vw, 2.8rem); }
  .h-lg { font-size: clamp(1.75rem, 7.5vw, 2.3rem); }
  .tool-hero h1 { font-size: clamp(1.6rem, 7.5vw, 2.1rem); }

  .hero-meta { gap: 7px; }
  .hero-meta .pill { font-size: .68rem; padding: 5px 11px; }

  /* Toolbar wraps onto two tidy rows. A horizontally scrolling toolbar hides
     controls behind a half-cut button, which reads as broken rather than
     scrollable — so the spacer is turned into a full-width flex break instead. */
  .wb-toolbar {
    flex-wrap: wrap; overflow: visible;
    gap: 8px; padding: 10px 12px; align-items: stretch;
  }
  .wb-toolbar .spacer { flex: 0 0 100%; height: 0; margin: 0; }
  .wb-toolbar .wb-sep { display: none; }

  /* Row 1 — the primary action takes the leftover space. */
  .wb-toolbar > .wb-group:first-child { flex: 1 1 auto; min-width: 0; }
  .wb-toolbar > .wb-group:first-child .wb-btn { width: 100%; justify-content: center; }

  /* Row 2 — secondary actions share the width evenly. */
  .wb-toolbar > .wb-group:last-child { flex: 1 1 100%; }
  .wb-toolbar > .wb-group:last-child .wb-btn { flex: 1 1 0; min-width: 0; justify-content: center; }

  .wb-btn { padding: 10px 12px; font-size: .8rem; gap: 6px; }
  .wb-select { padding: 10px 26px 10px 11px; font-size: .8rem; }
  .wb-toggle { font-size: .78rem; white-space: nowrap; padding-inline: 2px; }

  .workbench { border-radius: var(--r-md); }
  .ed { font-size: 12.5px; }
  .ed-gutter { padding-left: 10px; padding-right: 7px; }
  .ed, .tree, .tbl-wrap, .diff { min-height: 260px; }

  .wb-status { font-size: .7rem; gap: 10px; padding: 9px 12px; }
  .wb-error { padding: 12px 13px; }
  .wb-error .we-snippet { font-size: .7rem; }

  .example pre { font-size: .74rem; padding: 12px; }
  .faq summary { padding: 14px 16px; font-size: .92rem; }
  .faq .faq-body { padding: 0 16px 16px; font-size: .89rem; }

  .palette-backdrop { padding: 70px 12px 12px; }
  .palette-input { padding: 14px 16px; }

  .crumbs { font-size: .72rem; }
  .toast-host { bottom: 16px; left: 12px; right: 12px; transform: none; }
  .toast { width: 100%; justify-content: center; }
}

/* ---------- Small phone ---------- */
@media (max-width: 420px) {
  :root { --pad: 16px; }

  .brand span { font-size: .92rem; }
  .nav-actions { gap: 6px; }
  .icon-btn { width: 36px; height: 36px; }
  .search-trigger { padding: 7px 10px; }

  .drawer a { font-size: 1.15rem; padding: 11px 0; }

  .wb-btn span:not(.sr-only) { font-size: .78rem; }
  .wb-btn svg { width: 14px; height: 14px; }

  .hero-meta .pill:nth-child(n+3) { display: none; }

  .example pre { font-size: .7rem; }
  .tbl-wrap th, .tbl-wrap td { padding: 6px 9px; font-size: 11.5px; }
}

/* ---------- Landscape phone: reclaim vertical space ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .tool-hero { padding-top: calc(var(--nav-h) + 16px); padding-bottom: 12px; }
  .tool-hero .lede, .hero-meta { display: none; }
  .ed, .tree, .tbl-wrap, .diff { min-height: 200px; }
}

/* ---------- Touch targets ---------- */
@media (pointer: coarse) {
  .wb-btn { min-height: 40px; }
  .nav-links a, .footer-col a { padding-block: 10px; }
  .tree-tw { width: 22px; height: 24px; }
  .tree-copy { opacity: 1; }
  .btn:hover { transform: none; }
  a.tool-card:hover { transform: none; }
  .ph-btn { width: 32px; height: 32px; }
}

/* ---------- Wide screens: let the workbench breathe ---------- */
@media (min-width: 1600px) {
  .wrap-wide { max-width: 1560px; }
  .ed, .tree, .tbl-wrap, .diff { min-height: 520px; }
}

/* ---------- Print ---------- */
@media print {
  .nav, .footer, .wb-toolbar, .drawer, .palette-backdrop, .toast-host,
  .wb-status, .hero-meta, .search-trigger { display: none !important; }
  body::before { display: none; }
  body { background: #fff; color: #000; }
  .workbench { border: 1px solid #ccc; box-shadow: none; }
  .wb-panes { grid-template-columns: 1fr; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .8em; color: #555; }
}
