/* Robot Rescue (Tech Quest Academy, Mission 2) — UI styles.
   Starts from Game 1's style.css; the Robot Rescue additions are at the bottom.
   Flat, crisp panels over a painted world. No gradients on UI chrome, no novelty fonts.
   All sizes are in em so the whole UI scales with the 16:9 stage. */

:root {
  --ink: #f4f1ea;
  --ink-dim: #b9c0cf;
  --panel: rgba(18, 24, 38, 0.86);
  --panel-solid: #161d2e;
  --line: rgba(255, 255, 255, 0.10);
  --gold: #f2c14e;
  --coral: #e07a5f;
  --teal: #3ccfcf;
  --violet: #7b5cff;
  --good: #6fd08c;
  --bad: #ff8a7a;
  --key: #eef1f6;
  --key-edge: #b7bfcd;
  --key-ink: #1c2436;
  --font: system-ui, "Roboto", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Roboto Mono", "Cousine", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #0d1220;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  container-type: size;
  font-size: 2.55cqh;
  overflow: hidden;
  background: #0d1220;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

[hidden] { display: none !important; }

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

/* ---------- shared bits ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.6em;
  box-shadow: 0 0.4em 1.4em rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(3px);
}

.panel-label {
  font-size: 0.68em;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

kbd {
  display: inline-block;
  min-width: 1.7em;
  padding: 0.12em 0.45em 0.18em;
  margin: 0 0.08em;
  border-radius: 0.32em;
  background: var(--key);
  color: var(--key-ink);
  font: 700 0.82em/1.2 var(--font);
  text-align: center;
  box-shadow: 0 0.16em 0 var(--key-edge);
  vertical-align: 0.08em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
button:focus-visible {
  outline: 0.15em solid var(--gold);
  outline-offset: 0.15em;
}

.muted { color: var(--ink-dim); }
.nowrap { white-space: nowrap; }

/* ---------- HUD ---------- */

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

#mission {
  position: absolute;
  left: 1em; top: 1em;
  width: 21em;
  padding: 0.75em 0.95em 0.8em;
  transition: box-shadow 0.3s;
}
#mission.flash { box-shadow: 0 0 0 0.18em var(--gold), 0 0.4em 1.4em rgba(0,0,0,.3); }

.mission-text {
  margin: 0.3em 0 0.55em;
  font-size: 1.02em;
  font-weight: 600;
  line-height: 1.38;
}

.checklist {
  list-style: none;
  margin: 0; padding: 0.5em 0 0;
  border-top: 1px solid var(--line);
  font-size: 0.8em;
  color: var(--ink-dim);
}
.checklist li {
  display: flex; align-items: center; gap: 0.55em;
  padding: 0.18em 0;
}
.checklist li::before {
  content: "";
  flex: none;
  width: 0.95em; height: 0.95em;
  border-radius: 50%;
  border: 0.14em solid #5b6580;
}
.checklist li.done { color: var(--ink); }
.checklist li.done::before {
  border-color: var(--good);
  background: var(--good);
  box-shadow: inset 0 0 0 0.16em var(--panel-solid);
}

#topright {
  position: absolute; right: 1em; top: 1em;
  display: flex; gap: 0.5em; align-items: stretch;
}
.chip {
  display: flex; align-items: center; gap: 0.45em;
  padding: 0.4em 0.7em;
  font-size: 0.9em;
}
#coin-counter { font-weight: 800; font-size: 1.05em; padding: 0.4em 0.8em; }
#coin-counter.bump { animation: bump 0.35s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }
.coin-dot {
  width: 0.95em; height: 0.95em; border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 0 0 0.16em #c9962a;
}
.controls { gap: 0.25em; padding: 0.25em; }
.ctl {
  background: transparent;
  border: 0;
  border-radius: 0.4em;
  padding: 0.3em 0.55em;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--ink);
}
.ctl:hover { background: rgba(255,255,255,0.07); }
.ctl[aria-pressed="true"] { background: rgba(242, 193, 78, 0.2); color: var(--gold); }
.ctl kbd { font-size: 0.78em; min-width: 1.5em; }

#legend {
  position: absolute; right: 1em; bottom: 1em;
  font-size: 0.82em;
  color: var(--ink-dim);
}
#legend .arrows kbd { margin: 0 0.04em; }
#legend .sep { width: 1px; height: 1.2em; background: var(--line); margin: 0 0.3em; }

#speech-warning {
  position: absolute; left: 1em; bottom: 1em;
  font-size: 0.8em; color: var(--gold);
}

/* ---------- dialogue ---------- */

#dialog {
  position: absolute;
  left: 50%; bottom: 1.2em;
  transform: translateX(-50%);
  width: min(38em, 92%);
  padding: 0.9em 1.2em 0.8em;
  animation: rise 0.18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 0.6em); } }
.dialog-name {
  font-size: 0.75em;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}
#dialog.glitch .dialog-name { color: #b9a6ff; }
.dialog-text {
  margin: 0.3em 0 0.4em;
  font-size: 1.2em;
  line-height: 1.4;
  font-weight: 500;
}
.dialog-next {
  text-align: right;
  font-size: 0.75em;
  color: var(--ink-dim);
  animation: nudge 1.4s ease-in-out infinite;
}
@keyframes nudge { 50% { opacity: 0.55; } }

/* ---------- challenge ---------- */

#challenge {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 26, 0.55);
}
.ch-card {
  width: 46em; max-width: 94%;
  padding: 1.1em 1.4em 0.9em;
  background: var(--panel-solid);
}
.ch-head { display: flex; justify-content: space-between; align-items: flex-start; }
.ch-head h2 { margin: 0.1em 0 0; font-size: 1.45em; font-weight: 800; }
.ch-skill {
  font-size: 0.75em; font-weight: 700;
  padding: 0.35em 0.7em;
  border-radius: 999px;
  border: 1px solid rgba(60, 207, 207, 0.4);
  color: var(--teal);
}
.ch-instruction {
  margin: 0.7em 0 0.8em;
  padding: 0.65em 0.85em;
  border-left: 0.22em solid var(--gold);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 0 0.4em 0.4em 0;
  font-size: 1.12em;
  line-height: 1.45;
  font-weight: 600;
}

.ch-sign-wrap {
  padding: 0.6em;
  border-radius: 0.6em;
  background: #3a2a22;                /* bakery-sign wood */
  box-shadow: inset 0 0 0 0.25em #5b4031;
}
.ch-sign {
  display: flex; flex-wrap: wrap; justify-content: center;
  padding: 0.7em 0.5em;
  border-radius: 0.35em;
  background: #20262f;
  font: 700 2.05em/1.25 var(--mono);
  color: #ffe7b3;
  letter-spacing: 0.02em;
  min-height: 2.2em;
}
.ch-sign .ch {
  position: relative;
  display: inline-block;
  min-width: 0.62em;
  text-align: center;
  white-space: pre;
}
.ch-sign .ch.space-ok { background: rgba(111, 208, 140, 0.22); border-radius: 0.1em; }
.ch-sign .ch.space-bad { background: rgba(255, 138, 122, 0.55); border-radius: 0.1em; }
.ch-sign .ch.dot-ok { color: var(--good); }
.ch-sign .ch.case-bad { box-shadow: inset 0 -0.12em 0 rgba(255, 138, 122, 0.9); }
.ch-sign .gap {
  position: relative;
  display: inline-block;
  width: 0;
}
.ch-sign .gap.caret::after {
  content: "";
  position: absolute;
  left: -0.06em; top: 0.08em;
  width: 0.12em; height: 1.1em;
  background: var(--teal);
  border-radius: 0.06em;
  animation: blink 1s steps(1) infinite;
}
.ch-sign .gap.hint::before {
  content: "";
  position: absolute;
  left: -0.3em; top: 0;
  width: 0.6em; height: 1.25em;
  border-radius: 0.2em;
  background: rgba(242, 193, 78, 0.45);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.25; } }
.ch-sign.fixed { color: #fff3d1; text-shadow: 0 0 0.35em rgba(255, 210, 120, 0.6); }

.ch-feedback {
  min-height: 1.5em;
  margin: 0.7em 0 0.6em;
  font-size: 1.05em;
  font-weight: 600;
  text-align: center;
}
.ch-feedback.good { color: var(--good); }
.ch-feedback.bad { color: var(--bad); }
.ch-feedback.info { color: var(--ink-dim); }

.ch-foot {
  display: flex; justify-content: space-between;
  margin-top: 0.6em;
  font-size: 0.75em;
  color: var(--ink-dim);
}

/* on-screen keyboard map */
.kb {
  display: flex; flex-direction: column; gap: 0.22em;
  width: fit-content;
  margin: 0 auto;
  padding: 0.5em;
  border-radius: 0.5em;
  background: #0f1422;
  font-size: 0.62em;
}
.kb-row { display: flex; gap: 0.22em; }
.kb-key {
  height: 2.3em;
  width: 2.3em;
  display: flex; align-items: center; justify-content: center;
  border-radius: 0.35em;
  background: #262f45;
  color: #7f8aa5;
  font-weight: 700;
  box-shadow: 0 0.14em 0 #151b2b;
  transition: background 0.08s, transform 0.08s;
}
.kb-key { transition: background 0.08s, transform 0.08s, opacity 0.15s; }
.kb.has-focus .kb-key:not(.focus) { opacity: 0.45; }
.kb-key.focus {
  position: relative; z-index: 1;
  background: var(--gold);
  color: #1c2436;
  font-weight: 900;
  box-shadow: 0 0.14em 0 #b8892a, 0 0 0 0.2em #fff3d1, 0 0 1em 0.25em rgba(242, 193, 78, 0.75);
  animation: key-pulse 1.1s ease-in-out infinite;
}
@keyframes key-pulse {
  50% { box-shadow: 0 0.14em 0 #b8892a, 0 0 0 0.2em #fff3d1, 0 0 0.4em 0.05em rgba(242, 193, 78, 0.35); }
}
.kb-key.down { transform: translateY(0.12em); box-shadow: 0 0.02em 0 #151b2b; background: var(--teal); color: #0d1220; }
.kb-arrows { display: grid; grid-template-columns: repeat(3, 2.3em); grid-template-rows: 1.12em 1.12em; gap: 0.06em 0.22em; }
.kb-arrows .kb-key { height: 1.12em; font-size: 0.9em; }

/* ---------- full screens ---------- */

.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}

#title { background: rgba(10, 14, 26, 0.45); }
.title-card { text-align: center; }
.series {
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}
.series .dot { color: var(--ink-dim); }
.logo {
  margin: 0.15em 0 0;
  font-size: 5.2em;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.35);
}
.logo-glitch { position: relative; display: inline-block; }
.logo-glitch::before, .logo-glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0;
  pointer-events: none;
  mix-blend-mode: screen;
}
.logo-glitch::before { color: var(--violet); animation: jitter 2.6s infinite steps(1); }
.logo-glitch::after  { color: var(--teal);   animation: jitter 2.6s infinite steps(1) reverse; }
@keyframes jitter {
  0%, 86%, 100% { transform: translate(0, 0); opacity: 0; }
  88% { transform: translate(-0.05em, 0.02em); opacity: 0.9; clip-path: inset(10% 0 55% 0); }
  91% { transform: translate(0.06em, -0.02em); opacity: 0.9; clip-path: inset(60% 0 8% 0); }
  94% { transform: translate(-0.03em, 0); opacity: 0.9; clip-path: inset(35% 0 35% 0); }
}
.subtitle {
  margin-top: 0.35em;
  font-size: 1.5em;
  font-weight: 600;
  color: var(--ink);
}
.title-menu {
  display: flex; gap: 0.8em; justify-content: center; align-items: center;
  margin-top: 1.8em;
}
.primary, .ghost, .danger {
  border-radius: 0.5em;
  padding: 0.6em 1.2em;
  font-weight: 700;
}
.primary {
  background: var(--gold);
  color: #1c2436;
  border: 0;
  font-size: 1.15em;
  box-shadow: 0 0.2em 0 #b8892a;
}
.primary kbd { background: #1c2436; color: var(--gold); box-shadow: none; }
.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--ink);
}
.danger { background: var(--coral); border: 0; color: #fff; }
.title-hint { margin-top: 1.4em; color: var(--ink-dim); font-size: 0.9em; }

@media (prefers-reduced-motion: reduce) {
  .logo-glitch::before, .logo-glitch::after, .dialog-next, .ch-sign .gap.hint::before, .kb-key.focus { animation: none; }
  .mc-rays { animation: none !important; }
}

/* ---------- mission complete ---------- */

#complete { background: #121a33; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; }
.mc-card {
  overflow: hidden;
  position: relative;
  display: flex; align-items: center; gap: 2.4em;
  padding: 2em 2.6em;
  max-width: 92%;
  border-radius: 1em;
  background: rgba(14, 20, 38, 0.82);
  border: 1px solid rgba(242, 193, 78, 0.35);
  box-shadow: 0 0 0 0.4em rgba(242, 193, 78, 0.08), 0 1.5em 3em rgba(0,0,0,.4);
}
.mc-badge { position: relative; }
.mc-rays {
  position: absolute; left: 50%; top: 50%;
  width: 22em !important; height: 22em !important; margin: -11em 0 0 -11em;
  opacity: 0.13; filter: none !important;
  animation: spin 40s linear infinite !important;
}
@keyframes spin { to { transform: rotate(360deg); } }
.mc-badge svg:not(.mc-rays) {
  position: relative;
  width: 11em; height: auto;
  filter: drop-shadow(0 0.6em 1em rgba(0,0,0,0.45));
  animation: badge-in 0.9s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes badge-in { from { transform: scale(0.4) rotate(-12deg); opacity: 0; } }
.mc-title {
  margin: 0.15em 0 0.1em;
  font-size: 3.1em;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--gold);
  line-height: 1;
}
.mc-badge-name { font-size: 1.35em; font-weight: 700; }
.mc-list {
  list-style: none;
  margin: 1em 0 0.8em; padding: 0;
  font-size: 0.98em;
}
.mc-list li {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.3em 0;
}
.mc-list li::before {
  content: "✓";
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.35em; height: 1.35em;
  border-radius: 50%;
  background: var(--good);
  color: #0d1220;
  font-weight: 900;
  font-size: 0.85em;
}
.mc-list .tag { font-size: 0.75em; color: var(--ink-dim); margin-left: auto; padding-left: 1em; }
.mc-stamp { font-size: 0.78em; color: var(--ink-dim); }
.mc-actions { display: flex; gap: 0.6em; margin-top: 1.1em; font-size: 0.85em; }
.confirm {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6em;
  margin-top: 0.8em; font-size: 0.85em;
}

/* ---------- hero select ---------- */

#select { background: rgba(10, 14, 26, 0.6); }
.select-card { text-align: center; }
.select-title { margin: 0.25em 0 0.9em; font-size: 2.2em; font-weight: 800; }
.hero-row { display: flex; gap: 1.6em; justify-content: center; }
.hero-card {
  width: 10.5em;
  padding: 0.6em 0.6em 0.75em;
  background: var(--panel-solid);
  opacity: 0.6;
  transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s;
}
.hero-card canvas { display: block; width: 100%; height: auto; }
.hero-card.selected {
  opacity: 1;
  transform: translateY(-0.3em);
  box-shadow: 0 0 0 0.2em var(--gold), 0 0.8em 1.8em rgba(0, 0, 0, 0.4);
}
.hero-name { font-size: 1.2em; font-weight: 800; letter-spacing: 0.04em; }
.hero-card.selected .hero-name { color: var(--gold); }
.select-text { margin: 1.2em auto 0; max-width: 30em; font-size: 1.15em; font-weight: 600; line-height: 1.45; }

/* ---------- dialogue portrait ---------- */

#dialog.has-portrait { display: flex; gap: 1em; align-items: center; }
#dialog-portrait {
  flex: none;
  width: 5.2em; height: 5.2em;
  border-radius: 0.5em;
  background: #121a33;
  box-shadow: inset 0 0 0 1px rgba(160, 140, 255, 0.35);
}
.dialog-body { flex: 1; min-width: 0; }

/* Glitch thumbnail in the checklist */
.glitch-icon { width: 1.25em; height: 1.15em; vertical-align: -0.2em; margin-left: 0.2em; }

/* ---------- mouse / touch (optional; keyboard stays the main way to play) ---------- */
#game { touch-action: none; }
#dialog { cursor: pointer; user-select: none; }
.dialog-next .or-click { opacity: 0.7; font-weight: 600; }
.hero-card { cursor: pointer; }
.ch-sign { cursor: text; user-select: none; }


/* =====================================================================
   Robot Rescue additions
   ===================================================================== */

:root { --copper: #c87f4a; --mint: #7fe0c9; }

.ctl.hint { color: var(--gold); }

/* parts tray */
#tray {
  position: absolute; left: 1em; bottom: 1em;
  padding: 0.45em 0.6em 0.35em;
}
.tray-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1em; font-size: 0.85em; }
#tray-canvas { display: block; width: 21em; height: auto; margin-top: 0.2em; }
#speech-warning { left: 50%; bottom: 1em; transform: translateX(-50%); }

/* the HUD's sound/hint buttons stay on top of an activity; everything else steps aside */
#stage.in-act #hud { z-index: 5; }
#stage.in-act #mission, #stage.in-act #tray, #stage.in-act #legend, #stage.in-act #coin-counter, #stage.in-act #btn-hint { display: none; }

/* ---------- hands-on activity ---------- */
#act { position: absolute; inset: 0; background: #0d1220; }
#act-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.act-top {
  position: absolute; left: 1em; top: 1em;
  width: 40em;
  padding: 0.7em 1em 0.75em;
  background: rgba(18, 24, 38, 0.9);
}
.act-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1em; }
.act-head h2 { margin: 0.05em 0 0; font-size: 1.35em; font-weight: 800; }
.act-top .ch-instruction { margin: 0.5em 0 0; font-size: 1.08em; }
.act-bottom {
  position: absolute; left: 0; right: 0; bottom: 0.7em;
  display: flex; flex-direction: column; align-items: center; gap: 0.4em;
  pointer-events: none;
}
.act-bottom button { pointer-events: auto; }
.act-feedback {
  margin: 0;
  max-width: 60em;
  padding: 0.4em 0.9em;
  border-radius: 0.5em;
  background: rgba(18, 24, 38, 0.9);
  font-size: 1.05em; font-weight: 600; line-height: 1.35;
  text-align: center;
}
.act-feedback:empty { display: none; }
.act-feedback.good { color: var(--good); }
.act-feedback.bad { color: var(--bad); }
.act-feedback.info { color: var(--ink); }
.act-who {
  display: inline-block; margin-right: 0.3em;
  padding: 0.05em 0.5em; border-radius: 0.4em;
  background: rgba(127, 224, 201, 0.18); color: var(--mint);
  font-size: 0.8em; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}
.act-foot {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.25em 0.5em 0.25em 0.8em;
  font-size: 0.72em; color: var(--ink-dim);
  pointer-events: auto;
}
.act-foot .sep { width: 1px; height: 1.2em; background: var(--line); }

/* ---------- dialogue tweaks ---------- */
#dialog.byte .dialog-name { color: var(--mint); }

/* ---------- part card ---------- */
#partcard { background: rgba(10, 14, 26, 0.55); cursor: pointer; }
.pc-card {
  display: flex; align-items: center; gap: 1.4em;
  width: 44em; max-width: 94%;
  padding: 1.2em 1.6em;
  background: var(--panel-solid);
  border-color: rgba(242, 193, 78, 0.35);
  animation: rise-card 0.22s ease-out;
}
@keyframes rise-card { from { opacity: 0; transform: translateY(0.8em); } }
#pc-art {
  flex: none; width: 15em; height: auto;
  border-radius: 0.6em; background: #1f2a44;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}
.pc-body { flex: 1; min-width: 0; }
.pc-name { margin: 0.15em 0 0.25em; font-size: 2.1em; font-weight: 900; color: #fff; }
.pc-text { margin: 0 0 0.8em; font-size: 1.25em; line-height: 1.45; font-weight: 600; }
.pc-next { font-size: 0.8em; color: var(--ink-dim); animation: nudge 1.4s ease-in-out infinite; }

/* ---------- completion (Robot Rescue Badge) ---------- */
.mc-card.rr {
  border-color: rgba(200, 127, 74, 0.5);
  box-shadow: 0 0 0 0.4em rgba(200, 127, 74, 0.1), 0 1.5em 3em rgba(0,0,0,.4);
}
.mc-left { display: flex; flex-direction: column; align-items: center; gap: 0.2em; }
.rr-badge { display: flex; justify-content: center; }
.mc-card.rr .mc-badge svg:not(.mc-rays) { width: 12.5em; }
.mc-card.rr .mc-rays { opacity: 0.16; }
#mc-scene { width: 17em; height: auto; margin-top: -0.4em; }
.mc-game { font-size: 1.15em; font-weight: 700; color: var(--mint); margin-bottom: 0.15em; }
.mc-card.rr .mc-title { color: var(--gold); font-size: 2.9em; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .pc-next, .pc-card { animation: none; }
}
