/* =========================================================================
   Base: reset, document defaults, ambient background, scrollbars, focus,
   utility helpers. No component styling lives here.
   ========================================================================= */

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

* { margin: 0; }

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

body {
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Ambient backdrop: soft red aura over near-black, plus a faint grid. Fixed
   so it never scrolls; pointer-events:none so it never blocks input. */
.backdrop {
  position: fixed;
  inset: -32px;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background:
    linear-gradient(128deg, rgba(229, 57, 69, 0.12), transparent 30%),
    linear-gradient(308deg, rgba(110, 29, 38, 0.13), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 42%),
    var(--bg);
  transform: translate3d(0, var(--ambient-backdrop-y, 0px), 0) scale(1.015);
  transition: background-color var(--t-slow);
  will-change: transform;
}
.backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 78%);
  opacity: 0.6;
  transform: translate3d(
    var(--ambient-grid-x, 0px),
    var(--ambient-grid-y, 0px),
    0
  );
  will-change: transform;
}
.backdrop::after {
  content: "";
  position: absolute;
  width: 140%;
  height: 260px;
  top: -120px;
  left: -20%;
  background: linear-gradient(90deg, transparent 8%, rgba(229, 57, 69, 0.10) 46%, rgba(229, 57, 69, 0.16) 58%, transparent 92%);
  filter: blur(36px);
  opacity: 0.65;
  transform: rotate(-4deg) translate3d(-3%, 0, 0);
  animation: auraDrift 18s var(--ease) infinite alternate;
}
body.bg-paused .backdrop::after { animation-play-state: paused; }

@keyframes auraDrift {
  from { transform: rotate(-4deg) translate3d(calc(-3% + var(--ambient-drift-x, 0px)), var(--ambient-glow-y, 0px), 0); opacity: 0.52; }
  to { transform: rotate(-2deg) translate3d(calc(4% + var(--ambient-drift-x, 0px)), calc(28px + var(--ambient-glow-y, 0px)), 0); opacity: 0.76; }
}

/* =========================================================================
   Ambient background motion — three independent 2D layers over the base
   backdrop. Everything animates transform/opacity/filter only (compositor
   friendly), sits behind content at z-index -1, and is pointer-events:none
   via .backdrop. All layers halt together on `body.bg-paused` (set when the
   tab is hidden) so a background tab costs nothing.
   ========================================================================= */

/* ---- layer 1: aurora — three huge soft blobs, each drifting + breathing on
   its own timing so they never visibly loop in sync. */
.bd-aurora { position: absolute; inset: 0; overflow: hidden; }
.bd-aurora i {
  position: absolute;
  display: block;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
  will-change: transform, opacity;
}
.bd-aurora i:nth-child(1) {
  width: 46vw; height: 46vw; min-width: 380px; min-height: 380px;
  top: -14%; left: -8%;
  background: radial-gradient(circle, rgba(229, 57, 69, 0.34), transparent 68%);
  animation: auroraA 26s var(--ease) infinite alternate;
}
.bd-aurora i:nth-child(2) {
  width: 38vw; height: 38vw; min-width: 320px; min-height: 320px;
  top: 30%; right: -12%;
  background: radial-gradient(circle, rgba(160, 40, 70, 0.28), transparent 70%);
  animation: auroraB 34s var(--ease) infinite alternate;
}
.bd-aurora i:nth-child(3) {
  width: 30vw; height: 30vw; min-width: 260px; min-height: 260px;
  bottom: -12%; left: 32%;
  background: radial-gradient(circle, rgba(255, 70, 85, 0.20), transparent 72%);
  animation: auroraC 30s var(--ease) infinite alternate;
}
@keyframes auroraA {
  from { transform: translate3d(0, 0, 0) scale(1); opacity: 0.38; }
  to   { transform: translate3d(7vw, 5vh, 0) scale(1.18); opacity: 0.62; }
}
@keyframes auroraB {
  from { transform: translate3d(0, 0, 0) scale(1.1); opacity: 0.5; }
  to   { transform: translate3d(-6vw, -7vh, 0) scale(0.92); opacity: 0.28; }
}
@keyframes auroraC {
  from { transform: translate3d(0, 0, 0) scale(0.95); opacity: 0.3; }
  to   { transform: translate3d(-5vw, -4vh, 0) scale(1.22); opacity: 0.55; }
}

/* ---- layer 2: sweep — a single wide diagonal light bar that crosses the
   viewport slowly, then waits. The long pause is deliberate: it reads as an
   occasional highlight rather than a repeating animation. */
.bd-sweep {
  position: absolute;
  top: -30%; left: -60%;
  width: 45%; height: 170%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.045) 42%, rgba(255, 120, 130, 0.055) 55%, transparent);
  transform: rotate(18deg) translate3d(0, 0, 0);
  filter: blur(22px);
  opacity: 0;
  will-change: transform, opacity;
  animation: bdSweep 19s linear infinite;
}
@keyframes bdSweep {
  0%   { transform: rotate(18deg) translate3d(0, 0, 0); opacity: 0; }
  8%   { opacity: 0.85; }
  38%  { opacity: 0.85; }
  46%  { transform: rotate(18deg) translate3d(230vw, 0, 0); opacity: 0; }
  100% { transform: rotate(18deg) translate3d(230vw, 0, 0); opacity: 0; }
}

/* ---- layer 3: embers — small motes rising and fading out. Each gets its own
   delay/duration/x-drift so the field never pulses in unison. */
.bd-embers { position: absolute; inset: 0; overflow: hidden; }
.bd-embers i {
  position: absolute;
  bottom: -20px;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: rgba(255, 100, 112, 0.75);
  box-shadow: 0 0 7px 1px rgba(255, 70, 85, 0.4);
  opacity: 0;
  will-change: transform, opacity;
  animation: emberRise linear infinite;
}
@keyframes emberRise {
  0%   { transform: translate3d(0, 0, 0) scale(0.6); opacity: 0; }
  12%  { opacity: var(--ember-peak, 0.6); }
  70%  { opacity: var(--ember-peak, 0.6); }
  100% { transform: translate3d(var(--ember-x, 20px), -102vh, 0) scale(1); opacity: 0; }
}
.bd-embers i:nth-child(1)  { left: 6%;  animation-duration: 20s; animation-delay: -2s;  --ember-x: 26px;  --ember-peak: 0.5; }
.bd-embers i:nth-child(2)  { left: 14%; animation-duration: 27s; animation-delay: -11s; --ember-x: -18px; --ember-peak: 0.35; width: 2px; height: 2px; }
.bd-embers i:nth-child(3)  { left: 23%; animation-duration: 23s; animation-delay: -6s;  --ember-x: 34px;  --ember-peak: 0.45; }
.bd-embers i:nth-child(4)  { left: 31%; animation-duration: 31s; animation-delay: -18s; --ember-x: -28px; --ember-peak: 0.3; width: 2px; height: 2px; }
.bd-embers i:nth-child(5)  { left: 39%; animation-duration: 18s; animation-delay: -9s;  --ember-x: 16px;  --ember-peak: 0.55; }
.bd-embers i:nth-child(6)  { left: 47%; animation-duration: 29s; animation-delay: -22s; --ember-x: -34px; --ember-peak: 0.32; }
.bd-embers i:nth-child(7)  { left: 55%; animation-duration: 24s; animation-delay: -4s;  --ember-x: 22px;  --ember-peak: 0.48; width: 4px; height: 4px; }
.bd-embers i:nth-child(8)  { left: 63%; animation-duration: 33s; animation-delay: -15s; --ember-x: -20px; --ember-peak: 0.28; width: 2px; height: 2px; }
.bd-embers i:nth-child(9)  { left: 70%; animation-duration: 21s; animation-delay: -7s;  --ember-x: 30px;  --ember-peak: 0.5; }
.bd-embers i:nth-child(10) { left: 78%; animation-duration: 26s; animation-delay: -19s; --ember-x: -24px; --ember-peak: 0.4; }
.bd-embers i:nth-child(11) { left: 85%; animation-duration: 30s; animation-delay: -13s; --ember-x: 18px;  --ember-peak: 0.33; width: 2px; height: 2px; }
.bd-embers i:nth-child(12) { left: 92%; animation-duration: 22s; animation-delay: -3s;  --ember-x: -30px; --ember-peak: 0.52; }
.bd-embers i:nth-child(13) { left: 44%; animation-duration: 36s; animation-delay: -25s; --ember-x: 40px;  --ember-peak: 0.26; width: 2px; height: 2px; }
.bd-embers i:nth-child(14) { left: 18%; animation-duration: 34s; animation-delay: -30s; --ember-x: -38px; --ember-peak: 0.3; }

/* One switch stops every ambient layer (tab hidden / perf mode). */
body.bg-paused .bd-aurora i,
body.bg-paused .bd-sweep,
body.bg-paused .bd-embers i { animation-play-state: paused; }

/* Light theme: the same motion, dialled back so it reads on a bright surface. */
:root[data-theme="light"] .bd-aurora i { opacity: 0.34; filter: blur(80px); }
:root[data-theme="light"] .bd-sweep { opacity: 0; background: linear-gradient(90deg, transparent, rgba(229, 57, 69, 0.05) 50%, transparent); }
:root[data-theme="light"] .bd-embers i { background: rgba(217, 45, 58, 0.4); box-shadow: 0 0 6px 1px rgba(217, 45, 58, 0.18); }

/* Small screens: drop the ember field and the sweep — less paint on the
   devices least able to afford it, aurora alone still carries the look. */
@media (max-width: 720px) {
  .bd-embers, .bd-sweep { display: none; }
  .bd-aurora i { filter: blur(52px); }
}

/* ---- links + typography defaults */
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-lg); }
code, .mono { font-family: var(--font-mono); font-size: 0.86em; }
small { font-size: var(--fs-xs); }
button { font-family: inherit; }

/* ---- form controls: strip native chrome so styling is consistent */
input, textarea, select, button { font: inherit; color: inherit; }
textarea { resize: vertical; }
input[type="search"]::-webkit-search-cancel-button { appearance: none; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ---- focus: single accessible ring everywhere, keyboard-only */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
  border-radius: var(--r-xs);
}

/* ---- scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(229, 57, 69, 0.35) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.09);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(229, 57, 69, 0.5); background-clip: padding-box; }

/* ---- text helpers */
.muted { color: var(--text-2); }
.dim { color: var(--text-muted); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-red { color: var(--red-bright); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.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;
}

/* ---- visibility */
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---- entrance helpers reused across views */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0% { background-position: -420px 0; }
  100% { background-position: 420px 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- light-theme surface fixups (backdrop + scrollbars read inverted) ---- */
:root[data-theme="light"] .backdrop {
  background:
    radial-gradient(1200px 720px at 12% -8%, rgba(229, 57, 69, 0.10), transparent 60%),
    radial-gradient(1000px 700px at 92% 4%, rgba(229, 57, 69, 0.07), transparent 62%),
    var(--bg);
}
:root[data-theme="light"] .backdrop::before {
  opacity: 0.5;
  background-image:
    linear-gradient(rgba(20, 10, 25, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 10, 25, 0.035) 1px, transparent 1px);
}
:root[data-theme="light"] .backdrop::after { opacity: 0.4; }
:root[data-theme="light"] * { scrollbar-color: rgba(20, 10, 25, 0.22) transparent; }
:root[data-theme="light"] *::-webkit-scrollbar-thumb { background: rgba(20, 10, 25, 0.16); background-clip: padding-box; }
:root[data-theme="light"] *::-webkit-scrollbar-thumb:hover { background: rgba(229, 57, 69, 0.5); background-clip: padding-box; }
