/* Chip — Outer Space */

@font-face {
  font-family: "OpenDyslexic";
  src: url("https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff") format("woff");
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff") format("woff");
  font-weight: bold;
  font-display: swap;
}

:root {
  --bg: #0a0e27;
  --bg-soft: #131938;
  --bg-card: #1e2748;
  --text: #e6edff;
  --text-muted: #8a94b8;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --plasma: #f472b6;
  --cosmic: #a78bfa;
  --neon: #22d3ee;
  --solar: #fbbf24;
  --aurora: #34d399;

  --radius: 20px;
  --radius-lg: 28px;
  --shadow-card: 0 12px 36px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 28px rgba(56, 189, 248, 0.4);

  --font-stack: "OpenDyslexic", "Comic Sans MS", system-ui, sans-serif;
  --motion-fast: 200ms;
  --motion-med: 380ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  min-height: 100vh; min-height: 100svh;
  font-family: var(--font-stack);
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
body.app-chip {
  display: flex; flex-direction: column;
  position: relative;
}

/* SPACE BACKGROUND ---------------------------------------------------- */
.space-bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(167, 139, 250, 0.2) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 70%, rgba(56, 189, 248, 0.15) 0%, transparent 60%),
    var(--bg);
}
.stars {
  position: absolute; inset: -10% -10% -10% -10%;
  background-image:
    radial-gradient(2px 2px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 28% 56%, #fff, transparent),
    radial-gradient(2px 2px at 45% 12%, #fbbf24, transparent),
    radial-gradient(1px 1px at 62% 78%, #a78bfa, transparent),
    radial-gradient(2px 2px at 80% 36%, #fff, transparent),
    radial-gradient(1px 1px at 91% 64%, #38bdf8, transparent),
    radial-gradient(1px 1px at 5% 85%, #fff, transparent),
    radial-gradient(2px 2px at 36% 88%, #f472b6, transparent),
    radial-gradient(1px 1px at 18% 38%, #fff, transparent),
    radial-gradient(1px 1px at 71% 21%, #22d3ee, transparent);
  background-size: 100% 100%;
  animation: starPulse 4s ease-in-out infinite;
}
.stars-near { animation-duration: 6s; opacity: 1; }
.stars-far {
  background-size: 50% 50%;
  opacity: 0.7;
  animation-duration: 8s;
}
@keyframes starPulse {
  0%, 100% { filter: brightness(0.85); }
  50% { filter: brightness(1.2); }
}
.nebula {
  position: absolute;
  width: 360px; height: 360px; border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
}
.nebula-pink { left: -8%; bottom: 12%; background: var(--plasma); }
.nebula-cyan { right: -8%; top: 8%; background: var(--neon); opacity: 0.35; }

.comet {
  position: absolute;
  top: 14%; left: -10%;
  width: 100px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--neon), #fff);
  animation: comet 45s linear infinite;
  transform: rotate(-15deg);
  filter: blur(0.5px);
}
@keyframes comet {
  0%, 90%, 100% { transform: rotate(-15deg) translateX(-200px); opacity: 0; }
  91% { opacity: 1; }
  99% { transform: rotate(-15deg) translateX(120vw); opacity: 1; }
}

/* HEADER ------------------------------------------------------------ */
.header {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.25rem 0.5rem;
}
.mascot-wrap {
  position: relative; width: 140px; height: 140px; flex-shrink: 0;
  cursor: pointer; filter: drop-shadow(0 0 24px rgba(56, 189, 248, 0.3));
}
.mascot {
  width: 100%; height: 100%; object-fit: contain;
  transition: transform var(--motion-med) ease;
  animation: hover 4s ease-in-out infinite;
}
@keyframes hover {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.mascot.is-listening { animation-duration: 1.5s; }
.mascot.is-celebrating { animation: celebrate 0.8s ease 2; }
@keyframes celebrate {
  0%, 100% { transform: rotate(0) translateY(0); }
  25% { transform: rotate(-8deg) translateY(-10px); }
  75% { transform: rotate(8deg) translateY(-10px); }
}
.mascot-mouth {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  pointer-events: none;
}
.greeting h1 { margin: 0; font-size: 1.6rem; text-shadow: 0 0 12px rgba(56, 189, 248, 0.4); }
.muted { color: var(--text-muted); margin: 0.2rem 0 0; }

/* TABS -------------------------------------------------------------- */
.tabs, .submodes {
  display: flex; gap: 0.5rem; padding: 0.75rem 1rem;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .submodes::-webkit-scrollbar { display: none; }
.tab, .submode {
  flex: 1 1 auto; min-width: 110px; min-height: 56px;
  padding: 0.75rem 1.2rem;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-radius: 999px;
  background: var(--bg-card); color: var(--text);
  font-family: inherit; font-size: 1rem; cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: all var(--motion-fast);
  white-space: nowrap;
}
.tab:hover, .submode:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}
.tab-active, .submode-active {
  background: var(--accent); color: #001928;
  font-weight: bold; border-color: var(--neon);
  box-shadow: var(--shadow-glow);
}

/* CONTENT ----------------------------------------------------------- */
.content {
  flex: 1;
  padding: 0 1rem 6rem;
  max-width: 880px; width: 100%; margin: 0 auto;
}
.tab-panel { display: none; }
.tab-panel-active { display: block; }

.card {
  background: var(--bg-card);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1rem;
  position: relative;
}
.card::before, .card::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid var(--accent);
  opacity: 0.6;
}
.card::before { top: -1px; left: -1px; border-right: none; border-bottom: none; border-top-left-radius: var(--radius-lg); }
.card::after { bottom: -1px; right: -1px; border-left: none; border-top: none; border-bottom-right-radius: var(--radius-lg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.5rem; font-family: inherit; font-size: 1.05rem;
  min-height: 56px;
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  border: 2px solid rgba(56, 189, 248, 0.3);
  background: var(--bg-card); color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: all var(--motion-fast);
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); border-color: var(--accent); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #001928;
  font-weight: bold; border-color: var(--neon);
}
.btn-huge { font-size: 1.4rem; min-height: 72px; padding: 1rem 2rem; }

/* MIC --------------------------------------------------------------- */
.mic-row {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin: 1rem 0;
}
.mic-btn {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--neon);
  display: grid; place-items: center;
  font-size: 2.2rem; cursor: pointer; color: #001928;
  box-shadow: 0 0 32px rgba(56, 189, 248, 0.5);
  transition: transform var(--motion-fast);
}
.mic-btn:hover { transform: scale(1.04); }
.mic-btn.is-listening {
  background: var(--plasma);
  border-color: #be185d;
  animation: micPulse 1.2s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(244, 114, 182, 0.5); }
  50% { box-shadow: 0 0 48px rgba(244, 114, 182, 1); }
}

.transcript {
  flex: 1; min-width: 200px;
  padding: 1rem;
  background: var(--bg-soft);
  border-radius: var(--radius);
  font-size: 1.1rem;
  min-height: 56px;
  color: var(--text);
  border: 1px solid rgba(56, 189, 248, 0.15);
}
.transcript:empty::before {
  content: "Tap the mic to talk to Chip…";
  color: var(--text-muted);
}

/* HUD-style text */
.hud-label {
  font-size: 0.75rem; letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--neon);
  margin: 0 0 0.5rem;
}
.hud-line {
  font-family: ui-monospace, "Menlo", monospace;
  font-size: 0.9rem;
  color: var(--neon);
  opacity: 0.85;
}

/* MISSION GRID ------------------------------------------------------ */
.mission-scene {
  position: relative;
  background: radial-gradient(ellipse at center, #4a1a3a 0%, #1a0e2a 100%);
  border-radius: var(--radius-lg);
  aspect-ratio: 6/4;
  overflow: hidden;
  margin: 1rem 0;
  box-shadow: var(--shadow-card);
}
.mission-grid {
  position: absolute; inset: 0;
  display: grid;
  gap: 1px;
}
.cell {
  background:
    linear-gradient(rgba(34, 211, 238, 0.05), rgba(34, 211, 238, 0.02)),
    radial-gradient(circle at 50% 50%, transparent 50%, rgba(0,0,0,0.3) 100%);
  border: 1px solid rgba(34, 211, 238, 0.12);
  position: relative;
}
.entity {
  position: absolute;
  width: 80%; height: 80%; left: 10%; top: 10%;
  display: grid; place-items: center;
  font-size: clamp(1.2rem, 4vw, 2rem);
  transition: all 600ms cubic-bezier(.4, 1.2, .6, 1);
}
.entity.robot { z-index: 2; filter: drop-shadow(0 0 6px var(--accent)); }
.entity.goal {
  filter: drop-shadow(0 0 12px var(--solar));
  animation: glow 2s ease-in-out infinite;
}
.entity.wall { background: rgba(168, 85, 247, 0.3); border: 1px solid var(--cosmic); border-radius: 4px; }
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 12px var(--solar)); }
  50% { filter: drop-shadow(0 0 24px var(--solar)) drop-shadow(0 0 8px var(--plasma)); }
}

/* Thinking narration */
.narration {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.1), rgba(34, 211, 238, 0.02));
  border-left: 3px solid var(--neon);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0.75rem 0;
  font-size: 1.1rem;
}

.modal-root {
  position: fixed; inset: 0;
  background: rgba(10, 14, 39, 0.75);
  display: grid; place-items: center;
  padding: 1rem; z-index: 10;
  backdrop-filter: blur(8px);
}
.modal {
  background: var(--bg-card);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 520px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 60px rgba(56, 189, 248, 0.2);
}

.confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 20;
}

/* SCENE BACKGROUNDS ------------------------------------------------- */
.mode-scene {
  height: 200px;
  background-size: cover;
  background-position: center;
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(56, 189, 248, 0.2);
}
.mode-scene[data-scene="missions"] { background-image: url("assets/scenes/missions.webp"); }
.mode-scene[data-scene="wonder"] { background-image: url("assets/scenes/wonder.webp"); }
.mode-scene[data-scene="build-a-bot"] { background-image: url("assets/scenes/build-a-bot.webp"); }
.mode-scene[data-scene="inventor"] { background-image: url("assets/scenes/inventor.webp"); }
.mode-scene[data-scene="progress"] { background-image: url("assets/scenes/progress.webp"); }

/* STATS ------------------------------------------------------------- */
.stats {
  display: grid; gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  margin: 1rem 0;
}
.stat {
  background: var(--bg-card);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.stat-value { font-size: 1.8rem; font-weight: bold; color: var(--accent); text-shadow: 0 0 12px rgba(56, 189, 248, 0.4); }
.stat-label { font-size: 0.85rem; color: var(--text-muted); }

/* BUILD-A-BOT PICKER ------------------------------------------------ */
.parts-row {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  margin: 0.5rem 0 1rem;
}
.part {
  padding: 0.6rem 1rem;
  background: var(--bg-soft);
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  min-height: 56px;
}
.part:hover { border-color: var(--accent); }
.part.is-picked {
  border-color: var(--neon);
  background: linear-gradient(135deg, var(--bg-card), rgba(56, 189, 248, 0.15));
  box-shadow: var(--shadow-glow);
}

.compat-warning {
  background: var(--plasma);
  color: #2a0e1a;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
}

/* REDUCED MOTION ---------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .comet, .stars { animation: none !important; }
}

@media (max-width: 480px) {
  .header { flex-direction: column; text-align: center; }
}
