/* Class names avoid single common words (tree, button, actions, hint…): Monaco uses those
   inside the editor, and a page rule like .tree { padding } once broke its suggestion list. */

:root {
  color-scheme: dark;
  --bg: #17191b;
  --panel: #1e2124;
  --panel-raised: #262a2e;
  --border: #33393f;
  --text: #e8eaed;
  --muted: #a3abb3;
  --grass: #5fa83a;
  --grass-dark: #3c7a24;
  --grass-light: #8fd16a;
  --dirt: #7a5232;
  --blue: #2f6fd6;
  --blue-dark: #2457a8;
  --gold: #f2c14e;
  --red: #ff7070;
  --amber: #f2b84b;
  --code-bg: #2b3036;
  --editor-bg: #1e1e1e;
  --output-bg: #101213;
  --radius: 10px;
  --header-height: 60px;
  --mono: ui-monospace, "SF Mono", Menlo, "Cascadia Code", Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, select { font: inherit; color: inherit; }
/* No ligatures: learners must see === and =>, not ≡ and ⇒. */
code, pre, kbd, textarea {
  font-family: var(--mono);
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* --- top bar ------------------------------------------------------------------- */

.topbar {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: #121415;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A grass block: green top, dirt below. */
.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background:
    linear-gradient(var(--grass-light) 0 30%, transparent 30%),
    repeating-linear-gradient(90deg, var(--dirt) 0 7px, #6a4628 7px 14px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25), 0 0 0 1px rgba(255, 255, 255, .08);
}
.lesson-nav { display: flex; align-items: center; gap: 6px; margin: 0 auto; min-width: 0; }
.lesson-nav select {
  min-height: 44px;
  min-width: 0;
  max-width: min(440px, 40vw);
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-raised);
  font-weight: 600;
}
.topbar-end { display: flex; align-items: center; gap: 12px; }
.progress-text { color: var(--muted); font-size: .875rem; white-space: nowrap; }

/* --- buttons ------------------------------------------------------------------- */

.lab-button, .lab-icon-button {
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.lab-button { padding: 0 16px; }
.lab-icon-button {
  min-width: 44px;
  background: transparent;
  border-color: var(--border);
  font-size: 1.4rem;
  line-height: 1;
}
.lab-button:disabled, .lab-icon-button:disabled { opacity: .45; cursor: default; }
.lab-button:not(:disabled):active, .lab-icon-button:not(:disabled):active { transform: translateY(1px); }
.lab-button:focus-visible, .lab-icon-button:focus-visible, select:focus-visible,
.lab-link-button:focus-visible, .line-chip:focus-visible {
  outline: 3px solid rgba(143, 209, 106, .55);
  outline-offset: 2px;
}
/* Minecraft-style buttons: a darker bottom edge. */
.lab-button.run { background: var(--grass); color: #fff; box-shadow: inset 0 -3px 0 var(--grass-dark); }
.lab-button.check { background: var(--blue); color: #fff; box-shadow: inset 0 -3px 0 var(--blue-dark); }
.lab-button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.lab-button.ghost:not(:disabled):hover, .lab-icon-button:not(:disabled):hover { background: var(--panel-raised); }
.lab-link-button {
  background: none;
  border: 0;
  padding: 8px 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: .875rem;
}

/* --- layout -------------------------------------------------------------------- */

.app-layout {
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  display: grid;
  grid-template-columns: minmax(360px, min(44%, 640px)) minmax(0, 1fr);
}

/* --- lesson panel -------------------------------------------------------------- */

.lesson-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.lesson-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 22px 24px 12px max(24px, env(safe-area-inset-left));
  -webkit-overflow-scrolling: touch;
}
.kicker {
  margin: 0 0 6px;
  color: var(--grass-light);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.lesson-panel h1 { font-size: 1.75rem; }
.lesson-goal { margin: 6px 0 0; color: var(--muted); font-size: 1.02rem; }
.concepts { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; list-style: none; }
.concepts li {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .8rem;
}
.lesson-intro { font-size: 1.04rem; }
.lesson-intro p { margin: 14px 0 0; }
.lesson-intro ul, .lesson-intro ol { margin: 10px 0 0; padding-left: 22px; display: grid; gap: 6px; }
.lesson-panel code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--code-bg);
  font-size: .9em;
  overflow-wrap: anywhere;
}
kbd {
  display: inline-block;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  background: var(--panel-raised);
  font-size: .85em;
  line-height: 1.5;
}

/* A line of code split into labelled parts. */
.anatomy {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 4px 2px;
  margin: 14px 0 0;
  padding: 14px 12px 10px;
  border-radius: var(--radius);
  background: var(--editor-bg);
}
.anatomy-part { display: flex; flex-direction: column; align-items: center; max-width: 150px; }
.lesson-panel .anatomy-part code {
  padding: 3px 4px;
  border-radius: 4px 4px 0 0;
  background: none;
  border-bottom: 3px solid var(--part-color, var(--border));
  font-size: 1rem;
  white-space: pre;
  overflow-wrap: normal;
}
.anatomy-label { margin-top: 4px; color: var(--part-color, var(--muted)); font-size: .74rem; line-height: 1.25; text-align: center; }
.anatomy-part:nth-child(4n + 1) { --part-color: #8fd16a; }
.anatomy-part:nth-child(4n + 2) { --part-color: #f2c14e; }
.anatomy-part:nth-child(4n + 3) { --part-color: #6fb3ff; }
.anatomy-part:nth-child(4n + 4) { --part-color: #f28fb8; }

.code-example, .lesson-hint pre {
  margin: 12px 0 0;
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: var(--radius);
  background: var(--editor-bg);
  font-size: .88rem;
  line-height: 1.5;
}
.lesson-panel .code-example code { padding: 0; background: none; font-size: inherit; overflow-wrap: normal; }
.index-table { margin: 12px 0 0; border-collapse: collapse; font-size: .9rem; }
.index-table th, .index-table td { padding: 6px 12px; border: 1px solid var(--border); text-align: center; }
.index-table th { background: var(--panel-raised); font-weight: 500; }

.challenge {
  margin-top: 22px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: rgba(242, 193, 78, .08);
  border: 1px solid rgba(242, 193, 78, .35);
}
.challenge h2 { font-size: 1.05rem; color: var(--gold); }
.challenge > p { margin: 8px 0 0; font-size: 1.04rem; }
.challenge-steps { margin: 12px 0 0; padding-left: 24px; display: grid; gap: 6px; }
.challenge-steps li::marker { color: var(--gold); font-weight: 700; }
.checklist-heading { margin-top: 14px; color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.checklist { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.checklist li { position: relative; padding-left: 26px; color: var(--muted); font-size: .94rem; }
.checklist li::before { position: absolute; left: 2px; top: 0; content: "○"; }
.checklist li[data-status="passed"] { color: var(--grass-light); }
.checklist li[data-status="passed"]::before { content: "✓"; font-weight: 800; }
.checklist li[data-status="failed"] { color: var(--text); }
.checklist li[data-status="failed"]::before { content: "✗"; color: var(--red); font-weight: 800; }
.check-hint { display: block; color: var(--amber); font-size: .875rem; }

.success {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: rgba(95, 168, 58, .15);
  border: 1px solid var(--grass);
  animation: pop .35s ease-out;
}
.success-title { display: block; color: var(--grass-light); font-size: 1.2rem; }
.success-text { margin: 6px 0 12px; }
@keyframes pop {
  from { transform: scale(.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .success { animation: none; }
}

.lesson-help { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; justify-items: start; }
.hint-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; width: 100%; }
.lesson-hint {
  min-width: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--panel-raised);
  font-size: .95rem;
}
.lesson-hint strong { display: block; color: var(--gold); font-size: .8rem; }
.lesson-hint pre { margin-top: 8px; font-size: .8rem; }
.lesson-footer { margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--border); }

/* --- code panel ---------------------------------------------------------------- */

.code-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px 0 0;
  background: #252526;
  border-bottom: 1px solid #111;
}
.file-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--editor-bg);
  border-top: 2px solid var(--grass);
  font-family: var(--mono);
  font-size: .85rem;
}
.file-badge { color: #e8d44d; font-size: .7rem; font-weight: 800; }
.editor-status {
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.editor-status[data-state="ready"] { color: var(--grass-light); }
.editor-status[data-state="ready"]::before { content: "✓ "; }
.editor-status[data-state="warn"], .editor-status[data-state="error"] { color: var(--amber); }
.editor-status[data-state="warn"]::before, .editor-status[data-state="error"]::before { content: "⚠ "; }
.editor-host { flex: 1 1 auto; min-height: 180px; background: var(--editor-bg); position: relative; }
.fallback-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 12px 16px;
  border: 0;
  resize: none;
  background: var(--editor-bg);
  color: #d4d4d4;
  font: 15px/22px var(--mono);
  tab-size: 4;
  outline: none;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.flex-spacer { flex: 1; }

.output-panel {
  flex: 0 0 36%;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  background: var(--output-bg);
}
.output-header { display: flex; align-items: center; gap: 10px; padding: 8px 14px 0; }
.output-header h2 { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sim-badge {
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid rgba(242, 184, 75, .5);
  color: var(--amber);
  font-size: .72rem;
  font-weight: 700;
}
.output-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px 14px;
  font-size: .95rem;
  -webkit-overflow-scrolling: touch;
}
.out-placeholder { color: var(--muted); padding: 4px 0; }
.out-placeholder.small { font-size: .85rem; }
.out-event {
  margin: 10px 0 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.out-event:first-child { margin-top: 2px; }
.out-row { display: flex; align-items: baseline; gap: 10px; padding: 3px 0; }
.out-icon { flex: 0 0 22px; text-align: center; }
.out-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.out-meta { color: #7c858d; font-family: var(--mono); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.out-chat .out-text { font-family: var(--mono); }
.out-note { color: var(--amber); font-size: .9rem; }
.out-tip { color: var(--muted); font-size: .9rem; }
.out-log { color: #c9d1d9; font-family: var(--mono); font-size: .85rem; }
.out-warn { color: var(--amber); }
.out-error { color: #ff9d9d; }
.out-warning { color: var(--amber); }
.out-error-title { display: block; font-weight: 650; }
.out-error .out-error-title { color: #ffb3a8; }
.out-help { display: block; color: var(--text); margin-top: 2px; }
.out-raw { display: block; margin-top: 4px; color: #8b949e; font-family: var(--mono); font-size: .8rem; }
.fatal { margin-top: 6px; }
.line-chip {
  margin-right: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.line-chip:hover { background: rgba(255, 255, 255, .08); }

/* --- dialog, toast, boot error ----------------------------------------------------- */

dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { font-size: 1.25rem; padding-right: 44px; }
dialog p { color: var(--muted); }
dialog code { padding: 1px 5px; border-radius: 5px; background: var(--code-bg); }
.dialog-close { position: absolute; top: 14px; right: 14px; }
.folder-tree { margin: 0 0 14px; padding: 12px; border-radius: var(--radius); background: var(--editor-bg); font-size: .85rem; }
.file-card { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.file-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 8px 8px 12px; background: var(--panel-raised); }
.file-card-head strong { font-family: var(--mono); font-size: .875rem; }
.file-note { color: var(--muted); font-size: .85rem; }
.manifest { margin: 0; padding: 12px; max-height: 260px; overflow: auto; background: var(--editor-bg); font-size: .78rem; }
.fine-print { font-size: .85rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: #2d3a2a;
  border: 1px solid var(--grass);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.toast.error { background: #3a2626; border-color: var(--red); }
/* Full-screen confetti layer (see celebrate.js); taps go straight through it. */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 40;
  pointer-events: none;
}
.boot-error {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 30;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: #3a2626;
  border: 1px solid var(--red);
}

/* --- narrow screens: stack panels and let the page scroll ---------------------- */

@media (max-width: 860px) {
  .topbar { height: auto; min-height: var(--header-height); flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .lesson-nav { order: 3; width: 100%; }
  .lesson-nav select { flex: 1 1 0; max-width: none; }
  .topbar-end { margin-left: auto; }
  .app-layout { height: auto; display: block; }
  .lesson-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .lesson-scroll { height: auto; overflow: visible; }
  .editor-host { height: 380px; flex: none; }
  .output-panel { min-height: 260px; }
}
@media (max-width: 520px) {
  .brand-name, .progress-text { display: none; }
  .code-actions .lab-button.ghost { flex: 1; }
}
