:root {
  --bg: #080d1e;
  --board-bg: #070d20;
  --surface: #111936;
  --surface-2: #18234a;
  --border: #2a3b75;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --dir-up: #0ea5e9;
  --dir-up-dark: #0369a1;
  --dir-down: #3b82f6;
  --dir-down-dark: #1d4ed8;
  --dir-left: #14b8a6;
  --dir-left-dark: #0f766e;
  --dir-right: #06b6d4;
  --dir-right-dark: #0e7490;
  --action: #f59e0b;
  --action-dark: #b45309;
  --control: #a855f7;
  --control-dark: #7e22ce;
  --sensor: #ec4899;
  --sensor-dark: #be185d;
  --fn: #f97316;
  --fn-dark: #c2410c;
  --hat: #10b981;
  --hat-dark: #047857;
  --danger: #f43f5e;
  --gold: #facc15;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top, #131c3f 0%, var(--bg) 65%);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Custom sleek space scrollbars (no jarring white Windows scrollbars) */
* {
  scrollbar-width: thin;
  scrollbar-color: #33488a rgba(8, 13, 30, 0.4);
}

*::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

*::-webkit-scrollbar-track {
  background: rgba(8, 13, 30, 0.35);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
  background: #33488a;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #4b67bd;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.small {
  font-size: 0.82rem;
  margin: 2px 0 0;
}

.muted {
  color: var(--muted);
}

/* =========================================================
   SLIM TOPBAR
   ========================================================= */
.topbar {
  background: rgba(11, 17, 38, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-shrink: 0;
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  font-size: 1.55rem;
  line-height: 1;
}

.brand-name {
  font-size: 1.12rem;
  letter-spacing: 0.3px;
}

.level-pill,
.stars-pill,
.counter-pill,
.mission-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.stars-pill {
  border-color: rgba(250, 204, 21, 0.5);
  color: var(--gold);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.nav-btn {
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.77rem;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.nav-icon-btn {
  min-width: 34px;
  padding: 4px 8px;
}

.nav-btn:hover {
  transform: translateY(-1px);
  border-color: var(--dir-up);
}

.nav-btn.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.25);
}

/* =========================================================
   1-SCREEN RESPONSIVE SPLIT LAYOUT
   ========================================================= */
.game-layout {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: minmax(360px, 1.08fr) minmax(380px, 0.98fr);
  gap: 12px;
  align-items: stretch;
  flex: 1;
}

.stage-column,
.editor-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* Desktop viewport lock: everything fits cleanly in 1 screen with ZERO outer scrollbar! */
@media (min-width: 901px) and (min-height: 580px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .game-layout {
    min-height: 0;
    overflow: hidden;
  }

  .stage-column,
  .editor-column {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .canvas-frame {
    flex: 1 1 0;
    min-height: 220px;
    aspect-ratio: auto !important;
    max-height: none !important;
  }

  .controls-bar {
    flex-wrap: nowrap !important;
  }

  .workspace-panel {
    flex: 1 1 0;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .block-workspace {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .puzzle-board {
    flex: 1 1 0;
    min-height: 0;
    max-height: none !important;
  }
}

/* =========================================================
   MISSION & LIVING MASCOT SPEECH BUBBLE (COMPACT)
   ========================================================= */
.mission-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  flex-shrink: 0;
}

.mission-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.mission-title-row h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.mascot-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mascot-avatar-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--dir-up);
  background: radial-gradient(circle at 30% 30%, #1e3a8a, #0f172a);
  font-size: 1.35rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.mascot-avatar-btn:hover {
  transform: scale(1.1) rotate(-6deg);
}

.mascot-bubble {
  position: relative;
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 11px;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.32;
  color: #e2e8f0;
}

.mascot-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.mascot-bubble.warn {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.16);
  color: #fef08a;
}

.mascot-bubble.warn::before {
  background: #2b2316;
  border-color: #f59e0b;
}

.mascot-bubble.good {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

.mascot-bubble.good::before {
  background: #132c22;
  border-color: #22c55e;
}

/* =========================================================
   CANVAS STAGE
   ========================================================= */
.canvas-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 260px;
  max-height: 460px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* =========================================================
   SINGLE-ROW ACTION CONTROLS BAR
   ========================================================= */
.controls-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.btn {
  min-height: 42px;
  padding: 7px 11px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-weight: 700;
  font-size: 0.86rem;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-run {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border-color: #4ade80;
  flex: 1.3;
  min-width: 96px;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.35);
}

.btn-run.stopping {
  background: linear-gradient(180deg, #f43f5e, #e11d48);
  border-color: #fb7185;
  box-shadow: 0 4px 16px rgba(244, 63, 94, 0.35);
}

.btn-step {
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
  border-color: #38bdf8;
}

.btn-hint {
  background: linear-gradient(180deg, #eab308, #ca8a04);
  border-color: #fde047;
  color: #0f172a;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.btn-primary {
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
  border-color: #38bdf8;
}

.btn-success {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  border-color: #4ade80;
}

.btn-sm {
  min-height: 34px;
  padding: 5px 11px;
  font-size: 0.82rem;
}

/* =========================================================
   PANELS
   ========================================================= */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.palette-panel {
  flex-shrink: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.96rem;
}

.head-actions {
  display: flex;
  gap: 6px;
}

.mini-text-btn {
  min-height: 30px;
  padding: 3px 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.79rem;
  cursor: pointer;
}

.mini-text-btn:hover:not(:disabled) {
  border-color: var(--dir-up);
}

.mini-text-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mini-text-btn.danger:hover {
  border-color: var(--danger);
  color: #fda4af;
}

/* =========================================================
   CATEGORY COLOR TOKENS (SHARED BY PIECES + SVG JIGSAW KNOBS)
   ========================================================= */
.cat-dir-up {
  --piece-top: #38bdf8;
  --piece-mid: #0ea5e9;
  --piece-bot: #0369a1;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-dir-down {
  --piece-top: #60a5fa;
  --piece-mid: #3b82f6;
  --piece-bot: #1d4ed8;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-dir-left {
  --piece-top: #2dd4bf;
  --piece-mid: #14b8a6;
  --piece-bot: #0f766e;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-dir-right {
  --piece-top: #22d3ee;
  --piece-mid: #06b6d4;
  --piece-bot: #0e7490;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-action {
  --piece-top: #fbbf24;
  --piece-mid: #f59e0b;
  --piece-bot: #b45309;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-control {
  --piece-top: #c084fc;
  --piece-mid: #a855f7;
  --piece-bot: #7e22ce;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-sensor {
  --piece-top: #f472b6;
  --piece-mid: #ec4899;
  --piece-bot: #be185d;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}
.cat-fn {
  --piece-top: #fb923c;
  --piece-mid: #f97316;
  --piece-bot: #c2410c;
  background: linear-gradient(180deg, var(--piece-top), var(--piece-bot));
}

/* =========================================================
   COMPACT JIGSAW COMPASS PALETTE
   ========================================================= */
.block-palette {
  margin-top: 8px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
}

.compass-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(7, 13, 32, 0.65);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 7px 10px;
  flex: 1.1;
  min-width: 230px;
}

.compass-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.compass-center {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.92rem;
  flex-shrink: 0;
}

.palette-extras {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  flex: 0.95;
  min-width: 140px;
}

.palette-extras.extras-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 6px 10px;
  padding-right: 4px;
}

.palette-piece {
  position: relative;
  min-height: 36px;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.81rem;
  cursor: grab;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.28),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25),
    0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.palette-piece .palette-tab {
  position: absolute;
  right: -9px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 20px;
  pointer-events: none;
  z-index: 2;
}

.palette-piece.compass-btn .palette-tab {
  display: none;
}

.palette-piece:hover {
  transform: translateY(-2px);
  filter: brightness(1.1);
}

.palette-piece:active {
  transform: translateY(1px);
  cursor: grabbing;
}

.palette-piece.compass-btn {
  min-width: 86px;
  padding: 5px 8px;
}

.palette-piece.extra-btn {
  min-height: 36px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.palette-piece.hint-glow {
  box-shadow: 0 0 0 3px var(--gold), 0 0 20px rgba(250, 204, 21, 0.85);
  animation: hintPulse 0.65s ease-in-out infinite alternate;
}

@keyframes hintPulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* =========================================================
   QUICK-JUMP SCOPE TABS (PRINCIPAL / F1 / F2)
   ========================================================= */
.block-workspace {
  margin-top: 8px;
}

.scope-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.scope-tab {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s ease;
}

.scope-tab:hover {
  color: var(--text);
  border-color: var(--dir-up);
}

.scope-tab.active {
  background: rgba(250, 204, 21, 0.16);
  border-color: var(--gold);
  color: #fef08a;
}

.scope-count {
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  font-size: 0.72rem;
}

/* =========================================================
   REAL INTERLOCKING JIGSAW PUZZLE WORKSPACE (SVG KNOB + SOCKET!)
   ========================================================= */
.puzzle-board {
  min-height: 150px;
  max-height: 440px;
  overflow-y: auto;
  padding: 12px 14px 20px;
  border-radius: 12px;
  background:
    radial-gradient(rgba(148, 163, 184, 0.14) 1.2px, transparent 1.2px) 0 0 / 18px 18px,
    var(--board-bg);
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.puzzle-section {
  display: flex;
  flex-direction: column;
}

/* SVG Jigsaw Keyhole Socket & Bulb Knob */
.jigsaw-socket {
  position: absolute;
  left: 30px;
  top: -2px;
  width: 38px;
  height: 15px;
  pointer-events: none;
  z-index: 2;
}

.jigsaw-knob {
  position: absolute;
  left: 30px;
  bottom: -13.5px;
  width: 38px;
  height: 15px;
  pointer-events: none;
  z-index: 6;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}

.jigsaw-knob.inner-knob {
  left: 50px;
}

/* Rounded Event / Function Hat Piece at Top */
.puzzle-hat {
  --piece-bot: var(--hat-dark);
  position: relative;
  width: 100%;
  max-width: 330px;
  padding: 9px 14px;
  border-radius: 22px 22px 9px 9px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(180deg, #34d399, var(--hat-dark));
  color: #ffffff;
  font-weight: 800;
  font-size: 0.88rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.32),
    0 3px 10px rgba(16, 185, 129, 0.25);
  margin-bottom: 0;
  z-index: 60;
}

.puzzle-hat.hat-fn {
  --piece-bot: var(--fn-dark);
  background: linear-gradient(180deg, #fb923c, var(--fn-dark));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.32),
    0 3px 10px rgba(249, 115, 22, 0.25);
}

.puzzle-hat.hat-focused {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 0 0 2px var(--gold);
}

.hat-badge {
  font-size: 0.7rem;
  background: rgba(15, 23, 42, 0.45);
  color: var(--gold);
  padding: 2px 7px;
  border-radius: 999px;
}

.puzzle-stack {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Empty Jigsaw Drop Ghost Slot */
.puzzle-slot-empty {
  position: relative;
  margin-top: -1px;
  padding: 17px 12px 11px;
  border-radius: 10px;
  border: 2px dashed rgba(148, 163, 184, 0.38);
  background: rgba(24, 35, 74, 0.28);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  max-width: 320px;
}

.puzzle-slot-empty.inner {
  margin-top: -1px;
  padding: 15px 10px 9px;
  font-size: 0.78rem;
}

/* Interlocking Jigsaw Command Piece */
.puzzle-piece {
  position: relative;
  width: 100%;
  max-width: 320px;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.88rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: grab;
  transition: transform 0.14s ease, filter 0.15s ease;
}

.puzzle-cmd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 12px 10px 7px 10px;
  margin-top: -2px;
  border-radius: 9px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.26),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

.puzzle-left {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.drag-grip {
  opacity: 0.65;
  font-size: 0.92rem;
  letter-spacing: -2px;
  cursor: grab;
  user-select: none;
}

.piece-icon {
  font-size: 1.02rem;
  line-height: 1;
}

.remove-pill-btn {
  min-width: 26px;
  min-height: 26px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(15, 23, 42, 0.34);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.remove-pill-btn:hover {
  background: rgba(244, 63, 94, 0.92);
}

/* =========================================================
   TRUE C-SHAPED JIGSAW CLAMP PIECES (REPEAT & IF SENSOR)
   ========================================================= */
.puzzle-clamp {
  max-width: 370px;
  margin-top: -2px;
  background: transparent !important;
}

.puzzle-clamp-top {
  position: relative;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 10px 8px 10px;
  border-radius: 9px 9px 9px 0;
  border: 2px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.26);
}

.puzzle-clamp-jaw {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: stretch;
}

.puzzle-spine {
  width: 14px;
  flex-shrink: 0;
  border-left: 2px solid rgba(255, 255, 255, 0.28);
  border-right: 2px solid rgba(255, 255, 255, 0.16);
}

.spine-control,
.bottom-control {
  background: var(--control-dark);
}

.spine-sensor,
.bottom-sensor {
  background: var(--sensor-dark);
}

.puzzle-clamp-body {
  position: relative;
  flex: 1;
  padding: 0 6px 20px 8px;
  background: rgba(7, 13, 32, 0.55);
  border-right: 2px dashed rgba(168, 85, 247, 0.35);
  display: flex;
  flex-direction: column;
  gap: 0;
  cursor: pointer;
}

.puzzle-clamp-body.body-focused,
.puzzle-clamp-body.drop-inside {
  background: rgba(168, 85, 247, 0.16);
  border-right-color: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.35);
}

.puzzle-clamp-bottom {
  position: relative;
  z-index: 1;
  height: 16px;
  border-radius: 0 9px 9px 9px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top: none;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.28);
}

.sensor-select {
  background: rgba(15, 23, 42, 0.58);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 7px;
  padding: 2px 6px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.sensor-select option {
  background: #111936;
  color: #f8fafc;
}

.repeat-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(15, 23, 42, 0.42);
  padding: 2px 5px;
  border-radius: 8px;
}

.step-pill-btn {
  min-width: 24px;
  min-height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-weight: 900;
  font-size: 0.82rem;
  cursor: pointer;
}

.repeat-count {
  min-width: 22px;
  text-align: center;
  font-size: 0.84rem;
}

.focus-tag {
  position: absolute;
  right: 8px;
  bottom: 2px;
  z-index: 65;
  pointer-events: none;
  font-size: 0.68rem;
  color: var(--gold);
  font-weight: 700;
}

/* =========================================================
   SNAP, DRAG & DEBUGGER ANIMATIONS
   ========================================================= */
.snap-pop {
  animation: snapPop 0.28s cubic-bezier(0.22, 1.45, 0.36, 1);
}

@keyframes snapPop {
  0% { transform: scale(0.88) translateY(-10px); opacity: 0.65; }
  65% { transform: scale(1.03) translateY(2px); }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.puzzle-piece.dragging {
  opacity: 0.45;
}

.puzzle-piece.drop-before {
  box-shadow: 0 -4px 0 0 var(--gold);
}

.puzzle-piece.drop-after {
  box-shadow: 0 4px 0 0 var(--gold);
}

.block-active {
  filter: drop-shadow(0 0 10px rgba(250, 204, 21, 0.9));
  outline: 2.5px solid var(--gold);
  outline-offset: 1px;
  z-index: 80 !important;
}

.block-error {
  filter: drop-shadow(0 0 12px rgba(249, 115, 22, 0.95));
  outline: 2.5px solid #fb923c;
  outline-offset: 1px;
  animation: pulseBug 0.55s ease-in-out infinite alternate;
  z-index: 80 !important;
}

@keyframes pulseBug {
  from { transform: translateX(-2px); }
  to { transform: translateX(2px); }
}

/* =========================================================
   LIVE CODE PEEK PANEL (BOUNDED SO 1-SCREEN LAYOUT NEVER BREAKS)
   ========================================================= */
.code-peek-panel {
  flex-shrink: 0;
  max-height: 165px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.code-lang-tabs {
  display: flex;
  gap: 5px;
}

.tab-btn {
  padding: 3px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.76rem;
  cursor: pointer;
}

.tab-btn.active {
  border-color: var(--dir-up);
  color: var(--text);
  background: rgba(14, 165, 233, 0.2);
}

.code-peek-lines {
  margin-top: 6px;
  padding: 8px;
  border-radius: 10px;
  background: #070b17;
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  overflow: auto;
  flex: 1;
}

.code-line {
  display: flex;
  gap: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  white-space: pre;
}

.code-line.active-line {
  background: rgba(250, 204, 21, 0.22);
  color: #fef08a;
}

.code-ln {
  color: #475569;
  min-width: 20px;
  text-align: right;
  user-select: none;
}

/* =========================================================
   VICTORY OVERLAY
   ========================================================= */
.win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 13, 30, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.win-card {
  background: linear-gradient(180deg, #1b2856, #101836);
  border: 2px solid var(--gold);
  border-radius: 18px;
  padding: 20px;
  max-width: 390px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: popIn 0.28s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: scale(1); }
}

.win-stars {
  font-size: 2.4rem;
  letter-spacing: 6px;
  margin-bottom: 6px;
}

.star-icon.earned {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(250, 204, 21, 0.65);
}

.star-icon.empty {
  color: #334155;
}

.win-card h2 {
  margin: 0 0 6px;
  font-size: 1.25rem;
}

.win-sub {
  margin: 0 0 16px;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.win-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.win-actions .btn {
  flex: 1 1 auto;
}

/* =========================================================
   MODALS (PLANET MAP & GARAGE)
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 18px;
  max-width: 680px;
  width: 100%;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.15rem;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.world-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.world-header h4 {
  margin: 0;
  font-size: 1rem;
}

.concept-pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(168, 85, 247, 0.2);
  border: 1px solid rgba(168, 85, 247, 0.5);
  color: #e9d5ff;
  font-size: 0.76rem;
  font-weight: 700;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 9px;
}

.level-tile {
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.level-tile:hover {
  transform: translateY(-2px);
  border-color: var(--dir-up);
}

.level-tile.current {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.25);
}

.level-tile.completed {
  background: rgba(34, 197, 94, 0.1);
}

.level-num {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 700;
}

.level-title {
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

.level-stars {
  font-size: 1rem;
}

.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.skin-card {
  padding: 12px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.skin-card.equipped {
  border-color: #22c55e;
}

.skin-card.locked {
  opacity: 0.72;
}

.skin-avatar {
  width: 64px;
  height: 60px;
  border-radius: 16px;
  border: 3px solid;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.skin-visor {
  padding: 3px 9px;
  border-radius: 7px;
  font-size: 0.75rem;
  letter-spacing: 3px;
}

.skin-acc {
  position: absolute;
  top: -11px;
  font-size: 1.1rem;
}

/* =========================================================
   STORY CINEMATICS & WORLD ARRIVAL CARDS
   ========================================================= */
.story-modal {
  max-width: 620px;
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.72), 0 0 36px rgba(56, 189, 248, 0.18);
  animation: popIn 0.28s ease-out;
}

.story-modal.story-ending {
  border-color: var(--gold);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75), 0 0 42px rgba(250, 204, 21, 0.3);
}

.story-top {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.story-badge {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--gold);
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.4);
  padding: 4px 10px;
  border-radius: 999px;
}

.story-stage {
  background: radial-gradient(circle at 50% 45%, #172554 0%, #070d20 75%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

.story-art-svg {
  width: 100%;
  max-width: 440px;
  height: auto;
  display: block;
}

.story-copy {
  padding: 16px 22px 10px;
  text-align: center;
}

.story-copy h2 {
  margin: 0 0 8px;
  font-size: 1.32rem;
  color: #ffffff;
}

.story-copy p {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.5;
  color: #cbd5e1;
}

.story-footer {
  padding: 12px 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.story-dots {
  display: flex;
  gap: 7px;
  align-items: center;
}

.story-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #334155;
  transition: all 0.2s ease;
}

.story-dot.active {
  width: 26px;
  background: var(--gold);
}

.story-dot.done {
  background: #22c55e;
}

.story-nav-btns {
  display: flex;
  gap: 8px;
  align-items: center;
}

.arrival-hero {
  padding: 18px 20px 10px;
  background: radial-gradient(circle at 50% 35%, #172554 0%, #091026 80%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.arrival-orb {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.arrival-orb-icon {
  font-size: 2.6rem;
}

.arrival-ship-orbit {
  position: absolute;
  right: -28px;
  top: -12px;
  animation: shipHover 2.2s ease-in-out infinite;
}

.arrival-hero h2 {
  margin: 4px 0 0;
  font-size: 1.25rem;
}

.upgrade-pill,
.upgrade-pill-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #bae6fd;
  font-size: 0.8rem;
  font-weight: 700;
}

.upgrade-pill-sm {
  font-size: 0.74rem;
  padding: 3px 9px;
}

.arrival-bubble {
  margin: 14px 18px 6px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.arrival-avatar {
  font-size: 2rem;
  flex-shrink: 0;
}

.arrival-bubble p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #e2e8f0;
}

.arrival-footer {
  justify-content: flex-end;
}

/* =========================================================
   ANIMATED GALAXY & PLANET FLIGHT MAP (STARSHIP ESTRELA-1!)
   ========================================================= */
.journey-modal {
  max-width: 880px;
  max-height: 92dvh;
  border-color: rgba(56, 189, 248, 0.5);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.78);
}

.journey-head {
  padding: 10px 16px;
}

.galaxy-ribbon {
  padding: 10px 14px;
  background: rgba(7, 13, 32, 0.88);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  overflow-x: auto;
}

.galaxy-endpoint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}

.galaxy-endpoint.earth-saved,
.galaxy-endpoint.beacon-lit {
  background: rgba(250, 204, 21, 0.14);
  box-shadow: 0 0 14px rgba(250, 204, 21, 0.25);
}

.endpoint-icon {
  font-size: 1.45rem;
  line-height: 1;
}

.endpoint-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
}

.galaxy-link {
  flex: 1;
  min-width: 12px;
  height: 2px;
  border-top: 2px dashed rgba(148, 163, 184, 0.42);
}

.galaxy-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: rgba(24, 35, 74, 0.45);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.14s ease, border-color 0.15s ease, background 0.15s ease;
}

.galaxy-node:hover {
  transform: translateY(-2px);
  border-color: rgba(125, 211, 252, 0.6);
}

.galaxy-node.selected {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.14);
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.22);
}

.galaxy-node.world-done .galaxy-orb {
  box-shadow: 0 0 0 2px #34d399;
}

.galaxy-ship-pin {
  position: absolute;
  top: -8px;
  right: -2px;
  font-size: 0.92rem;
  animation: shipHover 1.6s ease-in-out infinite;
}

.galaxy-orb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.08rem;
  border: 1.5px solid rgba(255, 255, 255, 0.32);
}

.galaxy-node-label {
  font-size: 0.72rem;
  font-weight: 800;
}

.galaxy-node-stars {
  font-size: 0.68rem;
  color: var(--gold);
  font-weight: 700;
}

.planet-flight-stage {
  position: relative;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.planet-stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.act-pill {
  font-size: 0.84rem;
  font-weight: 800;
  color: #f8fafc;
}

.flight-svg-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 760 / 270;
  max-height: 280px;
  margin: 0 auto;
}

.planet-route-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.flight-route-dash {
  animation: routeFlow 12s linear infinite;
}

@keyframes routeFlow {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -160; }
}

.map-base-node {
  cursor: pointer;
}

.map-base-node:hover .base-pad-outer {
  filter: brightness(1.22);
}

.base-radar-ring {
  animation: radarSpin 6s linear infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes radarSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* 60fps Flight Cinema FX Overlay & Live Flight Status Pill */
.flight-fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.flight-status-pill {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(11, 17, 38, 0.88);
  border: 1.5px solid rgba(56, 189, 248, 0.65);
  color: #e0f2fe;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
  z-index: 8;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  animation: popIn 0.2s ease-out;
}

.flight-status-pill.good {
  border-color: #34d399;
  color: #bbf7d0;
}

.flight-status-pill.turbo,
.flight-status-pill.warp {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.2);
  color: #fef08a;
}

/* Flying Starship Estrela-1 Overlay */
.flying-starship {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--ship-rot, 0deg));
  transition:
    left 0.65s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.65s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.32s ease;
  pointer-events: none;
  z-index: 6;
  filter: drop-shadow(0 6px 12px rgba(56, 189, 248, 0.55));
}

.flying-starship.ship-flying {
  transition: none;
  filter: drop-shadow(0 0 18px rgba(250, 204, 21, 0.9));
}

.flying-starship .starship-svg {
  display: block;
  animation: shipHover 1.9s ease-in-out infinite;
}

.flying-starship.ship-zooming {
  filter: drop-shadow(0 0 18px rgba(250, 204, 21, 0.95));
}

.flying-starship.ship-landing {
  transform: translate(-50%, -18%) scale(0.55) rotate(25deg);
  opacity: 0.25;
  transition: all 0.28s ease-in;
}

.ship-flame {
  animation: flameFlicker 0.18s ease-in-out infinite alternate;
  transform-box: fill-box;
  transform-origin: right center;
}

@keyframes flameFlicker {
  from { transform: scaleX(0.82); opacity: 0.85; }
  to { transform: scaleX(1.22); opacity: 1; }
}

@keyframes shipHover {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.art-float {
  animation: shipHover 2.2s ease-in-out infinite;
}

.art-pulse {
  animation: artPulse 2s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes artPulse {
  0%, 100% { transform: scale(0.96); opacity: 0.65; }
  50% { transform: scale(1.06); opacity: 1; }
}

.art-meteor {
  animation: meteorDrop 1.4s ease-in-out infinite;
}

@keyframes meteorDrop {
  0% { transform: translate(12px, -10px); opacity: 0; }
  45% { opacity: 1; }
  100% { transform: translate(-10px, 10px); opacity: 0; }
}

/* Mission Briefing Deck at Bottom of Map */
.mission-deck {
  padding: 12px 16px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.mission-deck-info {
  flex: 1;
  min-width: 240px;
}

.mission-deck-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.mission-deck-story {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: #cbd5e1;
}

.mission-launch-btn {
  flex: 0 0 auto;
  min-width: 195px;
  padding: 10px 18px;
  font-size: 0.94rem;
}

.win-story-note {
  margin: 0 0 8px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #e0f2fe;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

/* =========================================================
   GARAGE STAR PROGRESS BAR
   ========================================================= */
.garage-progress {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(7, 13, 32, 0.65);
  border: 1px solid var(--border);
}

.garage-progress.all-unlocked {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.14);
  color: #fef08a;
  font-weight: 800;
  text-align: center;
}

.garage-progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.84rem;
  margin-bottom: 6px;
}

.garage-bar-track {
  height: 10px;
  border-radius: 999px;
  background: #1e293b;
  overflow: hidden;
}

.garage-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #facc15);
  transition: width 0.3s ease;
}

/* =========================================================
   CREATIVE LEVEL WORKSHOP ("🛠️ OFICINA DE FASES")
   ========================================================= */
.workshop-modal {
  max-width: 860px;
  max-height: 92dvh;
  border-color: rgba(250, 204, 21, 0.45);
}

.ws-body {
  padding: 12px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ws-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ws-title-input {
  flex: 1 1 180px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #070d20;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
}

.ws-title-input:focus {
  outline: none;
  border-color: var(--gold);
}

.ws-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.ws-chip {
  min-height: 32px;
  padding: 4px 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.ws-chip:hover {
  border-color: var(--dir-up);
}

.ws-chip.active {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.16);
  color: #fef08a;
}

.ws-brushes {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.brush-btn {
  min-height: 34px;
  padding: 4px 9px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: transform 0.1s ease, border-color 0.12s ease;
}

.brush-btn:hover {
  transform: translateY(-1px);
  border-color: var(--dir-up);
}

.brush-btn.active {
  border-color: var(--gold);
  background: rgba(250, 204, 21, 0.2);
  color: #fef08a;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.2);
}

.ws-grid-stage {
  padding: 8px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: linear-gradient(180deg, var(--ws-bg-top, #0b1026), var(--ws-bg-bot, #1a234e));
  display: flex;
  justify-content: center;
}

.ws-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  max-width: 420px;
  user-select: none;
  touch-action: none;
}

.ws-cell {
  aspect-ratio: 1;
  min-height: 32px;
  border-radius: 8px;
  border: 1.5px solid var(--ws-floor-border, #3b4e8f);
  background: var(--ws-floor, #253263);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: crosshair;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.08s ease;
}

.ws-cell:hover {
  transform: scale(1.06);
  border-color: var(--gold);
  z-index: 2;
}

.ws-cell.wt-wall {
  background: var(--ws-wall, #64748b);
  border-color: rgba(255, 255, 255, 0.22);
}

.ws-cell.wt-void {
  background: rgba(5, 8, 20, 0.5);
  border-style: dashed;
  border-color: rgba(148, 163, 184, 0.22);
}

.ws-cell.wt-robot {
  background: #0284c7;
  border-color: #7dd3fc;
}

.ws-cell.wt-goal {
  background: rgba(16, 185, 129, 0.35);
  border-color: #34d399;
  color: #fef08a;
}

.ws-cell.wt-button {
  background: rgba(34, 211, 238, 0.3);
  border-color: #22d3ee;
  color: #ecfeff;
}

.ws-cell.wt-laser {
  background: rgba(244, 63, 94, 0.28);
  border-color: #fb7185;
}

.ws-cell.wt-bridge {
  background: rgba(34, 211, 238, 0.14);
  border-style: dashed;
  border-color: #22d3ee;
  color: #67e8f9;
  font-size: 0.76rem;
}

.ws-cell.wt-portal1 {
  background: rgba(192, 132, 252, 0.28);
  border-color: #c084fc;
  font-size: 0.78rem;
}

.ws-cell.wt-portal2 {
  background: rgba(56, 189, 248, 0.28);
  border-color: #38bdf8;
  font-size: 0.78rem;
}

.ws-cell.wt-portal3 {
  background: rgba(251, 146, 60, 0.28);
  border-color: #fb923c;
  font-size: 0.78rem;
}

.ws-cell.wt-portal4 {
  background: rgba(244, 114, 182, 0.28);
  border-color: #f472b6;
  font-size: 0.78rem;
}

.ws-cell.wt-ice {
  background: linear-gradient(135deg, rgba(125, 211, 252, 0.45), rgba(2, 132, 199, 0.45));
  border-color: #7dd3fc;
}

.ws-cell.wt-crate {
  background: rgba(245, 158, 11, 0.32);
  border-color: #fbbf24;
}

.ws-options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.ws-opt-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.ws-par-val {
  min-width: 24px;
  text-align: center;
  font-size: 0.92rem;
}

.ws-saved-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.ws-saved-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.ws-saved-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ws-saved-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  overflow: hidden;
}

.ws-saved-open {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.ws-saved-open:hover {
  color: var(--gold);
}

.ws-saved-del {
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 4px 7px;
  font-size: 0.72rem;
  cursor: pointer;
}

.ws-saved-del:hover {
  background: rgba(244, 63, 94, 0.28);
  color: #fda4af;
}

.ws-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.ws-footer-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ws-status {
  font-size: 0.82rem;
  font-weight: 700;
}

.ws-status.good {
  color: #86efac;
}

.ws-status.warn {
  color: #fde047;
}

/* =========================================================
   MOBILE / SMALL TABLET STACKING
   ========================================================= */
@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .canvas-frame {
    max-height: 360px;
  }

  .block-palette {
    flex-wrap: wrap;
  }

  .compass-pad {
    min-width: 240px;
  }
}

/* ===== Daily Mission Button, Badges Modal & Gamified Achievement Toast ===== */
.nav-btn-daily {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.25), rgba(234, 88, 12, 0.16));
  border-color: rgba(251, 146, 60, 0.55);
  color: #fed7aa;
}

.nav-btn-daily:hover {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.42), rgba(234, 88, 12, 0.28));
  border-color: #fb923c;
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 12px;
  max-height: 58vh;
  overflow-y: auto;
  padding-right: 4px;
}

.badge-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.72);
  border: 1.5px solid rgba(148, 163, 184, 0.22);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.badge-card.unlocked {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.16), rgba(56, 189, 248, 0.12));
  border-color: rgba(250, 204, 21, 0.58);
  box-shadow: 0 4px 16px rgba(250, 204, 21, 0.14);
}

.badge-card.locked {
  opacity: 0.62;
  filter: grayscale(0.45);
}

.badge-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  background: rgba(30, 41, 59, 0.85);
}

.badge-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.badge-info strong {
  font-size: 0.88rem;
  color: #f8fafc;
}

.badge-info span {
  font-size: 0.75rem;
  color: #cbd5e1;
  line-height: 1.25;
}

.badge-check {
  margin-left: auto;
  color: #fde047;
  font-weight: 900;
  font-size: 1rem;
}

.achievement-toast-stack {
  position: fixed;
  top: 66px;
  right: 16px;
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.achievement-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  border: 2px solid #facc15;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45), 0 0 22px rgba(250, 204, 21, 0.35);
  color: #f8fafc;
  animation: toastSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.achievement-toast.toast-out {
  opacity: 0;
  transform: translateX(30px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-icon {
  font-size: 1.7rem;
  line-height: 1;
}

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toast-kicker {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fde047;
}

.toast-body strong {
  font-size: 0.92rem;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(36px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ===== Magnetic Tactile Drag & Drop Ghost & Glowing Snap Rails ===== */
.magnetic-drag-ghost {
  position: fixed;
  z-index: 1200;
  pointer-events: none;
  transform: translate(-50%, -65%) scale(1.06) rotate(-2deg);
  padding: 8px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.88rem;
  border: 2px solid #fde047;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.48), 0 0 18px rgba(250, 204, 21, 0.45);
  white-space: nowrap;
}

.puzzle-piece.drop-before {
  box-shadow: 0 -4px 0 0 #fde047, 0 -6px 16px rgba(250, 204, 21, 0.65);
}

.puzzle-piece.drop-after {
  box-shadow: 0 4px 0 0 #fde047, 0 6px 16px rgba(250, 204, 21, 0.65);
}

.puzzle-clamp-body.drop-inside {
  outline: 2.5px dashed #fde047;
  background: rgba(250, 204, 21, 0.14);
}

/* ===== AAA Game Engineering Lab Modal ===== */
.nav-btn-lab {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.28), rgba(56, 189, 248, 0.2));
  border-color: rgba(192, 132, 252, 0.58);
  color: #f3e8ff;
}

.nav-btn-lab:hover {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.45), rgba(56, 189, 248, 0.34));
  border-color: #c084fc;
}

.engine-lab-modal {
  max-width: 940px;
}

.lab-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.lab-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.72);
  color: #cbd5e1;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.16s ease;
}

.lab-tab:hover {
  border-color: #38bdf8;
  color: #f8fafc;
}

.lab-tab.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.3), rgba(168, 85, 247, 0.32));
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.25);
}

.lab-body {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(240px, 1fr);
  gap: 14px;
  align-items: start;
}

@media (max-width: 820px) {
  .lab-body {
    grid-template-columns: 1fr;
  }
}

.lab-stage-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.engine-lab-canvas {
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 2px solid rgba(56, 189, 248, 0.35);
  background: #090f24;
  cursor: crosshair;
  touch-action: none;
}

.lab-tip {
  font-size: 0.78rem;
  color: #bae6fd;
  text-align: center;
  font-weight: 600;
}

.lab-sidebar {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.72);
  border: 1.5px solid rgba(148, 163, 184, 0.22);
}

.lab-term-pill {
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.16);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
}

.lab-topic-title {
  margin: 0;
  font-size: 1.05rem;
  color: #f8fafc;
}

.lab-kid-copy {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.4;
  color: #e2e8f0;
}

.lab-pro-copy {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.38;
  color: #94a3b8;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.72);
}

.lab-toggle-btn {
  width: 100%;
  justify-content: center;
}

.lab-meters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.lab-meter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 6px;
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.lab-meter span {
  font-size: 0.66rem;
  color: #94a3b8;
  font-weight: 700;
}

.lab-meter strong {
  font-size: 0.86rem;
  color: #4ade80;
}

.lab-extra-stat {
  font-size: 0.74rem;
  color: #cbd5e1;
  text-align: center;
  min-height: 1.2em;
}

/* ===== Lab AAA Quick Challenge Quiz & Mastered Tab ===== */
.lab-tab.mastered {
  border-color: rgba(74, 222, 128, 0.55);
}

.lab-quiz-box {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.78);
  border: 1.5px solid rgba(250, 204, 21, 0.38);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lab-quiz-box.is-mastered {
  border-color: rgba(74, 222, 128, 0.6);
  background: rgba(6, 78, 59, 0.25);
}

.lab-quiz-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: #fde047;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lab-quiz-box.is-mastered .lab-quiz-title {
  color: #4ade80;
}

.lab-quiz-q {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: #f8fafc;
}

.lab-quiz-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lab-quiz-opt {
  flex: 1 1 140px;
  padding: 6px 9px;
  border-radius: 9px;
  border: 1.5px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.lab-quiz-opt:hover {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.18);
}

.lab-quiz-opt.correct {
  border-color: #4ade80;
  background: rgba(34, 197, 94, 0.25);
  color: #dcfce7;
}

.lab-quiz-msg {
  font-size: 0.76rem;
  font-weight: 700;
}

.lab-quiz-msg.good {
  color: #4ade80;
}

.lab-quiz-msg.warn {
  color: #fbbf24;
}

/* Ensure progress fill span renders cleanly in Lab AAA, Badges & Garage modals */
.garage-progress-fill {
  display: block;
  height: 100%;
}

.engine-lab-modal .lab-quiz-box {
  padding: 8px 10px;
  gap: 5px;
}

.engine-lab-modal .lab-quiz-opt {
  padding: 5px 8px;
}

/* Endless Arcade Mode ("Corrida Espacial") */
.nav-btn-arcade {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.28), rgba(236, 72, 153, 0.32));
  border-color: rgba(216, 180, 254, 0.6);
  color: #f5d0fe;
}

.nav-btn-arcade:hover {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.45), rgba(236, 72, 153, 0.48));
}

.arcade-hud-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(88, 28, 135, 0.65), rgba(157, 23, 77, 0.48));
  border: 1px solid rgba(216, 180, 254, 0.48);
  font-size: 0.84rem;
  font-weight: 800;
}

.arcade-hud-bar.hidden {
  display: none;
}

.arcade-chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  color: #f8fafc;
}

.arcade-combo {
  color: #fde047;
}

.arcade-score {
  color: #7dd3fc;
}

.arcade-exit-btn {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.55);
  background: rgba(239, 68, 68, 0.22);
  color: #fecaca;
  font-weight: 700;
  cursor: pointer;
}

.arcade-exit-btn:hover {
  background: rgba(239, 68, 68, 0.4);
}

/* Holographic Ghost Replay Toggle */
.btn-ghost-toggle.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.28), rgba(14, 165, 233, 0.35));
  border-color: rgba(103, 232, 249, 0.75);
  color: #cffafe;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.35);
}

/* Companion Drones & Smart Progressive Hint Nudge */
.drone-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.drone-section-head h4 {
  margin: 0;
  font-size: 0.98rem;
  color: #e2e8f0;
}

.drone-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2.5px solid #38bdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  margin: 0 auto 8px;
}

@keyframes hintNudgePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.65);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(250, 204, 21, 0);
    transform: scale(1.05);
  }
}

.btn-hint.hint-nudge {
  animation: hintNudgePulse 1.3s ease-in-out infinite;
  border-color: #facc15;
}

/* Exportable Space Passport & Certificate Modal */
.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.passport-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.passport-input {
  flex: 1;
  min-width: 210px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid rgba(56, 189, 248, 0.45);
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  font-size: 0.95rem;
  font-weight: 700;
}

.passport-canvas-wrap {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: #070b1e;
}

.passport-canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* 60fps Planet Biome Canvas & AAA Orbital Telemetry */
.planet-biome-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.planet-route-svg {
  position: relative;
  z-index: 1;
}

.planet-aaa-telemetry {
  position: absolute;
  left: 10px;
  bottom: 8px;
  z-index: 4;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(7, 11, 30, 0.78);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #bae6fd;
  font-size: 0.73rem;
  font-weight: 700;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.region-hub-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
  font-size: 0.78rem;
  font-weight: 700;
}

/* 3-Act Orbital Cinema, Replay Button & Space Fun Fact */
.planet-stage-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.replay-orbital-btn {
  border-color: rgba(251, 146, 60, 0.55) !important;
  color: #fed7aa !important;
}

.mission-deck-fact {
  margin: 4px 0 0;
  font-size: 0.79rem;
  color: #7dd3fc;
  line-height: 1.35;
}

@keyframes shipOrbitalLiftoff {
  0% {
    transform: translate(-50%, -50%) rotate(var(--ship-rot, 0deg)) scale(1);
    opacity: 1;
  }
  35% {
    transform: translate(-50%, -65%) rotate(-90deg) scale(1.1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -260%) rotate(-90deg) scale(0.55);
    opacity: 0;
  }
}

.flying-starship.ship-liftoff {
  animation: shipOrbitalLiftoff 0.62s cubic-bezier(0.32, 0, 0.67, 0) forwards;
}

@keyframes chunkStreamPop {
  0% {
    opacity: 0;
    transform: scale(0.94);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.planet-route-svg.streaming-chunks {
  animation: chunkStreamPop 0.9s ease-out both;
}

/* Act 2 Galaxy Transit Hide Surface + Act 4 Staggered Level Node Reveal */
.flight-svg-wrap.galaxy-transit .planet-route-svg,
.flight-svg-wrap.galaxy-transit .flying-starship {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

@keyframes baseNodePop {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

.planet-route-svg.streaming-chunks .map-base-node {
  opacity: 0;
  animation: baseNodePop 0.42s ease-out var(--node-delay, 0ms) forwards;
}

/* Interactive Step-by-Step Kids Guided Tutorial Bar */
.guided-tutorial-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.24), rgba(168, 85, 247, 0.26));
  border: 1.5px solid rgba(250, 204, 21, 0.65);
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.2);
}

.guided-tutorial-bar.hidden {
  display: none;
}

.tutorial-icon {
  font-size: 1.45rem;
  line-height: 1;
  flex-shrink: 0;
}

.tutorial-copy {
  flex: 1;
  min-width: 0;
}

.tutorial-dots {
  display: flex;
  gap: 5px;
  margin-bottom: 3px;
}

.tut-dot {
  width: 18px;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.35);
}

.tut-dot.done {
  background: #34d399;
}

.tut-dot.active {
  background: #facc15;
}

.tutorial-msg {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.3;
}

.tutorial-dismiss-btn {
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.5);
  color: #cbd5e1;
  border-radius: 8px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  flex-shrink: 0;
}

@keyframes runPulseGlow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.8), 0 0 18px rgba(250, 204, 21, 0.55);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(52, 211, 153, 0), 0 0 26px rgba(250, 204, 21, 0.85);
    transform: scale(1.06);
  }
}

.btn-run.tutorial-pulse-run {
  animation: runPulseGlow 1.15s ease-in-out infinite;
  border: 2px solid #fde047;
}

/* AAA Engine X-Ray Toggle & Bouncing Finger Pointer for Kids */
.btn-xray-toggle.active {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.28), rgba(6, 182, 212, 0.34));
  border-color: rgba(52, 211, 153, 0.8);
  color: #a7f3d0;
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.35);
}

@keyframes fingerBounce {
  0%, 100% {
    transform: translate(-50%, 0);
  }
  50% {
    transform: translate(-50%, -6px);
  }
}

.palette-piece.hint-glow {
  position: relative;
}

.palette-piece.hint-glow::after {
  content: '👆';
  position: absolute;
  left: 50%;
  top: -18px;
  font-size: 1.05rem;
  pointer-events: none;
  animation: fingerBounce 0.9s ease-in-out infinite;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

/* Pilot XP Pill, Space Quests Modal & Compact Controls Bar Polish */
.mission-stats-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.xp-level-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(168, 85, 247, 0.25));
  border: 1px solid rgba(125, 211, 252, 0.55);
  color: #e0f2fe;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.xp-level-pill:hover {
  border-color: #facc15;
}

.xp-mini-track {
  width: 38px;
  height: 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  overflow: hidden;
  display: inline-block;
}

.xp-mini-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #facc15);
  transition: width 0.35s ease;
}

.quests-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.quest-card {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.quest-card.done {
  border-color: rgba(52, 211, 153, 0.65);
  background: rgba(6, 78, 59, 0.32);
}

.quest-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.quest-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: #f8fafc;
}

.quest-reward {
  font-size: 0.78rem;
  font-weight: 800;
  color: #facc15;
  white-space: nowrap;
}

.quest-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quest-bar-row .garage-bar-track {
  flex: 1;
}

.quest-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: #94a3b8;
}

.controls-bar {
  gap: 6px;
  flex-wrap: wrap;
}

.controls-bar .btn {
  padding: 7px 11px;
  font-size: 0.84rem;
}

/* Pilot Center Tabs, Match History Logbook & Google Cloud/Backup Cards */
.pilot-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 10px;
}

.pilot-tab {
  flex: 1;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.65);
  color: #cbd5e1;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}

.pilot-tab.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(168, 85, 247, 0.3));
  border-color: #7dd3fc;
  color: #f8fafc;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 290px;
  overflow-y: auto;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: 0.84rem;
}

.history-title {
  font-weight: 700;
  color: #f8fafc;
}

.history-stars {
  color: #facc15;
  letter-spacing: 1px;
}

.history-meta {
  color: #94a3b8;
  font-size: 0.78rem;
  white-space: nowrap;
}

.profile-cloud-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cloud-status-card,
.backup-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.cloud-status-card.connected {
  border-color: rgba(52, 211, 153, 0.7);
}

.backup-actions {
  display: flex;
  gap: 8px;
}

.backup-import-label {
  cursor: pointer;
}

/* Global Galaxy Leaderboard & History Polish */
.history-empty {
  padding: 14px 12px;
  text-align: center;
}

.history-row.leaderboard-self {
  border-color: rgba(250, 204, 21, 0.72);
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.14), rgba(56, 189, 248, 0.16));
}

.lb-medal {
  display: inline-block;
  min-width: 26px;
  color: #facc15;
}

/* =========================================================
   UX/DX RESPONSIVE POLISH (DESKTOP 1280+ | TABLET | MOBILE 390px)
   ========================================================= */
@media (min-width: 1180px) {
  .topbar-inner {
    flex-wrap: nowrap;
  }

  .controls-bar {
    flex-wrap: nowrap;
    gap: 5px;
  }

  .controls-bar .btn {
    padding: 6px 9px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
}

@media (max-width: 900px) {
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .topbar-inner {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .brand {
    flex-shrink: 0;
  }

  .topbar-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
    padding-bottom: 2px;
  }

  .topbar-actions::-webkit-scrollbar {
    display: none;
  }

  .game-layout {
    gap: 10px;
    padding: 8px 10px 14px;
  }

  .canvas-frame {
    min-height: 240px;
    max-height: 38dvh;
  }

  .controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .controls-bar .btn {
    flex: 1 1 auto;
    min-height: 40px;
    justify-content: center;
  }

  .controls-bar .btn-run {
    flex: 1 1 42%;
  }
}

@media (max-width: 600px) {
  .brand-name {
    font-size: 0.96rem;
  }

  .level-pill {
    font-size: 0.72rem;
    padding: 2px 7px;
  }

  .mission-title-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .mission-title-row h1 {
    font-size: 1.02rem;
  }

  .mascot-bubble {
    font-size: 0.8rem;
    padding: 7px 10px;
  }

  .guided-tutorial-bar {
    padding: 7px 10px;
    gap: 8px;
  }

  .tutorial-msg {
    font-size: 0.78rem;
  }

  .modal-card {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: 92dvh;
    overflow-y: auto;
    padding: 14px;
    border-radius: 16px;
  }

  .pilot-tabs {
    display: flex;
    flex-shrink: 0;
    min-height: 38px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .pilot-tabs::-webkit-scrollbar {
    display: none;
  }

  .pilot-tab {
    flex: 0 0 auto;
    white-space: nowrap;
    font-size: 0.78rem;
    padding: 7px 10px;
  }

  .galaxy-ribbon {
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 4px;
  }

  .mission-deck {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .mission-launch-btn {
    width: 100%;
    min-height: 44px;
  }

  .quests-list {
    grid-template-columns: 1fr;
  }

  .history-row {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* Ranking Toolbar & Mobile Modal Grid Refinements */
.ranking-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

@media (max-width: 600px) {
  .modal-head {
    gap: 8px;
  }

  .badges-grid {
    grid-template-columns: 1fr;
  }

  .skin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
