/* ALVIS preview: core tokens + shared components.
   Direction A, "Machined Graphite". One accent (verdigris), hairlines, inset highlights, no drop shadows. */

:root {
  --font-display: "Funnel Display", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Martian Mono", ui-monospace, "SF Mono", monospace;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --r-1: 2px;
  --r-2: 4px;
  --r-3: 6px;

  --container: 1240px;
  --gutter: clamp(20px, 4vw, 48px);
  --nav-h: 64px;
}

/* Dark (default). Near-black like Raycast or Linear: depth comes from slightly lighter surfaces and hairlines, not shadows. */
:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08090a;
  --bg-2: #0c0d0e;
  --panel: #111214;
  --raised: #16171a;
  --inset: #1d1e21;
  --line: #1e1f22;
  --line-2: #2a2b2f;
  --ink: #eeeeec;
  --ink-2: #a1a19c;
  --ink-3: #81807b;
  --accent: #5f9c8c;
  --accent-2: #7fb7a8;
  --accent-ink: #06110e;
  --accent-wash: rgba(95, 156, 140, 0.11);
  --ok: #6fa37c;
  --warn: #c49a52;
  --danger: #c4675a;
  --hi: rgba(255, 255, 255, 0.04);
  --scrim: rgba(0, 0, 0, 0.66);
  --grid-ink: 238, 238, 236;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #e6e5e1;
  --bg-2: #e1e0db;
  --panel: #edece8;
  --raised: #f1f0ec;
  --inset: #dad9d4;
  --line: #cfcdc7;
  --line-2: #bebcb5;
  --ink: #1a1b1c;
  --ink-2: #57564f;
  --ink-3: #85837c;
  --accent: #3d7768;
  --accent-2: #2f6153;
  --accent-ink: #eef4f1;
  --accent-wash: rgba(61, 119, 104, 0.11);
  --ok: #3f7a4e;
  --warn: #93682a;
  --danger: #a24a3e;
  --hi: rgba(255, 255, 255, 0.55);
  --scrim: rgba(40, 40, 36, 0.38);
  --grid-ink: 26, 27, 28;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-padding-top: calc(var(--nav-h) + 24px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;
  transition: background-color 200ms ease, color 200ms ease;
}
img, svg, canvas { display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent); color: var(--accent-ink); }

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

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

.skip-link {
  position: fixed; left: 16px; top: -60px; z-index: 200;
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r-2);
  transition: top 160ms var(--ease-out);
}
.skip-link:focus { top: 12px; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); }

/* ── Typography (shadcn typography roles, re-tuned) ── */
.t-display {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.6rem, 6.4vw, 5.6rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  margin: 0;
  text-wrap: balance;
}
.t-h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2rem, 4.2vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.03em;
  margin: 0;
  text-wrap: balance;
}
.t-h3 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.25rem, 1.8vw, 1.6rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0;
}
.t-lede { font-size: clamp(1.05rem, 1.3vw, 1.2rem); line-height: 1.55; color: var(--ink-2); max-width: 60ch; margin: 0; text-wrap: pretty; }
.t-body { color: var(--ink-2); max-width: 64ch; }
.t-small { font-size: 0.875rem; color: var(--ink-2); }
.t-caption { font-size: 0.8125rem; color: var(--ink-3); }
.t-mono { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.t-muted { color: var(--ink-2); }
.t-subtle { color: var(--ink-3); }
.t-accent { color: var(--accent); }
.tnum { font-variant-numeric: tabular-nums; }

.prose { max-width: 70ch; }
.prose h1 { font-family: var(--font-display); font-weight: 500; font-size: clamp(2.2rem, 4vw, 3.2rem); letter-spacing: -0.03em; line-height: 1.04; margin: 0 0 16px; }
.prose h2 { font-family: var(--font-display); font-weight: 500; font-size: 1.5rem; letter-spacing: -0.015em; margin: 48px 0 12px; padding-top: 24px; border-top: 1px solid var(--line); }
.prose h3 { font-size: 1.05rem; font-weight: 600; margin: 28px 0 8px; }
.prose p, .prose li { color: var(--ink-2); }
.prose ul { padding-left: 1.2em; }
.prose li { margin: 6px 0; }
.prose li::marker { color: var(--ink-3); }
.prose a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.prose code { font-family: var(--font-mono); font-size: 0.8em; background: var(--raised); border: 1px solid var(--line); padding: 1px 5px; border-radius: var(--r-1); }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 16px 0; }
.prose th, .prose td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { color: var(--ink-3); font-weight: 500; font-size: 0.8rem; }

/* ── Buttons ── */
.btn {
  --btn-h: 40px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-h); padding: 0 16px;
  font-size: 0.9rem; font-weight: 500; letter-spacing: -0.005em;
  border-radius: var(--r-2);
  border: 1px solid var(--line-2);
  background: var(--raised);
  color: var(--ink);
  box-shadow: inset 0 1px 0 var(--hi);
  transition: transform 140ms var(--ease-out), background-color 150ms ease, border-color 150ms ease, color 150ms ease;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn--sm { --btn-h: 32px; padding: 0 12px; font-size: 0.82rem; }
.btn--lg { --btn-h: 48px; padding: 0 22px; font-size: 0.95rem; }
.btn--ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-2); }
.btn--line { background: transparent; box-shadow: none; }
.btn--accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: inset 0 1px 0 rgba(255,255,255,.18); }
.btn--danger { color: var(--danger); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn-icon { --btn-h: 36px; width: var(--btn-h); padding: 0; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--inset); border-color: var(--line-2); }
  .btn--ghost:hover { background: var(--raised); color: var(--ink); }
  .btn--line:hover { background: var(--raised); }
  .btn--accent:hover { background: var(--accent-2); border-color: var(--accent-2); }
}

/* ── Shimmer button (magicui), re-tuned: one slow spark tracing the border. Primary CTA only. ── */
.shimmer {
  --spark: 3.2s;
  position: relative;
  isolation: isolate;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 48px; padding: 0 24px;
  border-radius: var(--r-2);
  background: var(--ink);
  color: var(--bg);
  font-weight: 600; font-size: 0.95rem; letter-spacing: -0.01em;
  overflow: hidden;
  transition: transform 140ms var(--ease-out);
  white-space: nowrap;
}
.shimmer::before {
  content: "";
  position: absolute; inset: -150%;
  z-index: -2;
  background: conic-gradient(from 0deg, transparent 0 300deg, var(--accent) 330deg, transparent 360deg);
  animation: spark var(--spark) linear infinite;
}
.shimmer::after {
  content: "";
  position: absolute; inset: 1.5px;
  z-index: -1;
  border-radius: calc(var(--r-2) - 1px);
  background: var(--ink);
  box-shadow: inset 0 -8px 16px -10px rgba(var(--grid-ink), .0);
}
.shimmer:active { transform: scale(0.97); }
.shimmer svg { width: 16px; height: 16px; }
@keyframes spark { to { transform: rotate(1turn); } }

/* ── Chips, tags, kbd ── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 8px;
  border-radius: var(--r-1);
  background: var(--raised);
  border: 1px solid var(--line);
  font-size: 0.75rem; color: var(--ink-2);
  white-space: nowrap;
}
.chip--accent { color: var(--accent); background: var(--accent-wash); border-color: transparent; }
.chip--ok { color: var(--ok); }
.chip--warn { color: var(--warn); }
.chip--danger { color: var(--danger); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
kbd, .kbd {
  font-family: var(--font-mono); font-size: 0.68rem;
  padding: 1px 5px; border-radius: var(--r-1);
  border: 1px solid var(--line-2); background: var(--raised); color: var(--ink-2);
}

/* ── Fields ── */
.field { display: grid; gap: 6px; }
.field label, .label { font-size: 0.8rem; color: var(--ink-2); font-weight: 500; }
.input, .textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 0 12px; height: 40px;
  font-size: 0.9rem;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(0,0,0,.06);
  transition: border-color 150ms ease, background-color 150ms ease;
}
.textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .textarea:focus { outline: none; border-color: var(--accent); }
.field .hint { font-size: 0.78rem; color: var(--ink-3); }
.field .err { font-size: 0.78rem; color: var(--danger); }

/* ── Switch ── */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.85rem; color: var(--ink-2); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 32px; height: 18px; border-radius: 9px; position: relative;
  background: var(--inset); border: 1px solid var(--line-2);
  transition: background-color 160ms ease, border-color 160ms ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--ink-2);
  transition: transform 180ms var(--ease-out), background-color 160ms ease;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); background: var(--accent-ink); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Select (shadcn base select, restyled) ── */
.sel { position: relative; display: inline-block; min-width: 180px; }
.sel-trigger {
  width: 100%; height: 40px; padding: 0 10px 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--raised); border: 1px solid var(--line-2); border-radius: var(--r-2);
  box-shadow: inset 0 1px 0 var(--hi);
  font-size: 0.88rem; text-align: left;
  transition: border-color 150ms ease;
}
.sel-trigger svg { width: 14px; height: 14px; color: var(--ink-3); flex-shrink: 0; }
.sel[data-open] .sel-trigger { border-color: var(--accent); }
.sel-pop {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 60;
  min-width: 100%; max-height: 280px; overflow: auto;
  padding: 4px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-3);
  transform-origin: top left;
  opacity: 0; transform: scale(0.97) translateY(-4px); pointer-events: none;
  transition: opacity 140ms var(--ease-out), transform 160ms var(--ease-out);
}
.sel[data-up] .sel-pop { top: auto; bottom: calc(100% + 6px); transform-origin: bottom left; }
.sel[data-open] .sel-pop { opacity: 1; transform: none; pointer-events: auto; }
.sel-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: var(--r-2);
  font-size: 0.86rem; color: var(--ink-2); cursor: pointer;
}
.sel-opt[data-active] { background: var(--raised); color: var(--ink); }
.sel-opt[aria-selected="true"] { color: var(--ink); }
.sel-opt[aria-selected="true"]::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sel-group { padding: 8px 10px 4px; font-size: 0.72rem; color: var(--ink-3); }

/* ── Tooltip ── */
.tip {
  position: fixed; z-index: 120; pointer-events: none;
  max-width: 260px;
  padding: 6px 9px; border-radius: var(--r-2);
  background: var(--ink); color: var(--bg);
  font-size: 0.76rem; line-height: 1.35;
  opacity: 0; transform: scale(0.97);
  transition: opacity 125ms var(--ease-out), transform 125ms var(--ease-out);
}
.tip[data-show] { opacity: 1; transform: none; }
.tip[data-instant] { transition-duration: 0ms; }

/* ── Hover card ── */
.hcard {
  position: fixed; z-index: 110; width: 300px;
  padding: 14px; border-radius: var(--r-3);
  background: var(--panel); border: 1px solid var(--line-2);
  opacity: 0; transform: scale(0.97); pointer-events: none;
  transition: opacity 150ms var(--ease-out), transform 160ms var(--ease-out);
}
.hcard[data-show] { opacity: 1; transform: none; pointer-events: auto; }

/* ── Context menu (shadcn base context-menu) ── */
.ctx {
  position: fixed; z-index: 130; min-width: 210px;
  padding: 4px; border-radius: var(--r-3);
  background: var(--panel); border: 1px solid var(--line-2);
  opacity: 0; pointer-events: none;
  transition: opacity 120ms ease-out;
}
.ctx[data-show] { opacity: 1; pointer-events: auto; }
.ctx-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 7px 10px; border-radius: var(--r-2);
  font-size: 0.84rem; color: var(--ink-2); text-align: left;
}
.ctx-item:focus, .ctx-item[data-active] { outline: none; background: var(--raised); color: var(--ink); }
.ctx-item--danger { color: var(--danger); }
.ctx-item--danger:focus { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.ctx-label { padding: 6px 10px 4px; font-size: 0.72rem; color: var(--ink-3); }

/* ── Toast (Sonner-style stack) ── */
.toaster {
  position: fixed; right: 20px; bottom: 20px; z-index: 150;
  width: min(360px, calc(100vw - 40px));
  display: grid;
}
.toast {
  grid-area: 1 / 1;
  align-self: end;
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: start;
  padding: 14px 14px 14px 16px;
  border-radius: var(--r-3);
  background: var(--panel); border: 1px solid var(--line-2);
  box-shadow: inset 0 1px 0 var(--hi);
  --i: 0;
  transform: translateY(calc(var(--i) * -10px)) scale(calc(1 - var(--i) * 0.05));
  opacity: calc(1 - var(--i) * 0.25);
  transition: transform 400ms var(--ease-out), opacity 300ms ease;
  @starting-style { transform: translateY(110%); opacity: 0; }
}
.toast[data-out] { transform: translateY(110%); opacity: 0; transition-duration: 200ms; }
.toaster:hover .toast, .toaster:focus-within .toast { --spread: 1; }
.toast-ico { width: 16px; height: 16px; margin-top: 2px; color: var(--ink-3); }
.toast[data-variant="success"] .toast-ico { color: var(--ok); }
.toast[data-variant="error"] .toast-ico { color: var(--danger); }
.toast-title { font-size: 0.88rem; font-weight: 600; grid-column: 2; }
.toast-desc { font-size: 0.82rem; color: var(--ink-2); grid-column: 2; }
.toast-act { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
.toast-x { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; color: var(--ink-3); border-radius: var(--r-1); display: none; }

/* ── Skeleton ── */
.skel {
  position: relative; overflow: hidden;
  background: var(--raised);
  border-radius: var(--r-2);
  min-height: 10px;
}
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(var(--grid-ink), .05), transparent);
  transform: translateX(-100%);
  animation: skel 1.4s ease-in-out infinite;
}
@keyframes skel { to { transform: translateX(100%); } }
.skel-line { height: 10px; margin: 8px 0; }

/* ── Breadcrumb ── */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-3); list-style: none; margin: 0; padding: 0; }
.crumbs a { color: var(--ink-2); }
.crumbs li + li::before { content: "/"; margin-right: 8px; color: var(--line-2); }
.crumbs [aria-current] { color: var(--ink); }
@media (hover: hover) and (pointer: fine) { .crumbs a:hover { color: var(--ink); } }

/* ── Dialog ── */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 140; background: var(--scrim);
  display: grid; place-items: center; padding: 24px;
  opacity: 0; pointer-events: none; transition: opacity 200ms ease;
}
.dialog-scrim[data-show] { opacity: 1; pointer-events: auto; }
.dialog {
  width: min(960px, 100%); max-height: calc(100vh - 48px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-3);
  transform: scale(0.97); opacity: 0;
  transition: transform 220ms var(--ease-out), opacity 200ms var(--ease-out);
}
.dialog-scrim[data-show] .dialog { transform: none; opacity: 1; }

/* ── Flickering grid background (magicui), fixed behind content ── */
.bg-grid {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
          mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 0%, transparent 75%);
}
.bg-grid canvas { width: 100%; height: 100%; }

/* ── Section scaffolding ── */
.sec { position: relative; padding: clamp(96px, 12vw, 160px) 0; }
.sec + .sec { border-top: 1px solid var(--line); }
.sec-head { display: grid; gap: 18px; margin-bottom: clamp(40px, 6vw, 72px); }
.sec-head--split { grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); align-items: end; gap: 48px; }
.sec-kicker { font-size: 0.9rem; color: var(--accent); font-weight: 500; }
.sec-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 40px; }
@media (max-width: 860px) { .sec-head--split { grid-template-columns: 1fr; gap: 18px; } }

/* Reveal on enter: one orchestrated moment per section, not per element. */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 600ms var(--ease-out), transform 700ms var(--ease-out); }
.reveal[data-in] { opacity: 1; transform: none; }

/* Link with underline that draws in (gated) */
.ulink { position: relative; color: var(--ink); }
.ulink::after { content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 1px; background: currentColor; transform: scaleX(0.35); transform-origin: left; opacity: .5; transition: transform 220ms var(--ease-out), opacity 150ms ease; }
@media (hover: hover) and (pointer: fine) { .ulink:hover::after { transform: scaleX(1); opacity: 1; } }

.ph-note {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--warn);
  border: 1px dashed color-mix(in oklab, var(--warn) 55%, transparent);
  padding: 2px 8px; border-radius: var(--r-1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .reveal { transform: none; transition: opacity 300ms ease; }
  .shimmer::before { animation: none; background: none; }
  .toast { transition: opacity 200ms ease; transform: none; }
}
