/* Dune router — terminal phosphor theme. Mirrors the badge_puzzle_sites
   look so the player feels they have stepped between connected screens
   of one continuous artifact. */
:root {
  --bg: #07090a;
  --panel: #0d1311;
  --panel-2: #111815;
  --border: #1c2e25;
  --border-bright: #2a4636;
  --text: #c9f5dd;
  --text-dim: #6ea587;
  --text-muted: #3b6450;
  --phosphor: #5fe89c;
  --amber: #ffb000;
  --error: #ff5566;
  /* Per-state accent — set in body[data-state] rules below */
  --accent: var(--phosphor);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(ellipse at top, rgba(95,232,156,0.05), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0px, transparent 2px,
                              rgba(0,0,0,0.25) 2px, rgba(0,0,0,0.25) 3px);
  padding: 20px 16px 60px;
  display: flex;
  justify-content: center;
}

/* State-driven accent so each route has its own emotional tone */
body[data-state="origin"]      { --accent: #EA4335; }   /* red */
body[data-state="key_only"]    { --accent: #FBBC04; }   /* yellow */
body[data-state="lock_only"]   { --accent: #34A853; }   /* green */
body[data-state="scrambled"]   { --accent: var(--error); }
body[data-state="penultimate"] { --accent: var(--amber); }
body[data-state="final"]       { --accent: var(--amber); }
body[data-state="lost"]        { --accent: var(--text-muted); }

/* --- Final-state cosmic desert backdrop ---------------------------
   Pure CSS + inline SVG so nothing has to load from a CDN. Twin moons,
   a star field, a horizon glow, and two dune silhouettes. */
body[data-state="final"] {
  background-color: #0a0612;
  background-image:
    /* Twin moons of Arrakis */
    radial-gradient(circle at 22% 14%,
        rgba(255, 232, 196, 0.95) 0,
        rgba(255, 232, 196, 0.85) 14px,
        rgba(255, 232, 196, 0) 18px),
    radial-gradient(circle at 80% 9%,
        rgba(255, 192, 130, 0.85) 0,
        rgba(255, 192, 130, 0.75) 9px,
        rgba(255, 192, 130, 0) 13px),
    /* Stars (fixed positions, multiple radial dots) */
    radial-gradient(1px 1px at 10% 30%,  rgba(255,255,255,0.9), transparent 50%),
    radial-gradient(1px 1px at 40% 20%,  rgba(255,255,255,0.7), transparent 50%),
    radial-gradient(1px 1px at 65% 35%,  rgba(255,255,255,0.8), transparent 50%),
    radial-gradient(1px 1px at 85% 25%,  rgba(255,255,255,0.6), transparent 50%),
    radial-gradient(1px 1px at 15% 50%,  rgba(255,255,255,0.6), transparent 50%),
    radial-gradient(1px 1px at 55% 12%,  rgba(255,255,255,0.5), transparent 50%),
    radial-gradient(1px 1px at 30% 8%,   rgba(255,255,255,0.5), transparent 50%),
    radial-gradient(1px 1px at 92% 48%,  rgba(255,255,255,0.5), transparent 50%),
    /* Spice-glow horizon */
    radial-gradient(ellipse at 50% 78%,
        rgba(255, 168, 64, 0.45) 0%,
        rgba(255, 96, 32, 0.25) 22%,
        rgba(0, 0, 0, 0) 55%),
    /* Deep sky */
    linear-gradient(180deg, #06030a 0%, #190a1a 38%, #3a1612 72%, #0a0510 100%);
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  position: relative;
  overflow-x: hidden;
}
/* Dune silhouettes — inline SVG via data: URL, layered front + back */
body[data-state="final"]::before,
body[data-state="final"]::after {
  content: "";
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  height: 38vh;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: bottom center;
}
body[data-state="final"]::before {
  /* Back dunes — softer, lighter */
  height: 32vh;
  opacity: 0.55;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320' preserveAspectRatio='none'><path fill='%23552314' d='M0,180 C180,90 360,260 540,180 C720,100 900,240 1080,170 C1260,100 1380,200 1440,180 L1440,320 L0,320 Z'/></svg>");
}
body[data-state="final"]::after {
  /* Front dunes — darker, sharper */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320' preserveAspectRatio='none'><path fill='%23200a0a' d='M0,220 C200,120 360,300 600,230 C820,170 980,280 1180,210 C1320,170 1400,240 1440,230 L1440,320 L0,320 Z'/></svg>");
}
/* Drifting spice mote — single subtle moving particle for life */
body[data-state="final"] #app::after {
  content: "";
  position: fixed;
  top: 70%;
  left: -10px;
  width: 3px; height: 3px;
  background: rgba(255, 200, 120, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 180, 80, 0.9);
  animation: spice-drift 18s linear infinite;
  pointer-events: none;
}
@keyframes spice-drift {
  0%   { transform: translate(0, 0);              opacity: 0; }
  10%  {                                            opacity: 1; }
  90%  {                                            opacity: 1; }
  100% { transform: translate(110vw, -40vh);       opacity: 0; }
}

#app {
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  padding: 18px;
  box-shadow:
    0 0 0 1px rgba(95,232,156,0.05),
    0 20px 60px -10px rgba(0,0,0,0.7),
    inset 0 0 80px rgba(95,232,156,0.02);
  position: relative;
}
#app::before {
  content: "";
  position: absolute;
  top: 8px; right: 12px;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent);
  animation: blink 2s infinite;
}
@keyframes blink {
  0%, 60% { opacity: 1; }
  70%, 100% { opacity: 0.25; }
}

header {
  border-bottom: 1px dashed var(--border-bright);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.ascii-title {
  font-family: 'VT323', monospace;
  color: var(--phosphor);
  font-size: 28px;
  line-height: 1;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(95,232,156,0.5);
  margin-bottom: 6px;
}
.subtitle {
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

section { margin-bottom: 14px; }

.label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  display: block;
}

.info {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 10px 12px;
  font-size: 12px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  gap: 12px;
}
.info-row .key { color: var(--text-muted); letter-spacing: 1px; }
.info-row .val {
  color: var(--text);
  text-align: right;
  letter-spacing: 1px;
}
.info-row .val.status         { color: var(--accent); text-shadow: 0 0 6px rgba(95,232,156,0.3); }
.info-row .val.status.error   { color: var(--error); text-shadow: 0 0 6px rgba(255,85,102,0.4); }
.info-row .val.status.amber   { color: var(--amber); text-shadow: 0 0 6px rgba(255,176,0,0.4); }
.info-row .val.status.win     { color: var(--amber); text-shadow: 0 0 8px rgba(255,176,0,0.6); }

/* --- Epoch / Imperial reckoning (final state only) ------------- */
.epoch-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--amber);
  border-radius: 3px;
  padding: 12px 14px;
}
.epoch-stack { display: flex; flex-direction: column; gap: 4px; }
.epoch-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  gap: 12px;
}
.epoch-key {
  color: var(--text-muted);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
.epoch-val {
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(255,176,0,0.45);
}

/* --- Benediction line under the final reveal ------------------ */
.benediction {
  text-align: center;
  font-style: italic;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.4px;
  line-height: 1.6;
  margin: 6px 6px 0;
  opacity: 0.85;
}

/* On the final state, let the cosmic backdrop bleed through */
body[data-state="final"] #app {
  background: rgba(13, 19, 17, 0.78);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  box-shadow:
    0 0 0 1px rgba(255, 176, 0, 0.18),
    0 20px 80px -10px rgba(0, 0, 0, 0.9),
    inset 0 0 80px rgba(255, 176, 0, 0.04);
}
body[data-state="final"] .fragment-card.final .fragment {
  border-color: var(--amber);
  box-shadow: 0 0 24px rgba(255, 176, 0, 0.25);
}

.lore-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  padding: 16px 18px;
}
.lore-card .lore {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
  letter-spacing: 0.3px;
  font-style: italic;
  margin: 0;
}

.fragment-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 16px;
  text-align: center;
}
.fragment {
  display: block;
  word-break: break-all;
  color: var(--amber);
  font-size: 18px;
  letter-spacing: 1.5px;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255,176,0,0.5);
  background: var(--bg);
  border: 1px dashed var(--amber);
  border-radius: 3px;
  padding: 16px 14px;
  margin: 6px 0 14px;
  user-select: all;
}

.btn-secondary {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 12px 14px;
  border-radius: 3px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.15s;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  color: var(--text-dim);
}
.btn-secondary:hover { border-color: var(--phosphor); color: var(--phosphor); }
.btn-secondary:active { transform: translateY(1px); }

.footer-note {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 2px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

@media (max-width: 420px) {
  body { padding: 12px 10px 40px; }
  #app { padding: 14px; }
  .ascii-title { font-size: 22px; letter-spacing: 1.5px; }
  .fragment { font-size: 15px; padding: 12px; }
  .lore-card .lore { font-size: 12px; }
}
