/* style.css — the editor, aka "inside the lab". Dark like the hub's space
   map (hub.css): starting a mission is flying down from orbit to the lab. */

@font-face {
  font-family: 'Fredoka';
  src: url('vendor/fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --bg: #0d1022;
  --panel: #151a33;
  --border: #2b3153;
  --text: #e9ecfb;
  --muted: #9aa3c7;
  --goal-bg: #1b2145;
  --win-bg: #123222;
  --comment: #ffc46b; /* lesson instructions live in comments — keep them warm & readable */
  --accent: #38d9f5;
  --violet: #a78bfa;
  --run: #22c55e;
  --run-hover: #16a34a;
  --stop: #f87171;
  --echo: #67e8f9;
  --err: #ff8a8a;
  --chip: #202650;
  --display: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* our display rules must not beat the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#banner {
  background: #b45309;
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.45;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand {
  font-family: var(--display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
  margin-right: 4px;
  color: var(--accent);
}
.spacer { flex: 1; }

button, a.btn-link {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chip);
  color: var(--text);
  font-family: var(--display);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.015em;
  cursor: pointer;
}
a.btn-link { text-decoration: none; display: inline-block; }
button:hover:not(:disabled), a.btn-link:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary {
  background: var(--run);
  border-color: var(--run);
  color: #fff;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.3);
}
button.primary:hover:not(:disabled) {
  background: var(--run-hover);
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.45);
}
#stop.force { background: var(--stop); border-color: var(--stop); color: #16101c; }

/* Start-over confirm: centered so the destructive click can't land on the
   same toolbar spot as the first "Start over" press. */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(5, 7, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.confirm-card {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
}
.confirm-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
  font-family: var(--display);
  font-weight: 600;
}
.confirm-card p {
  margin: 0 0 18px;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--muted);
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.confirm-actions .confirm-danger {
  background: var(--stop);
  border-color: var(--stop);
  color: #16101c;
}

#status {
  font-size: 12.5px;
  color: var(--muted);
  background: var(--chip);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
#status[data-state="running"], #status[data-state="waiting-input"] { color: var(--accent); }

#goalbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--goal-bg);
  border-bottom: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.45;
}
#goalbar.done { background: var(--win-bg); border-left-color: var(--run); }
#goal-text {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}
#goal-text .mission-lead {
  flex: 1 1 100%;
  min-width: 0;
}
#goal-text .task {
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}
#goal-text .task.done { color: var(--run); border-color: var(--run); }
#next-level {
  background: var(--run);
  border-color: var(--run);
  color: #fff;
  padding: 6px 14px;
  white-space: nowrap;
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.3);
}
#next-level:hover { background: var(--run-hover); border-color: var(--run-hover); }

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* World 4 — CSS rocket launch overlay (effect: "rocket") */
#rocket-stage {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.35s ease;
}
#rocket-stage.fade-out { opacity: 0; pointer-events: none; }
.rocket-sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 100%, #1a3a5c 0%, transparent 55%),
    linear-gradient(180deg, #070b1a 0%, #12203a 55%, #1e3a5f 100%);
}
.rocket-star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.55;
}
@media (prefers-reduced-motion: no-preference) {
  .rocket-star { animation: star-twinkle 2.4s ease-in-out infinite; }
  @keyframes star-twinkle {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.9; }
  }
}
.rocket-pad {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 90vw);
  height: 72px;
  background:
    linear-gradient(180deg, #3a4258 0%, #232836 40%, #1a1e2c 100%);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -2px 0 #f59e0b inset;
}
.rocket-pad::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  width: 56%;
  height: 10px;
  background: #4b5568;
  border-radius: 4px 4px 0 0;
}
.rocket-craft {
  position: absolute;
  bottom: 78px;
  left: 50%;
  width: 56px;
  height: 120px;
  margin-left: -28px;
  z-index: 2;
  transform: translateY(0);
}
.rocket-body {
  position: absolute;
  inset: 18px 10px 28px;
  background: linear-gradient(90deg, #e8ecf4 0%, #f8fafc 45%, #c5ccd8 100%);
  border-radius: 8px 8px 4px 4px;
  border: 2px solid #1e293b;
}
.rocket-nose {
  position: absolute;
  left: 50%;
  top: -26px;
  width: 36px;
  height: 28px;
  margin-left: -18px;
  background: linear-gradient(180deg, #f87171, #dc2626);
  border: 2px solid #1e293b;
  border-bottom: none;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.rocket-window {
  position: absolute;
  left: 50%;
  top: 14px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7dd3fc, #0284c7 70%);
  border: 2px solid #1e293b;
}
.rocket-fin {
  position: absolute;
  bottom: -2px;
  width: 0;
  height: 0;
  border-style: solid;
}
.rocket-fin.left {
  left: -14px;
  border-width: 0 14px 22px 0;
  border-color: transparent #f59e0b transparent transparent;
}
.rocket-fin.right {
  right: -14px;
  border-width: 0 0 22px 14px;
  border-color: transparent transparent transparent #f59e0b;
}
.rocket-flame {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 18px;
  height: 28px;
  margin-left: -9px;
  border-radius: 40% 40% 50% 50%;
  background: linear-gradient(180deg, #fef08a 0%, #f97316 45%, #ef4444 100%);
  opacity: 0;
  transform-origin: top center;
}
.rocket-smoke {
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 40px;
  height: 20px;
  margin-left: -20px;
  border-radius: 50%;
  background: rgba(226, 232, 240, 0.35);
  opacity: 0;
  filter: blur(4px);
}
.rocket-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  margin: 0;
  font-family: var(--display);
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 700;
  color: #fde68a;
  letter-spacing: 0.06em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
  opacity: 0;
  z-index: 3;
  pointer-events: none;
}
.rocket-dismiss {
  position: absolute;
  bottom: 28px;
  z-index: 4;
  border: 1px solid rgba(253, 230, 138, 0.45);
  background: rgba(15, 23, 42, 0.65);
  color: #fde68a;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
}
#rocket-stage.launch .rocket-flame,
#rocket-stage.instant .rocket-flame,
#rocket-stage.crash .rocket-flame { opacity: 1; }
#rocket-stage.launch .rocket-smoke { opacity: 1; }
#rocket-stage.launch .rocket-craft {
  animation: rocket-lift 4.2s cubic-bezier(0.33, 0.05, 0.55, 1) forwards;
}
#rocket-stage.launch .rocket-flame {
  animation: flame-flicker 0.18s ease-in-out infinite alternate;
}
#rocket-stage.launch .rocket-smoke {
  animation: smoke-puff 1.2s ease-out 0.15s forwards;
}
#rocket-stage.launch .rocket-banner {
  animation: banner-in 0.5s ease 1.1s forwards;
}
#rocket-stage.launch .rocket-dismiss,
#rocket-stage.instant .rocket-dismiss,
#rocket-stage.crash .rocket-dismiss,
#rocket-stage.crash-instant .rocket-dismiss {
  animation: dismiss-in 0.4s ease 1.6s forwards;
}
#rocket-stage.instant .rocket-craft {
  transform: translateY(-110vh);
}
#rocket-stage.instant .rocket-banner { opacity: 1; transform: translateX(-50%) translateY(0); }
#rocket-stage.instant .rocket-dismiss { opacity: 1; }

/* Crash: wobble up a bit, tip over, boom — funny fail, not scary */
.rocket-boom {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, #fde68a 0%, #f97316 40%, #ef4444 70%, transparent 75%);
  opacity: 0;
  pointer-events: none;
}
.rocket-banner.crash { color: #fda4af; }
#rocket-stage.crash .rocket-craft {
  animation: rocket-crash 2.4s cubic-bezier(0.4, 0.05, 0.6, 1) forwards;
}
#rocket-stage.crash .rocket-flame {
  animation: flame-flicker 0.18s ease-in-out infinite alternate, flame-die 0.6s ease 0.9s forwards;
}
#rocket-stage.crash .rocket-smoke {
  animation: smoke-puff 0.9s ease-out 1.05s forwards;
}
#rocket-stage.crash .rocket-boom {
  animation: boom-burst 0.85s ease-out 1.15s forwards;
}
#rocket-stage.crash .rocket-banner {
  animation: banner-in 0.45s ease 1.35s forwards;
}
#rocket-stage.crash-instant .rocket-craft {
  transform: translate(48px, 28px) rotate(78deg);
  opacity: 0.85;
}
#rocket-stage.crash-instant .rocket-flame { opacity: 0; }
#rocket-stage.crash-instant .rocket-boom { opacity: 0.9; transform: scale(4); }
#rocket-stage.crash-instant .rocket-banner { opacity: 1; transform: translateX(-50%) translateY(0); }
#rocket-stage.crash-instant .rocket-dismiss { opacity: 1; }

@keyframes rocket-lift {
  0% { transform: translateY(0) rotate(0deg); }
  12% { transform: translateY(4px) rotate(-1.5deg); }
  22% { transform: translateY(-8px) rotate(1deg); }
  100% { transform: translateY(-120vh) rotate(0deg); }
}
@keyframes rocket-crash {
  0% { transform: translate(0, 0) rotate(0deg); }
  18% { transform: translate(0, -36px) rotate(-4deg); }
  32% { transform: translate(6px, -52px) rotate(8deg); }
  48% { transform: translate(-10px, -40px) rotate(-22deg); }
  68% { transform: translate(28px, 8px) rotate(55deg); }
  82% { transform: translate(42px, 24px) rotate(72deg); }
  100% { transform: translate(48px, 28px) rotate(78deg); }
}
@keyframes flame-flicker {
  from { transform: scaleY(0.85) scaleX(1.05); filter: brightness(1); }
  to { transform: scaleY(1.15) scaleX(0.92); filter: brightness(1.25); }
}
@keyframes flame-die {
  to { opacity: 0; transform: scaleY(0.2); }
}
@keyframes smoke-puff {
  0% { opacity: 0.6; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(2.8) translateY(10px); }
}
@keyframes boom-burst {
  0% { opacity: 0; transform: scale(0.4); }
  35% { opacity: 1; transform: scale(3.2); }
  100% { opacity: 0; transform: scale(5.5); }
}
@keyframes banner-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes dismiss-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Guided tour: blocker swallows clicks; the spot's giant box-shadow dims
   everything except the highlighted element; the card explains it. */
.tour-blocker {
  position: fixed;
  inset: 0;
  z-index: 89;
}
.tour-spot {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(5, 7, 16, 0.72);
  transition: all 0.25s ease;
}
.tour-card {
  position: fixed;
  z-index: 91;
  max-width: 320px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.tour-card h3 { margin: 0 0 6px; font-size: 16px; font-family: var(--display); font-weight: 600; }
.tour-card p { margin: 0 0 14px; font-size: 14.5px; line-height: 1.5; }
.tour-controls { display: flex; align-items: center; gap: 12px; }
.tour-count { color: var(--muted); font-size: 12.5px; flex: 1; }
.tour-card button.tour-skip {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
}
.tour-card button.tour-next {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d1022;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
}
#editor {
  flex: 1.2;
  min-width: 0;
  border-right: 1px solid var(--border);
}
.CodeMirror {
  height: 100%;
  font-size: 15px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  line-height: 1.55;
}
/* Blend material-darker's charcoal into the lab's indigo. */
.cm-s-material-darker.CodeMirror { background: #10142c; }
.cm-s-material-darker .CodeMirror-gutters { background: #10142c; }
/* Comments carry the lesson instructions ("YOUR TURN" steps) — override the
   theme's de-emphasized grey with a readable color. The span selector
   out-specifies the theme rules regardless of load order. */
.CodeMirror span.cm-comment { color: var(--comment); }

.console {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}
#output {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 14.5px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
#output .err { color: var(--err); }
#output .echo { color: var(--echo); font-weight: 600; }
#output .dim { color: var(--muted); }
#output .win { color: var(--run); font-weight: 700; }

/* Boot sequence — rendered inside #output like a real terminal boot log,
   so the tour's console/input spotlights still show the real UI. The first
   ▶ Run clears it along with the rest of the output. */
.boot { display: block; white-space: normal; color: var(--muted); }
.boot .boot-head {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-family: var(--display);
  font-weight: 600;
  font-size: 15.5px;
  margin: 2px 0 10px;
}
.boot .robot { font-size: 24px; }
@media (prefers-reduced-motion: no-preference) {
  .boot:not(.done) .robot { animation: boot-pulse 1.6s ease-in-out infinite; }
  @keyframes boot-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
}
.boot .lines div { margin: 3px 0; }
.boot .lines div::before { content: '▸ '; color: var(--accent); }
.boot .bar {
  height: 14px;
  max-width: 420px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0 6px;
}
.boot .fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--violet));
  transition: width 0.35s ease;
}
.boot.done .fill { background: var(--run); }
.boot .pct { font-size: 12px; color: var(--muted); }
.boot .online { color: var(--run); font-weight: 700; margin-top: 10px; }
.boot .online::before { content: none; }
.boot .fail { color: var(--err); }

#input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
#input-row .chev { color: var(--muted); font-weight: 700; }
#input-row.active { box-shadow: inset 0 2px 0 var(--accent); }
#input-row.active .chev { color: var(--accent); }
#input-field {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 14.5px ui-monospace, "SF Mono", Menlo, monospace;
}
#input-field:focus { outline: 2px solid var(--accent); border-color: transparent; }
#input-field::placeholder { color: var(--muted); opacity: 1; }

footer {
  padding: 7px 14px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
}

#toast {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: min(92vw, 560px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 840px) {
  main { flex-direction: column; }
  #editor {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex: 1.1;
  }
}
