:root {
  --sky: #8ec8e6;
  --ink: #1c3147;
  --navy: #1b2a41;
  --panel: #22324a;
  --slot: #2c3f5c;
  --cream: #f4efe4;
  --gold: #f0c419;
  --blue: #2f7de1;
  --left: #e07a2f;
  --right: #e8a317;
  --use: #2f9e62;
  --loop: #7b5ce0;
  --iff: #d24b6e;
  --while: #1a9b9b;
  --ok: #2f9e62;
  --bad: #c44536;
  --scene-h: 360px;
  --chip: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(1200px 420px at 50% -40px, #c5e6f6 0%, var(--sky) 55%, #7eb56a 140%);
  color: var(--ink);
  font-family: "Source Sans Pro", sans-serif;
}

button, .chip, .cmd, .lvl-btn {
  touch-action: manipulation;
}

input, select, textarea {
  font-size: 16px;
}

img, svg, canvas {
  max-width: 100%;
}

.brand-mark {
  max-width: none;
}

.topbar {
  min-height: 64px;
  background: #fffef8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  box-shadow: 0 1px 0 #0001;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-share {
  border: 0;
  background: #eef6ee;
  color: var(--ink);
  font-weight: 700;
  font-family: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.cert-promo {
  text-align: center;
  max-width: 720px;
  margin: 0 auto 12px;
  color: #1d6f42;
  font-weight: 700;
}

.cert-promo-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 800;
  color: #1d6f42;
  text-decoration: underline;
  cursor: pointer;
}

.site-foot a {
  color: #1d6f42;
  font-weight: 800;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-mark { display: block; flex: 0 0 48px; width: 48px; height: 48px; }

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-family: "Freckle Face", cursive;
  font-size: 28px;
  color: #1d6f42;
}

.brand-by {
  font-size: 14px;
  font-weight: 700;
  color: #1c3147;
  letter-spacing: 0.02em;
}

.stage {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px max(12px, env(safe-area-inset-right)) 40px max(12px, env(safe-area-inset-left));
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.workspace > .panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.blocks-panel {
  background: #f3ead6;
}

.blocks-panel .panel-head {
  background: #e4d4b4;
  color: var(--ink);
}

.blocks-panel .text-tool { color: #3a2a18; }

.blocks-panel .how-btn {
  background: var(--gold);
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 10px;
}

.blocks-panel .sequence {
  flex: 1;
  background: #efe4cc;
}

.code-view {
  flex: 1;
  min-height: 220px;
  max-height: 420px;
  overflow: auto;
  background: #121c2b;
  padding: 10px 0;
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.55;
}

.code-line {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  padding: 2px 12px 2px 0;
  color: #d7e2f0;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.code-line:hover, .code-line.is-pair { background: #1c2a40; }

.code-line.is-pair { border-left-color: #7db4ff; }

.code-line.is-run {
  background: #2a3a22;
  border-left-color: var(--gold);
}

.cmd.is-pair, .block.is-pair {
  outline: 3px solid #7db4ff;
  outline-offset: 2px;
}

.code-line .tok {
  white-space: pre;
}

.code-line .ln {
  text-align: right;
  color: #6b7c96;
  user-select: none;
}

.code-line .why {
  color: #8b9bb4;
  font-size: 11px;
  white-space: nowrap;
  padding-top: 2px;
}

.code-line.forward .tok { color: #7db4ff; }
.code-line.left .tok, .code-line.right .tok { color: #f0b35a; }
.code-line.use .tok { color: #6dce98; }
.code-line.loop .tok { color: #c4b0ff; }
.code-line.iff .tok { color: #f08aa3; }
.code-line.while .tok { color: #5ed0d0; }
.code-line.comment .tok { color: #7d8ba0; font-style: italic; }
.code-line.wrap .tok { color: #9db0c9; }
.code-kw { color: #c792ea; font-weight: 600; }
.code-num { color: var(--gold); }

.code-caption {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  color: #c9d4e5;
  background: #18263c;
}

.lang-toggle { display: flex; gap: 4px; }

.lang-btn {
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  background: #2c3f5c;
  color: #d7e4f5;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
}

.lang-btn.is-on { background: var(--gold); color: var(--ink); }

.scene-wrap {
  position: relative;
  height: var(--scene-h);
}

#scene {
  width: 100%;
  height: var(--scene-h);
  display: block;
  cursor: grab;
}

.lynx-say {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  max-width: min(520px, 86%);
  margin: 0;
  background: #fffef8;
  color: #1c3147;
  border: 2px solid #1d6f42;
  border-radius: 16px 16px 16px 4px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  box-shadow: 0 6px 16px #0002;
  z-index: 3;
  pointer-events: none;
}

.lynx-say.fail { border-color: var(--bad); }
.lynx-say.win { border-color: var(--ok); color: #1d6f42; }

.lynx-say[hidden] { display: none; }

.lynx-name-lab {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1d6f42;
}

.lynx-name-lab input {
  width: 96px;
  height: 32px;
  border: 2px solid #1d6f42;
  border-radius: 8px;
  padding: 0 8px;
  font: 700 16px "Source Sans Pro", sans-serif;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}

.ghost-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  margin: 0;
  background: #fff8e6cc;
  color: #5a4308;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}

.ghost-hint[hidden] { display: none; }

.cam-bar {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
}

.cam-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: #1b2a41cc;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

.cam-btn:hover { background: #1b2a41; }
.cam-btn.muted { opacity: 0.45; }

.hud { position: relative; min-height: 0; }

.level-meta {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.lesson-pill {
  margin: 0;
  background: #1d6f42;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin: 8px auto 4px;
}

.progress-track {
  flex: 1;
  height: 8px;
  background: #fff8;
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: #1d6f42;
  border-radius: 99px;
}

#progressLabel {
  font-size: 12px;
  font-weight: 700;
  color: #1c3147;
}

.now-running {
  text-align: center;
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 14px;
  background: #1b2a41;
  color: var(--gold);
  margin: 0 auto 12px;
  padding: 8px 14px;
  border-radius: 8px;
  max-width: 720px;
}

.lesson-coach {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto 12px;
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 4px 12px #0002;
}

.lesson-coach[hidden],
.now-running[hidden],
.coach-banner[hidden] {
  display: none !important;
}

.lesson-coach p { margin: 0; }

.cheat-sheet {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  background: #162338;
}

.cheat-item {
  font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  font-size: 11px;
  background: #22324a;
  color: #d7e2f0;
  border-radius: 6px;
  padding: 4px 8px;
}

.cheat-item b { color: #7db4ff; }

.chip-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.chip-lab {
  font-size: 12px;
  font-weight: 700;
  color: #3a2a18;
  max-width: 76px;
  text-align: center;
  line-height: 1.15;
}

.level-kicker {
  margin: 0;
  text-align: center;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: #2a6a3a;
}

.star-line {
  margin: 0;
  color: var(--gold);
  font-size: 22px;
  letter-spacing: 2px;
  text-shadow: 0 1px 0 #0002;
}

.tool-row { display: none; }

.tool-btn, .text-tool, .btn-step, .speed-btn {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-family: inherit;
}

.tool-btn {
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  box-shadow: 0 2px 0 #0002;
}

.coach-banner, .coach-tip {
  text-align: center;
  background: #fff6d4;
  border: 1px solid #e0c35a;
  color: #5a4308;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 auto 12px;
  max-width: 560px;
}

.coach-tip { margin: 0 16px 12px; }

.keys-hint {
  text-align: center;
  font-size: 13px;
  color: #1c314799;
  margin: 12px 0 0;
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-tool {
  background: transparent;
  color: #d7e4f5;
  font-size: 13px;
  padding: 6px 8px;
}

.run-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 200px;
}

.speed {
  display: flex;
  gap: 4px;
}

.speed-btn {
  flex: 1;
  padding: 6px 0;
  background: #d9c9a6;
  color: var(--ink);
  font-size: 12px;
}

.speed-btn.is-on { background: var(--gold); color: var(--ink); }

.run-btns {
  display: flex;
  gap: 8px;
}

.btn-step {
  flex: 0 0 72px;
  height: 72px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 #b7c2ce;
}

.teach-pulse {
  position: relative;
  z-index: 6;
  box-shadow: 0 0 0 6px #fff, 0 0 0 10px var(--gold);
  animation: teachring 1.2s ease infinite;
}

@keyframes teachring {
  0%, 100% { box-shadow: 0 0 0 6px #fff, 0 0 0 10px var(--gold); }
  50% { box-shadow: 0 0 0 8px #fff, 0 0 0 14px #ffe08a; }
}

.btn-step:disabled, .text-tool:disabled { opacity: 0.45; cursor: default; }

.sequence.drop, .block-body.drop, .block-else.drop {
  outline: 2px dashed var(--gold);
}

.cmd { cursor: grab; }
.cmd:active { cursor: grabbing; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 20;
  box-shadow: 0 8px 20px #0004;
}

.lvl-btn.locked {
  background: #c5d0d8;
  color: #5a6a76;
  cursor: not-allowed;
}

.lvl-btn .mini-stars {
  display: block;
  font-size: 9px;
  letter-spacing: 0;
  color: #b8860b;
}

.level-title {
  margin: 4px 0 8px;
  text-align: center;
  font-family: "Freckle Face", cursive;
  font-size: 30px;
  font-weight: 400;
  line-height: 1.15;
  color: #2a6a3a;
  white-space: pre-line;
}

.level-hint {
  text-align: center;
  white-space: pre-line;
  color: #244;
  margin: 0 auto 10px;
  max-width: 640px;
  min-height: 0;
  font-size: 15px;
}

.panel {
  background: var(--navy);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 24px #0002;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  background: #162338;
  color: #fff;
}

.panel-head pre {
  margin: 0;
  font-family: "Source Sans Pro", sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.trash {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M9 3h6l1 2h5v2H3V5h5l1-2zm1 6h2v9h-2V9zm4 0h2v9h-2V9zM7 9h2v9H7V9z'/></svg>") center/22px no-repeat;
  cursor: pointer;
  opacity: 0.9;
}

.sequence {
  min-height: 92px;
  padding: 14px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
  background: #efe4cc;
}

.slot {
  width: var(--chip);
  height: var(--chip);
  border: 2px dashed #b79a6a;
  border-radius: 10px;
  background: #f7efe0;
}

.cmd {
  width: var(--chip);
  height: var(--chip);
  border: 0;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  position: relative;
  box-shadow: 0 3px 0 #0004;
}

.cmd.active { outline: 3px solid #fff; }

.block {
  background: #fffaf0;
  border: 2px solid #c4a574;
  border-radius: 12px;
  padding: 8px;
  min-width: min(220px, 100%);
  flex: 1 1 100%;
}

.cmd.is-fail, .block.is-fail, .code-line.is-fail {
  outline: 3px solid var(--bad);
  outline-offset: 2px;
  animation: failpulse 0.9s ease 2;
}

.code-line.is-fail { background: #3a2222; border-left-color: var(--bad); }

@keyframes failpulse {
  0%, 100% { outline-color: var(--bad); }
  50% { outline-color: #ff8a7a; }
}

.block.focused { border-color: var(--gold); }

.block-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  margin-bottom: 8px;
}

.block-body, .block-else {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
  padding: 8px;
  border-radius: 8px;
  background: #f3e6c8;
}

.block-else { background: #f0d9d0; }

.else-label {
  color: #6a3a32;
  font-size: 12px;
  font-weight: 700;
  margin: 6px 0 4px;
}

.count {
  display: flex;
  align-items: center;
  gap: 4px;
}

.count button {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.cond {
  border: 0;
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 1px 0 #0002;
}

.palette-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: center;
  background: #e6d5b0;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex: 1;
}

.cmd.forward, .chip.forward { background: var(--blue); }
.cmd.left, .chip.left { background: var(--left); }
.cmd.right, .chip.right { background: var(--right); }
.cmd.use, .chip.use { background: var(--use); }
.cmd.loop, .chip.loop { background: var(--loop); }
.cmd.if, .chip.if { background: var(--iff); }
.cmd.while, .chip.while { background: var(--while); }

.chip {
  width: var(--chip);
  height: var(--chip);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0005;
}

.chip:active { transform: translateY(2px); box-shadow: 0 2px 0 #0005; }

.icon-arrow::after,
.cmd.forward::after,
.chip.forward::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border: 12px solid transparent;
  border-left: 18px solid #fff;
  margin: 20px auto 0 22px;
}

.cmd.left::after, .chip.left::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border: 12px solid transparent;
  border-bottom: 18px solid #fff;
  margin: 16px auto 0;
}

.cmd.right::after, .chip.right::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border: 12px solid transparent;
  border-top: 18px solid #fff;
  margin: 22px auto 0;
}

.cmd.use::after, .chip.use::after {
  content: "✦";
  display: block;
  text-align: center;
  font-size: 28px;
  line-height: var(--chip);
}

.cmd.loop::after, .chip.loop::after {
  content: "↻";
  display: block;
  text-align: center;
  font-size: 32px;
  line-height: var(--chip);
}

.cmd.if::after, .chip.if::after {
  content: "IF";
  display: block;
  text-align: center;
  font-weight: 800;
  line-height: var(--chip);
  font-size: 18px;
}

.cmd.while::after, .chip.while::after {
  content: "while";
  display: block;
  text-align: center;
  font-weight: 800;
  line-height: var(--chip);
  font-size: 12px;
}

.block-head .cmd::after {
  line-height: 36px;
  margin: 0;
}

.block-head .cmd.forward::after {
  border-width: 8px;
  border-left-width: 12px;
  margin: 10px auto 0 12px;
}

.block-head .cmd.loop::after {
  font-size: 20px;
}

.block-head .cmd.if::after {
  font-size: 12px;
}

.block-head .cmd.while::after {
  font-size: 9px;
}

.btn-run {
  flex: 1;
  height: 72px;
  border: 0;
  border-radius: 10px;
  background: var(--gold);
  color: #1c3147;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 0 #c9a00e;
}

.btn-run:disabled { opacity: 0.55; cursor: default; }

.play-tri {
  width: 0;
  height: 0;
  border: 12px solid transparent;
  border-left: 18px solid #1c3147;
  margin-left: 6px;
}

.btn-levels {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.btn-levels::before {
  content: "▦ ";
}

.overlay {
  position: fixed;
  inset: 0;
  background: #8ec8e6ee;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
  overflow: auto;
  z-index: 12;
}

.overlay[hidden] { display: none !important; }

.dialog {
  width: min(420px, 92vw);
  background: #f7f1e6;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 16px 40px #0003;
}

.dialog.picker {
  width: min(640px, 94vw);
  max-height: min(88dvh, 900px);
  display: flex;
  flex-direction: column;
}

.dialog-head {
  background: var(--ok);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog.fail .dialog-head,
.success-banner.fail .dialog-head { background: var(--bad); }

.dialog-head p,
.dialog-head pre {
  margin: 0;
  font-family: "Source Sans Pro", sans-serif;
  font-size: 20px;
  font-weight: 700;
}

.success-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto 12px;
  background: #eef8ef;
  border: 2px solid var(--ok);
  color: #1d6f42;
  border-radius: 12px;
  padding: 10px 12px;
}

.success-banner[hidden] { display: none !important; }

.success-banner.fail {
  background: #fde8e4;
  border-color: var(--bad);
  color: #6a2218;
}

.success-copy { min-width: 0; }

.success-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.success-title {
  font-family: "Freckle Face", cursive;
  font-size: 28px;
  font-weight: 400;
  margin: 2px 0 0;
  color: inherit;
  white-space: pre-line;
}

.success-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.success-banner .btn-next {
  height: 40px;
  padding: 0 14px;
  font-size: 16px;
}

.banner-close {
  border: 0;
  background: #1d6f4222;
  color: #1d6f42;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 36px;
}

.banner-close:hover { background: #1d6f4233; }

.dialog-art {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  background: #efe6d4;
}

.dialog-title {
  font-family: "Freckle Face", cursive;
  text-align: center;
  font-size: 36px;
  font-weight: 400;
  margin: 10px 16px 16px;
  color: #2a6a3a;
  white-space: pre-line;
}

.dialog.fail .dialog-title { color: var(--bad); }

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 20px 20px;
}

.btn-next, .btn-close {
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
}

.btn-retry {
  height: 44px;
  border: 0;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.level-list {
  padding: 12px 16px 8px;
  flex: 1 1 auto;
  max-height: min(52vh, 360px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog.picker > .btn-close {
  margin: 8px 16px 16px;
  flex-shrink: 0;
}

.group-name {
  margin: 10px 0 6px;
  font-family: "Freckle Face", cursive;
  font-size: 22px;
  color: #2a6a3a;
}

.group-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lvl-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: #d7ecdf;
  font-weight: 800;
  cursor: pointer;
}

.lvl-btn.done { background: var(--gold); }
.lvl-btn.current { outline: 3px solid #2a6a3a; }

.site-foot {
  text-align: center;
  font-size: 14px;
  padding: 8px max(20px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  color: #1c3147;
}

.site-foot p { margin: 0; }

.cert-overlay {
  position: fixed;
  inset: 0;
  padding: max(20px, env(safe-area-inset-top)) 12px max(32px, env(safe-area-inset-bottom));
  align-items: flex-start;
  overflow: auto;
  z-index: 20;
}

.cert-card {
  width: min(920px, 96vw);
  margin: 0 auto;
  background: #fffef8;
  border-radius: 16px;
  padding: 16px 18px 12px;
  box-shadow: 0 16px 40px #0003;
}

.cert-heading { font-size: 28px; margin-bottom: 8px; line-height: 1.2; }

.cert-name-lab {
  display: block;
  text-align: center;
  font-weight: 700;
  margin: 0 0 6px;
}

.cert-name {
  display: block;
  width: min(420px, 90%);
  margin: 0 auto 14px;
  height: 44px;
  border: 2px solid #1d6f42;
  border-radius: 8px;
  padding: 0 12px;
  font: 700 16px "Source Sans Pro", sans-serif;
  text-align: center;
  color: var(--ink);
  background: #fff;
}

.cert-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 8px 24px #0002;
  background: #f7f1e6;
}

.cert-actions {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 14px;
}

.cert-actions .btn-next,
.cert-actions .btn-retry,
.cert-actions .btn-close {
  min-width: 160px;
  flex: 1;
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
}

.fail-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto 12px;
  background: #fde8e4;
  border: 2px solid var(--bad);
  color: #6a2218;
  border-radius: 10px;
  padding: 10px 12px;
}

.fail-banner[hidden] { display: none !important; }

.fail-banner p { margin: 0; font-weight: 700; }

.fail-actions { display: flex; gap: 8px; flex-shrink: 0; }

.debug-strip {
  text-align: center;
  max-width: 720px;
  margin: 0 auto 10px;
  background: #fff3c4;
  border: 1px solid #e0c35a;
  color: #5a4308;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
}

.debug-strip[hidden] { display: none; }

.pack-overlay { padding-top: 48px; }

.pack-card { padding-bottom: 8px; }

.pack-kicker {
  text-align: center;
  letter-spacing: 0.16em;
  font-weight: 800;
  text-transform: uppercase;
  color: #2a6a3a;
  margin: 16px 0 0;
}

.pack-text {
  text-align: center;
  margin: 0 24px 8px;
  color: #244;
  font-size: 18px;
  line-height: 1.4;
}

.pack-blurb {
  margin: 0 0 8px;
  color: #3a4a3a;
  font-size: 14px;
}

.workspace-tabs {
  display: none;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.pane-tab {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  flex: 1;
  font-weight: 700;
  font-family: inherit;
  background: #fff8;
  cursor: pointer;
}

.pane-tab.is-on { background: var(--gold); }

.lesson-coach {
  border: 2px solid var(--gold);
}

@media (max-width: 900px) {
  :root { --scene-h: 280px; }
  .workspace { grid-template-columns: 1fr; }
  .code-view { max-height: 240px; min-height: 160px; }
  .workspace-tabs { display: flex; }
  .workspace .panel { display: none; }
  .workspace .panel.is-show { display: flex; flex-direction: column; }
  .palette-row {
    flex-direction: column;
    align-items: stretch;
  }
  .run-col { flex-basis: auto; width: 100%; }
  .btn-run, .btn-step { flex: 1; }
  .level-list { max-height: min(48dvh, 360px); }
}

@media (max-width: 720px) {
  :root {
    --scene-h: 220px;
    --chip: 56px;
  }
  .brand-name { font-size: 22px; }
  .level-title { font-size: 24px; }
  .success-title { font-size: 22px; }
  .dialog-title { font-size: 28px; }
  .pack-text { font-size: 16px; margin: 0 16px 8px; }
  .btn-run, .btn-step { height: 56px; font-size: 16px; }
  .icon-arrow::after,
  .cmd.forward::after,
  .chip.forward::after {
    border-width: 10px;
    border-left-width: 15px;
    margin: 16px auto 0 18px;
  }
  .cmd.left::after, .chip.left::after {
    border-width: 10px;
    border-bottom-width: 15px;
    margin: 12px auto 0;
  }
  .cmd.right::after, .chip.right::after {
    border-width: 10px;
    border-top-width: 15px;
    margin: 18px auto 0;
  }
  .cmd.use::after, .chip.use::after { font-size: 24px; }
  .cmd.loop::after, .chip.loop::after { font-size: 28px; }
  .keys-hint { display: none; }
  .code-line .why { display: none; }
  .fail-banner,
  .success-banner { flex-direction: column; text-align: center; }
  .success-actions,
  .fail-actions { justify-content: center; width: 100%; }
  .success-banner .btn-next { width: 100%; }
  .cert-actions { flex-direction: column; }
  .cert-actions .btn-next,
  .cert-actions .btn-retry,
  .cert-actions .btn-close { min-width: 0; width: 100%; }
  .blocks-panel .panel-tools { flex-wrap: wrap; }
  .lesson-coach { flex-direction: column; text-align: center; }
  .lynx-say { font-size: 14px; padding: 6px 10px; }
  .now-running { font-size: 12px; overflow-wrap: anywhere; }
  .count button { width: 32px; height: 32px; }
  .cond { min-height: 36px; font-size: 16px; }
  .speed-btn { min-height: 36px; font-size: 14px; }
  .cam-btn { width: 44px; height: 44px; }
  .top-share { min-height: 44px; }
  .cert-promo { padding: 0 8px; }
  .cert-heading { font-size: 22px; }
  .cert-card { padding: 12px 10px 10px; }
  .btn-levels { min-height: 44px; }
  .block-head { flex-wrap: wrap; }
}

@media (max-width: 520px) {
  :root {
    --scene-h: 200px;
    --chip: 52px;
  }
  .hide-narrow { display: none; }
  .brand-by { display: none; }
  .brand-mark { width: 36px; height: 36px; flex-basis: 36px; }
  .brand-name { font-size: 20px; }
  .level-title { font-size: 22px; }
  .level-hint { font-size: 14px; padding: 0 4px; }
  .chip-lab { font-size: 11px; max-width: 64px; }
  .icon-arrow::after,
  .cmd.forward::after,
  .chip.forward::after {
    border-width: 9px;
    border-left-width: 13px;
    margin: 14px auto 0 16px;
  }
  .cmd.if::after, .chip.if::after { font-size: 15px; }
  .cmd.while::after, .chip.while::after { font-size: 10px; }
  .palette-row { padding: 10px; }
  .sequence { padding: 10px 8px; gap: 8px; }
  .lynx-name-lab input { width: 88px; }
  #certPromoNote { display: block; margin-top: 4px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  :root { --scene-h: 140px; }
  .lynx-say { font-size: 13px; padding: 4px 10px; top: 4px; }
  .ghost-hint { display: none; }
  .cam-bar { bottom: 4px; right: 4px; }
  .cam-btn { width: 36px; height: 36px; }
}

@media (pointer: coarse) {
  .text-tool { min-height: 36px; padding: 8px 10px; }
  .trash { width: 44px; height: 44px; }
}
