:root {
  --bg: #0f1116;
  --panel: #171b22;
  --panel-border: #2a3140;
  --text: #edf1f7;
  --muted: #9ba6b5;
  --accent: #53d1b6;
  --accent-2: #ffd166;
  --danger: #ff6b6b;
  --canvas: #06080c;
  --sidebar-width: 380px;
  --mobile-controls-height: 230px;
  --editor-height: 540px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(83, 209, 182, 0.12), transparent 30%),
    linear-gradient(180deg, #0c0f14, #0f1116 40%, #0a0d11);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 100vh minmax(320px, var(--sidebar-width));
  gap: 0;
  min-height: 100vh;
  align-items: start;
}

.inspector-panel {
  background: rgba(23, 27, 34, 0.82);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

.stage-panel {
  position: relative;
  width: 100vh;
  height: 100vh;
  padding: 0;
  margin: 0;
}

.stage-panel:fullscreen,
.stage-panel.is-fullscreen {
  width: 100vw;
  height: 100vh;
  background: var(--canvas);
}

.stage-display {
  position: relative;
  width: 100vh;
  height: 100vh;
}

.stage-panel:fullscreen .stage-display,
.stage-panel.is-fullscreen .stage-display {
  width: 100%;
  height: 100%;
}

.runtime-banner {
  margin-bottom: 16px;
}

.runtime-banner.is-error {
  border-color: rgba(255, 107, 107, 0.25);
  background: rgba(70, 19, 19, 0.28);
}

.runtime-banner.is-warning {
  border-color: rgba(255, 209, 102, 0.25);
  background: rgba(80, 57, 10, 0.24);
}

.remote-status {
  align-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.remote-rpm-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.remote-rpm-control input {
  width: 86px;
}

.scene-error-banner {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255, 107, 107, 0.45);
  background:
    linear-gradient(180deg, rgba(110, 24, 24, 0.92), rgba(64, 16, 16, 0.92)),
    rgba(70, 19, 19, 0.28);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.scene-error-copy {
  display: grid;
  gap: 8px;
}

.scene-error-copy strong {
  color: #ffd7d7;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
}

#scene-error-message {
  margin: 0;
  max-height: 180px;
  overflow: auto;
  color: #fff0f0;
  font-size: 0.8rem;
  line-height: 1.45;
  background: rgba(8, 3, 3, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px;
}

.scene-error-actions {
  display: flex;
  justify-content: flex-start;
}

#scene-error-debug-button {
  appearance: none;
  border: 1px solid rgba(255, 214, 214, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff4f4;
  padding: 8px 14px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

#scene-error-debug-button:hover {
  background: rgba(255, 255, 255, 0.18);
}

.debug-title,
.inspector-block h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: start;
}

.status-row-debug {
  margin-top: 12px;
}

.top-status-row {
  margin-top: 8px;
}

.status-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(83, 209, 182, 0.1);
  border: 1px solid rgba(83, 209, 182, 0.3);
  color: var(--accent);
  font-size: 0.8rem;
}

#frame-canvas-gl,
#frame-canvas-2d {
  position: absolute;
  inset: 0;
  width: 100vh;
  height: 100vh;
  display: block;
  background:
    radial-gradient(circle at center, rgba(83, 209, 182, 0.06), transparent 52%),
    var(--canvas);
  border-radius: 0;
  border: none;
}

.base-preview {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 3;
  width: 162px;
  min-height: 92px;
  display: grid;
  grid-template-columns: 94px 1fr;
  grid-template-rows: 8px 72px;
  gap: 3px 8px;
  padding: 8px 9px;
  border: 4px solid #030405;
  border-radius: 8px;
  background: linear-gradient(135deg, #121821, #07090d 62%);
  box-shadow: 0 9px 24px rgba(0, 0, 0, .48), inset 0 0 0 1px rgba(119, 176, 231, .14);
  pointer-events: none;
}

.base-preview-strip { grid-column: 1 / -1; grid-row: 1; height: 5px; align-self: center; border-radius: 999px; opacity: .82; box-shadow: 0 0 10px rgba(0,0,0,.65); }
.base-preview-dial { grid-column: 1; grid-row: 2; position: relative; box-sizing: border-box; isolation: isolate; width: 94px; height: 60px; margin-top: 2px; border: 8px solid #010204; border-radius: 12px; background: #010204; box-shadow: 0 0 0 1px #202a35; }
.base-preview-dial::before { position: absolute; z-index: 0; top: 7px; right: 7px; left: 7px; height: 34px; border-radius: 4px; background: var(--base-dial-color, #222222); box-shadow: inset 0 0 18px var(--base-dial-glow, rgba(0, 0, 0, 0)); content: ""; }
.base-preview-dial-copy { position: absolute; z-index: 1; top: 12px; left: 0; width: 100%; font: 700 9px/1.08 "Courier New", monospace; letter-spacing: -.06em; text-align: center; color: #010204; text-shadow: 0 1px rgba(255,255,255,.18); }
.base-preview-servo { position: absolute; z-index: 2; left: 42px; top: 49px; width: 38px; height: 3px; transform-origin: 0 50%; transform: rotate(220deg); border-radius: 3px; background: #020304; box-shadow: none; }
.base-preview-servo i { position: absolute; left: -4px; top: -3px; width: 9px; height: 9px; border-radius: 50%; background: #010204; }
.base-preview-buttons { grid-column: 2; grid-row: 2; display: flex; align-items: center; justify-content: space-between; padding-top: 15px; }
.base-preview-buttons i { position: relative; width: 27px; height: 27px; border-radius: 50%; background: #eeeeea; box-shadow: 0 0 0 3px #121417, inset 0 -2px 3px rgba(0,0,0,.35); }
.base-preview-buttons b { position: absolute; left: 9px; top: 9px; width: 9px; height: 9px; border-radius: 50%; background: #3d0707; box-shadow: inset 0 0 3px #000; }
.base-preview-buttons b.is-lit { background: #ee241c; box-shadow: 0 0 9px #f63129, inset 0 0 3px #fff1e7; }

.mobile-controls {
  display: none;
}

.mobile-control-caption {
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mobile-stick-panel,
.mobile-buttons-panel {
  display: grid;
  gap: 10px;
}

.touch-stick {
  width: min(38vw, 180px);
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
}

.touch-stick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.08), transparent 45%),
    radial-gradient(circle at center, rgba(83, 209, 182, 0.12), rgba(10, 13, 18, 0.94));
  border: 1px solid rgba(83, 209, 182, 0.18);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 18px 36px rgba(0, 0, 0, 0.28);
}

.touch-stick-base::before,
.touch-stick-base::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.08);
}

.touch-stick-base::before {
  top: 14%;
  bottom: 14%;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
}

.touch-stick-base::after {
  left: 14%;
  right: 14%;
  top: 50%;
  height: 1px;
  transform: translateY(-50%);
}

.touch-stick-knob {
  --stick-x: 0px;
  --stick-y: 0px;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.08) 34%, rgba(83, 209, 182, 0.14) 100%),
    #132129;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow:
    inset 0 2px 12px rgba(255, 255, 255, 0.08),
    0 10px 18px rgba(0, 0, 0, 0.3);
}

.mobile-buttons-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  grid-template-areas:
    ". top ."
    "left . right"
    ". bottom .";
  gap: 10px;
  align-items: center;
  justify-items: center;
}

.mobile-meta-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.touch-meta-button {
  appearance: none;
  min-width: 72px;
  padding: 9px 14px;
  border: 1px solid rgba(119, 176, 231, 0.3);
  border-radius: 999px;
  background: rgba(119, 176, 231, 0.12);
  color: #e5f2ff;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  touch-action: none;
  user-select: none;
}

.touch-meta-button.is-pressed {
  transform: scale(0.96);
  background: rgba(119, 176, 231, 0.3);
}

.touch-button {
  --touch-button-rgb: 255, 209, 102;
  --touch-button-text: #fff2c8;
  appearance: none;
  width: min(16vw, 76px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(var(--touch-button-rgb), 0.28);
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.24), transparent 38%),
    linear-gradient(180deg, rgba(var(--touch-button-rgb), 0.18), rgba(var(--touch-button-rgb), 0.34));
  color: var(--touch-button-text);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  box-shadow:
    inset 0 2px 12px rgba(255, 255, 255, 0.06),
    0 12px 20px rgba(0, 0, 0, 0.26);
  touch-action: none;
  user-select: none;
}

.touch-button-top {
  grid-area: top;
  --touch-button-rgb: 255, 193, 53;
  --touch-button-text: #fff3bf;
}

.touch-button-left {
  grid-area: left;
  --touch-button-rgb: 86, 163, 255;
  --touch-button-text: #e5f2ff;
}

.touch-button-right {
  grid-area: right;
  --touch-button-rgb: 239, 79, 79;
  --touch-button-text: #ffe5e5;
}

.touch-button-bottom {
  grid-area: bottom;
  --touch-button-rgb: 96, 199, 86;
  --touch-button-text: #e7ffe2;
}

.touch-button.is-pressed {
  transform: scale(0.95);
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.16), transparent 38%),
    linear-gradient(180deg, rgba(var(--touch-button-rgb), 0.26), rgba(var(--touch-button-rgb), 0.52));
  box-shadow:
    inset 0 2px 10px rgba(0, 0, 0, 0.18),
    0 6px 12px rgba(0, 0, 0, 0.22);
}

.debug-meta {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.debug-meta-header {
  margin-top: 10px;
  margin-bottom: 20px;
}

.inspector-panel-shell {
  display: grid;
  grid-template-rows: auto minmax(360px, var(--editor-height)) auto;
  gap: 12px;
  padding: 12px;
  min-height: 100vh;
}

.inspector-panel {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.inspector-block {
  padding: 14px;
  border-radius: 14px;
  background: rgba(10, 13, 18, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.settings-block {
  display: grid;
  gap: 10px;
}

.section-heading-block {
  padding-bottom: 10px;
}

.section-heading-block h2 {
  color: var(--accent);
}

.settings-option {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-option-select {
  justify-content: space-between;
}

.block-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-option-select select {
  appearance: none;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 19, 26, 0.9);
  color: inherit;
  font: inherit;
  padding: 6px 10px;
}

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

.copy-actions {
  justify-content: end;
}

#toggle-fullscreen-button,
#toggle-inspector-button,
#collect-memory-button {
  appearance: none;
  border-radius: 999px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  padding: 7px 12px;
}

#toggle-fullscreen-button {
  border: 1px solid rgba(138, 180, 255, 0.35);
  background: rgba(138, 180, 255, 0.12);
  color: #d7e7ff;
}

#toggle-fullscreen-button:hover {
  background: rgba(138, 180, 255, 0.18);
}

#toggle-fullscreen-button[aria-pressed="true"] {
  border-color: rgba(83, 209, 182, 0.35);
  background: rgba(83, 209, 182, 0.12);
  color: var(--accent);
}

#toggle-inspector-button {
  border: 1px solid rgba(83, 209, 182, 0.35);
  background: rgba(83, 209, 182, 0.12);
  color: var(--accent);
}

#toggle-inspector-button:hover {
  background: rgba(83, 209, 182, 0.18);
}

#collect-memory-button {
  border: 1px solid rgba(138, 180, 255, 0.28);
  background: rgba(138, 180, 255, 0.08);
  color: #d7e7ff;
}

#collect-memory-button:hover {
  background: rgba(138, 180, 255, 0.14);
}

#collect-memory-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

#copy-diagnostics-button {
  appearance: none;
  border: 1px solid rgba(83, 209, 182, 0.35);
  border-radius: 999px;
  background: rgba(83, 209, 182, 0.12);
  color: var(--accent);
  padding: 7px 12px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

#copy-diagnostics-button:hover {
  background: rgba(83, 209, 182, 0.18);
}

#copy-diagnostics-status {
  min-width: 52px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.summary-card {
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.memory-summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.primary-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.editor-panel-shell {
  min-height: min(60vh, var(--editor-height));
}

.editor-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-height: min(60vh, var(--editor-height));
  height: 100%;
  overflow: hidden;
}

.editor-toolbar,
.editor-subtoolbar,
.editor-actions,
.editor-active-file-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-toolbar,
.editor-subtoolbar,
.editor-active-file-bar {
  justify-content: space-between;
}

.editor-toolbar,
.editor-subtoolbar,
.editor-actions {
  flex-wrap: wrap;
}

.editor-actions {
  justify-content: flex-end;
}

.editor-actions button,
#editor-open-path-button {
  appearance: none;
  border-radius: 999px;
  border: 1px solid rgba(83, 209, 182, 0.28);
  background: rgba(83, 209, 182, 0.1);
  color: var(--text);
  padding: 7px 12px;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.editor-actions button:hover,
#editor-open-path-button:hover {
  background: rgba(83, 209, 182, 0.16);
}

.editor-actions button:disabled,
#editor-open-path-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.editor-path-field {
  display: grid;
  gap: 6px;
  flex: 1 1 220px;
  min-width: 0;
}

.editor-path-field span,
.editor-section-caption,
.editor-active-meta {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-path-field input {
  width: 100%;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(5, 8, 12, 0.82);
  color: var(--text);
  padding: 9px 11px;
  font: 0.84rem/1.2 "IBM Plex Sans", "Segoe UI", sans-serif;
}

.editor-content {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(140px, 190px) minmax(0, 1fr);
  gap: 12px;
}

.editor-file-list-shell,
.editor-workspace {
  min-height: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(4, 7, 11, 0.58);
}

.editor-file-list-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 10px;
  gap: 10px;
}

.editor-file-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 4px;
}

.editor-empty-state {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.editor-file-button {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  padding: 8px 9px;
  cursor: pointer;
  font: 0.78rem/1.35 "IBM Plex Mono", "SFMono-Regular", monospace;
  word-break: break-word;
}

.editor-file-main {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-file-preview {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-position: 0 0, 4px 4px;
  background-size: 8px 8px;
}

.editor-file-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  image-rendering: pixelated;
}

.editor-game-preview {
  flex: 0 0 auto;
  width: 72px;
  height: 34px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-position: 0 0, 4px 4px;
  background-size: 8px 8px;
}

.editor-game-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
}

.editor-file-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-file-kind {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 3px 7px;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.editor-file-button:hover {
  background: rgba(83, 209, 182, 0.08);
  border-color: rgba(83, 209, 182, 0.14);
}

.editor-file-button.is-active {
  background: rgba(83, 209, 182, 0.14);
  border-color: rgba(83, 209, 182, 0.28);
  color: var(--accent);
}

.editor-workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.editor-active-file-bar {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  min-width: 0;
}

.editor-active-file {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 0.82rem/1.3 "IBM Plex Mono", "SFMono-Regular", monospace;
}

.editor-surface,
.editor-message {
  min-height: 0;
}

.editor-surface {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.editor-text-surface,
.editor-sprite-surface {
  width: 100%;
  height: 100%;
}

.editor-text-surface[hidden],
.editor-sprite-surface[hidden] {
  display: none !important;
}

.piskel-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #111;
}

.editor-message {
  position: absolute;
  inset: 34px 0 0;
  display: grid;
  place-items: center;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  background:
    linear-gradient(180deg, rgba(4, 7, 11, 0.76), rgba(4, 7, 11, 0.92));
}

.editor-message.is-ready {
  display: none;
}

.editor-message.is-error {
  color: #ffd7d7;
}

.summary-card strong {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-bottom: 4px;
}

pre {
  margin: 10px 0 0;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--accent-2);
  font-size: 0.78rem;
  line-height: 1.45;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
}

textarea {
  width: 100%;
  margin: 10px 0 0;
  min-height: 260px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(5, 8, 12, 0.9);
  color: var(--accent-2);
  padding: 12px;
  font-size: 0.78rem;
  line-height: 1.45;
  font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    width: 100vw;
    height: auto;
  }

  .stage-display,
  #frame-canvas-gl,
  #frame-canvas-2d {
    width: 100vw;
    height: 100vw;
  }

  .mobile-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
    padding: 18px 16px 22px;
    background:
      linear-gradient(180deg, rgba(10, 13, 18, 0.04), rgba(10, 13, 18, 0.34)),
      rgba(10, 13, 18, 0.52);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  .debug-meta,
  .copy-header {
    flex-direction: column;
  }

  .copy-actions {
    width: 100%;
    justify-content: space-between;
  }

  .inspector-panel-shell {
    grid-template-rows: auto auto auto;
    min-height: auto;
  }

  .editor-panel-shell {
    min-height: 520px;
  }

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

  .stage-panel:fullscreen,
  .stage-panel.is-fullscreen.is-mobile-layout {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: stretch;
    justify-items: stretch;
    overflow: hidden;
  }

  .stage-panel:fullscreen .stage-display,
  .stage-panel.is-fullscreen.is-mobile-layout .stage-display {
    width: min(100vw, max(0px, calc(100vh - var(--mobile-controls-height))));
    height: min(100vw, max(0px, calc(100vh - var(--mobile-controls-height))));
    max-width: 100%;
    max-height: 100%;
    margin: auto;
  }

  .stage-panel:fullscreen .mobile-controls,
  .stage-panel.is-fullscreen.is-mobile-layout .mobile-controls {
    min-height: var(--mobile-controls-height);
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    background:
      linear-gradient(180deg, rgba(6, 8, 12, 0.22), rgba(6, 8, 12, 0.72)),
      rgba(8, 11, 16, 0.94);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
}

@media (max-width: 720px) {
  .editor-content {
    grid-template-columns: 1fr;
  }

  .editor-file-list-shell {
    max-height: 180px;
  }
}

@media (max-width: 560px) {
  .mobile-controls {
    gap: 14px;
    padding: 16px 12px 18px;
  }

.touch-button {
    width: min(18vw, 72px);
  }
}

/* Editor-first shell overrides */

:root {
  --editor-panel-width: minmax(0, 1fr);
}

.app-shell {
  position: relative;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
  overflow: hidden;
}

.app-shell.is-editor-open {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.app-shell.is-inspector-open {
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  height: 100vh;
  overflow: hidden;
}

.editor-panel-shell {
  min-height: 100vh;
  padding: 12px 10px 12px 12px;
  background: rgba(8, 11, 16, 0.96);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.editor-panel-shell[hidden] {
  display: none !important;
}

.editor-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.editor-toolbar,
.editor-actions,
.editor-active-file-bar,
.editor-drawer-header,
.editor-open-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-toolbar,
.editor-active-file-bar,
.editor-open-form {
  justify-content: space-between;
}

.editor-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.editor-drawer-shell {
  position: absolute;
  top: 44px;
  left: 0;
  right: 0;
  z-index: 8;
  pointer-events: none;
}

.editor-drawer {
  width: min(360px, calc(100% - 24px));
  margin-left: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(9, 13, 19, 0.96);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(16px);
  pointer-events: auto;
}

.editor-drawer-header {
  justify-content: flex-start;
  margin-bottom: 6px;
}

.editor-create-actions {
  display: grid;
  gap: 8px;
}

.editor-create-actions button,
.editor-dialog-actions button {
  appearance: none;
  border-radius: 12px;
  border: 1px solid rgba(83, 209, 182, 0.2);
  background: rgba(83, 209, 182, 0.08);
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.editor-create-actions button:hover,
.editor-dialog-actions button:hover {
  background: rgba(83, 209, 182, 0.14);
}

.editor-create-actions button:disabled,
.editor-dialog-actions button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.editor-create-help,
.editor-list-group,
.editor-dialog-hint,
.editor-dialog-header p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.editor-create-help {
  margin-top: 10px;
}

.editor-list-group {
  margin: 10px 0 4px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-open-form {
  flex-wrap: wrap;
}

.editor-file-list {
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.editor-workspace {
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 10px;
  border: 0;
  background: rgba(4, 7, 11, 0.42);
  overflow: hidden;
}

.editor-active-file-bar {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.editor-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(9, 13, 19, 0.98);
  color: var(--text);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
  padding: 0;
}

.editor-dialog::backdrop {
  background: rgba(3, 5, 8, 0.72);
  backdrop-filter: blur(3px);
}

.editor-dialog-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.editor-dialog-header {
  display: grid;
  gap: 6px;
}

.editor-dialog-header h2 {
  margin: 0;
  font-size: 1rem;
}

.editor-dialog-header p,
.editor-dialog-hint {
  margin: 0;
}

.editor-dialog-field {
  display: grid;
  gap: 6px;
}

.editor-dialog-field span {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor-dialog-field input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(5, 8, 12, 0.9);
  color: var(--text);
  padding: 10px 12px;
}

.editor-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.editor-dialog-actions #editor-create-cancel {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

.stage-panel {
  position: relative;
  width: auto;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: stretch;
  justify-items: center;
  padding: 18px;
  gap: 14px;
}

.app-shell.is-editor-open .stage-panel {
  padding-left: 12px;
}

.app-shell.is-inspector-open .stage-panel {
  padding-right: 12px;
}

.stage-toolbar {
  width: min(100%, 1080px);
  display: flex;
  justify-content: flex-start;
}

.stage-panel:fullscreen .stage-toolbar,
.stage-panel.is-fullscreen .stage-toolbar {
  display: none;
}

.stage-primary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stage-control-button,
.stage-fullscreen-toggle {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(7, 10, 14, 0.78);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.stage-control-button {
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  line-height: 1;
}

#toggle-editor-button,
#toggle-inspector-button {
  border-color: rgba(83, 209, 182, 0.35);
  background: rgba(83, 209, 182, 0.12);
  color: var(--accent);
}

.stage-control-button:hover,
.stage-fullscreen-toggle:hover {
  background: rgba(12, 17, 24, 0.9);
}

.stage-control-button[aria-pressed="true"],
.stage-control-button[aria-expanded="true"] {
  border-color: rgba(83, 209, 182, 0.3);
  color: var(--accent);
  background: rgba(83, 209, 182, 0.12);
}

.stage-display {
  position: relative;
  width: min(calc(100vh - 120px), calc(100vw - 36px), 1080px);
  height: min(calc(100vh - 120px), calc(100vw - 36px), 1080px);
  max-width: 100%;
  max-height: 100%;
  justify-self: center;
}

.stage-panel:fullscreen,
.stage-panel.is-fullscreen {
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-items: stretch;
  justify-items: center;
}

.stage-panel:fullscreen .stage-display,
.stage-panel.is-fullscreen .stage-display {
  width: min(calc(100vw - 36px), calc(100vh - 36px));
  height: min(calc(100vw - 36px), calc(100vh - 36px));
  margin: auto;
}

.app-shell.is-editor-open .stage-display {
  width: min(calc(100vh - 120px), calc(50vw - 40px), 920px);
  height: min(calc(100vh - 120px), calc(50vw - 40px), 920px);
}

.app-shell.is-inspector-open .stage-display {
  width: min(calc(100vh - 120px), calc(100vw - 460px), 920px);
  height: min(calc(100vh - 120px), calc(100vw - 460px), 920px);
}

/* The stage is a dark panel like the rest of the UI, and the display is a black
   disc inset in it, so the edge of the fan shows up (in screenshots too). */
.stage-display {
  background: var(--panel);
  border-radius: 28px;
  overflow: hidden;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.38),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

#frame-canvas-gl,
#frame-canvas-2d {
  inset: 4%;
  width: 92%;
  height: 92%;
  background: #000;
}

/* The disc's edge is an overlay above the canvas rather than a border-radius
   on it: a hardware-accelerated WebGL canvas is not always clipped to its
   rounded corners, and then its black square covers the panel and the outline.
   The huge shadow paints the panel colour over everything outside the circle,
   and the ring is the fan's edge. */
.stage-display::after {
  content: "";
  position: absolute;
  inset: 4%;
  z-index: 1;
  border-radius: 50%;
  pointer-events: none;
  box-shadow:
    0 0 0 2px #394356,
    0 0 0 100vmax var(--panel);
}

.stage-fullscreen-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 4;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
}

.fullscreen-icon {
  position: relative;
  width: 16px;
  height: 16px;
}

.fullscreen-icon::before,
.fullscreen-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid currentColor;
}

.fullscreen-icon::before {
  clip-path: polygon(0 0, 42% 0, 42% 18%, 18% 18%, 18% 42%, 0 42%);
}

.fullscreen-icon::after {
  clip-path: polygon(58% 0, 100% 0, 100% 42%, 82% 42%, 82% 18%, 58% 18%, 58% 0, 58% 100%, 82% 100%, 82% 82%, 100% 82%, 100% 100%, 58% 100%, 0 100%, 0 58%, 18% 58%, 18% 82%, 42% 82%, 42% 100%, 0 100%, 0 0);
  opacity: 0.88;
}

.scene-error-banner {
  width: min(100%, 1080px);
  margin-bottom: 0;
}

.inspector-panel {
  height: 100vh;
  padding: 12px 12px 12px 10px;
  position: sticky;
  top: 0;
  align-self: start;
  width: auto;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.inspector-panel[hidden] {
  display: none !important;
}

.primary-actions,
.top-status-row,
.debug-meta-header,
.inspector-panel-shell {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    min-height: 100dvh;
    overflow: visible;
  }

  .app-shell.is-editor-open {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .app-shell.is-inspector-open {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .editor-panel-shell {
    min-height: auto;
    padding: 10px 10px 0;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }

  .editor-panel {
    height: min(56vh, 620px);
  }

  .editor-drawer-shell {
    top: 42px;
  }

  .editor-drawer {
    width: min(100%, calc(100vw - 32px));
  }

  .inspector-panel {
    height: auto;
    padding: 10px 10px 0;
    position: relative;
    top: auto;
    align-self: stretch;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    max-height: none;
    overflow: visible;
  }

  .stage-panel,
  .app-shell.is-editor-open .stage-panel,
  .app-shell.is-inspector-open .stage-panel {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto auto;
    padding: 14px;
  }

  .stage-toolbar {
    width: 100%;
  }

  .stage-display,
  .app-shell.is-editor-open .stage-display,
  .app-shell.is-inspector-open .stage-display {
    width: min(calc(100vw - 28px), calc(100dvh - 240px), 720px);
    height: min(calc(100vw - 28px), calc(100dvh - 240px), 720px);
  }

  .mobile-controls {
    display: grid;
    width: 100%;
  }

  .stage-panel:fullscreen .stage-display,
  .stage-panel.is-fullscreen .stage-display {
    width: min(calc(100vw - 28px), calc(100dvh - 28px));
    height: min(calc(100vw - 28px), calc(100dvh - 28px));
  }

}

@media (max-width: 720px) {
  .stage-toolbar {
    width: 100%;
  }

  .stage-primary-actions {
    width: 100%;
    justify-content: space-between;
  }

  .stage-control-button {
    flex: 1 1 0;
    text-align: center;
  }

  .editor-open-form {
    align-items: stretch;
  }

  .editor-open-form .editor-path-field,
  .editor-open-form #editor-open-path-button {
    width: 100%;
  }
}
.keyboard-help {
  width: min(960px, calc(100vw - 40px));
  max-height: calc(100dvh - 40px);
  box-sizing: border-box;
  padding: 28px;
  border: 1px solid #3d555a;
  border-radius: 20px;
  background: #101a20;
  color: #ecf4f6;
  overflow: auto;
  box-shadow: 0 24px 100px #0009;
}
.keyboard-help::backdrop { background: #03070ccc; }
.keyboard-help-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.keyboard-help h1 { margin: 0; font-size: 26px; }
.keyboard-help-header p { margin: 8px 0 24px; color: #aebfc5; }
.keyboard-help-header button { white-space: nowrap; padding: 8px 12px; }
.keyboard-help-players { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.keyboard-player { --player-color: #87ddc4; min-width: 0; container-type: inline-size; }
.keyboard-player-2 { --player-color: #f5afc3; }
.keyboard-player h2 { margin: 0 0 12px; color: var(--player-color); font-size: 20px; }
.keyboard-player small { display: block; margin-top: 6px; color: #aebfc5; font-size: 13px; font-weight: normal; }
.keyboard-diagram { position: relative; width: 100%; }
.keyboard-key { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; border: 1px solid var(--player-color); border-bottom-width: 3px; border-radius: 7px; background: #213039; color: #fff; }
.keyboard-key kbd { font-family: inherit; font-size: clamp(12px, 4.2cqw, 20px); font-weight: 700; }
.keyboard-key span { color: var(--player-color); font-size: clamp(7px, 2.3cqw, 11px); }
.keyboard-key-long kbd { font-size: clamp(9px, 2.8cqw, 14px); }

.keyboard-key-context { border-color: #40505a; color: #6f828b; background: #17232b; }
.keyboard-key.is-held { background: var(--player-color); color: #0c1c23; box-shadow: 0 0 18px #ffffff40; }
.keyboard-key.is-held span { color: #0c1c23; }
.keyboard-help-footer { margin-top: 22px; font-size: 13px; line-height: 1.6; color: #aebfc5; }
.keyboard-help-footer p { margin: 8px 0 0; }
.keyboard-help-footer kbd { color: #ecf4f6; font-family: inherit; }
@media (max-width: 700px) {
  .keyboard-help { padding: 20px; }
  .keyboard-help h1 { font-size: 22px; }
  .keyboard-help-players { grid-template-columns: 1fr; gap: 20px; }
}
