:root {
  --ink: #0c1329;
  --muted: #475569;
  --soft: #7b8797;
  --accent: #d97706;
  --accent-2: #0369a1;
  --panel: #ffffff;
  --edge: #dbe3ed;
  --bg: #f4f1ea;
  --max: 1440px;
  --radius: 18px;
  --shadow: 0 24px 40px rgba(15, 23, 42, 0.15);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% 8%, rgba(3, 105, 161, 0.18), transparent 35%),
    radial-gradient(circle at 12% 22%, rgba(217, 119, 6, 0.2), transparent 40%),
    linear-gradient(180deg, #f7f4ef 0%, #f2efe8 100%);
}

h1,
h2,
h3 {
  margin: 0 0 12px;
  font-family: "Fraunces", "Georgia", serif;
}

h1 {
  font-size: clamp(2.3rem, 4vw, 3.8rem);
}

h2 {
  font-size: clamp(1.8rem, 2.5vw, 2.7rem);
}

p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 20px 50px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.24em;
}

.nav {
  display: flex;
  gap: 18px;
  color: var(--muted);
}

.hero {
  margin-top: 28px;
  max-width: 980px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--soft);
}

.hero-actions {
  margin-top: 22px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 11px 18px;
  border: 1px solid var(--edge);
  font-weight: 600;
}

.btn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), #ea580c);
}

.panel {
  margin-top: 72px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--edge);
  padding: 28px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.card {
  background: #fff;
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 16px;
}

#games {
  margin-top: 44px;
}

.section-title {
  margin-bottom: 20px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  gap: 18px;
}

.game-list {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.game-option {
  width: 100%;
  text-align: left;
  border: 1px solid var(--edge);
  background: #f8fafc;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.game-option:last-child {
  margin-bottom: 0;
}

.game-option.active {
  border-color: var(--accent-2);
  background: #ecfeff;
  transform: translateY(-1px);
}

.game-option .title {
  display: block;
  color: var(--ink);
  font-weight: 700;
}

.game-option .desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.play-surface {
  min-height: 720px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.game-meta {
  margin-bottom: 14px;
}

.game-meta p:last-child {
  margin-bottom: 0;
}

.lab-game h3 {
  margin-bottom: 8px;
}

.hud {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.hud-item {
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(241, 245, 249, 0.9));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  min-width: 96px;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.action-row button,
.choice-grid button {
  font: inherit;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.action-row button:hover,
.choice-grid button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
}

.src-debug-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: -2px 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(14, 165, 233, 0.28);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(239, 246, 255, 0.96), rgba(224, 242, 254, 0.9));
}

.src-mission-card {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.2fr);
  gap: 18px 24px;
  align-items: center;
  margin: 0 0 16px;
  padding: 20px;
  border: 1px solid rgba(56, 189, 248, 0.38);
  border-radius: 16px;
  background:
    radial-gradient(circle at right top, rgba(34, 211, 238, 0.2), transparent 34%),
    linear-gradient(135deg, #0f2742, #163d61);
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.16);
}

.src-mission-copy h4,
.src-track-heading h4 {
  margin: 0 0 6px;
  color: #f8fafc;
  font-size: 1.15rem;
}

.src-mission-copy p:not(.src-mission-kicker) {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.9rem;
  line-height: 1.5;
}

.src-mission-kicker,
.src-panel-kicker {
  margin: 0 0 5px;
  color: #38bdf8;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.src-starter-rigs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.src-starter-rig {
  min-height: 92px;
  padding: 11px;
  border: 1px solid rgba(186, 230, 253, 0.35);
  border-radius: 12px;
  color: #e0f2fe;
  background: rgba(15, 23, 42, 0.42);
  cursor: pointer;
  text-align: left;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.src-starter-rig:hover,
.src-starter-rig:focus-visible,
.src-starter-rig.is-recommended {
  border-color: #67e8f9;
  background: rgba(14, 116, 144, 0.36);
  transform: translateY(-2px);
}

.src-starter-rig span,
.src-starter-rig strong,
.src-starter-rig small {
  display: block;
}

.src-starter-rig span { color: #67e8f9; font-size: 0.67rem; font-weight: 700; }
.src-starter-rig strong { margin: 4px 0; font-size: 0.85rem; }
.src-starter-rig small { color: #bae6fd; font-size: 0.72rem; line-height: 1.3; }

.src-steps {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  color: #e0f2fe;
  font-size: 0.78rem;
  list-style: none;
}

.src-steps li { display: inline-flex; align-items: center; gap: 7px; }
.src-steps b { display: grid; width: 19px; height: 19px; place-items: center; border-radius: 50%; color: #082f49; background: #67e8f9; font-size: 0.68rem; }

.src-debug-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #075985;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.src-debug-select {
  min-width: 160px;
  border: 1px solid rgba(14, 165, 233, 0.35);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  color: #0f172a;
  background: linear-gradient(180deg, #ffffff, #e0f2fe);
}

.src-part-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 10px;
}

.src-part-chip {
  border-style: dashed;
  user-select: none;
}

.src-part-chip.is-selected {
  border-color: #0ea5e9;
  color: #075985;
  background: linear-gradient(180deg, #ecfeff, #bae6fd);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.16);
}

.bb-level-picker-label {
  font-size: 0.82rem;
  color: #64748b;
  align-self: center;
  margin-left: 4px;
}

.bb-level-picker {
  border: 1px solid rgba(148, 163, 184, 0.55);
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  background: linear-gradient(180deg, #ffffff, #f1f5f9);
  color: #0f172a;
}

.board {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 280px;
  border: 1px solid var(--edge);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(3, 105, 161, 0.08), rgba(217, 119, 6, 0.08)),
    #fff;
  overflow: hidden;
}

.target {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, #ef4444 40%, #991b1b 100%);
  border: none;
}

.status {
  margin-top: 10px;
  color: #64748b;
  font-size: 0.95rem;
  min-height: 24px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 150px));
  gap: 10px;
}

.choice {
  border: 2px solid var(--edge);
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  background: #fff;
}

.choice.active {
  border-color: var(--accent-2);
  background: #ecfeff;
}

.src-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.src-panel {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 14px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 245, 249, 0.95));
}

.src-panel h4 {
  margin: 2px 0 6px;
}

.src-panel-kicker { color: #0284c7; }

.src-help {
  margin: 0 0 8px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.src-hint {
  margin: 8px 0 0;
  font-size: 0.88rem;
  color: #475569;
  min-height: 44px;
}

.src-draw {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: #f8fafc;
  touch-action: none;
  cursor: crosshair;
}

.src-world-wrap {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 14px;
  padding: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 245, 249, 0.95));
}

.src-track-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 4px 8px;
}

.src-track-heading h4 { color: #0f172a; }

#src-track-goal {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  color: #075985;
  background: #e0f2fe;
  font-size: 0.72rem;
  font-weight: 700;
}

.src-world {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
  border: 1px solid rgba(30, 41, 59, 0.38);
  background: #020617;
}

/* Sketch Rig Challenge: make the builder read like a deliberate workshop, not a raw debug panel. */
.src-game .src-command-bar {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(280px, 1fr) auto auto;
  gap: 10px;
  align-items: stretch;
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid rgba(56, 189, 248, 0.34);
  border-radius: 14px;
  background: linear-gradient(135deg, #102a43, #173e62);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.src-game .src-level-control,
.src-game .src-run-control,
.src-game .src-edit-control {
  display: flex;
  gap: 7px;
  align-items: center;
}

.src-game .src-level-control { min-width: 0; }

.src-game .src-level-readout {
  display: grid;
  min-width: 96px;
  line-height: 1.1;
}

.src-game .src-level-readout span,
.src-game .src-level-readout small {
  color: #bae6fd;
  font-size: 0.67rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.src-game .src-level-readout strong {
  margin: 3px 0 2px;
  overflow: hidden;
  color: #f8fafc;
  font-size: 0.94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.src-game .src-command-bar .btn {
  min-height: 38px;
  border-color: rgba(186, 230, 253, 0.38);
  color: #e0f2fe;
  background: rgba(15, 23, 42, 0.26);
  font-size: 0.78rem;
}

.src-game .src-command-bar .btn:hover:not(:disabled),
.src-game .src-command-bar .btn:focus-visible {
  border-color: #67e8f9;
  background: rgba(14, 116, 144, 0.44);
}

.src-game .src-command-bar .src-run-button {
  min-width: 92px;
  border-color: #67e8f9;
  color: #082f49;
  background: linear-gradient(180deg, #a5f3fc, #67e8f9);
  box-shadow: 0 7px 16px rgba(8, 145, 178, 0.28);
  font-weight: 800;
}

.src-game .src-command-bar .src-run-button:hover,
.src-game .src-command-bar .src-run-button:focus-visible {
  color: #082f49;
  background: linear-gradient(180deg, #cffafe, #a5f3fc);
}

.src-game .src-command-bar .btn:disabled {
  cursor: not-allowed;
  opacity: 0.43;
}

.src-game .src-dev-tools { position: relative; }

.src-game .src-dev-tools .src-debug-panel {
  position: absolute;
  z-index: 8;
  top: calc(100% + 8px);
  right: 0;
  width: min(420px, calc(100vw - 36px));
  margin: 0;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.2);
}

.src-game .src-course-brief {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 0 12px;
  padding: 11px 13px;
  border: 1px solid rgba(125, 211, 252, 0.42);
  border-radius: 12px;
  background: linear-gradient(90deg, #ecfeff, #f8fafc);
}

.src-game .src-course-brief > div {
  display: grid;
  gap: 3px;
}

.src-game .src-course-label {
  color: #0369a1;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.src-game .src-course-brief strong {
  color: #0f172a;
  font-size: 0.86rem;
  line-height: 1.38;
}

.src-game .src-course-preview {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.src-game .src-course-preview li {
  padding: 5px 8px;
  border: 1px solid rgba(14, 116, 144, 0.26);
  border-radius: 999px;
  color: #0f766e;
  background: #fff;
  font-size: 0.69rem;
  font-weight: 800;
  white-space: nowrap;
}

.src-game .src-course-preview li.is-cleared {
  border-color: rgba(22, 163, 74, 0.35);
  color: #166534;
  background: #dcfce7;
}

.src-game .src-layout {
  grid-template-columns: minmax(340px, 0.82fr) minmax(430px, 1.4fr);
  gap: 14px;
}

.src-game .src-builder-panel {
  padding: 13px;
  border-color: rgba(14, 116, 144, 0.28);
  background:
    linear-gradient(90deg, rgba(14, 165, 233, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(14, 165, 233, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, #fbfeff, #eaf7fb);
  background-size: 20px 20px, 20px 20px, auto;
}

.src-game .src-part-palette {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 10px 0 8px;
}

.src-game .src-part-chip {
  display: grid;
  min-height: 53px;
  padding: 7px 8px;
  border-style: solid;
  border-left-width: 4px;
  border-color: rgba(100, 116, 139, 0.38);
  color: #1e293b;
  background: rgba(255, 255, 255, 0.86);
  cursor: pointer;
  text-align: left;
}

.src-game .src-part-chip b { font-size: 0.78rem; }
.src-game .src-part-chip small { margin-top: 2px; color: #64748b; font-size: 0.65rem; line-height: 1.15; }
.src-game .src-part-chip--structure { border-left-color: #64748b; }
.src-game .src-part-chip--wheel { border-left-color: #d97706; }
.src-game .src-part-chip--leg { border-left-color: #16a34a; }
.src-game .src-part-chip--fin { border-left-color: #2563eb; }
.src-game .src-part-chip--tail { border-left-color: #7c3aed; }
.src-game .src-part-chip--arm { border-left-color: #db2777; }

.src-game .src-part-chip:hover,
.src-game .src-part-chip:focus-visible,
.src-game .src-part-chip.is-selected {
  border-color: #0ea5e9;
  border-left-color: #0ea5e9;
  color: #075985;
  background: linear-gradient(180deg, #ecfeff, #cffafe);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
}

.src-game .src-placement-note {
  min-height: 32px;
  margin: 0 0 8px;
  color: #0f766e;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.4;
}

.src-game .src-draw {
  border: 2px solid rgba(14, 116, 144, 0.34);
  box-shadow: 0 8px 18px rgba(14, 116, 144, 0.08);
}

.src-game .src-draw:focus-visible,
.src-game .src-world:focus-visible,
.src-game button:focus-visible,
.src-game summary:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.55);
  outline-offset: 3px;
}

.src-game .src-canvas-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 8px 0 2px;
}

.src-game .src-canvas-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 999px;
  color: #334155;
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.63rem;
  font-weight: 700;
}

.src-game .src-canvas-legend span::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.src-game .src-legend-chassis { color: #0284c7 !important; }
.src-game .src-legend-wheel { color: #b45309 !important; }
.src-game .src-legend-leg { color: #15803d !important; }
.src-game .src-legend-stability { color: #7c3aed !important; }
.src-game .src-legend-com { color: #dc2626 !important; }

.src-game .src-inspect-panel {
  margin-top: 13px;
  padding: 12px;
  border: 1px solid rgba(79, 70, 229, 0.22);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(248, 250, 252, 0.96), rgba(238, 242, 255, 0.92));
}

.src-game .src-inspect-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.src-game .src-inspect-heading h4 { margin: 2px 0 0; }

.src-game .src-readiness-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  color: #475569;
  background: #e2e8f0;
  font-size: 0.68rem;
  font-weight: 800;
}

.src-game .src-readiness-badge[data-state="ready"] { color: #166534; background: #dcfce7; }
.src-game .src-readiness-badge[data-state="attention"] { color: #9a3412; background: #ffedd5; }

.src-game .src-readiness-copy {
  margin: 8px 0;
  color: #334155;
  font-size: 0.81rem;
  line-height: 1.45;
}

.src-game .src-analysis-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.src-game .src-analysis-item {
  display: grid;
  gap: 2px;
  min-height: 48px;
  padding: 7px 8px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
}

.src-game .src-analysis-item span { color: #64748b; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.src-game .src-analysis-item strong { color: #334155; font-size: 0.75rem; line-height: 1.22; }
.src-game .src-analysis-item.is-ready { border-color: rgba(34, 197, 94, 0.35); background: rgba(240, 253, 244, 0.84); }
.src-game .src-analysis-item.is-ready strong { color: #166534; }
.src-game .src-analysis-item.is-attention { border-color: rgba(249, 115, 22, 0.34); background: rgba(255, 247, 237, 0.85); }
.src-game .src-analysis-item.is-attention strong { color: #9a3412; }

.src-game .src-selection-inspector {
  display: grid;
  gap: 3px;
  margin-top: 9px;
  padding: 8px 9px;
  border-left: 3px solid #7c3aed;
  border-radius: 0 8px 8px 0;
  background: rgba(237, 233, 254, 0.68);
}

.src-game .src-selection-inspector strong { color: #4c1d95; font-size: 0.78rem; }
.src-game .src-selection-inspector span { color: #5b6173; font-size: 0.72rem; line-height: 1.35; }

.src-game .src-element-actions {
  display: flex;
  gap: 6px;
  margin: 8px 0;
}

.src-game .src-element-actions .btn { min-height: 34px; font-size: 0.72rem; }

.src-game .src-elements-list {
  display: grid;
  gap: 5px;
  max-height: 256px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.src-game .src-element-button {
  display: grid;
  width: 100%;
  gap: 2px;
  padding: 8px 9px;
  border: 1px solid rgba(148, 163, 184, 0.34);
  border-left: 4px solid #64748b;
  border-radius: 8px;
  color: #334155;
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  text-align: left;
}

.src-game .src-element-button strong { font-size: 0.75rem; }
.src-game .src-element-button span { color: #64748b; font-size: 0.68rem; line-height: 1.28; }
.src-game .src-element-button--chassis { border-left-color: #0284c7; }
.src-game .src-element-button--wheel, .src-game .src-element-button--loop { border-left-color: #d97706; }
.src-game .src-element-button--leg { border-left-color: #16a34a; }
.src-game .src-element-button--fin { border-left-color: #2563eb; }
.src-game .src-element-button--tail { border-left-color: #7c3aed; }
.src-game .src-element-button--arm { border-left-color: #db2777; }
.src-game .src-element-button.is-selected { border-color: #7c3aed; background: #f5f3ff; box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.13); }
.src-game .src-element-button.is-inactive { border-style: dashed; opacity: 0.62; }

.src-game .src-metrics-details { margin-top: 9px; }
.src-game .src-metrics-details summary { color: #475569; cursor: pointer; font-size: 0.72rem; font-weight: 800; }
.src-game .src-engineering-hud { gap: 5px; margin: 7px 0 0; }
.src-game .src-engineering-hud .hud-item { flex: 1 1 70px; min-width: 70px; padding: 6px 7px; }
.src-game .src-engineering-hud .hud-item strong { display: block; color: #64748b; font-size: 0.61rem; letter-spacing: 0.04em; text-transform: uppercase; }
.src-game .src-engineering-hud .hud-item div { margin-top: 2px; color: #0f172a; font-size: 0.78rem; font-weight: 800; }

.src-game .src-world-wrap {
  position: relative;
  padding: 10px;
  overflow: hidden;
  border-color: rgba(14, 116, 144, 0.3);
  background: linear-gradient(180deg, #f8fdff, #e9f6fb);
}

.src-game .src-track-heading { margin: 3px 4px 9px; }

.src-game .src-run-result {
  position: absolute;
  z-index: 4;
  right: 22px;
  bottom: 20px;
  left: 22px;
  max-width: 460px;
  padding: 15px;
  border: 1px solid rgba(186, 230, 253, 0.55);
  border-radius: 13px;
  color: #e0f2fe;
  background: linear-gradient(135deg, rgba(8, 47, 73, 0.95), rgba(15, 23, 42, 0.94));
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.35);
}

.src-game .src-run-result[data-outcome="success"] { border-color: rgba(134, 239, 172, 0.64); }
.src-game .src-run-result h4 { margin: 3px 0 5px; color: #fff; font-size: 1rem; }
.src-game .src-run-result p { margin: 0 0 11px; color: #cbd5e1; font-size: 0.8rem; line-height: 1.42; }
.src-game .src-result-kicker { color: #67e8f9; font-size: 0.65rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.src-game .src-run-result > div { display: flex; flex-wrap: wrap; gap: 7px; }
.src-game .src-run-result .btn { min-height: 35px; font-size: 0.74rem; }

.src-game .src-status-card {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(14, 165, 233, 0.26);
  border-radius: 10px;
  color: #0f4c6e;
  background: linear-gradient(90deg, #effcff, #f8fafc);
  font-size: 0.84rem;
  line-height: 1.4;
}

@media (max-width: 1220px) {
  .src-game .src-command-bar { grid-template-columns: 1fr 1fr; }
  .src-game .src-edit-control { justify-content: flex-end; }
  .src-game .src-dev-tools { justify-self: end; }
}

@media (max-width: 1100px) {
  .src-game .src-layout { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .src-game .src-command-bar { grid-template-columns: 1fr; gap: 8px; }
  .src-game .src-level-control,
  .src-game .src-run-control,
  .src-game .src-edit-control { justify-content: space-between; }
  .src-game .src-level-control .btn,
  .src-game .src-run-control .btn,
  .src-game .src-edit-control .btn { flex: 1 1 auto; }
  .src-game .src-level-readout { flex: 1 1 90px; }
  .src-game .src-dev-tools { justify-self: stretch; }
  .src-game .src-dev-tools > .btn { width: 100%; }
  .src-game .src-dev-tools .src-debug-panel { right: auto; left: 0; }
  .src-game .src-course-brief { align-items: flex-start; flex-direction: column; }
  .src-game .src-course-preview { justify-content: flex-start; }
  .src-game .src-part-palette { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .src-game .src-analysis-summary { grid-template-columns: 1fr 1fr; }
  .src-game .src-run-result { right: 12px; bottom: 12px; left: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .src-game *,
  .src-game *::before,
  .src-game *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

.lab-finish-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.82);
  text-align: center;
}

.lab-finish-overlay.show {
  display: flex;
}

.lab-finish-card {
  max-width: 320px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid rgba(226, 232, 240, 0.7);
  background: rgba(2, 6, 23, 0.86);
  color: #f8fafc;
}

.lab-finish-title {
  margin: 0 0 8px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.lab-finish-text {
  margin: 0 0 12px;
  color: #cbd5e1;
  font-size: 0.92rem;
}

.cm-grid-wrap {
  position: relative;
  display: inline-block;
}

.nr-game .status {
  color: #c4b5fd;
}

.nr-game .nr-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: #cbd5e1;
  margin-top: 0;
  margin-bottom: 10px;
}

.nr-game .nr-legend img {
  width: 16px;
  height: 16px;
  filter: invert(88%) sepia(14%) saturate(341%) hue-rotate(183deg) brightness(97%) contrast(95%);
}

.nr-game .hud-item {
  border-color: rgba(125, 211, 252, 0.42);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(30, 41, 59, 0.9));
  color: #e2e8f0;
}

.nr-game .hud-item strong {
  color: #a5f3fc;
}

.nr-game .hud-item div {
  color: #f5f3ff;
}

.site-footer {
  margin-top: 40px;
  border-top: 1px solid var(--edge);
  padding-top: 18px;
  color: var(--soft);
  font-size: 0.9rem;
}

.td-grid-wrap {
  margin-top: 10px;
}

.td-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
}

.legend.tower {
  background: #0ea5e9;
}

.legend.enemy {
  background: #dc2626;
}

.legend.core {
  background: #0f172a;
}

.td-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(28px, 46px));
  gap: 6px;
}

.td-cell {
  height: 42px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}

.td-cell:disabled {
  cursor: default;
}

.td-cell.tower {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
}

.td-cell.enemy {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

.td-cell.core {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #0f172a;
}

.bb-canvas-wrap {
  width: 100%;
  max-width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 80% -10%, rgba(56, 189, 248, 0.25), transparent 35%),
    radial-gradient(circle at 10% 110%, rgba(251, 146, 60, 0.18), transparent 40%),
    #0b132b;
  box-shadow:
    0 24px 40px rgba(15, 23, 42, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.bb-canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  filter: saturate(1.06) contrast(1.03);
}

.bb-resume-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: none;
  padding: 12px 24px;
  border-radius: 999px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(15, 23, 42, 0.9);
  color: #f8fafc;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 18px 35px rgba(2, 6, 23, 0.45);
}

.bb-resume-overlay.show {
  display: inline-flex;
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

.pf-game .hud {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.pf-game .hud-item {
  border: 1px solid rgba(251, 191, 143, 0.58);
  border-radius: 12px;
  padding: 9px 10px;
  background:
    linear-gradient(180deg, rgba(255, 247, 237, 0.96), rgba(255, 237, 213, 0.92)),
    radial-gradient(circle at 20% 0%, rgba(251, 146, 60, 0.2), transparent 35%);
  box-shadow:
    0 10px 18px rgba(88, 28, 21, 0.09),
    inset 0 1px 0 rgba(255, 255, 255, 0.84);
  position: relative;
  overflow: hidden;
}

.pf-game .hud-item::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.35) 48%, transparent 78%);
  transform: translateX(-120%);
  animation: pfHudShine 6s ease-in-out infinite;
  pointer-events: none;
}

.pf-game .hud-item strong {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7c2d12;
}

.pf-game .hud-item div {
  font-weight: 700;
  color: #431407;
  margin-top: 3px;
}

.pf-game .action-row {
  gap: 8px;
  margin-bottom: 10px;
}

.pf-game .action-row .btn.ghost {
  border-color: rgba(251, 191, 143, 0.72);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.96), rgba(255, 237, 213, 0.94));
  color: #431407;
  box-shadow: 0 6px 14px rgba(124, 45, 18, 0.12);
}

.pf-game .action-row .btn.ghost:hover {
  border-color: rgba(251, 146, 60, 0.72);
  box-shadow: 0 10px 20px rgba(124, 45, 18, 0.18);
}

.pf-game .status {
  color: #7c2d12;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.pf-theme-banner {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(251, 191, 143, 0.7);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, rgba(255, 237, 213, 0.95), rgba(254, 215, 170, 0.94));
  color: #7c2d12;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.pf-canvas-wrap {
  width: 100%;
  max-width: 100%;
  border: 1px solid rgba(190, 107, 96, 0.5);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 80% -10%, rgba(255, 189, 125, 0.26), transparent 42%),
    radial-gradient(circle at 16% 118%, rgba(190, 98, 126, 0.23), transparent 46%),
    linear-gradient(180deg, #ffe5c7, #f8c9af 72%, #f0b2a6);
  box-shadow:
    0 30px 50px rgba(127, 29, 29, 0.25),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.pf-canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  image-rendering: pixelated;
  filter: saturate(1.06) contrast(1.04);
}

.pf-overlay {
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
  z-index: 2;
  display: none;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid rgba(226, 232, 240, 0.85);
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  font: 700 1rem "Space Grotesk", "Segoe UI", sans-serif;
  letter-spacing: 0.03em;
}

.pf-overlay.show {
  display: inline-flex;
}

.pf-settings {
  display: grid;
  grid-template-columns: auto minmax(160px, 320px);
  gap: 8px 12px;
  align-items: center;
  margin: 10px 0 14px;
  max-width: 560px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 143, 0.56);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.96), rgba(255, 237, 213, 0.93));
}

.pf-settings label {
  color: #7c2d12;
  font-size: 0.88rem;
}

.pf-settings input[type="range"] {
  width: 100%;
  accent-color: #ea580c;
}

.pf-editor-panel {
  margin: 10px 0 14px;
  border: 1px solid rgba(251, 191, 143, 0.58);
  border-radius: 12px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.97), rgba(255, 237, 213, 0.94));
}

.pf-editor-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pf-editor-row input[type="range"] {
  flex: 1 1 220px;
  min-width: 180px;
  accent-color: #ea580c;
}

.pf-editor-row label,
.pf-editor-row strong {
  color: #7c2d12;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pf-editor-level-label {
  color: #7c2d12;
  font-size: 0.82rem;
  font-weight: 700;
  margin-left: 2px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 237, 213, 0.9);
  border: 1px solid rgba(251, 191, 143, 0.62);
}

.pf-editor-palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 6px;
  width: 100%;
}

.pf-editor-tile {
  border: 1px solid rgba(180, 83, 9, 0.3);
  border-radius: 10px;
  background: #fff7ed;
  color: #7c2d12;
  padding: 7px 8px;
  display: grid;
  gap: 2px;
  justify-items: start;
  text-align: left;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.pf-editor-tile .glyph {
  font: 700 0.95rem "Space Grotesk", "Consolas", monospace;
}

.pf-editor-tile .label {
  font-size: 0.7rem;
  line-height: 1.1;
}

.pf-editor-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(234, 88, 12, 0.62);
  box-shadow: 0 8px 14px rgba(124, 45, 18, 0.14);
}

.pf-editor-tile.active {
  border-color: rgba(234, 88, 12, 0.78);
  background: linear-gradient(180deg, #fff7ed, #fed7aa);
  box-shadow: 0 10px 18px rgba(124, 45, 18, 0.18);
}

.pf-editor-help {
  margin: 8px 0;
  color: #92400e;
  font-size: 0.82rem;
}

.pf-editor-advanced summary {
  cursor: pointer;
  color: #9a3412;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.pf-editor-json {
  width: 100%;
  min-height: 180px;
  border: 1px solid rgba(180, 83, 9, 0.3);
  border-radius: 10px;
  padding: 10px;
  resize: vertical;
  font: 500 0.78rem/1.4 "Space Grotesk", "Consolas", monospace;
  color: #431407;
  background: rgba(255, 255, 255, 0.86);
}

.pf-touch {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pf-touch-btn {
  border: 1px solid rgba(180, 83, 9, 0.42);
  border-radius: 999px;
  padding: 10px 16px;
  font: 700 0.9rem "Space Grotesk", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #fff7ed, #ffedd5);
  color: #7c2d12;
  min-width: 76px;
  box-shadow: 0 8px 16px rgba(127, 29, 29, 0.14);
}

.pf-touch-btn:active {
  transform: translateY(1px);
  box-shadow: 0 4px 8px rgba(127, 29, 29, 0.17);
}

@media (min-width: 901px) {
  .pf-touch {
    display: none;
  }
}

@media (max-width: 580px) {
  .pf-settings {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .pf-editor-row {
    align-items: stretch;
  }

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

  .src-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .src-layout {
    grid-template-columns: 1fr;
  }

  .src-mission-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .src-mission-card {
    padding: 16px;
  }

  .src-starter-rigs {
    grid-template-columns: 1fr;
  }

  .src-starter-rig {
    min-height: 0;
  }

  .src-track-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

@keyframes pfHudShine {
  0%,
  70%,
  100% {
    transform: translateX(-120%);
  }
  82% {
    transform: translateX(120%);
  }
}
