:root {
  color-scheme: light;
  --ink: #171918;
  --muted: #717773;
  --line: #dfe2dd;
  --paper: #f3f4f0;
  --surface: #ffffff;
  --game-shell: #171918;
  --green: #16845b;
  --green-dark: #0d6846;
  --amber: #d59a28;
  --coral: #d7624d;
  --focus: #1879d2;
}

* { box-sizing: border-box; }

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

.access-gate {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #171918;
}

.access-card {
  width: min(100%, 360px);
  padding: 32px;
  border: 1px solid #3b413d;
  border-radius: 8px;
  color: #f3f4f0;
  background: #202321;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

.access-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: #171918;
  background: #f3f4f0;
  font-size: 16px;
  font-weight: 800;
}

.access-card h1 {
  margin: 24px 0 8px;
  font-size: 22px;
}

.access-card p {
  margin: 0 0 18px;
  color: #aeb4af;
  font-size: 13px;
}

.access-field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #59615b;
  border-radius: 6px;
  color: #f3f4f0;
  background: #171918;
  font: inherit;
}

.access-field input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.access-card button {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  font-weight: 700;
  cursor: pointer;
}

.access-card button:hover { background: var(--green-dark); }

.access-error {
  display: block;
  margin-top: 10px;
  color: #f08b78;
  font-size: 12px;
}

.access-locked .app-header,
.access-locked .workspace { visibility: hidden; }

.access-granted .access-gate { display: none; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--game-shell);
  font-family: "Geist", "Avenir Next", "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}

button,
select { font: inherit; }

button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(24, 121, 210, .24);
  outline-offset: 2px;
}

body {
  display: flex;
  flex-direction: column;
}

.app-header {
  position: relative;
  z-index: 10;
  flex: 0 0 68px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  min-width: 0;
  padding: 10px 18px;
  border-bottom: 1px solid #d7dad5;
  background: rgba(250, 250, 247, .98);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .08);
}

.brand {
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-copy strong { font-size: 17px; }
.brand-copy small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.current-level {
  min-width: 0;
  overflow: hidden;
  margin-left: 4px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.current-level.is-pending {
  color: var(--accent, #2f6f4f);
}

.stage-controls {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: end;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(27, 31, 28, .05);
}

.select-field {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  border-right: 1px solid var(--line);
}

.select-field > span {
  color: #858a86;
  font-size: 11px;
  font-weight: 700;
}

.select-field select {
  max-width: 132px;
  height: 32px;
  padding: 0 26px 0 4px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.stage-field select { width: 180px; max-width: 180px; }

.load-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease, box-shadow .2s ease;
}

.load-button:hover {
  background: #303431;
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(23, 25, 24, .16);
}

.load-icon {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid currentColor;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, var(--game-pane-width, 56fr)) 7px minmax(500px, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.game-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--game-shell);
}

.workspace-resizer {
  position: relative;
  z-index: 4;
  width: 7px;
  min-height: 0;
  border-right: 1px solid #d5d8d2;
  border-left: 1px solid #2e322f;
  background: #e8eae5;
  cursor: col-resize;
  touch-action: none;
  transition: background .18s ease;
}

.workspace-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 2px;
  height: 42px;
  border-radius: 1px;
  background: #a8ada8;
  transform: translateY(-50%);
  transition: height .18s ease, background .18s ease;
}

.workspace-resizer:hover,
.workspace-resizer:focus-visible,
.is-resizing .workspace-resizer { background: #d9e7df; }

.workspace-resizer:hover::after,
.workspace-resizer:focus-visible::after,
.is-resizing .workspace-resizer::after {
  height: 62px;
  background: var(--green);
}

.workspace-resizer:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.is-resizing { cursor: col-resize; user-select: none; }

#GameDiv,
#GameCanvas { width: 100%; height: 100%; }

#GameCanvas {
  display: block;
  outline: none;
}

#splash {
  position: absolute;
  inset: 0;
  display: none;
  background: var(--game-shell);
}

.progress-bar {
  position: absolute;
  top: 50%;
  right: 20%;
  left: 20%;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: #303430;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
}

.code-pane {
  display: grid;
  grid-template-rows: 92px 54px minmax(180px, 1fr) 154px 116px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
  animation: panel-enter .45s cubic-bezier(.22, .8, .25, 1) both;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #eceee9;
}

.metric-card {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr;
  align-items: center;
  gap: 3px 6px;
  padding: 10px 11px 9px 13px;
  overflow: hidden;
  border: 1px solid #e2e4df;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(31, 35, 32, .04);
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--green);
}

.metric-steps::before { background: var(--amber); }
.metric-energy::before { background: var(--coral); }

.metric-label {
  color: #555b57;
  font-size: 11px;
  font-weight: 700;
}

.metric-card strong {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

.metric-caption {
  align-self: end;
  color: #a1a6a2;
  font-size: 9px;
  font-weight: 600;
}

.code-toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfbf8;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.toolbar-actions-primary { margin-left: auto; }

.toolbar-divider {
  width: 1px;
  height: 20px;
  flex: 0 0 1px;
  margin: 0 1px;
  background: var(--line);
}

.tool-button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid #d8dcd6;
  border-radius: 5px;
  color: #505652;
  background: #fff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .18s ease, color .18s ease, background .18s ease, transform .18s ease;
}

.tool-button:hover:not(:disabled) {
  border-color: #aeb4af;
  color: var(--ink);
  background: #f4f5f2;
  transform: translateY(-1px);
}

.run-button {
  min-width: 66px;
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.run-button:hover:not(:disabled) {
  border-color: var(--green-dark);
  color: #fff;
  background: var(--green-dark);
}

.debug-button {
  border-color: #2b2e2c;
  color: #fff;
  background: #2b2e2c;
}

.debug-button:hover:not(:disabled) {
  border-color: #111312;
  color: #fff;
  background: #111312;
}

.step-button {
  border-color: #267aa8;
  color: #fff;
  background: #267aa8;
}

.stop-button {
  border-color: var(--coral);
  color: #fff;
  background: var(--coral);
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: .36;
  filter: grayscale(.45);
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid currentColor;
}

.stop-icon {
  width: 7px;
  height: 7px;
  border-radius: 1px;
  background: currentColor;
}

#editor-host {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

#code-area,
#blockly-area {
  width: 100%;
  height: 100%;
}

#code-area {
  font-size: 15px;
}

#blockly-area {
  background: #f7f8f5;
}

#code-area[hidden],
#blockly-area[hidden] {
  display: none;
}

body[data-mode="0"] .action-panel { display: none; }
body[data-mode="0"] .code-pane {
  grid-template-rows: 92px 54px minmax(260px, 1fr) 116px;
}

.ace_editor { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace !important; }
.ace_gutter { border-right: 1px solid #e3e2dc; }
.ace_marker-layer .ace_active-line { background: rgba(22, 132, 91, .06) !important; }

.ace_marker-layer .debug-current-line {
  position: absolute;
  border-left: 3px solid var(--amber);
  background: rgba(213, 154, 40, .2);
}

.action-panel {
  min-width: 0;
  overflow: hidden;
  border-bottom: 1px solid #d8dbd5;
  background: #f5f6f2;
}

.panel-header,
.console-header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 11px 5px 13px;
}

.panel-header > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.panel-kicker {
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
}

.panel-header strong { font-size: 12px; }

.panel-count {
  color: #858b86;
  font-size: 10px;
  font-weight: 650;
}

.action-palette {
  height: 114px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 78px;
  grid-template-rows: 86px;
  align-content: start;
  justify-content: start;
  gap: 7px;
  padding: 6px 11px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-color: #a9aea9 transparent;
  scrollbar-width: thin;
}

.action-button {
  width: 78px;
  height: 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 4px 5px;
  overflow: hidden;
  border: 1px solid #dde0da;
  border-radius: 6px;
  color: #4d534f;
  background: #fff;
  box-shadow: 0 2px 5px rgba(33, 37, 34, .04);
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

.action-button:hover {
  border-color: rgba(22, 132, 91, .55);
  box-shadow: 0 7px 16px rgba(35, 45, 39, .09);
  transform: translateY(-3px);
}

.action-button img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1);
}

.action-button:hover img { transform: scale(1.08); }

.action-button span {
  max-width: 68px;
  overflow: hidden;
  font-size: 10px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.console-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 36px minmax(0, 1fr);
  overflow: hidden;
  color: #d9ded9;
  background: #191c1a;
}

.console-header {
  height: 36px;
  padding: 0 13px;
  border-bottom: 1px solid #303431;
  color: #aeb4af;
  background: #202321;
}

.console-header > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.console-header strong { font-size: 11px; }
.console-header > span {
  color: #717873;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
}

.console-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #717873;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
}

.console-clear {
  position: relative;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  color: #919893;
  background: transparent;
  cursor: pointer;
  transition: color .18s ease, background .18s ease;
}

.console-clear::before,
.console-clear::after {
  content: "";
  position: absolute;
  top: 11px;
  left: 7px;
  width: 10px;
  height: 1px;
  background: currentColor;
}

.console-clear::before { transform: rotate(45deg); }
.console-clear::after { transform: rotate(-45deg); }
.console-clear:hover { color: #fff; background: #333735; }

.console-light {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 132, 91, .12);
}

.console-panel[data-tone="error"] .console-light {
  background: var(--coral);
  box-shadow: 0 0 0 3px rgba(215, 98, 77, .13);
}

#code-output {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 11px 13px;
  overflow: auto;
  color: #c3c9c4;
  background: #191c1a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
}

@keyframes panel-enter {
  from { opacity: .2; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 1180px) and (min-width: 901px) {
  .app-header { gap: 12px; }
  .brand-copy small { display: none; }
  .code-pane { grid-template-rows: 92px 88px minmax(180px, 1fr) 154px 116px; }
  .code-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 34px 34px;
    gap: 4px 8px;
  }
  .toolbar-actions-secondary { grid-column: 1; grid-row: 1; }
  .toolbar-actions-primary { grid-column: 1; grid-row: 2; justify-content: flex-end; }
  .toolbar-divider { display: none; }
  body[data-mode="0"] .code-pane { grid-template-rows: 92px 88px minmax(260px, 1fr) 116px; }
}

@media (max-width: 900px) {
  html, body { overflow: hidden; }
  .app-header {
    grid-template-columns: auto 1fr;
    gap: 12px;
  }
  .stage-controls { justify-self: end; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 42vh) minmax(620px, 1fr);
    overflow-y: auto;
  }
  .workspace-resizer { display: none; }
  .game-pane {
    border-right: 0;
    border-bottom: 1px solid #30332f;
  }
  .code-pane {
    grid-template-rows: 92px 54px minmax(250px, 1fr) 154px 116px;
    min-height: 620px;
  }
  body[data-mode="0"] .code-pane { grid-template-rows: 92px 54px minmax(320px, 1fr) 116px; }
}

@media (max-width: 640px) {
  .app-header {
    flex-basis: 118px;
    grid-template-columns: 1fr;
    grid-template-rows: 42px 52px;
    gap: 4px;
    padding: 8px 10px;
  }
  .brand-copy { flex-direction: row; align-items: baseline; gap: 7px; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; border-radius: 7px; }
  .stage-controls { width: 100%; justify-self: stretch; }
  .select-field { flex: 1; min-width: 0; }
  .select-field select { width: 100%; min-width: 0; max-width: none; }
  .load-button { padding: 0 11px; }
  .workspace { grid-template-rows: minmax(260px, 38vh) minmax(686px, 1fr); }
  .code-pane {
    grid-template-rows: 84px 120px minmax(260px, 1fr) 154px 116px;
    min-height: 686px;
  }
  .metrics { padding: 7px; gap: 5px; }
  .metric-card { padding: 8px 7px 7px 9px; }
  .metric-card strong { font-size: 16px; }
  .metric-caption { display: none; }
  .code-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: 34px 34px 34px;
    gap: 3px 6px;
  }
  .toolbar-actions-secondary { grid-column: 2; grid-row: 1; }
  .toolbar-actions-primary { grid-column: 1 / 3; grid-row: 2 / 4; flex-wrap: wrap; justify-content: flex-end; }
  .toolbar-divider { display: none; }
  body[data-mode="0"] .code-pane { grid-template-rows: 84px 120px minmax(320px, 1fr) 116px; }
}

@media (max-height: 700px) and (min-width: 1181px) {
  .app-header { flex-basis: 60px; }
  .code-pane { grid-template-rows: 80px 50px minmax(150px, 1fr) 136px 96px; }
  .metrics { padding: 7px; }
  .action-palette { height: 96px; grid-template-rows: 74px; }
  .action-button { height: 74px; }
  .action-button img { width: 36px; height: 36px; }
  body[data-mode="0"] .code-pane { grid-template-rows: 80px 50px minmax(220px, 1fr) 96px; }
}

@media (max-height: 700px) and (min-width: 901px) and (max-width: 1180px) {
  .code-pane { grid-template-rows: 76px 88px minmax(120px, 1fr) 122px 96px; }
  .metrics { padding: 6px; }
  .metric-card { padding-top: 7px; padding-bottom: 7px; }
  .action-palette { height: 82px; grid-template-rows: 64px; padding-top: 3px; padding-bottom: 8px; }
  .action-button { height: 64px; gap: 2px; padding-top: 3px; }
  .action-button img { width: 34px; height: 34px; }
  body[data-mode="0"] .code-pane { grid-template-rows: 76px 88px minmax(190px, 1fr) 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
