.game-lab {
  --lab-green: #69ffac;
  --lab-purple: #9b7bff;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 201, 77, .09), transparent 25rem),
    radial-gradient(circle at 86% 35%, rgba(53, 224, 255, .07), transparent 28rem),
    #07080c;
}

.lab-hero {
  padding: clamp(3rem, 7vw, 6.4rem) 0 2.6rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 201, 77, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 201, 77, .055) 1px, transparent 1px);
  background-size: 36px 36px;
}

.lab-hero__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
  gap: clamp(2rem, 7vw, 5rem);
  align-items: end;
}

.lab-hero h1 {
  margin: 0;
  font: clamp(2.6rem, 9vw, 6.7rem)/1.08 var(--font-display);
  letter-spacing: -.07em;
}

.lab-hero h1 em { color: var(--amber); font-style: normal; text-shadow: 0 0 30px rgba(255, 201, 77, .42); }
.lab-hero p:not(.eyebrow) { max-width: 680px; margin: 1.3rem 0 0; color: var(--text-dim); font-size: clamp(1rem, 2.2vw, 1.25rem); }

.lab-progress {
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(11, 14, 21, .82);
  box-shadow: var(--shadow);
}

.lab-progress > span,
.lab-progress > strong { display: block; }
.lab-progress > span { color: var(--text-dim); font: .55rem/1.5 var(--font-display); letter-spacing: .12em; text-transform: uppercase; }
.lab-progress > strong { margin: .5rem 0 .75rem; color: var(--amber); font: 1.15rem/1.5 var(--font-display); }
.lab-progress > div { height: 8px; overflow: hidden; border: 1px solid var(--line); background: #050609; }
.lab-progress i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--amber), var(--cyan)); box-shadow: var(--glow-cyan); transition: width .28s ease; }
.lab-progress button { margin-top: .8rem; padding: 0; border: 0; background: none; color: var(--cyan); cursor: pointer; font-weight: 800; }

.lab-shell {
  width: min(100% - 1.5rem, 1500px);
  margin: 1.5rem auto clamp(2rem, 6vw, 5rem);
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(480px, 1.05fr);
  gap: 1rem;
}

.lab-game-panel,
.lab-code-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #303a51;
  border-radius: 14px;
  background: #0a0d14;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .5);
}

.panel-title {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid #303a51;
  background: #131925;
  font: .53rem/1.4 var(--font-display);
  letter-spacing: .1em;
}

.panel-title span { color: var(--text-dim); }
.panel-title strong { color: var(--lab-green); }
.panel-title strong.is-error { color: var(--neon); }
.panel-title strong.is-dirty { color: var(--amber); }

.lab-screen { position: relative; aspect-ratio: 720 / 440; overflow: hidden; background: #020409; }
.lab-screen canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.game-hud {
  position: absolute;
  inset: .65rem .75rem auto;
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  pointer-events: none;
  color: rgba(255,255,255,.7);
  font: clamp(.39rem, 1vw, .56rem)/1.5 var(--font-display);
  text-shadow: 0 2px 3px #000;
}
.game-hud b { color: #fff; }

.lab-game-actions,
.editor-toolbar,
.run-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .8rem 1rem;
  border-top: 1px solid #222b3d;
  color: var(--text-dim);
  font-size: .78rem;
}

.lab-game-actions button,
.editor-toolbar button {
  padding: .45rem .65rem;
  border: 1px solid #37435d;
  border-radius: 6px;
  background: #161d2a;
  color: var(--text);
  cursor: pointer;
  font-size: .72rem;
  font-weight: 800;
}
.lab-game-actions button:hover,
.editor-toolbar button:hover { border-color: var(--cyan); }

.touch-pad {
  display: none;
  grid-template-columns: auto auto auto 1fr;
  align-items: center;
  gap: .45rem;
  padding: .8rem;
  border-top: 1px solid #222b3d;
}
.touch-pad div { display: grid; gap: .3rem; }
.touch-pad button {
  min-width: 52px;
  min-height: 52px;
  border: 1px solid #42506c;
  border-radius: 10px;
  background: #171e2d;
  color: var(--text);
  touch-action: none;
  user-select: none;
  font-weight: 900;
}
.touch-pad button.is-pressed { border-color: var(--cyan); background: #24334b; transform: translateY(1px); }
.touch-pad .touch-fire { justify-self: end; min-width: 90px; border-color: rgba(255, 201, 77, .55); color: var(--amber); }

.mission-console { padding: 1rem; border-bottom: 1px solid #222b3d; background: linear-gradient(135deg, rgba(255,201,77,.07), transparent 45%); }
.mission-console label { display: block; margin-bottom: .35rem; color: var(--cyan); font: .5rem/1.5 var(--font-display); letter-spacing: .1em; text-transform: uppercase; }
.mission-console select {
  width: 100%;
  padding: .7rem 2.2rem .7rem .75rem;
  border: 1px solid #3b4660;
  border-radius: 7px;
  background: #111725;
  color: var(--text);
  font: 700 .88rem/1.4 var(--font-body);
}
.mission-console h2 { margin: .9rem 0 .3rem; color: var(--amber); font: clamp(.7rem, 1.5vw, .9rem)/1.6 var(--font-display); }
.mission-console p { min-height: 3.2em; margin: 0; color: var(--text-dim); font-size: .9rem; line-height: 1.55; }
.mission-target { display: flex; align-items: center; gap: .65rem; margin-top: .75rem; }
.mission-target span { color: var(--text-faint); font: .48rem/1.5 var(--font-display); text-transform: uppercase; }
.mission-target code { padding: .25rem .45rem; border: 1px solid rgba(105,255,172,.24); border-radius: 5px; background: rgba(105,255,172,.06); color: var(--lab-green); font-size: .78rem; }

.editor-toolbar { border-top: 0; border-bottom: 1px solid #222b3d; background: #0d121c; }
.editor-toolbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .7rem; }

#code-editor {
  display: block;
  width: 100%;
  min-height: 490px;
  resize: vertical;
  border: 0;
  border-radius: 0;
  padding: 1rem 1.1rem 2rem;
  background:
    linear-gradient(90deg, #0d121c 0 3.1rem, #273047 3.1rem 3.15rem, #080b11 3.15rem);
  color: #d8e2f5;
  caret-color: var(--amber);
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  tab-size: 2;
  white-space: pre;
}
#code-editor:focus { outline: 0; box-shadow: inset 0 0 0 2px rgba(53,224,255,.28); }

.run-row { align-items: stretch; min-height: 72px; background: #0d121c; }
.run-row .btn { flex: 0 0 auto; padding: .85rem 1.1rem; }
#terminal-output {
  flex: 1;
  min-width: 0;
  padding: .55rem .7rem;
  border-left: 2px solid var(--lab-green);
  background: rgba(105,255,172,.045);
  color: var(--lab-green);
  font: .75rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#terminal-output.is-error { border-left-color: var(--neon); background: rgba(255,47,69,.05); color: #ff8290; }

.bridge { padding: clamp(1.2rem, 4vw, 2.2rem); border: 1px solid #34405a; border-radius: var(--radius); background: linear-gradient(145deg, #111724, #0a0d14); box-shadow: var(--shadow); }
.bridge__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.bridge__head h2 { margin: 0; font-size: clamp(1.25rem, 3vw, 2rem); line-height: 1.25; }
.bridge__badge { flex: 0 0 auto; padding: .55rem .75rem; border: 1px solid rgba(255,201,77,.45); border-radius: 999px; color: var(--amber); font: .5rem/1.4 var(--font-display); }
.bridge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.bridge-grid article { padding: 1rem; border: 1px solid #2a344a; border-radius: 10px; background: rgba(255,255,255,.025); }
.bridge-grid article > span,
.bridge-code > span { display: block; margin-bottom: .45rem; color: var(--cyan); font: .48rem/1.5 var(--font-display); letter-spacing: .1em; text-transform: uppercase; }
.bridge-grid strong { display: block; color: var(--text); }
.bridge-grid p { margin: .45rem 0 0; color: var(--text-dim); font-size: .88rem; }
.bridge-code pre { min-height: 100px; margin: 0; overflow: auto; padding: .8rem; border-radius: 7px; background: #05070b; color: var(--lab-green); font-size: .74rem; }

.code-map__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.code-map__grid article { padding: 1.25rem; border-top: 3px solid var(--line); background: rgba(255,255,255,.025); }
.code-map__grid article:nth-child(3n+1) { border-color: var(--amber); }
.code-map__grid article:nth-child(3n+2) { border-color: var(--cyan); }
.code-map__grid article:nth-child(3n) { border-color: var(--lab-purple); }
.code-map__grid b { color: var(--amber); font: .58rem/1.4 var(--font-display); }
.code-map__grid h3 { margin: .6rem 0 .35rem; }
.code-map__grid p { margin: 0; color: var(--text-dim); font-size: .9rem; }

.orientation {
  width: min(100% - 2rem, 660px);
  max-height: min(90vh, 760px);
  overflow: auto;
  border: 1px solid rgba(255,201,77,.6);
  border-radius: 16px;
  padding: clamp(1.3rem, 5vw, 2.4rem);
  background: #0c1018;
  color: var(--text);
  box-shadow: 0 0 0 1px rgba(255,201,77,.15), 0 30px 100px #000;
}
.orientation::backdrop { background: rgba(2,3,6,.86); backdrop-filter: blur(6px); }
.orientation__signal { color: var(--cyan); font: .55rem/1.5 var(--font-display); letter-spacing: .14em; }
.orientation h2 { margin: .8rem 0; color: var(--amber); font: clamp(1.2rem, 4vw, 2rem)/1.35 var(--font-display); }
.orientation p { color: var(--text-dim); }
.orientation strong { color: var(--text); }
.orientation .btn { width: 100%; margin-top: .8rem; }

@media (max-width: 1050px) {
  .lab-shell { grid-template-columns: 1fr; width: min(100% - 1rem, 820px); }
  #code-editor { min-height: 440px; }
}

@media (max-width: 760px) {
  .lab-hero__inner,
  .bridge-grid,
  .code-map__grid { grid-template-columns: 1fr; }
  .lab-hero { padding-top: 2.5rem; }
  .lab-shell { margin-top: .75rem; }
  .touch-pad { display: grid; }
  .lab-game-actions span { display: none; }
  .bridge__head { align-items: flex-start; flex-direction: column; }
  .run-row { flex-direction: column; }
  #terminal-output { border-top: 2px solid var(--lab-green); border-left: 0; }
  #terminal-output.is-error { border-top-color: var(--neon); }
  #code-editor { min-height: 390px; font-size: 12px; }
}

@media (max-width: 540px) {
  .game-lab .nav { gap: .45rem; }
  .game-lab .nav a { font-size: .58rem; letter-spacing: .04em; }
  .game-hud { inset: .35rem .4rem auto; }
  .touch-pad button { min-width: 46px; min-height: 48px; }
  .touch-pad .touch-fire { min-width: 78px; }
  .editor-toolbar { flex-wrap: wrap; }
  .editor-toolbar span { order: 3; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .lab-progress i { transition: none; }
}
