/* ───────────── Tokens ───────────── */
:root {
  --bg: #ecebe6;
  --bg-2: #e2e0d9;
  --fg: #0d0d10;
  --muted: #77746c;
  --faint: rgba(13, 13, 16, 0.10);
  --line: rgba(13, 13, 16, 0.14);
  --accent: #d0021b;
  --panel: rgba(236, 235, 230, 0.78);
  --cipher: rgba(13, 13, 16, 0.55);
  --cipher-hit: #d0021b;
  --grain-opacity: 0.09;
  --vignette: rgba(120, 115, 100, 0.18);

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --gutter: clamp(16px, 3.2vw, 40px);
  --ease: cubic-bezier(.7, 0, .2, 1);
  --mx: -999px;
  --my: -999px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #060608;
    --bg-2: #0d0d11;
    --fg: #e9e7e2;
    --muted: #6d6c74;
    --faint: rgba(233, 231, 226, 0.08);
    --line: rgba(233, 231, 226, 0.12);
    --accent: #ff2d44;
    --panel: rgba(10, 10, 13, 0.72);
    --cipher: rgba(233, 231, 226, 0.5);
    --cipher-hit: #ff2d44;
    --grain-opacity: 0.06;
    --vignette: rgba(0, 0, 0, 0.75);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #060608;
  --bg-2: #0d0d11;
  --fg: #e9e7e2;
  --muted: #6d6c74;
  --faint: rgba(233, 231, 226, 0.08);
  --line: rgba(233, 231, 226, 0.12);
  --accent: #ff2d44;
  --panel: rgba(10, 10, 13, 0.72);
  --cipher: rgba(233, 231, 226, 0.5);
  --cipher-hit: #ff2d44;
  --grain-opacity: 0.06;
  --vignette: rgba(0, 0, 0, 0.75);
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-display);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

::selection { background: var(--accent); color: var(--bg); }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

a { color: inherit; text-decoration: none; }

b { font-weight: 500; color: var(--fg); }

:focus-visible { outline: 1px dashed var(--accent); outline-offset: 4px; }

/* ───────────── Layers ───────────── */
#field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

.cipher {
  position: fixed;
  inset: 0;
  margin: 0;
  z-index: 0;
  font: 400 13px/1.45 var(--font-mono);
  letter-spacing: 0.08em;
  color: var(--cipher);
  white-space: pre;
  overflow: hidden;
  user-select: none;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(circle 170px at var(--mx) var(--my), #000 0%, rgba(0,0,0,.35) 45%, transparent 100%);
          mask-image: radial-gradient(circle 170px at var(--mx) var(--my), #000 0%, rgba(0,0,0,.35) 45%, transparent 100%);
}
.cipher em { font-style: normal; color: var(--cipher-hit); }

.grain {
  position: fixed;
  inset: -50%;
  z-index: 2;
  pointer-events: none;
  opacity: var(--grain-opacity);
  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='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.9s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -4%); }
  60% { transform: translate(-4%, -1%); }
  80% { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 40%, var(--vignette) 100%);
}

/* ───────────── Bars ───────────── */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: var(--gutter);
  font: 400 11px/1 var(--font-mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.bar--top { top: 0; padding-top: max(var(--gutter), env(safe-area-inset-top)); }
.bar--bottom { bottom: 0; padding-bottom: max(var(--gutter), env(safe-area-inset-bottom)); }

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--fg); }
.brand__mark { width: 20px; height: 26px; color: inherit; transition: transform .6s var(--ease), color .3s; }
.brand:hover .brand__mark { transform: rotateY(180deg); color: var(--accent); }
.brand__name { font: 500 12px/1 var(--font-mono); letter-spacing: 0.32em; }

.bar__right { display: flex; align-items: center; gap: 22px; }

.status { display: inline-flex; align-items: center; gap: 8px; }
.status__dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
  70%, 100% { box-shadow: 0 0 0 9px transparent; }
}

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: border-color .3s, transform .3s var(--ease);
}
.theme-toggle:hover { border-color: var(--fg); transform: rotate(-25deg); }
.theme-toggle__orb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--fg);
  position: relative;
  overflow: hidden;
}
.theme-toggle__orb::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg);
  top: -3px; left: 5px;
  transition: transform .6s var(--ease);
}
:root[data-theme="light"] .theme-toggle__orb::after { transform: translate(9px, -9px); }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .theme-toggle__orb::after { transform: translate(9px, -9px); }
}

.meta { display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.meta--right { justify-content: flex-end; }
.meta__sep { opacity: .4; }
.meta b { font-variant-numeric: tabular-nums; }

.hint {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font: 400 11px/1 var(--font-mono);
  transition: color .3s;
}
.hint:hover { color: var(--fg); }
.hint kbd {
  font: 500 11px/1 var(--font-mono);
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--fg);
  animation: blink 2s steps(1) infinite;
}
@keyframes blink { 50% { border-color: var(--accent); color: var(--accent); } }

/* ───────────── Hero ───────────── */
.hero {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--gutter) + 56px);
  z-index: 4;
  pointer-events: none;
  max-width: 980px;
}

.kicker {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 18px;
  font: 400 11px/1 var(--font-mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}
.kicker__line { width: 36px; height: 1px; background: currentColor; }

.headline {
  position: relative;
  margin: 0;
  font-weight: 500;
  font-size: clamp(34px, 6.4vw, 92px);
  line-height: 0.98;
  letter-spacing: -0.035em;
  pointer-events: auto;
  width: fit-content;
}
.headline::before,
.headline::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}
.headline.is-glitching::before {
  opacity: .9; color: var(--accent);
  animation: glitch-a .38s steps(2) 2;
}
.headline.is-glitching::after {
  opacity: .7; color: var(--muted);
  animation: glitch-b .38s steps(2) 2;
}
@keyframes glitch-a {
  0% { clip-path: inset(10% 0 60% 0); transform: translate(-4px, 0); }
  50% { clip-path: inset(55% 0 20% 0); transform: translate(3px, 1px); }
  100% { clip-path: inset(30% 0 45% 0); transform: translate(-2px, -1px); }
}
@keyframes glitch-b {
  0% { clip-path: inset(70% 0 5% 0); transform: translate(4px, 0); }
  50% { clip-path: inset(5% 0 75% 0); transform: translate(-3px, -1px); }
  100% { clip-path: inset(40% 0 35% 0); transform: translate(2px, 1px); }
}

.sub {
  margin: 22px 0 0;
  font: 400 clamp(13px, 1.2vw, 15px)/1.6 var(--font-mono);
  color: var(--muted);
  min-height: 1.6em;
}
.caret { color: var(--accent); animation: caret 1s steps(1) infinite; margin-left: 2px; }
@keyframes caret { 50% { opacity: 0; } }

/* ───────────── Terminal ───────────── */
.term {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(var(--gutter) + 52px);
  width: min(640px, calc(100% - 2 * var(--gutter)));
  transform: translateX(-50%);
  background: var(--panel);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
          backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.45);
  font: 400 13px/1.6 var(--font-mono);
  overflow: hidden;
  animation: term-in .45s var(--ease);
}
.term[hidden] { display: none; }
@keyframes term-in {
  from { opacity: 0; transform: translate(-50%, 16px) scale(.98); filter: blur(6px); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); filter: blur(0); }
}
.term__head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
}
.term__dots { display: inline-flex; gap: 6px; }
.term__dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); border: 1px solid var(--line); }
.term__dots i:first-child { background: var(--accent); border-color: transparent; }
.term__title { flex: 1; }
.term__close { color: var(--muted); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; }
.term__close:hover { color: var(--fg); border-color: var(--fg); }
.term__body {
  height: min(300px, 42vh);
  overflow-y: auto;
  padding: 14px 16px 4px;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
}
.term__body .ln { margin: 0; }
.term__body .cmd { color: var(--fg); }
.term__body .cmd::before { content: "› "; color: var(--accent); }
.term__body .out { color: var(--muted); }
.term__body .hi { color: var(--accent); }
.term__body .ok { color: var(--fg); }
.term__body a { color: var(--fg); border-bottom: 1px solid var(--accent); }
.term__input { display: flex; align-items: center; gap: 10px; padding: 10px 16px 14px; }
.term__prompt { color: var(--accent); }
.term__input input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--fg);
  font: inherit;
  caret-color: var(--accent);
  min-width: 0;
}

/* ───────────── Cursor ───────────── */
.cursor { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.cursor__ring, .cursor__dot {
  position: absolute;
  top: 0; left: 0;
  border-radius: 50%;
  will-change: transform;
}
.cursor__ring {
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border: 1px solid var(--fg);
  opacity: .5;
  transition: width .3s var(--ease), height .3s var(--ease), margin .3s var(--ease), opacity .3s, border-color .3s;
}
.cursor__dot {
  width: 4px; height: 4px;
  margin: -2px 0 0 -2px;
  background: var(--accent);
}
.cursor.is-hover .cursor__ring { width: 58px; height: 58px; margin: -29px 0 0 -29px; opacity: 1; border-color: var(--accent); }
.cursor.is-down .cursor__ring { width: 20px; height: 20px; margin: -10px 0 0 -10px; }
@media (hover: hover) and (pointer: fine) {
  html.has-cursor, html.has-cursor * { cursor: none !important; }
  html.has-cursor .term__input input { cursor: text !important; }
}
@media not ((hover: hover) and (pointer: fine)) { .cursor { display: none; } }

/* ───────────── Toast ───────────── */
.toast {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font: 500 12px/1.5 var(--font-mono);
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  opacity: 0;
  transition: opacity .5s;
  pointer-events: none;
  white-space: pre;
}
.toast.is-on { opacity: 1; }

.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; font-family: var(--font-mono); color: var(--muted); z-index: 10; }

/* ───────────── Theme transition ───────────── */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* ───────────── Glitch-everything (easter egg) ───────────── */
html.is-breach body { animation: breach .12s steps(2) 8; }
@keyframes breach {
  0% { filter: invert(0) hue-rotate(0); transform: translate(0); }
  50% { filter: invert(1) hue-rotate(90deg); transform: translate(3px, -2px); }
  100% { filter: invert(0); transform: translate(-2px, 1px); }
}

/* ───────────── Responsive ───────────── */
@media (max-width: 820px) {
  .status__label { display: none; }
  .meta--right { display: none; }
  .bar--bottom { justify-content: space-between; }
}
@media (max-width: 560px) {
  .status { display: none; }
  .brand__name { font-size: 11px; letter-spacing: .26em; }
  .bar--bottom { flex-direction: column-reverse; align-items: flex-start; gap: 14px; }
  .hero { bottom: calc(var(--gutter) + 92px); }
  .sub { font-size: 12.5px; }
  .term { bottom: calc(var(--gutter) + 72px); }
  .cipher { font-size: 11px; }
}
@media (max-height: 560px) and (min-width: 561px) {
  .headline { font-size: clamp(28px, 5vw, 56px); }
  .sub { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .status__dot, .hint kbd, .caret { animation: none; }
  .term { animation: none; }
}
