/* Layout: full-screen paper world (canvas) + a dark "real code" editor docked right (landscape) or bottom (portrait). Pip the pencil guides from a corner. */
:root {
  --paper: #ffffff;
  --ink: #2b2b2b;
  --pencil: #ffc53d;
  --pencil-deep: #e8a92a;
  --eraser: #ff8fb1;
  --editor: #1d2033;
  --editor-2: #272b44;
  --editor-line: #343a5c;
  --who: #7cc4ff;
  --what: #c9a8ff;
  --becomes: #ffb86b;
  --muted: #8d93b5;
  --good: #3ccf7a;
  --font-ui: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --font-code: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Consolas, monospace;
  --panel-w: min(460px, 46vw);
  --tap: 52px;
  color-scheme: light;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
#app { position: fixed; inset: 0; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; cursor: pointer; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--who); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none; z-index: 5;
}
#hud > * { pointer-events: auto; }
.hud-right { display: flex; gap: 10px; }
.chip, .round {
  height: var(--tap); border: 3px solid var(--ink); background: var(--paper);
  border-radius: 999px; font-size: 22px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s;
}
.chip { padding: 0 18px 0 10px; }
.chip span:first-child { font-size: 28px; }
.round { min-width: var(--tap); justify-content: center; padding: 0 10px; }
.round b { font-size: 18px; }
.chip:active, .round:active, .go:active, .opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#voiceBtn.off { opacity: .45; }
.round.stat { box-shadow: none; border-style: dashed; }
.round.save { font-size: 20px; min-width: 44px; }
.round.save.warn { border-color: var(--eraser); background: #fff0f5; }

/* ---------- Pip + speech bubble ---------- */
#pip {
  position: absolute; z-index: 6;
  left: max(12px, env(safe-area-inset-left, 0px));
  top: calc(env(safe-area-inset-top, 0px) + 74px);
  display: flex; align-items: flex-start; gap: 6px;
  max-width: calc(100vw - var(--panel-offset, 0px) - 24px);
  transition: max-width .3s;
  pointer-events: none;
}
#pip > * { pointer-events: auto; }
.pip-body { width: 54px; height: 108px; flex: none; transform-origin: 50% 100%; animation: pip-bob 2.6s ease-in-out infinite; }
#pip.talking .pip-body { animation: pip-talk .35s ease-in-out infinite alternate; }
#pipBtn { position: relative; flex: none; background: none; border: 0; padding: 0 6px; border-radius: 18px; min-height: var(--tap); }
#pipBtn .pip-body { display: block; }
.pip-hint {
  position: absolute; top: -4px; right: -16px; font-size: 26px; display: none;
  animation: hint-pulse 1.4s ease-in-out infinite;
}
#pip.collapsed .pip-hint { display: block; }
#pip.nudge .pip-body { animation: pip-nudge 1.6s ease-in-out infinite; }
@keyframes hint-pulse { 50% { transform: scale(1.25); } }
@keyframes pip-nudge { 0%, 60%, 100% { transform: rotate(0); } 15% { transform: rotate(-14deg) translateY(-8px); } 30% { transform: rotate(12deg); } 45% { transform: rotate(-6deg); } }
#hushBtn {
  position: absolute; top: -16px; right: -16px; width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--paper); font-size: 15px; font-weight: 700; z-index: 1;
}
@keyframes pip-bob { 50% { transform: rotate(-4deg) translateY(-3px); } }
@keyframes pip-talk { from { transform: rotate(-5deg); } to { transform: rotate(5deg) translateY(-4px); } }
#bubble {
  position: relative; background: var(--paper); border: 3px solid var(--ink); border-radius: 22px;
  padding: 14px 16px 12px; margin-top: 22px; min-width: 0; max-width: 560px;
  box-shadow: 0 5px 0 var(--ink);
  animation: pop-in .25s ease-out;
}
#bubble::before {
  content: ""; position: absolute; left: -14px; top: 22px; width: 20px; height: 20px;
  background: var(--paper); border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
  transform: rotate(45deg);
}
#bubble { display: flex; flex-wrap: wrap; align-items: flex-end; column-gap: 12px; }
#bubbleText { flex: 1 1 240px; margin: 0; font-size: 22px; line-height: 1.35; font-weight: 500; text-wrap: pretty; }
#bubbleText code, .card code {
  font-family: var(--font-code); font-size: .9em; background: var(--editor); color: #f3f4ff;
  padding: 1px 7px; border-radius: 7px; white-space: nowrap;
}
.bubble-actions { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0 auto; }
.mini { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); font-size: 18px; }
.go {
  min-height: 48px; padding: 0 22px; border: 3px solid var(--ink); border-radius: 999px;
  background: var(--pencil); font-size: 21px; font-weight: 700; box-shadow: 0 4px 0 var(--ink);
}
.go.big { width: 100%; min-height: 58px; font-size: 24px; background: var(--good); }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }

/* ---------- Code panel ---------- */
#codePanel {
  position: absolute; z-index: 7; top: 0; right: 0; bottom: 0; width: var(--panel-w);
  background: var(--editor); color: #eef0ff;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  transform: translateX(105%); transition: transform .35s cubic-bezier(.2,.9,.3,1.1);
  box-shadow: -6px 0 0 var(--ink);
}
#codePanel.open { transform: none; }
#codePanel header {
  display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 18px;
  border-bottom: 2px solid var(--editor-line);
}
.file { display: flex; align-items: center; gap: 10px; font-family: var(--font-code); font-size: 19px; color: var(--muted); flex: 1; min-width: 0; }
.file-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pencil); flex: none; }
.goal { font-size: 18px; font-weight: 600; background: var(--editor-2); padding: 6px 12px; border-radius: 999px; color: var(--pencil); }
.x { width: 48px; height: 48px; border-radius: 50%; border: 2px solid var(--editor-line); background: var(--editor-2); color: #fff; font-size: 22px; flex: none; }
.lines { flex: 1; overflow-y: auto; padding: 12px 10px 20px 6px; -webkit-overflow-scrolling: touch; }
.line {
  display: grid; grid-template-columns: 38px 26px 1fr 30px; align-items: center;
  min-height: 64px; border-radius: 14px; padding: 4px 4px; position: relative;
  transition: background .2s, opacity .2s;
}
.line.dim { opacity: .3; pointer-events: none; }
.line.focus { background: var(--editor-2); box-shadow: inset 0 0 0 3px var(--pencil); }
.line.fresh { animation: fresh 1.2s ease-in-out 3; }
@keyframes fresh { 50% { background: #3b3360; } }
.gutter { font-size: 24px; text-align: center; }
.ln { font-family: var(--font-code); color: #5a6088; font-size: 16px; text-align: right; padding-right: 6px; }
.stmt { font-family: var(--font-code); font-size: 21px; display: flex; align-items: center; flex-wrap: wrap; gap: 0; min-width: 0; position: relative; }
.t-who { color: var(--who); font-weight: 700; }
.t-dot { color: #fff; }
.t-what { color: var(--what); font-weight: 700; }
.t-eq { color: var(--muted); margin: 0 8px; }
.t-val {
  font: inherit; font-weight: 700; color: var(--becomes);
  background: #33283a; border: 2px solid #6b4a3a; border-radius: 12px;
  min-height: 48px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 3px 0 #120f1c;
}
.t-val.num { color: #8ff0b4; background: #213a33; border-color: #2f6b52; }
.t-val .sw { width: 22px; height: 22px; border-radius: 6px; border: 2px solid #fff; flex: none; }
.t-val .sw.rainbow { background: linear-gradient(90deg, #ff4d4d, #ffb84d, #fff04d, #4dff88, #4dc3ff, #b84dff); }
.line.focus .t-val { animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-3px) scale(1.05); } }
.star { font-size: 20px; text-align: center; opacity: 0; transition: opacity .3s; }
/* commands and loops: build("house"), repeat 6 times { plant("tulip") } */
.t-kw { color: #ff8fb1; font-weight: 700; margin: 0 8px 0 0; }
.t-kw + .t-val, .t-num + .t-kw, .t-val + .t-kw, .cnt + .t-kw { margin-left: 8px; }
.t-fn { color: #7ce0d6; font-weight: 700; }
.t-paren { color: #fff; }
.t-str { color: var(--becomes); font-weight: 700; }
.t-num { color: #8ff0b4; font-weight: 700; }
.line.indent .stmt { padding-left: 30px; }
.t-kw.brace { margin: 0 0 0 8px; }
.t-val.act { color: #7ce0d6; background: #1f3640; border-color: #2f6170; }
.line.static { cursor: default; }
.go.big.run { background: var(--pencil); }
.line.changed .star { opacity: 1; }

/* WHO / WHAT / BECOMES labels */
.anatomy .stmt { padding-bottom: 30px; }
.tag {
  position: absolute; bottom: -2px; font-family: var(--font-ui); font-size: 14px; font-weight: 700;
  letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; color: var(--editor);
  transform: translateX(-50%); white-space: nowrap; animation: pop-in .3s ease-out backwards;
}
.tag.who { background: var(--who); }
.tag.what { background: var(--what); animation-delay: .5s; }
.tag.becomes { background: var(--becomes); animation-delay: 1s; }
#codeFooter { padding: 12px 16px 16px; border-top: 2px solid var(--editor-line); }

/* Picker */
#picker {
  position: absolute; inset: 0; background: var(--editor); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) 0;
  animation: slide-up .25s ease-out;
}
@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } }
.picker-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; }
.picker-head h3 { margin: 0; font-size: 24px; font-weight: 600; }
.picker-line { font-family: var(--font-code); font-size: 21px; padding: 4px 18px 10px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: baseline; }
.picker-line b { color: var(--becomes); }
.options {
  flex: 1; overflow-y: auto; padding: 8px 16px 16px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 12px; align-content: start;
}
.opt {
  min-height: 104px; border: 3px solid var(--editor-line); background: var(--editor-2); border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 17px; font-weight: 600; color: #eef0ff; padding: 8px 4px; box-shadow: 0 4px 0 #0f1120;
}
.opt.on { border-color: var(--pencil); background: #3a3352; }
.opt .big { font-size: 38px; line-height: 1; }
.opt .dot { width: 46px; height: 46px; border-radius: 50%; border: 3px solid #fff; }
.opt .dot.none { background: #fff; border-style: dashed; }
.opt canvas { width: 72px; height: 72px; }
.opt .num { font-family: var(--font-code); font-size: 40px; color: #8ff0b4; }
.stepper { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 12px 0; }
.stepper button { width: 76px; height: 76px; border-radius: 50%; font-size: 40px; font-weight: 700; border: 3px solid var(--ink); background: var(--pencil); color: var(--ink); box-shadow: 0 4px 0 #0f1120; }
.stepper output { font-family: var(--font-code); font-size: 64px; min-width: 110px; text-align: center; color: #8ff0b4; }
.type-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px 18px; border-top: 2px solid var(--editor-line); flex-wrap: wrap; }
.type-row label { font-size: 19px; font-weight: 600; color: var(--muted); }
.type-row input {
  flex: 1; min-width: 120px; height: 52px; border-radius: 14px; border: 3px solid var(--editor-line);
  background: #11131f; color: var(--becomes); font-family: var(--font-code); font-size: 22px; padding: 0 14px;
}
.type-row.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- Overlays (players, puzzles, chest, postcard, secrets) ---------- */
#overlay {
  position: absolute; inset: 0; z-index: 20; background: rgb(43 43 43 / .45);
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) max(16px, env(safe-area-inset-right, 0px)) calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
}
#overlay.solid { background: var(--paper); }
.card {
  box-sizing: border-box; min-width: 0;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink);
  padding: 24px; width: min(720px, 100%); max-height: 100%; overflow-y: auto;
  animation: pop-in .3s ease-out; text-align: center;
}
.card h1 { font-size: clamp(44px, 8vw, 76px); margin: 0 0 4px; font-weight: 700; letter-spacing: -.01em; }
.card h2 { font-size: 30px; margin: 0 0 12px; font-weight: 600; text-wrap: balance; }
.card p { font-size: 21px; margin: 8px 0; line-height: 1.4; }
.card .sub { color: #6c6c7a; }
.title-doodle { display: block; margin: 0 auto 8px; width: 160px; height: 100px; }
.gap-top { margin-top: 18px; }
.error { color: #c4213a; font-weight: 600; min-height: 1em; }
.error:empty { display: none; }
.signin-card .signin { max-width: 440px; margin: 0 auto; }
.signin-card .form-row input[type=password] { height: 56px; font-family: inherit; font-size: 24px; border: 3px solid var(--ink); border-radius: 16px; padding: 0 16px; }
.big-link { display: inline-flex; align-items: center; text-decoration: none; color: var(--ink); background: var(--pencil); }
.local-login { margin: 18px auto 0; max-width: 460px; text-align: left; }
.local-login summary { font-size: 18px; font-weight: 600; cursor: pointer; text-align: center; color: #555; }
.linkish { background: none; border: 0; font-size: 18px; font-weight: 600; color: #3b4bd8; text-decoration: underline; margin-top: 12px; }
.player-wrap { position: relative; }
.form-row input[type=password] { height: 56px; font-family: inherit; font-size: 24px; border: 3px solid var(--ink); border-radius: 16px; padding: 0 16px; }
.grownups { text-align: left; }
.grownups h2, .grownups > .row { text-align: center; }
.grownups h3 { font-size: 22px; margin: 20px 0 8px; border-bottom: 2px solid #ececf2; padding-bottom: 4px; }
.gu-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px dashed #e2e2ea; }
.gu-row .av { font-size: 36px; }
.gu-main { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 20px; }
.gu-main .sub { font-size: 15px; }
.gu-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.gu-actions .warn { font-size: 15px; color: #c4213a; }
.gu-list { margin: 0; padding-left: 20px; font-size: 16px; line-height: 1.6; }
.gu-list li.alert { color: #c4213a; font-weight: 600; }
.ghost.small, .go.small { min-height: 40px; font-size: 16px; padding: 0 14px; }
.go.danger { background: #ff8f8f; }
.row.left { justify-content: flex-start; align-items: center; }
button:disabled { opacity: .6; }
.players { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin: 20px 0 8px; }
.player {
  position: relative; width: 150px; min-height: 160px; border: 3px solid var(--ink); border-radius: 24px; background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 22px; font-weight: 600; box-shadow: 0 5px 0 var(--ink);
}
.player .av { font-size: 60px; line-height: 1; }
.player.new { border-style: dashed; color: #6c6c7a; }
.player-wrap .del { position: absolute; top: -12px; right: -12px; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); font-size: 16px; }
.form-row { display: flex; flex-direction: column; gap: 8px; margin: 14px auto; max-width: 440px; text-align: left; }
.form-row label { font-size: 19px; font-weight: 600; }
.form-row input[type=text] { height: 56px; font-family: inherit; font-size: 24px; border: 3px solid var(--ink); border-radius: 16px; padding: 0 16px; }
.avatars { display: flex; flex-wrap: wrap; gap: 10px; }
.avatars button { width: 64px; height: 64px; font-size: 36px; border-radius: 18px; border: 3px solid #d6d6de; background: var(--paper); }
.avatars button.on { border-color: var(--ink); background: #fff5d6; }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 19px; font-weight: 600; }
.toggle input { width: 28px; height: 28px; accent-color: var(--good); }
.row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.ghost { min-height: 48px; padding: 0 20px; border: 3px solid var(--ink); border-radius: 999px; background: var(--paper); font-size: 19px; font-weight: 600; }

/* Puzzle */
.puzzle .codebox { display: inline-block; font-family: var(--font-code); font-size: 26px; background: var(--editor); color: #eef0ff; padding: 12px 20px; border-radius: 16px; margin: 6px 0 12px; }
.codebox .t-val { min-height: 0; padding: 2px 8px; box-shadow: none; }
.puzzle canvas.preview { width: 100%; max-width: 420px; aspect-ratio: 5 / 3; border: 3px solid var(--ink); border-radius: 16px; display: block; margin: 0 auto 14px; }
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.answer {
  min-height: 96px; border: 3px solid var(--ink); border-radius: 20px; background: var(--paper); box-shadow: 0 5px 0 var(--ink);
  font-size: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px;
}
.answer small { font-size: 18px; font-weight: 600; }
.answer.code { font-family: var(--font-code); font-size: 19px; background: var(--editor); color: #eef0ff; }
.answer.wrong { animation: shake .4s; opacity: .4; }
.answer.right { background: #d8f8e5; border-color: var(--good); }
.answer.code.right { background: #1f4a37; }
.stars { font-size: 30px; letter-spacing: 6px; }

/* Chest + confetti */
.chest { font-size: 140px; line-height: 1; display: inline-block; animation: wiggle 1s ease-in-out infinite; background: none; border: 0; }
@keyframes wiggle { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
.prize { font-size: 120px; line-height: 1.1; animation: prize .6s cubic-bezier(.2,1.6,.4,1); }
@keyframes prize { from { transform: scale(0) rotate(-30deg); } }
.confetti { position: fixed; top: -20px; width: 12px; height: 18px; z-index: 30; pointer-events: none; animation: fall 2.2s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* Postcard + secrets */
.postcard img { width: 100%; border: 3px solid var(--ink); border-radius: 16px; display: block; }
.postcard pre { text-align: left; font-family: var(--font-code); font-size: 16px; background: var(--editor); color: #eef0ff; padding: 14px 16px; border-radius: 16px; overflow-x: auto; margin: 12px 0 0; line-height: 1.5; }
.postcard pre .t-who { color: var(--who); } .postcard pre .t-what { color: var(--what); } .postcard pre .v { color: var(--becomes); }
.postcard pre .t-eq { margin: 0; color: var(--muted); } .postcard pre .t-kw { margin: 0; } .postcard pre .t-fn { color: #7ce0d6; }
.secrets { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 12px; text-align: left; }
.secret { border: 3px dashed #c8c8d4; border-radius: 16px; padding: 10px 12px; font-size: 17px; line-height: 1.3; }
.secret .e { font-size: 28px; }
.secret.found { border-style: solid; border-color: var(--good); background: #effcf4; }
.secret code { font-size: 14px !important; white-space: normal !important; }

/* The Town Builder certificate */
.certificate .ideas { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 14px; }
.certificate .idea { border: 3px solid var(--good); background: #effcf4; border-radius: 999px; padding: 6px 14px; font-size: 18px; font-weight: 600; }
.cert-pic { width: 100%; max-width: 560px; max-height: 38vh; object-fit: cover; border: 3px solid var(--ink); border-radius: 16px; display: block; margin: 0 auto; box-sizing: border-box; }
.puzzle .codebox { max-width: 100%; }
.code-lines { display: inline-flex; flex-direction: column; text-align: left; }
.code-lines .cl { white-space: pre; }
.code-lines .t-kw, .code-lines .t-eq { margin: 0; }
.code-lines .t-str { color: var(--becomes); } .code-lines .t-num { color: #8ff0b4; } .code-lines .t-eq { color: var(--muted); }
.answer.code .code-lines { font-size: 17px; line-height: 1.35; }

/* Path puzzles: a map, a program, arrows to add steps */
.card.pathcard { width: min(1060px, 100%); padding: 18px 20px; }
.path-head { display: flex; align-items: center; justify-content: center; gap: 12px; }
.path-head h2 { margin: 0; }
.path-wrap { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, 1fr); gap: 16px; margin-top: 12px; align-items: start; text-align: left; }
.path-board { display: block; width: 100%; aspect-ratio: 3 / 2; border-radius: 16px; background: #fff; }
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side .row { margin-top: 0; justify-content: stretch; }
.side .row > * { flex: 1; }
.prog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prog-head .file { color: #555a77; font-size: 17px; flex: none; }
.meter { font-size: 16px; font-weight: 600; color: #555a77; }
.meter.full { color: #c4213a; }
.prog { background: var(--editor); border-radius: 16px; padding: 8px 6px; min-height: 150px; max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.pline { display: grid; grid-template-columns: 26px 30px 1fr 44px; align-items: center; min-height: 48px; border-radius: 12px; color: #eef0ff; }
.pline .ln { font-family: var(--font-code); color: #5a6088; font-size: 15px; text-align: right; padding-right: 4px; }
.pline .gutter { font-size: 20px; }
.pline .stmt { font-family: var(--font-code); font-size: 18px; background: none; border: 0; color: inherit; text-align: left; padding: 6px 4px; border-radius: 10px; display: flex; align-items: center; flex-wrap: wrap; }
.pline button.stmt:not(:disabled):active { background: var(--editor-2); }
.pline.d1 .stmt { padding-left: 26px; }
.pline.hot { background: #2f3a6b; box-shadow: inset 0 0 0 3px var(--who); }
.pline.bad { background: #4a2233; box-shadow: inset 0 0 0 3px #ff6b81; }
.pline.picked { background: #3a3352; box-shadow: inset 0 0 0 3px var(--pencil); }
.pline.picked .gutter::after { content: "✏️"; font-size: 14px; }
.pline .rm { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--editor-line); background: var(--editor-2); color: #fff; font-size: 16px; }
.pline .cnt { width: 40px; height: 40px; border-radius: 50%; border: 2px solid #2f6b52; background: #213a33; color: #8ff0b4; font-size: 24px; font-weight: 700; margin: 0 6px; line-height: 1; }
.pline .t-num { font-size: 22px; }
.pline .iter { margin-left: 10px; font-family: var(--font-ui); font-size: 14px; font-weight: 700; background: var(--who); color: var(--editor); border-radius: 999px; padding: 2px 8px; }
.pline.close { min-height: 30px; }
.slot { min-height: 42px; margin: 2px 6px 2px 56px; border: 2px dashed #4a5180; border-radius: 12px; background: none; color: #8d93b5; font-size: 16px; font-weight: 600; text-align: left; padding: 0 12px; }
.slot.d1 { margin-left: 82px; }
.slot.on { border-color: var(--pencil); color: var(--pencil); }
.pads { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pad { min-height: 64px; border: 3px solid var(--ink); border-radius: 16px; background: var(--paper); font-size: 32px; box-shadow: 0 4px 0 var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pad.loop { background: #ffe1ee; font-size: 26px; }
.pad small { font-size: 13px; font-weight: 700; margin-top: 2px; }
.pad:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.go.run { background: var(--good); }
.path-msg { min-height: 1.4em; font-size: 21px; font-weight: 600; margin: 12px 0 0; }
@media (max-width: 760px), (orientation: portrait) {
  .path-wrap { grid-template-columns: minmax(0, 1fr); }
  .prog { max-height: 220px; }
}
@media (max-width: 600px) {
  .card.pathcard { padding: 14px 12px; }
  .path-head h2 { font-size: 24px; }
  .pline { grid-template-columns: 20px 24px 1fr 38px; min-height: 42px; }
  .pline .stmt { font-size: 15px; }
  .pline .cnt { width: 32px; height: 32px; font-size: 20px; margin: 0 4px; }
  .pline .rm { width: 34px; height: 34px; }
  .slot { margin-left: 44px; min-height: 36px; font-size: 14px; }
  .slot.d1 { margin-left: 64px; }
  .pad { min-height: 54px; font-size: 26px; }
  .path-msg { font-size: 18px; }
  .badge-big { font-size: 60px; }
  .certificate .ideas { gap: 6px; margin: 6px 0 10px; }
  .certificate .idea { font-size: 15px; padding: 3px 10px; border-width: 2px; }
  .cert-pic { max-height: 30vh; }
}

/* Lesson done + lesson map */
.badge-big { font-size: 96px; line-height: 1.1; animation: prize .6s cubic-bezier(.2,1.6,.4,1); }
.trail { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.trail .dot { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #d6d6de; display: grid; place-items: center; font-size: 20px; color: var(--ink); font-weight: 700; }
.trail .dot.done { border-color: var(--good); background: #effcf4; }
.trail .dot.next { border-color: var(--ink); background: var(--pencil); animation: nudge 1s ease-in-out infinite; }
.trail .dot.soon { border-style: dashed; }
.next-up { display: flex; align-items: center; gap: 14px; justify-content: center; text-align: left; border: 3px solid var(--ink); border-radius: 20px; padding: 10px 18px; background: #fff8de; margin: 8px auto 0; max-width: 520px; }
.next-up .e { font-size: 52px; }
.next-up b { display: block; font-size: 22px; }
.next-up .sub { font-size: 17px; }
.bar { height: 18px; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; background: #f1f1f5; margin: 6px auto 4px; max-width: 520px; }
.bar i { display: block; height: 100%; background: var(--good); }
.plan .chapter { text-align: left; margin-top: 14px; }
.plan .chapter h3 { font-size: 22px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.plan .count { font-size: 15px; color: #6c6c7a; font-weight: 600; }
.stops { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.stop { border: 3px solid #d6d6de; border-radius: 20px; background: var(--paper); padding: 12px; text-align: left; display: flex; flex-direction: column; gap: 4px; font-size: 18px; min-height: 150px; }
.stop .e { font-size: 40px; line-height: 1; }
.stop .learn { font-size: 15px; color: #555; }
.stop .learn code { font-size: 13px !important; }
.stop .prize { font-size: 15px; font-weight: 600; margin-top: auto; }
.stop.done { border-color: var(--good); background: #effcf4; }
.stop.next { border-color: var(--ink); background: #fff8de; box-shadow: 0 5px 0 var(--ink); }
.stop.locked, .stop.soon { opacity: .6; border-style: dashed; }

/* Portrait: code panel becomes a bottom sheet, Pip moves to the top */
@media (orientation: portrait) {
  :root { --panel-w: 100vw; }
  #codePanel { top: auto; height: 52vh; width: 100%; transform: translateY(105%); box-shadow: 0 -6px 0 var(--ink); border-radius: 24px 24px 0 0; padding-right: 0; }
  #pip { max-width: calc(100vw - 24px); }
  .lines { padding-bottom: 8px; }
}
@media (max-width: 600px) {
  :root { --tap: 44px; }
  .chip, .round { font-size: 18px; border-width: 2px; }
  .hud-right { gap: 6px; }
  .round.stat { display: none; }
  #bubbleText { font-size: 19px; }
  .stmt { font-size: 19px; }
  .card { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
