:root {
  --bg-top: #152033;
  --bg-mid: #255b92;
  --bg-bottom: #ffd38b;
  --panel: rgba(8, 15, 33, 0.8);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #fbf6ed;
  --muted: #ddd2c2;
  --accent: #ffd77d;
  --accent-2: #87f3d8;
  --shadow: 0 28px 68px rgba(4, 7, 19, 0.34);
  --drawer-width: min(26rem, 92vw);
  --safe-top: max(0.9rem, env(safe-area-inset-top));
  --safe-right: max(0.9rem, env(safe-area-inset-right));
  --safe-bottom: max(0.9rem, env(safe-area-inset-bottom));
  --safe-left: max(0.9rem, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
}

body {
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.08), transparent 33%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 56%, var(--bg-bottom) 100%);
}

.shell {
  position: fixed;
  inset: 0;
  min-height: 100svh;
  height: 100svh;
}

.panel {
  min-height: 0;
  backdrop-filter: blur(18px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.intro {
  position: fixed;
  top: var(--safe-top);
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  width: var(--drawer-width);
  max-width: calc(100vw - (var(--safe-left) + var(--safe-right)));
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.15rem;
  overflow-x: hidden;
  overflow-y: hidden;
  touch-action: pan-y pinch-zoom;
  transform: translateX(calc(100% + 1.25rem));
  transition: transform 180ms ease, opacity 180ms ease;
  opacity: 0;
  z-index: 30;
}

body.menu-open .intro {
  transform: translateX(0);
  opacity: 1;
}

.menu-backdrop {
  position: fixed;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(6, 10, 22, 0.48);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 24;
}

body.menu-open .menu-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.9rem;
}

.menu-close {
  flex: none;
  min-height: 2.75rem;
  padding-inline: 1rem;
  background: rgba(255, 255, 255, 0.08);
}

.drawer-card {
  display: grid;
  gap: 0.75rem;
  padding: 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
}

.settings-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.settings-tab {
  min-height: 2.85rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.settings-tab.active {
  background: linear-gradient(135deg, rgba(135, 243, 216, 0.3), rgba(125, 182, 255, 0.22));
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.drawer-panels {
  position: relative;
  flex: 1;
  min-height: 0;
}

.settings-panel {
  display: none;
  min-height: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scrollbar-width: none;
  touch-action: pan-y;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  padding-right: 0.15rem;
}

.settings-panel.is-active {
  display: grid;
  align-content: start;
  gap: 0.9rem;
}

.settings-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.section-heading {
  display: grid;
  gap: 0.16rem;
}

.section-heading span,
.section-heading strong {
  display: block;
}

.section-heading span {
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-size: 0.68rem;
}

.section-heading strong {
  font-size: 1.03rem;
}

.drawer-section,
.drawer-subsection {
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.drawer-subsection {
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.submenu-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
  cursor: pointer;
}

.submenu-summary::-webkit-details-marker {
  display: none;
}

.submenu-summary span,
.submenu-summary strong {
  display: block;
}

.submenu-summary span {
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-size: 0.68rem;
}

.submenu-summary strong {
  margin-top: 0.12rem;
  font-size: 1rem;
}

.submenu-summary::after {
  content: "+";
  flex: none;
  color: var(--accent);
  font-size: 1.35rem;
  line-height: 1;
  transition: transform 160ms ease;
}

.drawer-section[open] > .submenu-summary::after,
.drawer-subsection[open] > .submenu-summary::after {
  transform: rotate(45deg);
}

.nested-summary {
  padding: 0.82rem 0.92rem;
}

.nested-summary strong {
  font-size: 0.94rem;
}

.submenu-body {
  display: grid;
  gap: 0.8rem;
  padding: 0 1rem 1rem;
}

.nested-body {
  padding: 0 0.85rem 0.85rem;
}

.flat-group {
  display: grid;
  gap: 0.55rem;
}

.eyebrow,
.mini-label {
  margin: 0 0 0.45rem;
  color: var(--accent-2);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  line-height: 0.95;
  letter-spacing: -0.04em;
}

h1 {
  font-size: clamp(2.4rem, 5vw, 4rem);
}

h2 {
  font-size: 2rem;
}

.lede,
.lesson-copy,
.concept-copy,
.status,
.goal,
.tips li {
  color: var(--muted);
  line-height: 1.55;
}

.link {
  display: inline-block;
  margin-top: 0.9rem;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.mode-button {
  background: rgba(255, 255, 255, 0.08);
}

.mode-button.active {
  background: linear-gradient(135deg, rgba(135, 243, 216, 0.36), rgba(255, 215, 125, 0.28));
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.lesson-box,
.concept-box {
  padding: 0.9rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.goal {
  margin: 0.85rem 0 0;
  color: var(--accent);
  font-weight: 700;
}

.readouts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0;
}

.readouts div,
.stats div {
  padding: 0.72rem 0.78rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
}

.readouts dt,
.stats dt {
  margin: 0 0 0.35rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.66rem;
}

.readouts dd,
.stats dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.controls {
  display: grid;
  gap: 0.8rem;
}

.chem-sandbox-panel {
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.destruction-panel {
  display: grid;
  gap: 0.95rem;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
}

.destruction-quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.destruction-group {
  display: grid;
  gap: 0.55rem;
}

.destruction-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.destruction-button {
  border-radius: 16px;
  min-height: 2.9rem;
  background: rgba(255, 255, 255, 0.08);
}

.destruction-button.active {
  background: linear-gradient(135deg, rgba(255, 191, 116, 0.34), rgba(255, 109, 91, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.sandbox-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.sandbox-button {
  border-radius: 16px;
  min-height: 2.8rem;
  text-align: center;
  font-size: 0.92rem;
}

.sandbox-button.methane {
  background: linear-gradient(135deg, rgba(255, 200, 120, 0.34), rgba(255, 148, 92, 0.2));
}

.sandbox-button.oxygen {
  background: linear-gradient(135deg, rgba(151, 217, 255, 0.34), rgba(125, 182, 255, 0.18));
}

.sandbox-button.lava,
.sandbox-button.acid {
  background: linear-gradient(135deg, rgba(255, 122, 89, 0.32), rgba(255, 75, 75, 0.18));
}

.sandbox-button.laser,
.sandbox-button.crystal {
  background: linear-gradient(135deg, rgba(199, 168, 255, 0.32), rgba(125, 182, 255, 0.18));
}

.sandbox-button.water,
.sandbox-button.soap {
  background: linear-gradient(135deg, rgba(135, 243, 216, 0.28), rgba(151, 217, 255, 0.18));
}

.sandbox-button.metal,
.sandbox-button.nitrogen,
.sandbox-button.dryice {
  background: linear-gradient(135deg, rgba(231, 236, 245, 0.24), rgba(189, 198, 219, 0.14));
}

.sandbox-button.slime,
.sandbox-button.paint {
  background: linear-gradient(135deg, rgba(255, 143, 210, 0.28), rgba(140, 255, 177, 0.16));
}

.sandbox-button.stardust {
  background: linear-gradient(135deg, rgba(255, 227, 145, 0.3), rgba(199, 168, 255, 0.18));
}

.is-hidden {
  display: none;
}

.control {
  display: grid;
  gap: 0.35rem;
  font-weight: 700;
}

.control input {
  width: 100%;
  min-height: 2.2rem;
}

.coding-panel {
  display: grid;
  gap: 0.9rem;
}

.code-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.code-tab {
  background: rgba(255, 255, 255, 0.08);
}

.code-tab.active {
  background: linear-gradient(135deg, rgba(135, 243, 216, 0.26), rgba(125, 182, 255, 0.22));
}

.code-box {
  padding: 1rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.block-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.block-button {
  border-radius: 16px;
  min-height: 2.7rem;
  text-align: left;
}

.block-button.move {
  background: linear-gradient(135deg, rgba(125, 182, 255, 0.34), rgba(125, 182, 255, 0.18));
}

.block-button.jump {
  background: linear-gradient(135deg, rgba(255, 191, 116, 0.36), rgba(255, 141, 91, 0.2));
}

.program-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.program-step {
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  font-weight: 700;
}

.python-editor {
  width: 100%;
  min-height: 9rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(9, 17, 36, 0.7);
  color: var(--text);
  padding: 0.85rem;
  font: 600 0.95rem "SFMono-Regular", "Consolas", monospace;
  resize: vertical;
}

.terminal-output {
  margin: 0.8rem 0 0;
  min-height: 10rem;
  max-height: 18rem;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(6, 12, 26, 0.86);
  color: #bdf7d5;
  padding: 0.85rem;
  white-space: pre-wrap;
  font: 600 0.9rem/1.5 "SFMono-Regular", "Consolas", monospace;
}

.code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

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

.primary-action {
  display: grid;
}

.primary-action .primary {
  width: 100%;
}

.auxiliary-actions {
  margin-bottom: 0.1rem;
}

.action-card {
  background: rgba(8, 15, 33, 0.94);
  box-shadow: 0 16px 34px rgba(4, 8, 18, 0.24);
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.9rem 1rem;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  min-height: 3rem;
}

input[type="range"],
.link {
  touch-action: manipulation;
}

.primary {
  background: linear-gradient(135deg, #ffbf74, #ff8d5b);
}

.secondary {
  background: rgba(255, 255, 255, 0.08);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
}

.tips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.7rem;
}

.tips li {
  padding: 0.95rem 1rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.tips span {
  color: var(--accent);
  font-weight: 700;
}

.stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
  border-radius: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  overflow: hidden;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  position: relative;
  z-index: 3;
}

.menu-button {
  width: 3.6rem;
  min-width: 3.6rem;
  min-height: 3.6rem;
  display: grid;
  place-items: center;
  gap: 0.28rem;
  border-radius: 20px;
  background: rgba(8, 15, 33, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-button span {
  display: block;
  width: 1.35rem;
  height: 0.15rem;
  border-radius: 999px;
  background: var(--text);
}

.stage-chip {
  min-width: 0;
  padding: 0.7rem 0.95rem;
  border-radius: 18px;
  background: rgba(8, 15, 33, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stage-chip p,
.stage-chip strong {
  display: block;
  margin: 0;
}

.stage-chip p {
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
}

.stage-chip strong {
  margin-top: 0.18rem;
  font-size: 1rem;
}

.canvas-frame {
  position: relative;
  min-height: 0;
  flex: 1;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.16), transparent 18%),
    linear-gradient(180deg, rgba(9, 17, 36, 0.98), rgba(28, 75, 122, 0.92) 62%, rgba(255, 211, 139, 0.35));
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y pinch-zoom;
}

.stage-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  padding: 0.65rem 0.9rem;
  border-radius: 20px;
  background: rgba(8, 15, 33, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--muted);
  pointer-events: none;
}

.stage-overlay p {
  margin: 0;
}

.action-toast {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translate(-50%, 1rem);
  min-width: min(18rem, calc(100% - 2rem));
  max-width: calc(100% - 2rem);
  padding: 0.85rem 1rem;
  border-radius: 18px;
  background: rgba(7, 16, 34, 0.88);
  border: 1px solid rgba(135, 243, 216, 0.3);
  box-shadow: 0 18px 36px rgba(4, 8, 18, 0.32);
  color: var(--text);
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.01em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.action-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.status {
  min-height: 3rem;
  margin: 0.75rem 0 0;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: rgba(8, 15, 33, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

@media (max-width: 700px) {
  .settings-tab {
    min-height: 3rem;
  }

  .lede {
    display: none;
  }

  h1 {
    font-size: clamp(1.9rem, 9vw, 2.35rem);
  }

  h2 {
    font-size: 1.45rem;
  }

  .stats,
  .readouts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .readouts dd,
  .stats dd {
    font-size: 1rem;
  }

  .readouts dt,
  .stats dt {
    font-size: 0.68rem;
  }

  .canvas-frame {
    min-height: 0;
  }

  .intro {
    width: calc(100vw - (var(--safe-left) + var(--safe-right)));
  }

  .stage-overlay {
    padding: 0.55rem 0.75rem;
    font-size: 0.92rem;
  }

  .action-toast {
    bottom: 0.8rem;
    min-width: calc(100% - 1.5rem);
    max-width: calc(100% - 1.5rem);
    padding: 0.78rem 0.9rem;
    font-size: 0.94rem;
  }

  .stage-chip {
    padding: 0.62rem 0.78rem;
  }

  .lesson-box,
  .concept-box,
  .tips li,
  .readouts div,
  .stats div {
    border-radius: 16px;
  }

  .drawer-card {
    padding: 0.82rem;
  }

  .section-heading strong {
    font-size: 0.92rem;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --drawer-width: min(21rem, 46vw);
  }

  .intro {
    top: max(0.55rem, env(safe-area-inset-top));
    right: max(0.55rem, env(safe-area-inset-right));
    bottom: max(0.55rem, env(safe-area-inset-bottom));
    padding: 0.9rem;
    gap: 0.75rem;
  }

  .drawer-header {
    align-items: center;
  }

  h1 {
    font-size: clamp(1.7rem, 4.4vw, 2.3rem);
  }

  .eyebrow,
  .mini-label {
    margin-bottom: 0.3rem;
    font-size: 0.68rem;
  }

  .lede,
  .lesson-copy,
  .concept-copy,
  .status,
  .goal,
  .tips li {
    line-height: 1.35;
    font-size: 0.98rem;
  }

  .link {
    margin-top: 0.35rem;
  }

  .lesson-box,
  .concept-box,
  .chem-sandbox-panel,
  .code-box,
  .readouts div,
  .stats div,
  .tips li {
    padding: 0.78rem;
    border-radius: 18px;
  }

  .readouts,
  .stats,
  .controls,
  .coding-panel,
  .chem-sandbox-panel {
    gap: 0.55rem;
  }

  .drawer-card {
    padding: 0.72rem;
  }

  .settings-tab {
    min-height: 2.6rem;
  }

  .section-heading strong {
    font-size: 0.86rem;
  }

  .actions {
    gap: 0.55rem;
  }

  button {
    min-height: 2.75rem;
    padding: 0.75rem 0.9rem;
  }

  .stage {
    padding:
      max(0.55rem, env(safe-area-inset-top))
      max(0.55rem, env(safe-area-inset-right))
      max(0.55rem, env(safe-area-inset-bottom))
      max(0.55rem, env(safe-area-inset-left));
    align-items: center;
  }

  .stage-toolbar {
    margin-bottom: 0.55rem;
    width: min(100%, 46rem);
    align-self: center;
  }

  .menu-button {
    width: 3.15rem;
    min-width: 3.15rem;
    min-height: 3.15rem;
    border-radius: 18px;
  }

  .stage-chip {
    padding: 0.55rem 0.72rem;
  }

  .stage-chip strong {
    font-size: 0.92rem;
  }

  .canvas-frame {
    width: min(100%, 46rem);
    max-width: 46rem;
    align-self: center;
  }

  .stage-overlay {
    top: 0.7rem;
    left: 0.7rem;
    right: auto;
    max-width: min(58%, 23rem);
    padding: 0.5rem 0.7rem;
    font-size: 0.88rem;
    border-radius: 16px;
  }

  .action-toast {
    bottom: 0.7rem;
    padding: 0.68rem 0.82rem;
    border-radius: 16px;
    font-size: 0.88rem;
  }

  .status {
    width: min(100%, 38rem);
    align-self: center;
    min-height: 0;
    margin-top: 0.55rem;
    padding: 0.7rem 0.85rem;
    font-size: 0.95rem;
    line-height: 1.3;
  }

  .readouts div,
  .stats div {
    padding: 0.6rem 0.66rem;
  }

  .readouts dd,
  .stats dd {
    font-size: 0.9rem;
  }
}
