/* =========================================================
   CHROMA — base layer
   Tokens, fonts, reset, primitives, boot + fallback
   ========================================================= */

@font-face {
  font-family: "Syne";
  src: url("/fonts/syne-latin.woff2") format("woff2");
  font-weight: 600 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --void: #07030d;
  --ink: #0b0616;
  --ink-soft: #100a1f;
  --surface: rgba(22, 13, 42, 0.88);
  --surface-strong: #160d2a;
  --surface-raised: #21133d;
  --surface-deep: #0d0719;

  --paper: #f6f1ff;
  --muted: #b3a5c9;
  --faint: #807297;

  --line: rgba(235, 226, 255, 0.1);
  --line-strong: rgba(235, 226, 255, 0.18);
  --line-hot: rgba(255, 255, 255, 0.26);

  --cyan: #5ff5ff;
  --magenta: #ff4fd8;
  --violet: #a98bff;
  --coral: #ff8a5f;
  --gold: #ffcd6e;
  --lime: #c7ff64;
  --danger: #ff7188;
  --success: #7dffc4;

  --accent: var(--cyan);
  --accent-soft: rgba(95, 245, 255, 0.14);

  --font-display: "Syne", "Arial Black", "Segoe UI", sans-serif;
  --font-ui: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;

  --brand-gradient: linear-gradient(104deg, #5ff5ff 0%, #a98bff 32%, #ff4fd8 66%, #ff8a5f 100%);
  --primary-gradient: linear-gradient(105deg, #ff4fd8 0%, #ff6ea8 48%, #ff8a5f 100%);

  --shadow-panel: 0 40px 90px rgba(0, 0, 0, 0.46), 0 2px 0 rgba(255, 255, 255, 0.035) inset;
  --shadow-button: 0 12px 34px rgba(255, 79, 216, 0.24);

  --ui-pad: clamp(16px, 2vw, 26px);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--void);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(60% 55% at 42% 36%, rgba(97, 54, 190, 0.26), transparent 70%),
    radial-gradient(45% 50% at 88% 12%, rgba(255, 79, 216, 0.13), transparent 72%),
    linear-gradient(180deg, #090411 0%, #07030d 70%);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.is-focus-mode {
  overflow: hidden;
}

::selection {
  background: var(--magenta);
  color: #15051f;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

button:disabled,
button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.42;
}

a {
  color: var(--cyan);
  text-decoration-color: rgba(95, 245, 255, 0.35);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--paper);
}

img,
svg {
  display: block;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

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

input,
textarea {
  border-radius: 0;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

/* scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(169, 139, 255, 0.36) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(95, 245, 255, 0.4), rgba(255, 79, 216, 0.4));
  background-clip: padding-box;
}

/* ---------- utilities ---------- */

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 500;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 160ms ease;
}

.skip-link:focus-visible {
  transform: translateY(0);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- buttons ---------- */

.btn {
  --btn-pad-y: 12px;
  --btn-pad-x: 18px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.015em;
  line-height: 1;
  white-space: nowrap;
  transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms ease,
    border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, filter 160ms ease;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn:active {
  transform: translateY(1px) scale(0.995);
}

.btn-primary {
  padding-right: calc(var(--btn-pad-x) + 2px);
  background: var(--primary-gradient);
  color: #19051a;
  font-weight: 700;
  box-shadow: var(--shadow-button), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-primary:hover {
  filter: brightness(1.08) saturate(1.04);
  transform: translateY(-1px);
  box-shadow: 0 16px 42px rgba(255, 79, 216, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.48);
}

.btn-ghost {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
}

.btn-ghost:hover {
  border-color: var(--line-hot);
  background: rgba(255, 255, 255, 0.06);
  color: var(--paper);
}

.btn-quiet {
  min-height: 34px;
  padding: 8px 11px;
  border-color: transparent;
  color: var(--faint);
  font-size: 11.5px;
}

.btn-quiet:hover {
  background: rgba(255, 255, 255, 0.055);
  color: var(--paper);
}

.btn-danger {
  border-color: rgba(255, 113, 136, 0.32);
  background: rgba(255, 113, 136, 0.09);
  color: #ff9cab;
}

.btn-danger:hover {
  border-color: rgba(255, 113, 136, 0.55);
  background: rgba(255, 113, 136, 0.16);
  color: #ffd4da;
}

.btn-block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.36;
  transform: none;
  filter: none;
  box-shadow: none;
}

/* ---------- stage + atmosphere ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  touch-action: none;
  cursor: grab;
}

.stage.is-dragging {
  cursor: grabbing;
}

.stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  outline: none;
}

.stage-wash {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 2, 10, 0.58) 0%, transparent 21%, transparent 62%, rgba(5, 2, 10, 0.5) 100%),
    radial-gradient(130% 85% at 50% 42%, transparent 48%, rgba(4, 1, 10, 0.52) 100%);
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(105% 75% at 50% 45%, transparent 56%, rgba(3, 1, 8, 0.46) 100%);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.036;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.86' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

/* ---------- boot ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(48% 48% at 50% 46%, rgba(85, 43, 160, 0.28), transparent 70%),
    radial-gradient(36% 32% at 70% 30%, rgba(255, 79, 216, 0.12), transparent 75%),
    #07030d;
  transition: opacity 620ms cubic-bezier(0.4, 0, 0.2, 1), visibility 620ms;
}

.boot.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-aura {
  position: absolute;
  width: min(74vw, 880px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, rgba(95, 245, 255, 0.09), transparent 64%),
    conic-gradient(from 90deg, transparent, rgba(255, 79, 216, 0.1), transparent 38%, rgba(95, 245, 255, 0.09), transparent 72%);
  filter: blur(14px);
  animation: boot-aura-drift 14s linear infinite;
}

.boot-grid {
  position: absolute;
  inset: 0;
  opacity: 0.6;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 86px 86px;
  mask-image: radial-gradient(56% 56% at 50% 50%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(56% 56% at 50% 50%, #000 0%, transparent 78%);
}

.boot-content {
  position: relative;
  z-index: 2;
  width: min(370px, calc(100vw - 48px));
  text-align: center;
  animation: boot-in 700ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.boot-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(26px, 4vw, 34px);
  letter-spacing: 0.17em;
  line-height: 1;
}

.boot-mark {
  width: 30px;
  height: 30px;
}

.boot-kicker {
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--faint);
}

.boot-orbit {
  position: relative;
  width: 148px;
  height: 148px;
  margin: 34px auto 30px;
}

.orbit-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.orbit-a {
  inset: 8%;
  border-top-color: rgba(95, 245, 255, 0.9);
  border-right-color: rgba(95, 245, 255, 0.16);
  animation: orbit-spin 3.8s linear infinite;
  box-shadow: 0 0 26px rgba(95, 245, 255, 0.08);
}

.orbit-b {
  inset: 22%;
  border-bottom-color: rgba(255, 79, 216, 0.85);
  border-left-color: rgba(255, 79, 216, 0.14);
  animation: orbit-spin 5.6s linear infinite reverse;
}

.orbit-c {
  inset: 37%;
  border: 1px dashed rgba(255, 205, 110, 0.24);
  animation: orbit-spin 12s linear infinite;
}

.orbit-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 20px 4px rgba(255, 255, 255, 0.5), 0 0 48px 10px rgba(255, 79, 216, 0.24);
  animation: core-pulse 2.2s ease-in-out infinite;
}

.boot-progress {
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.boot-progress > span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-gradient);
  box-shadow: 0 0 14px rgba(255, 79, 216, 0.55);
  transition: width 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.boot-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 11px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.boot-percent,
#boot-percent {
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.boot-detail {
  min-height: 18px;
  margin-top: 16px;
  font-size: 11.5px;
  color: var(--faint);
}

.boot-note {
  margin-top: 26px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(128, 114, 151, 0.7);
}

.boot-note a {
  color: var(--faint);
}

/* ---------- fallback ---------- */

.fallback {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #07030d;
}

.fallback[hidden] {
  display: none;
}

.fallback-card {
  width: min(560px, 100%);
  padding: clamp(26px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, rgba(34, 20, 60, 0.92), rgba(12, 7, 23, 0.97));
  box-shadow: var(--shadow-panel);
}

.fallback-card h1 {
  margin-top: 13px;
  font-family: var(--font-display);
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.08;
}

.fallback-card p {
  margin-top: 14px;
  max-width: 52ch;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
}

.fallback-card ul {
  margin: 18px 0 24px;
  padding-left: 18px;
  color: var(--faint);
  font-size: 12.5px;
  line-height: 1.8;
}

.fallback-card strong {
  color: var(--muted);
}

.noscript-card {
  position: fixed;
  inset: auto 24px 24px 24px;
  z-index: 400;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface-strong);
}

/* ---------- animations ---------- */

@keyframes boot-aura-drift {
  to { transform: rotate(360deg); }
}

@keyframes orbit-spin {
  to { transform: rotate(360deg); }
}

@keyframes core-pulse {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(0.68); opacity: 0.55; }
}

@keyframes boot-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* UI entrance after boot (opacity only: transforms belong to layout) */
body.is-ready .topbar {
  animation: fade-in 500ms ease both;
}

body.is-ready .rail {
  animation: fade-in 540ms 80ms ease both;
}

body.is-ready .panel {
  animation: fade-in 520ms 60ms ease both;
}

body.is-ready .stage-plate {
  animation: fade-in 620ms 120ms ease both;
}

body.is-ready .actionbar,
body.is-ready .view-bar {
  animation: fade-in 560ms 180ms ease both;
}

/* low-end UI effects are reduced, never the content */
body[data-quality="potato"] .grain {
  display: none;
}

body[data-quality="potato"] .boot-aura {
  filter: none;
}

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

  .boot {
    transition-duration: 0.01ms;
  }
}
