:root {
  color-scheme: light;
  --bg: #F4F5F7;
  --tile: #FFFFFF;
  --tile-border: #E3E6EB;
  --tile-letter: #C5CBD5;
  --text: #0F172A;
  --text-muted: #475569;
  --accent: #5B5BF0;
  --accent-2: #0891B2;
  --card: rgba(255, 255, 255, 0.72);
  --card-border-a: rgba(91, 91, 240, 0.45);
  --card-border-b: rgba(8, 145, 178, 0.30);
  --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 24px 64px -16px rgba(15, 23, 42, 0.18);
  --lit-fill: color-mix(in srgb, var(--accent) 10%, var(--tile));
  --lit-glow: 0 0 0 transparent;
  --scanlines: none;
  --switch-bg: rgba(255, 255, 255, 0.7);

  --font-sans: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark tokens: once for "system" when the OS is dark, once for an explicit choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0B0D12;
    --tile: #12151C;
    --tile-border: #1E232D;
    --tile-letter: #2A3140;
    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --accent: #8B8BFF;
    --accent-2: #22D3EE;
    --card: rgba(18, 21, 28, 0.70);
    --card-border-a: rgba(139, 139, 255, 0.45);
    --card-border-b: rgba(34, 211, 238, 0.25);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 24px 80px -16px rgba(0, 0, 0, 0.7);
    --lit-fill: color-mix(in srgb, var(--accent) 14%, var(--tile));
    --lit-glow: 0 0 24px color-mix(in srgb, var(--accent) 45%, transparent);
    --scanlines: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px);
    --switch-bg: rgba(18, 21, 28, 0.7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0D12;
  --tile: #12151C;
  --tile-border: #1E232D;
  --tile-letter: #2A3140;
  --text: #F1F5F9;
  --text-muted: #94A3B8;
  --accent: #8B8BFF;
  --accent-2: #22D3EE;
  --card: rgba(18, 21, 28, 0.70);
  --card-border-a: rgba(139, 139, 255, 0.45);
  --card-border-b: rgba(34, 211, 238, 0.25);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 24px 80px -16px rgba(0, 0, 0, 0.7);
  --lit-fill: color-mix(in srgb, var(--accent) 14%, var(--tile));
  --lit-glow: 0 0 24px color-mix(in srgb, var(--accent) 45%, transparent);
  --scanlines: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px);
  --switch-bg: rgba(18, 21, 28, 0.7);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

/* ---- Tile field ---- */

.tiles, .lit-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Fade the field out around the card so it reads as texture, not content. */
  -webkit-mask-image: radial-gradient(ellipse 46% 48% at 50% 50%, transparent 30%, rgba(0, 0, 0, 0.55) 70%, #000 100%);
          mask-image: radial-gradient(ellipse 46% 48% at 50% 50%, transparent 30%, rgba(0, 0, 0, 0.55) 70%, #000 100%);
}

.tile rect {
  fill: var(--tile);
  stroke: var(--tile-border);
  stroke-width: 1;
}

.tile text {
  fill: var(--tile-letter);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 26px;
  text-anchor: middle;
  dominant-baseline: central;
}

.lit {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--lit-fill);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: var(--lit-glow);
  color: var(--accent);
  font-weight: 500;
  font-size: 26px;
  line-height: 1;
  opacity: 0;
  animation: flicker 3.6s linear forwards;
}

/* Two quick dips on the way in, like a display segment catching. */
@keyframes flicker {
  0%   { opacity: 0; }
  4%   { opacity: 1; }
  6%   { opacity: 0.25; }
  9%   { opacity: 1; }
  11%  { opacity: 0.5; }
  13%  { opacity: 1; }
  65%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Card ---- */

.card {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  padding: clamp(36px, 7vw, 64px) clamp(24px, 6vw, 56px);
  border-radius: 28px;
  background: var(--card);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
          backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--card-shadow);
  text-align: center;
  isolation: isolate;
}

/* 1px gradient hairline border. */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--card-border-a), transparent 40%, transparent 60%, var(--card-border-b));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}

/* Scanlines (dark only; --scanlines is none in light). */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--scanlines);
  pointer-events: none;
  z-index: -1;
}

.welcome {
  margin: 0;
  font-size: clamp(48px, 12vw, 84px);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 1;
  background: linear-gradient(100deg, var(--accent) 10%, var(--accent-2) 90%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  /* Keep descenders and the gradient clip from cropping. */
  padding-bottom: 0.08em;
}

.lede {
  margin: 20px auto 0;
  max-width: 30ch;
  font-size: clamp(16px, 2.4vw, 18px);
  line-height: 1.5;
  color: var(--text-muted);
}

.status {
  margin: 28px 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  opacity: 0.8;
}

.status .sep { color: var(--accent); }

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.1em;
  margin-left: 0.35em;
  vertical-align: -0.2em;
  background: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ---- Theme switch ---- */

.theme-switch {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--switch-bg);
  border: 1px solid var(--tile-border);
  -webkit-backdrop-filter: blur(12px);
          backdrop-filter: blur(12px);
}

.theme-switch button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
}

.theme-switch button:hover { color: var(--text); }

.theme-switch button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}

.theme-switch button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.theme-switch svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (prefers-reduced-motion: reduce) {
  .cursor, .lit { animation: none; }
  .lit { display: none; }
}
