/* Escape room tool (n5/escape-room.html). Load after main.css and starter.css.
   Pairs with assets/js/escape-room.js. The station's consoles are dark in both themes;
   the question cards inside them keep the normal starter look. */

.escape {
  --deck: #0d1336;
  --deck-2: #182057;
  --deck-line: #2c3a7a;
  --deck-text: #eef1ff;
  --deck-muted: #aab4e8;
  --glow: #5eead4;
  --warn: #fbbf24;
  --mono: ui-monospace, Menlo, Consolas, monospace;
}
.escape [hidden] { display: none !important; }

/* A dark console panel with a starfield behind its scene */
.deck {
  margin: 24px 0;
  border: var(--edge-w) solid var(--edge);
  border-radius: 20px;
  background: var(--deck);
  color: var(--deck-text);
  box-shadow: var(--pop);
  overflow: hidden;
}
.scene {
  display: block;
  width: 100%;
  height: clamp(150px, 23vw, 240px);
  background-color: #0b1030;
  background-image:
    radial-gradient(circle at 20px 30px, rgba(255, 255, 255, 0.9) 1px, transparent 2px),
    radial-gradient(circle at 70px 80px, rgba(255, 255, 255, 0.6) 1px, transparent 2px),
    radial-gradient(circle at 130px 20px, rgba(143, 176, 255, 0.8) 1.5px, transparent 2.5px),
    linear-gradient(#0b1030, #1b1f52);
  background-size: 110px 90px, 170px 130px, 230px 150px, 100% 100%;
}
.scene.is-win { height: clamp(220px, 34vw, 340px); background: #060920; }
.scene-status { font-family: var(--mono); font-size: 17px; font-weight: 700; letter-spacing: 0.1em; fill: var(--warn); }
.scene-status.is-good { fill: var(--glow); }
.scene-small { font-family: var(--mono); font-size: 14px; fill: var(--deck-muted); }

.console-text { padding: 16px 22px 20px; }
.console-text h2 { margin: 0 0 6px; color: #fff; font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.15; }
.console-text p { margin: 0 0 10px; }
.console-tag {
  display: table;
  margin-bottom: 10px !important;
  padding: 2px 10px;
  border: 2px solid currentColor;
  border-radius: 6px;
  color: var(--glow);
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.console-tag.is-warn { color: var(--warn); }

/* Briefing */
.rules { margin: 4px 0 18px; padding: 0; list-style: none; }
.rules li { position: relative; margin: 0 0 8px; padding-left: 26px; }
.rules li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.45em;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--glow);
  box-shadow: 0 0 8px var(--glow);
}

/* The big amber button: start, go through a door, launch */
.launch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 10px 26px;
  border: 3px solid #1d1442;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 4px 4px 0 #05030d;
  color: #1d1442;
  font: inherit;
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.launch:active { transform: translate(4px, 4px); box-shadow: none; }

/* Heads-up display: sticks to the top of the screen once the mission starts */
.hud {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 20px;
  margin: 16px 0 0;
  padding: 8px 16px;
  border: var(--edge-w) solid var(--edge);
  border-radius: 16px;
  background: var(--deck);
  box-shadow: var(--pop-sm);
  color: var(--deck-text);
}
.hud-item { display: flex; flex-direction: column; }
.hud-label { color: var(--deck-muted); font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; }
.hud-clock, .hud-doors { color: var(--glow); font-family: var(--mono); font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.hud-penalty { margin-left: 8px; color: var(--warn); font-family: var(--mono); font-size: 0.95rem; font-weight: 700; }
.hud-code { display: flex; gap: 5px; }
.code-slot {
  display: grid;
  place-items: center;
  width: 32px;
  height: 38px;
  border: 2px dashed #5d6aa8;
  border-radius: 8px;
  color: var(--glow);
  font-family: var(--font-head);
  font-size: 1.3rem;
  font-weight: 800;
}
.code-slot.is-filled { border-style: solid; border-color: var(--glow); background: rgba(94, 234, 212, 0.14); }
@media (max-width: 600px) {
  .hud { padding: 6px 12px; gap: 6px 14px; }
  .hud-clock, .hud-doors { font-size: 1.25rem; }
  .code-slot { width: 28px; height: 34px; font-size: 1.1rem; }
  .hud-item.is-doors { display: none; }
}

/* Station map: one button per room, joined by corridors */
.station-map {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 0;
}
.map-room {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 70px;
  padding: 6px 4px;
  border: var(--edge-w) solid var(--edge);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--pop-sm);
  color: var(--text);
  font: inherit;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.map-room + .map-room::before {
  content: "";
  position: absolute;
  top: 50%;
  left: calc(-10px - var(--edge-w));
  width: 10px;
  height: 4px;
  margin-top: -2px;
  background: var(--edge);
}
.map-num { font-family: var(--font-head); font-size: 1.15rem; font-weight: 800; line-height: 1; }
.map-name { font-size: 0.9rem; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.map-state { color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.map-room.is-locked { border-style: dashed; box-shadow: none; opacity: 0.6; cursor: default; }
.map-room.is-current { border-color: var(--edge); background: var(--deck); color: #fff; }
.map-room.is-current .map-state { color: var(--warn); }
.map-room.is-cleared { border-color: var(--good); background: var(--good-bg); }
.map-room.is-cleared .map-state { color: var(--good); }
.map-room:not(:disabled):active { transform: translate(3px, 3px); box-shadow: none; }
@media (max-width: 600px) {
  .station-map { gap: 6px; }
  .map-room + .map-room::before { left: calc(-6px - var(--edge-w)); width: 6px; }
  .map-name { font-size: 0.72rem; }
  .map-state { font-size: 0.62rem; }
}

/* Rooms */
.room { scroll-margin-top: 90px; }
.room-body { padding: 4px 18px 6px; }
/* The cards keep the page's own text colour, not the console's pale one */
.room-body .q { box-shadow: 4px 4px 0 #05030d; color: var(--text); }
.room-body .figure .circuit { max-width: 520px; }
.room:not(.is-cleared) .room-bar { display: none; }
.room-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 0 22px 18px; }
.room-bar p { margin: 0; color: var(--deck-muted); font-weight: 600; }
.room-bar strong { color: var(--glow); }
.room-bar .tool { border-color: var(--deck-muted); background: var(--deck-2); box-shadow: none; color: #fff; }
.room.is-collapsed .scene { height: 90px; }
.room.is-collapsed .room-story,
.room.is-collapsed .room-body,
.room.is-collapsed .door { display: none; }
.room.is-entering { animation: er-enter 0.6s ease-out; }

/* In each scene, some parts show only while the room is broken, others once it's fixed */
.scene .when-done { display: none; }
.room.is-cleared .scene .when-done { display: inline; }
.room.is-cleared .scene .when-broken { display: none; }
.room.is-cleared .scene .alarm { animation: none; opacity: 0.2; }
.scene .charge rect { fill: var(--warn); transition: fill 0.6s 1.2s; }
.scene .charge { transform-box: fill-box; transform-origin: 50% 100%; transform: scaleY(0.12); transition: transform 1.6s ease 0.6s; }
.room.is-cleared .scene .charge { transform: none; }
.room.is-cleared .scene .charge rect { fill: var(--glow); }
.scene .orbit { transform-box: view-box; transform-origin: 300px 125px; }
.scene .needle { transform-box: fill-box; transform-origin: 50% 100%; transform: rotate(-30deg); }
.room.is-cleared .scene .needle { animation: none; transform: rotate(25deg); }

/* Door at the end of each room: one light per question, then it slides open */
.door {
  position: relative;
  height: 250px;
  margin: 10px 18px 22px;
  border: 3px solid var(--deck-line);
  border-radius: 16px;
  background: radial-gradient(circle at 50% 55%, #17606a, #0a1c2e 70%);
  overflow: hidden;
}
.door-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background:
    linear-gradient(transparent 48%, rgba(0, 0, 0, 0.25) 48%, rgba(0, 0, 0, 0.25) 52%, transparent 52%),
    linear-gradient(90deg, #444c88, #6c76b8 45%, #4a5390);
  transition: transform 0.9s cubic-bezier(0.7, 0, 0.3, 1) 0.5s;
}
.door-leaf.is-left { left: 0; }
.door-leaf.is-right { right: 0; }
.door-leaf::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22px;
  background: repeating-linear-gradient(45deg, var(--warn) 0 12px, #1d1442 12px 24px);
}
.door-leaf.is-left::after { right: 0; }
.door-leaf.is-right::after { left: 0; }
.door.is-open .door-leaf.is-left { transform: translateX(-101%); }
.door.is-open .door-leaf.is-right { transform: translateX(101%); }

.door-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: min(280px, calc(100% - 40px));
  padding: 14px 16px;
  border: 3px solid #8fb0ff;
  border-radius: 14px;
  background: #0b1030;
  text-align: center;
  transform: translate(-50%, -50%);
  transition: opacity 0.4s 0.35s, transform 0.4s 0.35s;
}
.door.is-open .door-panel { opacity: 0; transform: translate(-50%, -50%) scale(0.85); pointer-events: none; }
.door-panel p { margin: 0; }
.door-status { color: #fff; font-family: var(--mono); font-size: 1rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.door-progress { color: var(--deck-muted); font-size: 0.95rem; }
.padlock { display: block; width: 40px; height: 48px; margin: 0 auto 6px; }
.padlock .shackle { transition: transform 0.3s; }
.door.is-open .padlock .shackle { transform: translateY(-8px); }
.door.is-open .padlock .body { fill: var(--glow); }
.door-lights { display: flex; justify-content: center; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.door-lights li {
  width: 18px;
  height: 18px;
  border: 2px solid #8fb0ff;
  border-radius: 50%;
  background: #2c3a7a;
  transition: background 0.3s, box-shadow 0.3s;
}
.door-lights li.is-on { border-color: var(--glow); background: var(--glow); box-shadow: 0 0 10px var(--glow); }

.door-beyond {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s 1.1s;
}
.door.is-open .door-beyond { opacity: 1; }
.door:not(.is-open) .door-beyond { visibility: hidden; }
.door-beyond p { margin: 0; }
.door-label { color: var(--deck-muted); font-family: var(--mono); font-size: 0.9rem; letter-spacing: 0.08em; text-transform: uppercase; }
.door-letter { color: var(--glow); font-family: var(--font-head); font-size: 4rem; font-weight: 800; line-height: 1; text-shadow: 0 0 18px rgba(94, 234, 212, 0.6); }
.door-beyond .launch { margin-top: 8px; }

/* Emergency override, offered after three wrong answers to a calculation */
.override {
  margin-top: 12px;
  border-color: var(--bad);
  color: var(--bad);
}

/* Countdown over the last door, after "Launch the escape pod" */
.countdown {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(6, 9, 32, 0.94);
  color: var(--warn);
  font-family: var(--font-head);
  font-size: 6rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 0 30px rgba(251, 191, 36, 0.6);
}
.countdown.is-go { color: var(--glow); font-size: 3.5rem; text-shadow: 0 0 30px rgba(94, 234, 212, 0.7); text-transform: uppercase; }

/* Final screen. Its resting look is the finished one; .is-launching (added by the script when
   the pod launches, not when a finished mission is reopened) plays the arrival on top */
.end-card { margin-top: 28px; }
.end-scene { position: relative; }
.sparks { position: absolute; left: 50%; top: 45%; width: 0; height: 0; pointer-events: none; }
.spark { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 2px; background: var(--c); opacity: 0; }
.spark.is-round { border-radius: 50%; }
.end-tag { box-shadow: 0 0 14px rgba(94, 234, 212, 0.45); }
.end-label { margin: 8px 0 4px !important; color: var(--deck-muted); font-family: var(--mono); font-size: 0.9rem; letter-spacing: 0.08em; text-transform: uppercase; }
.end-code { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px !important; }
.end-code span {
  display: grid;
  place-items: center;
  width: 58px;
  height: 68px;
  border: 3px solid var(--glow);
  border-radius: 12px;
  background: rgba(94, 234, 212, 0.14);
  color: var(--glow);
  font-family: var(--font-head);
  font-size: 2.4rem;
  font-weight: 800;
  text-shadow: 0 0 14px rgba(94, 234, 212, 0.6);
}
@media (max-width: 600px) {
  .end-code span { width: 46px; height: 56px; font-size: 1.9rem; }
}
.end-stats { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 0 0 14px; }
.end-stats dt { color: var(--deck-muted); font-family: var(--mono); font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; }
.end-stats dd { margin: 0; color: #fff; font-family: var(--mono); font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.end-topics { margin-bottom: 20px; }

.escape-tools { margin-top: 8px; }
.tool.is-armed { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }

/* Motion, for anyone who hasn't asked their device to reduce it */
@media (prefers-reduced-motion: no-preference) {
  .scene .pulse { animation: er-pulse 2.4s ease-in-out infinite; }
  .scene .pulse.is-2 { animation-delay: 0.4s; }
  .scene .pulse.is-3 { animation-delay: 0.8s; }
  .scene .blink { animation: er-blink 1.2s steps(2, jump-none) infinite; }
  .scene .scroll { animation: er-scroll 1.6s linear infinite; }
  .scene .flicker { transform-box: fill-box; transform-origin: 100% 50%; animation: er-flicker 0.16s ease-in-out infinite alternate; }
  .scene .flicker.is-2 { animation-duration: 0.11s; }
  .scene .needle { animation: er-jitter 0.7s ease-in-out infinite alternate; }
  .scene .needle.is-2 { animation-duration: 0.45s; }
  .scene .orbit { animation: er-orbit 14s linear infinite; }
  .scene .flow { stroke-dasharray: 6 10; animation: er-flow 0.8s linear infinite; }
  .scene .bob { animation: er-bob 3.2s ease-in-out infinite; }
  .code-slot.is-new { animation: er-pop 0.6s ease-out; }
  .countdown span { animation: er-count 0.7s ease-out both; }

  /* The win screen: stars stream past, and the pod flies in when it first launches */
  .scene .drift-slow { animation: er-drift-a 10s linear infinite; }
  .scene .drift-fast { animation: er-drift-b 3.5s linear infinite; }
  .scene .speed { animation: er-speed 0.45s linear infinite; }
  .is-launching .pod-fly { transform-box: view-box; transform-origin: 400px 135px; animation: er-fly-in 1.7s cubic-bezier(0.15, 0.85, 0.25, 1) both; }
  .is-launching .end-flash { animation: er-flash 0.9s ease-out 1.15s both; }
  .is-launching .spark { animation: er-spark 1.4s cubic-bezier(0.2, 0.8, 0.3, 1) both; animation-delay: calc(1.25s + var(--d)); }
  .is-launching .end-tag { animation: er-rise 0.6s ease-out 1.4s both; }
  .is-launching .end-title { animation: er-rise 0.6s ease-out 1.55s both; }
  .is-launching .end-label { animation: er-rise 0.5s ease-out 1.75s both; }
  .is-launching .end-code span { animation: er-letter 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) both; animation-delay: calc(1.9s + var(--i) * 0.18s); }
  .is-launching .end-stats,
  .is-launching .console-text > p:last-child { animation: er-rise 0.6s ease-out 2.9s both; }
}
@media (prefers-reduced-motion: reduce) {
  .door-leaf, .door-panel, .door-beyond, .scene .charge, .padlock .shackle { transition-duration: 0.01s; transition-delay: 0s; }
}
@keyframes er-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@keyframes er-blink { 0% { opacity: 1; } 100% { opacity: 0.15; } }
@keyframes er-scroll { to { transform: translateX(-60px); } }
@keyframes er-flicker { from { transform: scaleX(0.86); } to { transform: scaleX(1.04); } }
@keyframes er-jitter { from { transform: rotate(-50deg); } to { transform: rotate(40deg); } }
@keyframes er-orbit { to { transform: rotate(360deg); } }
@keyframes er-flow { to { stroke-dashoffset: -32; } }
@keyframes er-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes er-pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes er-enter { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes er-count { from { opacity: 0; transform: scale(1.8); } to { opacity: 1; transform: none; } }
@keyframes er-drift-a { to { transform: translateX(-200px); } }
@keyframes er-drift-b { to { transform: translateX(-260px); } }
@keyframes er-speed { from { transform: translateX(0); opacity: 0.7; } to { transform: translateX(-40px); opacity: 0; } }
@keyframes er-fly-in { from { transform: translate(-560px, -170px) scale(0.3); } to { transform: none; } }
@keyframes er-flash { 0% { opacity: 0; } 15% { opacity: 0.6; } 100% { opacity: 0; } }
@keyframes er-spark {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1.3); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(0.4); }
}
@keyframes er-rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes er-letter { from { opacity: 0; transform: translateY(-30px) scale(0.3) rotate(-25deg); } to { opacity: 1; transform: none; } }

/* ---------- Circuit boards in a room (circuit-builder.js with data-preset) ---------- */
.board-how {
  margin: 14px 0 4px;
  padding: 12px 16px;
  border: 2px dashed var(--deck-muted);
  border-radius: 12px;
  color: #fff;
}
.board-how p { margin: 0 0 6px; }
.board-how ul { margin: 0; padding-left: 1.2em; }
.board-how li + li { margin-top: 4px; }
.room-body .cb { margin-top: 20px; }
.room-body .cb-task { margin-bottom: 10px; }
.room-body .cb-workspace { box-shadow: 4px 4px 0 #05030d; color: var(--text); }
/* Only two or three parts to choose from: keep their boxes button-sized */
.room-body .cb-palette { grid-template-columns: repeat(auto-fit, minmax(74px, 140px)); }
/* Small enough for the question, the parts and the whole circuit to fit on an iPad screen together */
.room-body .cb-stage { max-width: 700px; margin: 0 auto; }
.q.is-solved > .override { display: none; }
/* The builder keeps room under a question for its longest message, so the circuit never moves.
   Here that would be a big empty gap, and a message only appears when a part is let go, so the
   room isn't kept. */
.room-body .cb-tasks { min-height: 0 !important; }
/* iPad landscape and wider: the question sits beside its circuit, so both are on screen at once */
@media (min-width: 900px) {
  .room-body .cb { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.1fr); gap: 14px; align-items: start; }
}
