/* Base, aurora background, shell (nav, dock), dialogs, toasts, palette */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 220ms var(--ease) both vt-out; }
::view-transition-new(root) { animation: 450ms var(--ease) both vt-in; }
@keyframes vt-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(12px); } }

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 88px; }
html.lenis, html.lenis body { height: auto; }
.lenis.lenis-smooth { scroll-behavior: auto !important; }
.lenis.lenis-stopped { overflow: hidden; }
body {
  margin: 0; min-height: 100vh; background: var(--ink); color: var(--text);
  font: 400 15px/24px var(--font-sans); -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility; overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: var(--radius-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
::selection { background: rgba(109, 74, 255, 0.55); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* Aurora light, fixed behind everything. --p is page scroll progress 0..1 (set by shell.js). */
.aurora { position: fixed; inset: 0; z-index: -2; overflow: hidden; pointer-events: none; background: radial-gradient(120% 80% at 50% 0%, #0b0d18 0%, var(--ink) 60%); }
.aurora i { position: absolute; display: block; border-radius: 50%; filter: blur(90px); will-change: transform; }
.aurora .a1 { width: 70vw; height: 46vw; left: -10vw; bottom: -26vw; background: var(--aurora-violet); animation: drift-a 22s ease-in-out infinite alternate; opacity: calc(0.7 - var(--p, 0) * 0.35); }
.aurora .a2 { width: 60vw; height: 40vw; right: -12vw; bottom: -24vw; background: var(--aurora-cyan); animation: drift-b 26s ease-in-out infinite alternate; opacity: calc(0.6 - var(--p, 0) * 0.3); }
.aurora .a3 { width: 40vw; height: 30vw; left: 30vw; bottom: -20vw; background: rgba(109, 74, 255, 0.55); animation: drift-c 18s ease-in-out infinite alternate; }
@keyframes drift-a { to { transform: translate3d(12vw, -6vw, 0) scale(1.15); } }
@keyframes drift-b { to { transform: translate3d(-14vw, -4vw, 0) scale(1.1); } }
@keyframes drift-c { to { transform: translate3d(-8vw, -8vw, 0) scale(1.25); } }
.grain { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0.05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }
.progress { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: calc(var(--z-nav) + 1); transform-origin: 0 50%; transform: scaleX(var(--p, 0)); background: linear-gradient(90deg, var(--brand), var(--cyan)); }

/* Top nav */
.nav { position: sticky; top: 0; z-index: var(--z-nav); display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); height: 64px; padding: 0 var(--page-gutter); background: linear-gradient(180deg, rgba(7, 8, 13, 0.85), rgba(7, 8, 13, 0)); backdrop-filter: blur(10px); mask-image: linear-gradient(#000 75%, transparent); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--cyan)); box-shadow: var(--glow-brand); }
.brand-mark svg { width: 16px; height: 16px; fill: #fff; }
.nav-links { position: relative; display: flex; gap: 2px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-pill); background: rgba(20, 24, 38, 0.55); backdrop-filter: blur(16px); }
.nav-links a { position: relative; z-index: 1; padding: 6px 14px; border-radius: var(--radius-pill); font: 500 13px/20px var(--font-sans); color: var(--text-muted); transition: color 150ms var(--ease); }
.nav-links a:hover, .nav-links a[aria-current="page"] { color: var(--text); }
.nav-lens { position: absolute; z-index: 0; top: 4px; left: 0; height: calc(100% - 8px); border-radius: var(--radius-pill); background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.4); transition: transform 350ms var(--ease), width 350ms var(--ease), opacity 200ms; opacity: 0; pointer-events: none; }
.nav-right { display: flex; align-items: center; gap: var(--space-3); }
.credits-chip { padding: 6px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--glass); font: 500 12px/18px var(--font-mono); letter-spacing: 0.04em; color: var(--cyan-soft); white-space: nowrap; transition: background 150ms; }
.credits-chip:hover { background: var(--surface-3); }
.credits-chip.low { color: var(--warn); border-color: var(--warn); }
.nav-right .icon-btn[aria-current="page"] { color: var(--text); border-color: var(--violet); }
.status-dot { display: inline-flex; align-items: center; gap: 8px; font: 500 12px/16px var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-subtle); }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px var(--success); }
.status-dot.off::before { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 6px; font: 500 11px/16px var(--font-mono); color: var(--text-muted); }

/* Dock */
.dock-wrap { position: fixed; left: 0; right: 0; bottom: 24px; z-index: var(--z-dock); display: flex; justify-content: center; pointer-events: none; transition: transform 450ms var(--ease), opacity 300ms; }
.dock-wrap.away { transform: translateY(24px); opacity: 0.45; }
.dock-wrap:hover, .dock-wrap:focus-within { transform: none; opacity: 1; }
.dock { position: relative; pointer-events: auto; display: inline-flex; gap: 4px; padding: 8px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-xl); backdrop-filter: blur(24px) saturate(1.4); box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255, 255, 255, 0.07); }
.dock a { position: relative; z-index: 1; display: grid; justify-items: center; gap: 4px; min-width: 72px; padding: 10px 12px; border-radius: var(--radius-lg); font: 600 12px/16px var(--font-sans); color: var(--text-muted); transition: color 150ms var(--ease), transform 300ms var(--spring); }
.dock a:hover { color: var(--text); transform: translateY(-3px); }
.dock a[aria-current="page"] { color: var(--text); }
.dock svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.dock .count { position: absolute; top: 4px; right: 14px; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--cyan); color: var(--ink); font: 600 11px/18px var(--font-mono); text-align: center; animation: pop 400ms var(--spring); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }
.dock-lens { position: absolute; z-index: 0; top: 8px; left: 0; height: calc(100% - 16px); border-radius: var(--radius-lg); background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.45); transition: transform 350ms var(--ease), width 350ms var(--ease), opacity 200ms; opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
  .nav-links, .nav .status-dot, .nav .kbd, #open-palette { display: none; }
  .credits-chip { padding: 4px 10px; }
  .dock-wrap { bottom: 12px; padding: 0 8px; }
  .dock { width: 100%; max-width: 460px; gap: 2px; padding: 6px; border-radius: var(--radius-lg); }
  .dock a { flex: 1 1 0; min-width: 0; padding: 8px 0; font-size: 10px; letter-spacing: -0.02em; border-radius: var(--radius-md); }
  .dock .count { right: 6px; }
}

/* Reveal on scroll */
.reveal { opacity: 0; transform: translateY(24px); filter: blur(6px); transition: opacity 700ms var(--ease), transform 700ms var(--ease), filter 700ms var(--ease); transition-delay: calc(var(--i, 0) * 70ms); }
.reveal.in { opacity: 1; transform: none; filter: none; }
.no-js .reveal { opacity: 1; transform: none; filter: none; }

/* Dialogs */
dialog { color: var(--text); padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-2); box-shadow: var(--shadow-card); max-width: min(960px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; opacity: 0; transform: translateY(16px) scale(0.97); transition: opacity 250ms var(--ease), transform 350ms var(--ease), overlay 350ms allow-discrete, display 350ms allow-discrete; }
dialog[open] { opacity: 1; transform: none; }
@starting-style { dialog[open] { opacity: 0; transform: translateY(16px) scale(0.97); } }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(8px); opacity: 0; transition: opacity 250ms var(--ease), overlay 250ms allow-discrete, display 250ms allow-discrete; }
dialog[open]::backdrop { opacity: 1; }
@starting-style { dialog[open]::backdrop { opacity: 0; } }
.dialog-body { padding: var(--space-6); display: grid; gap: var(--space-4); }
.dialog-body h2 { margin: 0; font: 600 22px/28px var(--font-sans); letter-spacing: -0.02em; }
.dialog-body p { margin: 0; color: var(--text-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Command palette */
.palette { width: min(640px, calc(100vw - 24px)); margin-top: 12vh; }
.palette-input { display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); border-bottom: 1px solid var(--line); }
.palette-input svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--text-subtle); stroke-width: 1.75; stroke-linecap: round; }
.palette-input input { flex: 1; height: 56px; background: transparent; border: 0; font-size: 17px; }
.palette-input input:focus-visible { outline: none; }
.palette-input input::placeholder { color: var(--text-subtle); }
.palette-list { list-style: none; margin: 0; padding: var(--space-2); max-height: 50vh; overflow: auto; }
.palette-group { padding: 10px 12px 4px; font: 500 11px/16px var(--font-mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-subtle); }
.palette-item { display: flex; align-items: center; gap: var(--space-3); padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer; color: var(--text-muted); }
.palette-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.palette-item .hint { margin-left: auto; font: 500 12px/16px var(--font-mono); color: var(--text-subtle); }
.palette-item[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.4); }
.palette-empty { padding: var(--space-6); text-align: center; color: var(--text-subtle); }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 10px var(--space-6); align-items: center; }
.shortcuts dt { display: flex; gap: 4px; }
.shortcuts dd { margin: 0; color: var(--text-muted); }

/* Toasts */
.toasts { position: fixed; right: var(--space-6); bottom: 120px; z-index: var(--z-toast); display: grid; gap: var(--space-2); justify-items: end; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-card); font-size: 14px; line-height: 22px; animation: toast-in 450ms var(--spring) both; }
.toast.out { animation: toast-out 250ms var(--ease) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
@media (max-width: 760px) { .toasts { right: 12px; left: 12px; justify-items: center; } }

.stopped { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; text-align: center; padding: var(--space-6); background: var(--scrim); backdrop-filter: blur(16px); animation: vt-in 450ms var(--ease); }
.stopped h2 { margin: 0 0 8px; font: 600 40px/44px var(--font-sans); letter-spacing: -0.04em; }
.stopped p { margin: 0; color: var(--text-muted); }

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