:root {
  --bg: #eef3f7;
  --ink: #16202a;
  --muted: #647486;
  --panel: #ffffff;
  --line: #d9e2ec;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --energy: #f5b841;
  --danger: #c2410c;
  --tile: #d8edf0;
  --tile-edge: #a8cad0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

[hidden] {
  display: none !important;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #f8fafc;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.menu-shell {
  display: grid;
  align-content: center;
  gap: 30px;
  width: min(920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.menu-hero {
  display: grid;
  gap: 10px;
}

.menu-hero h1 {
  font-size: 54px;
}

.menu-hero p:last-child {
  max-width: 560px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.mode-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.mode-card {
  display: grid;
  gap: 8px;
  min-height: 170px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #ffffff;
  box-shadow: 0 18px 44px rgba(32, 52, 71, 0.1);
}

.mode-card:hover {
  border-color: var(--accent);
}

.mode-card:hover strong {
  color: var(--accent-strong);
}

.mode-card strong {
  font-size: 28px;
}

.mode-card span:last-child {
  color: var(--muted);
  line-height: 1.45;
}

.mode-label {
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #ffffff;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  width: min(1380px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.game-panel {
  display: grid;
  min-width: 0;
  gap: 12px;
  align-content: start;
  align-items: start;
  justify-items: center;
}

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 960px;
}

#game-canvas,
#editor-canvas {
  display: block;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 48 / 31;
  border: 1px solid #c8d7e2;
  border-radius: 8px;
  background: #dfeaf1;
  box-shadow: 0 20px 50px rgba(32, 52, 71, 0.12);
}

.view-toggle-btn {
  min-height: 36px;
  padding: 0 12px;
  border-color: rgba(15, 118, 110, 0.38);
  color: #ffffff;
  background: var(--accent);
  font-size: 13px;
}

.view-toggle-btn:hover:not(:disabled),
.level-btn.active:hover:not(:disabled),
.editor-tool.active:hover:not(:disabled),
.primary-btn:hover:not(:disabled) {
  border-color: var(--accent-strong);
  color: #ffffff;
  background: var(--accent-strong);
}

.camera-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 8px;
  width: min(600px, 100%);
}

.camera-controls button {
  min-height: 40px;
  padding: 0 10px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 16px;
  padding: 18px;
  border-left: 1px solid #d6e0ea;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
}

.brand-block {
  padding-bottom: 4px;
}

.top-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.top-link-row a,
.small-link-btn {
  display: inline-grid;
  min-height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

.top-link-row a:hover,
.small-link-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #ffffff;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.05;
}

h2 {
  font-size: 15px;
}

#level-summary {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.level-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.level-empty {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px dashed #c8d7e2;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.level-section {
  display: grid;
  gap: 10px;
}

.level-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.command-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.level-actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.chapter-select-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.chapter-select-label select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #f8fafc;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.lock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.lock-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.level-btn {
  display: grid;
  grid-template-rows: 18px 16px;
  align-content: center;
  justify-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 6px 4px;
  line-height: 1;
}

.level-btn.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.level-btn.locked {
  color: #8695a5;
}

.level-number {
  font-size: 15px;
  font-weight: 900;
}

.level-stars {
  min-height: 14px;
  color: #111827;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1px;
}

.level-btn.active .level-stars {
  color: #ffffff;
}

.level-btn.locked .level-stars {
  color: #9aa8b6;
}

.panel-section {
  display: grid;
  gap: 10px;
}

.hint-section {
  padding-top: 2px;
}

.hint-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.hint-list li {
  padding-left: 2px;
}

.hint-list .hint-empty {
  list-style: none;
  margin-left: -20px;
  color: #8a99a8;
  font-style: italic;
}

.editor-hints {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.editor-solution {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.solution-list {
  display: grid;
  gap: 8px;
}

.solution-row {
  display: grid;
  gap: 4px;
}

.solution-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.solution-commands {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.solution-chip {
  display: inline-grid;
  min-height: 24px;
  place-items: center;
  border: 1px solid #c9d7e5;
  border-radius: 6px;
  padding: 0 7px;
  color: var(--ink);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 900;
}

.solution-empty {
  color: #8a99a8;
  font-size: 13px;
  font-style: italic;
}

.editor-panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.86);
}

.editor-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.editor-tool {
  min-height: 36px;
  padding: 0 6px;
  font-size: 12px;
}

.editor-tool.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.editor-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.editor-fields label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.editor-fields select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-weight: 800;
}

.topdown-grid {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.topdown-cell {
  position: relative;
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  border: 1px dashed #c5d4e2;
  border-radius: 6px;
  color: #9aa8b6;
  background: #f8fafc;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.topdown-cell.tile {
  border-style: solid;
  border-color: #9ebfca;
  color: #174147;
  background: #d8edf0;
}

.topdown-cell.h1 {
  background: #b9dde3;
}

.topdown-cell.h2 {
  background: #94c4ce;
}

.topdown-cell.node {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.38);
}

.topdown-cell.blocked {
  border-color: #64748b;
  color: #475569;
  background: #c7d1d8;
  box-shadow: inset 0 0 0 2px rgba(71, 85, 105, 0.28);
}

.topdown-cell.robot::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--energy);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75);
}

.editor-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#editor-json {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: #ffffff;
  font:
    12px/1.45 Consolas,
    "Courier New",
    monospace;
}

.editor-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.editor-actions button {
  min-height: 36px;
}

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

.section-heading button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.command-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 54px;
  gap: 10px;
  padding: 10px;
  text-align: left;
}

.command-icon {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-size: 18px;
}

.command-icon-forward {
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
}

.command-label {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.command-label strong {
  font-size: 14px;
}

.command-label span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.program-section {
  min-height: 180px;
}

.p1-section,
.p2-section {
  min-height: 132px;
}

.program-tab {
  min-height: 32px;
  padding: 0 12px;
}

.program-tab.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.program-tab.active:hover:not(:disabled) {
  border-color: var(--accent-strong);
  color: #ffffff;
  background: var(--accent-strong);
}

#slot-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

#p1-slot-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.program-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.slot {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px dashed #b8c9d8;
  border-radius: 8px;
  color: #8797a6;
  background: rgba(255, 255, 255, 0.65);
  font-weight: 800;
}

.slot.filled {
  border-style: solid;
  color: var(--ink);
  background: #ffffff;
}

.slot.command-forward {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.slot.active {
  border-color: var(--energy);
  box-shadow: 0 0 0 3px rgba(245, 184, 65, 0.22);
}

.run-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 8px;
}

.run-row button {
  min-height: 46px;
}

.primary-btn {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.primary-btn:hover:not(:disabled) {
  border-color: var(--accent-strong);
  color: #ffffff;
  background: var(--accent-strong);
}

.status-line {
  min-height: 42px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.status-line.success {
  color: var(--accent-strong);
  font-weight: 800;
}

.status-line.fail {
  color: var(--danger);
  font-weight: 800;
}

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

  .control-panel {
    border-left: 0;
    border-top: 1px solid #d6e0ea;
  }
}

@media (max-width: 560px) {
  .mode-menu {
    grid-template-columns: 1fr;
  }

  .menu-hero h1 {
    font-size: 40px;
  }

  .command-grid,
  .run-row {
    grid-template-columns: 1fr;
  }

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

  .program-slots {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  h1 {
    font-size: 28px;
  }
}
