:root {
  color-scheme: dark;
  --bg: #070b14;
  --ink: #eef3fb;
  --muted: #93a0b5;
  --accent: #7ec2ff;
  --line: rgba(140, 170, 220, 0.14);
  --card: rgba(16, 22, 36, 0.88);
  --radius: 16px;
  --font: "Segoe UI", ui-sans-serif, system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --gap: 12px;
  --max: 1120px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .mesh, [data-keel-surface="card"], .reveal { animation: none !important; transition: none !important; }
}
html, body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body { overflow-x: hidden; }
.mesh {
  position: fixed; inset: -15% -10% auto; height: 55vh; z-index: 0; pointer-events: none;
  background:
    radial-gradient(45% 50% at 15% 30%, rgba(80,140,255,.20), transparent 60%),
    radial-gradient(40% 40% at 85% 15%, rgba(140,100,255,.14), transparent 55%);
  filter: blur(10px);
}
.noise {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.skip { position:absolute; left:-999px; top:8px; background:#111; color:#fff; padding:8px 12px; z-index:30; }
.skip:focus { left: 8px; }

/* ===== Engine HostDocument layout contract (SSOT) ===== */
#keel-root { position: relative; z-index: 1; max-width: var(--max); margin: 0 auto; padding: 0 20px 56px; }
#keel-root [data-rect] {
  position: static !important; left: auto !important; top: auto !important;
  width: auto !important; height: auto !important;
}
#keel-root [data-keel-layout="stack"] { display: flex; flex-direction: column; align-items: stretch; }
#keel-root [data-keel-layout="row"] { display: flex; flex-direction: row; align-items: center; flex-wrap: wrap; }
#keel-root [data-keel-layout="row"]:not([data-keel-surface="nav"]):not([data-keel-surface="cta-row"]):not([data-keel-surface="foot"]) {
  /* tight chrome rows may still wrap; playground toolbars wrap too */
}
#keel-root [data-keel-layout="wrap"] { display: flex; flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: inherit; }
#keel-root [data-keel-layout="scroll"] { overflow: auto; max-height: 70vh; }
/* tick-3 layout integrity */
#keel-root [data-keel-layout="wrap"] > *,
#keel-root [data-keel-surface="grid"] > * { min-width: 0; }
#keel-root [data-keel-surface="nav"] > a { white-space: nowrap; }
#keel-root h1, #keel-root h2, #keel-root h3 { max-width: 100%; overflow-wrap: anywhere; }
#keel-root [style*="gap"] { /* engine gap inline */ }

/* Page column */
#keel-root > [data-keel-layout="stack"],
#keel-root > div[data-keel-layout="stack"] { gap: 1.1rem; width: 100%; padding-top: 0.15rem; }

/* Surfaces (closed tokens) */
/* Full-bleed sticky chrome (React/Solid app-shell class density) */
#keel-root [data-keel-surface="nav"],
#keel-root nav[data-keel-surface="nav"] {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.55rem;
  /* break out of content column to viewport edges */
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  margin-bottom: 0.75rem;
  padding: 0.55rem max(1rem, calc((100vw - var(--max)) / 2 + 0.25rem));
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.88);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-sizing: border-box;
}
#keel-root [data-keel-surface="brand"] {
  font-weight: 750; letter-spacing: -0.02em; color: var(--ink) !important; font-size: 1.1rem;
  padding: 0.25rem 0.4rem; border: 1px solid rgba(140,180,255,.35); border-radius: 10px;
}
#keel-root [data-keel-surface="nav-link"] {
  color: var(--muted) !important; font-size: 0.9rem; padding: 0.32rem 0.62rem; border-radius: 999px; text-decoration: none;
}
#keel-root [data-keel-surface="nav-link"].is-active,
#keel-root [data-keel-surface="nav-link"][aria-current="page"] {
  color: var(--ink) !important; background: rgba(120,160,255,.12); box-shadow: inset 0 0 0 1px rgba(120,160,255,.22);
}
#keel-root [data-keel-surface="nav-cta"] {
  color: var(--accent) !important; border: 1px solid rgba(126,194,255,.35); border-radius: 999px;
  padding: 0.4rem 0.85rem; text-decoration: none; font-size: 0.92rem;
}
#keel-root [data-keel-surface="hero"],
#keel-root [data-keel-surface="band"] {
  display: flex; flex-direction: column; gap: 0.85rem; padding: 0.5rem 0 0.25rem;
}
#keel-root [data-keel-surface="panel"] {
  display: flex; flex-direction: column; gap: 0.85rem;
  padding: 1.15rem 1.2rem; border-radius: calc(var(--radius) + 2px);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18,24,40,.82), rgba(10,14,24,.72));
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
#keel-root [data-keel-surface="grid"] {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: stretch;
}
#keel-root [data-keel-surface="card"] {
  flex: 1 1 240px; min-width: min(100%, 220px); max-width: 100%;
  display: flex; flex-direction: column; gap: 0.45rem;
  padding: 1rem 1.05rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
#keel-root [data-keel-surface="card"]:hover {
  transform: translateY(-2px); border-color: rgba(130,170,255,.32);
  box-shadow: 0 16px 40px rgba(0,0,0,.3);
}
#keel-root [data-keel-surface="cta-row"] {
  display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 0.35rem;
}
#keel-root [data-keel-surface="btn-primary"],
#keel-root [data-keel-surface="btn-ghost"] {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; padding: 0.7rem 1.15rem; font-weight: 600; text-decoration: none; font-size: 0.95rem;
}
#keel-root [data-keel-surface="btn-primary"] {
  color: #071018 !important; background: linear-gradient(135deg, #8fd0ff, #6b8cff);
  box-shadow: 0 10px 28px rgba(90,140,255,.25);
}
#keel-root [data-keel-surface="btn-ghost"] {
  color: var(--ink) !important; border: 1px solid var(--line); background: rgba(255,255,255,.03);
}
#keel-root [data-keel-surface="metric"] {
  flex: 1 1 120px; padding: 0.85rem 1rem; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(12,18,30,.75); display: flex; flex-direction: column; gap: 0.2rem;
}
#keel-root [data-keel-surface="chip"] {
  display: inline-flex; padding: 0.4rem 0.75rem; border-radius: 999px;
  border: 1px solid rgba(120,160,255,.25); background: rgba(20,28,44,.85); font-size: 0.82rem; font-weight: 600;
}
#keel-root [data-keel-surface="field"],
#keel-root textarea[data-keel-surface="field"],
#keel-root textarea.field {
  width: min(100%, 440px); min-height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(8,12,22,.9); color: var(--ink);
  padding: 0.75rem 0.9rem; font: inherit; resize: vertical;
}
#keel-root textarea:focus, #keel-root [data-keel-focused="1"] {
  outline: none; border-color: rgba(120,170,255,.55) !important;
  box-shadow: 0 0 0 3px rgba(100,150,255,.16);
}
#keel-root [data-keel-surface="foot"] {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; align-items: center;
  margin-top: 1.5rem; padding-top: 1.1rem; border-top: 1px solid var(--line);
}
#keel-root [data-keel-surface="playground"] {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem;
}
@media (max-width: 860px) {
  #keel-root [data-keel-surface="playground"] { grid-template-columns: 1fr; }
}

/* Typography */
#keel-root a { color: var(--accent); text-decoration: none; }
#keel-root a:hover { color: #a9d6ff; }
#keel-root h1 { font-size: clamp(2rem, 4.5vw, 3.05rem); line-height: 1.08; letter-spacing: -0.035em; margin: 0.15em 0 0.35em; font-weight: 720; color: var(--ink); }
#keel-root h2 { font-size: clamp(1.3rem, 2.2vw, 1.7rem); margin: 0 0 0.4em; letter-spacing: -0.02em; }
#keel-root h3 { font-size: 1.05rem; margin: 0; }
#keel-root [data-keel-surface="eyebrow"], #keel-root .eyebrow {
  font-size: 0.72rem; letter-spacing: 0.14em; font-weight: 650; color: var(--accent); text-transform: uppercase;
}
#keel-root [data-keel-surface="lead"], #keel-root .lead { color: var(--muted); font-size: 1.05rem; max-width: 42rem; }
#keel-root span, #keel-root [data-keel-surface="body"] { color: var(--muted); max-width: 46rem; }
#keel-root [data-keel-surface="metric-value"] {
  font-size: 1.9rem; font-weight: 730; letter-spacing: -0.03em;
  background: linear-gradient(135deg, #9fd0ff, #b8a6ff); -webkit-background-clip: text; color: transparent;
}
#keel-root table.matrix { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
#keel-root table.matrix th, #keel-root table.matrix td {
  border: 1px solid var(--line); padding: 0.55rem 0.65rem; text-align: left; vertical-align: top;
}
#keel-root table.matrix th { background: rgba(20,28,44,.9); color: var(--ink); }
#keel-root table.matrix td { color: var(--muted); }
#keel-root table.matrix .ok { color: #7ddea0; }
#keel-root table.matrix .partial { color: #e6c07b; }
#keel-root table.matrix .no { color: #f07178; }
#keel-root .spacer-flex { flex: 1 1 auto; min-width: 0.5rem; }

.engine-badge { position: relative; z-index: 1; max-width: var(--max); margin: 0 auto; padding: 0 20px 40px; font-size: 12px; color: #738098; }
.engine-badge a { color: #8eb7ff; }
.engine-badge code { font-family: var(--mono); font-size: 11px; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .25s; }

/* Playground host widgets (progressive enhancement) */
#pg-editor, #pg-md {
  width: 100%; min-height: 220px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(8,12,22,.92); color: var(--ink); padding: 0.85rem; font: 13px/1.45 var(--mono);
}
#pg-preview {
  min-height: 220px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(12,18,30,.75); padding: 1rem;
}
#pg-preview [data-keel-layout="stack"] { gap: 0.65rem; }
#pg-preview [data-keel-layout="row"] { gap: 0.5rem; }
#pg-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
#pg-toolbar button {
  border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.04);
  color: var(--ink); padding: 0.45rem 0.8rem; cursor: pointer; font: inherit; font-size: 0.85rem;
}
#pg-toolbar button:hover { border-color: rgba(130,170,255,.4); }

#keel-root a:focus-visible, #keel-root button:focus-visible, #keel-root textarea:focus-visible {
  outline: 2px solid #7ec2ff; outline-offset: 2px;
}
#keel-root [data-keel-surface="nav"] { row-gap: 0.45rem; }
#keel-root [data-keel-surface="panel"] [data-keel-surface="field"] { margin: 0.25rem 0; }
#keel-root [data-keel-surface="panel"] [data-keel-surface="btn-primary"] { align-self: flex-start; margin-top: 0.35rem; }

/* Playground code / table cells (class escape hatch on engine nodes) */
#pg-preview .code-block, #keel-root .code-block {
  font-family: var(--mono); white-space: pre-wrap; display: block;
  padding: 0.65rem 0.75rem; border-radius: 10px; background: rgba(0,0,0,.28);
  border: 1px solid var(--line); color: var(--ink);
}
#pg-preview .code, #keel-root .code {
  font-family: var(--mono); font-size: 0.88em;
}

#pg-preview .strong, #keel-root .strong { font-weight: 700; color: var(--ink); }
#pg-preview .inline-runs, #keel-root .inline-runs {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.35rem;
}

/* Client route transition (progressive; reduced-motion off) */
#keel-root.is-route-enter > *:not([data-keel-surface="nav"]) {
  animation: keel-route-in .28s ease both;
}
@keyframes keel-route-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  #keel-root.is-route-enter > *:not([data-keel-surface="nav"]) { animation: none; }
}
