:root{color-scheme:dark;--bg:#111725;--panel:#202b3e;--ink:#edf0f7;--muted:#b5c1d3;--purple:#9385ed;--mint:#65d5ac;font-family:Arial,Helvetica,sans-serif;background:var(--bg);color:var(--ink)}
/* Long hints scroll inside Instructions; they must not stretch the game off screen. */
@media(min-width:1101px){
  #workspace[data-layout=split]{height:calc(100dvh - var(--story-toolbar-height,96px));min-height:0}
  #workspace[data-layout=split]>.instructions{overflow-y:auto}
  #workspace[data-layout=split]>.code,#workspace[data-layout=split]>.play{min-height:0}
  #workspace[data-layout=split] .portrait-stage,#workspace[data-layout=split] #portrait-frame{min-height:0}
}
/* Keep the whole room and its controls visible on classroom laptop displays. */
#workspace .room-stage{width:min(100%,calc((100dvh - var(--story-toolbar-height,96px) - 194px) * 1.77778));min-width:min(100%,320px)}
*{box-sizing:border-box}body{margin:0}button,input,textarea{font:inherit}button,a,input,textarea{touch-action:manipulation}button,.file-button{border:1px solid transparent;border-radius:10px;padding:11px 15px;background:#2a3850;color:inherit;cursor:pointer;font-weight:600}button:hover,.file-button:hover{filter:brightness(1.12)}button:disabled{opacity:.45;cursor:default}button:focus-visible,a:focus-visible,input:focus-visible,textarea:focus-visible,canvas:focus-visible{outline:3px solid #ddb967;outline-offset:3px}[hidden]{display:none!important}a{color:#c6bbff}.primary{background:var(--mint);color:#132d2a}.navbar{min-height:96px;display:flex;align-items:center;justify-content:space-between;gap:20px;padding:16px 22px;background:#172132;flex-wrap:wrap}.brand{display:flex;align-items:center;gap:13px;text-decoration:none;color:inherit;font-weight:700}.brand>b{display:grid;place-items:center;width:40px;height:40px;background:var(--purple);border-radius:12px;font-size:26px;color:#fff}.brand small{display:block;font-size:11px;letter-spacing:.3px;margin-top:5px;color:var(--muted);font-weight:400}nav,.utilities{display:flex;gap:4px;flex-wrap:wrap}nav button,.utilities button{background:transparent;font-weight:400}nav button[aria-pressed=true]{background:#8075de;font-weight:700;color:white}h1{font-size:29px;line-height:1.16;margin:18px 0 24px}h2{font-size:20px;margin:12px 0}p{line-height:1.55}button{min-height:44px}.eyebrow{text-transform:uppercase;letter-spacing:2px;font-size:12px;font-weight:700;color:#b9c6df}.title-screen{text-align:center;max-width:680px;margin:25px auto;padding:24px}.title-screen h1{font-size:clamp(36px,5vw,58px);margin:12px}.title-screen .eyebrow{color:#b9a8fc}.subtitle{color:var(--muted);font-size:19px}.title-art{height:135px;display:flex;align-items:center;justify-content:center;gap:25px}.title-art canvas{image-rendering:pixelated}.pixel-star{color:#ddb967;font-size:45px}.small-star{font-size:26px;color:var(--mint)}#start-form{max-width:365px;margin:22px auto}#start-form>label{display:block;text-align:left;font-weight:600;margin-bottom:10px}input,textarea{background:#101b2c;color:var(--ink);border:1px solid #53617a;border-radius:8px;padding:11px;max-width:100%}#learner-name{width:100%}fieldset{border:0;padding:12px 0;display:flex;gap:12px}legend{padding-top:15px;color:var(--muted);text-align:left;font-size:14px}.avatar-choice{display:flex;align-items:center;gap:5px;padding:8px;background:#202b3e;border:2px solid transparent;border-radius:12px;flex:1;cursor:pointer}.avatar-choice:has(input:checked){border-color:var(--purple)}.avatar-choice input{accent-color:var(--purple)}.avatar-choice canvas{width:40px;height:40px;image-rendering:pixelated}#start{width:100%;font-size:18px}.title-note{font-size:14px;color:var(--muted)}#workspace{display:grid;grid-template-columns:minmax(270px,.92fr) minmax(290px,1fr) minmax(420px,1.8fr);gap:16px;padding:18px;align-items:stretch;min-height:calc(100dvh - var(--story-toolbar-height,96px))}.card{border-radius:18px;min-width:0;overflow:hidden;background:var(--panel);padding:24px;position:relative}.instructions{background:#fbf7ee;color:#29334a;font-size:18px}.instructions .eyebrow{color:#736398}.instructions p{margin:16px 0}.instructions button{background:#e6edf1;color:#29334a;border-color:#c6d0d8}.instructions .primary{background:#65d5ac;border-color:transparent}.try-card{background:#eee8fc;border-radius:14px;padding:12px 18px;margin:24px 0}.hint-actions{display:grid;gap:10px;margin-top:32px}.hint-actions button+button{background:transparent}.muted{font-size:14px;color:#69748a}.hint-panel{background:#e9edf5;border-radius:10px;padding:16px;margin-top:15px}.hint-panel button{padding:4px 8px;font-size:14px}#repair-feedback{font-size:16px}#repair-feedback[data-error=true]{color:#8e2632;border-left:3px solid #ab3a47;padding-left:12px}#success-panel{background:#e3f2e9;border-radius:12px;padding:16px}#success-panel h2{color:#24634b}.code{background:#1b2537;display:flex;flex-direction:column;padding:0}.panel-heading{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:22px 24px}.panel-heading p{margin:22px 0 0}.panel-heading h2{margin:18px 0 0}.code .panel-heading{border-bottom:1px solid #344158}.code-line{display:flex;align-items:center;gap:14px;margin:28px 12px;background:#252e43;border-radius:9px;padding:12px 10px;font-size:19px;overflow-x:auto}.code-line code{white-space:nowrap}.line-number{color:#75839c}.keyword{color:#b6a5f7}.value-input{background:#f0d78e;color:#302615;font:700 19px monospace;width:76px;min-width:58px;border:0;padding:8px 5px;border-radius:6px}.code-actions{display:flex;gap:10px;padding:0 24px}.code-actions button{font-weight:400}.code-bottom{margin-top:auto;padding:24px;display:flex;flex-wrap:wrap;gap:10px;font-size:13px;color:var(--muted)}#draft-status:before{content:'●';color:#80cfb0;margin-right:8px}.error-link{font-size:14px;margin:20px 24px;color:#ffb7b7}.play{padding:0 20px 20px;display:flex;flex-direction:column}.play>.panel-heading{padding:22px 4px}.room-stage{position:relative;max-width:1200px;width:100%;margin:auto;background:#312e47;border-radius:14px;overflow:hidden}#room-canvas{width:100%;display:block;touch-action:none}.room-controls{display:flex;flex-wrap:wrap;justify-content:space-between;gap:12px;margin:18px 0 0}.walk-controls,#places{display:flex;gap:8px;flex-wrap:wrap}.walk-controls button{user-select:none}.room-controls button{font-size:14px}.bubble{position:absolute;bottom:23%;left:5%;width:min(500px,85%);background:#fff9ed;color:#29334a;padding:18px 24px;border-radius:18px;box-shadow:0 8px 28px #0004}.bubble:after{content:'';position:absolute;bottom:-16px;left:25px;border-top:18px solid #fff9ed;border-right:18px solid transparent}.bubble p{font-size:20px;margin:0 0 12px}.bubble button{background:#e6ddf6;color:#352a50}.portrait-stage{position:relative;flex:1;min-height:430px;border-radius:14px;overflow:hidden;background:#35324a;display:flex;align-items:center;justify-content:center}#portrait-frame{width:100%;height:100%;min-height:430px;border:0;aspect-ratio:480/420}#preview-loading{position:absolute;padding:20px;background:#292b40e8;border-radius:12px}#workspace[data-layout=play],#workspace[data-layout=instructions],#workspace[data-layout=code]{grid-template-columns:minmax(0,1fr)}#workspace[data-layout=play]>.instructions,#workspace[data-layout=play]>.code,#workspace[data-layout=code]>.instructions,#workspace[data-layout=code]>.play,#workspace[data-layout=instructions]>.code,#workspace[data-layout=instructions]>.play{display:none}#workspace[data-layout=instructions]>.instructions{width:min(760px,100%);margin:auto;min-height:70vh}#workspace[data-layout=code]>.code{width:min(1000px,100%);margin:auto;min-height:70vh}#workspace[data-layout=play]>.play{width:100%;min-height:76vh}#workspace[data-layout=play] #portrait-frame{height:65vh;min-height:430px}#workspace[data-layout=play] .portrait-stage{max-width:950px;width:100%;margin:auto}.celebration{position:absolute;inset:6%;color:#ffe6a0;font-size:55px;display:flex;justify-content:space-around;align-items:center;pointer-events:none;animation:sparkle 950ms ease-out both}.celebration span{align-self:flex-start}.success-bubble{position:absolute;bottom:15px;left:5%;right:5%;padding:14px 18px;border-radius:14px;background:#fff8e9;color:#29334a;font-size:17px;box-shadow:0 3px 15px #0003}.portrait-stage.repaired{box-shadow:inset 0 0 0 3px #8bd7b3}dialog{border:1px solid #52617b;background:#202b3e;color:var(--ink);border-radius:20px;padding:28px;width:min(520px,calc(100% - 30px));max-height:88dvh}dialog::backdrop{background:#080e1ec4}dialog h2{font-size:26px;margin-top:0}dialog>button{margin-top:12px}dialog label{display:block;margin:14px 0 8px}.check-label{display:flex;gap:12px;align-items:center}.check-label input{width:20px;height:20px;accent-color:var(--mint)}.dummy-screen{border:6px solid #152033;background:#081720;border-radius:12px;color:var(--mint);text-align:center;font-size:75px;padding:35px 12px}.dummy-screen span{display:block;font:14px monospace;letter-spacing:3px}.teacher-dialog{width:min(800px,calc(100% - 30px))}.teacher-dialog input:not([type=file]),.teacher-dialog textarea{width:100%;margin-bottom:12px}.teacher-dialog label{font-weight:600}#text-fields{border-top:1px solid #53617a}#teacher-message{background:#152033;border-radius:8px;padding:12px;position:sticky;top:-28px;z-index:1}#text-dirty{color:#e4c58c}.teacher-actions{display:flex;flex-wrap:wrap;align-items:center;gap:10px}.file-button{display:inline-block!important;margin:0!important}.file-button input{display:block;font-size:12px;max-width:225px;margin-top:8px}.confirm-box{border:1px solid #dabd72;border-radius:10px;padding:15px;margin:18px 0}.confirm-box button{margin:4px}#toast{position:fixed;bottom:22px;left:50%;transform:translateX(-50%);padding:14px 24px;background:#d5f0e2;color:#173529;border-radius:12px;box-shadow:0 6px 24px #0005;max-width:90%;z-index:10}#save-warning{background:#f7dca6;color:#513711;padding:12px 24px}body.reduce-motion *,body.reduce-motion *:before,body.reduce-motion *:after{animation:none!important;scroll-behavior:auto!important}@keyframes sparkle{0%{opacity:0;transform:scale(.7)}35%{opacity:1}100%{opacity:0;transform:scale(1.12)}}@media(prefers-reduced-motion:reduce){*{animation:none!important}}@media(max-width:1100px){.navbar{gap:10px;padding:12px}.brand small{display:none}#workspace{gap:10px;padding:10px;grid-template-columns:minmax(225px,1fr) minmax(245px,1fr) minmax(320px,1.35fr)}.card{padding:18px}.code{padding:0}.play{padding:0 12px 12px}.instructions{font-size:16px}h1{font-size:25px}.code-line{font-size:16px;gap:8px}.value-input{font-size:16px;width:65px}.panel-heading{padding:18px 12px}.code-actions{padding:0 12px}.navbar nav button,.utilities button{padding:9px 10px}}@media(max-width:820px){#workspace[data-layout=split]{grid-template-columns:1fr 1fr}#workspace[data-layout=split]>.play{grid-column:1/-1;min-height:480px}.navbar{justify-content:center}.brand{margin-right:auto}.utilities{margin-left:auto}.navbar nav{order:3;width:100%;justify-content:center}.bubble p{font-size:16px}.bubble{padding:12px}.room-controls{justify-content:center}#places{justify-content:center}}@media(max-width:520px){#workspace[data-layout=split]{grid-template-columns:1fr}.code{min-height:300px}.portrait-stage,#portrait-frame{min-height:330px}.room-stage{overflow:visible;margin:0}.bubble{bottom:12%;left:4%;width:92%}.bubble p{font-size:14px}.bubble button{padding:6px 10px}.brand span{font-size:13px}.utilities button{font-size:12px;padding:7px}.navbar{gap:4px}.title-screen{margin:0 auto}}

#hall-progress{display:block;margin-top:8px;color:#b5c1d3;font-size:12px}.value-input{width:72px}#editable-lines .code-line{margin-bottom:10px}#editable-lines{margin-bottom:18px}#text-group{width:100%;padding:12px;border:1px solid #53617a;border-radius:8px;background:#152033;color:#edf0f7;font:inherit;margin:4px 0 18px}.code-line code{font-size:18px}@media(max-width:1100px){.code-line code{font-size:15px}.value-input{width:60px}}

/* Coordinate chapter: the existing workspace, with a book and playable repairs. */
#chapter-editor{padding:20px 18px;overflow-y:auto;flex:1;min-height:0;order:1}
#workspace[data-chapter=true] .code-bottom{order:2;margin-top:0}
#chapter-editor>label{display:block;margin-bottom:8px;color:#b5c1d3}
#chapter-object{width:100%;border:1px solid #53617a;border-radius:8px;background:#152033;color:#edf0f7;font:inherit;padding:10px}
.chapter-command{display:flex;align-items:end;gap:5px;flex-wrap:wrap;background:#252e43;border-radius:12px;padding:16px 10px;margin:22px 0;line-height:2;font-size:17px}
.chapter-input-cell{display:flex;flex-direction:column;gap:2px}.chapter-input-cell>span{font-size:12px;line-height:1.3;color:#b5c1d3}.chapter-command code{white-space:nowrap}
#chapter-anchor{color:#b5c1d3;line-height:1.6}#chapter-editor .code-actions{padding:0;flex-wrap:wrap}
#chapter-stage{position:relative;flex:1;min-height:220px;display:grid;place-items:center;background:#202c3c;border-radius:14px;overflow:hidden}
#chapter-frame{width:100%;height:100%;min-height:220px;border:0;display:block}
#chapter-loading{position:absolute;padding:16px;border-radius:12px;background:#202b3eee}
#chapter-controls{flex-shrink:0}#chapter-result{align-self:flex-end;margin-top:12px;flex-shrink:0}
#chapter-answers{display:grid;gap:8px}#chapter-answers button{text-align:left;font-size:16px}#chapter-answers button[aria-pressed=true]{border:2px solid #776298;background:#e3d7f6}
#chapter-body p{font-size:17px;line-height:1.6}#chapter-feedback[data-error=true]{color:#963141}
.chapter-navigation{display:grid;gap:10px;margin-top:22px}#chapter-back,#chapter-library{font-size:14px}
#chapter-instructions .hint-actions{margin-top:20px}#chapter-instructions h1{font-size:27px}
#chapter-bubble{font-size:16px}#journal-entries section{border-top:1px solid #53617a;padding:12px 0}
#workspace[data-chapter=true][data-layout=play] #chapter-stage{min-height:55vh}
@media(min-width:821px){#workspace[data-chapter-reading=true][data-layout=split]{grid-template-columns:minmax(300px,1fr) minmax(360px,1.65fr)}#workspace[data-chapter-reading=true][data-layout=split]>.code{display:none}}
@media(max-width:820px){#chapter-stage{min-height:330px}#chapter-frame{min-height:330px}#workspace[data-chapter-reading=true][data-layout=split]{grid-template-columns:1fr}#workspace[data-chapter-reading=true][data-layout=split]>.code{display:none}}
/* Readable supplied code gradually opens into a complete-statement editor. */
.provided-code{white-space:pre-wrap;overflow-wrap:anywhere;font:13px/1.7 monospace;color:#b7c6d9;margin:18px 0;background:#152033;padding:12px;border-radius:8px}
#chapter-source{display:block;width:100%;min-height:240px;resize:vertical;background:#111e30;color:#edf5ff;border:1px solid #859bb7;border-radius:8px;padding:12px;font:15px/1.7 monospace;tab-size:2}
#chapter-source-label{color:var(--muted)}#chapter-feedback{white-space:pre-wrap;overflow-wrap:anywhere}
#chapter-stage:has(#chapter-frame[style*="opacity: 0"]){background:white}
#chapter-reference{margin:18px 0;padding:10px;background:#e5e9e9;border-radius:10px}#chapter-reference figcaption{font-weight:600;font-size:14px;margin-bottom:8px}#chapter-plan{width:100%;height:auto;display:block;border:1px solid #a8b7c1}#chapter-plan-description{font-size:13px;line-height:1.5;margin:8px 0 0}
#challenges-dialog{width:min(700px,calc(100% - 30px))}#challenge-search,#teacher-challenge{width:100%;font:inherit;padding:12px;background:#132134;color:#edf5ff;border:1px solid #859bb7;border-radius:8px}#challenge-list{max-height:48vh;overflow:auto}#challenge-list h3{margin-top:20px}#challenge-list button{display:block;width:100%;text-align:left;margin:7px 0}#teacher-preview-banner{display:flex;align-items:center;justify-content:center;gap:12px;flex-wrap:wrap;padding:8px 16px;background:#ead9a3;color:#3e3322;font-size:14px}#teacher-preview-banner button{padding:7px 12px;min-height:36px}.teacher-preview-controls{border:1px solid #63748a;padding:16px;border-radius:12px;margin-bottom:24px}.teacher-preview-controls button{margin-top:12px}@media(min-width:821px){body[data-teacher-preview=true] #workspace[data-layout=split]{height:calc(100dvh - var(--story-toolbar-height,156px));min-height:0}}

#teacher-preview-banner button{color:#fff8e8}
/* Variables: readable full sketches and explicit teacher project reviews. */
#variables-editor{padding:16px;overflow:auto;flex:1;min-height:0;order:1}
#variables-editor>label{display:block;margin-bottom:10px;color:#b4e4d5}
.variables-code-wrap{display:flex;min-height:320px;border:1px solid #7184a1;border-radius:10px;overflow:hidden;background:#111e30}
#variables-source{flex:1;min-width:0;border:0;border-radius:0;resize:vertical;min-height:320px;white-space:pre;overflow:auto;font:14px/1.7 monospace;padding:12px 8px;tab-size:2;background:#111e30}
#variables-line-numbers{flex:0 0 34px;color:#8294af;font:14px/1.7 monospace;text-align:right;margin:0;padding:12px 5px;overflow:hidden;max-height:320px;background:#152438;user-select:none}
#variables-code-note{font-size:13px;color:#b5c1d3}#variables-editor .code-actions{padding:0;flex-wrap:wrap}
#variables-memory{margin:18px 0;border-top:1px solid #53617a;padding-top:12px}#variables-values{font:13px/1.6 monospace;white-space:pre-wrap;overflow-wrap:anywhere;color:#c5e5db}
#variables-stage{position:relative;flex:1;min-height:250px;display:grid;place-items:center;background:#162638;border-radius:14px;overflow:hidden}
#variables-frame{width:100%;height:100%;min-height:250px;border:0;display:block}#variables-loading{position:absolute;padding:14px;background:#202b3eee;border-radius:10px}
#variables-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px;flex-shrink:0}#variables-actions button{font-size:13px;padding:9px 11px}
#variables-feedback{white-space:pre-wrap;overflow-wrap:anywhere;font-size:15px;border-left:3px solid #65aa94;padding-left:12px}#variables-feedback[data-error=true]{color:#8e2632;border-color:#ab3a47}
#variables-hint{white-space:pre-wrap;overflow-wrap:anywhere;font:14px/1.6 monospace}
#variables-body p{font-size:17px;line-height:1.65}#variables-instructions h1{font-size:27px}#variables-answers{display:grid;gap:8px}#variables-answers button{text-align:left;font-size:15px}#variables-answers button[aria-pressed=true]{background:#ded4f0;border-color:#776298}
#variables-project{padding:16px;background:#e2efe9;border-radius:12px;margin-top:20px;font-size:16px}#variables-project li{margin-bottom:8px;line-height:1.5}#variables-explanation{display:block;width:100%;margin:12px 0;background:#fff;color:#263747}#variables-review-status{font-size:14px}.variables-bubble{background:#fff6e6;color:#29334a;border-radius:14px;padding:12px 16px;margin:10px 0;font-size:16px}
#variables-review{padding:16px;border:1px solid #748a9b;border-radius:12px;margin:0 0 20px}.project-review-card{padding:14px;margin:12px 0;background:#152438;border-radius:12px}.project-review-card textarea{width:100%}.project-review-card .provided-code{max-height:260px;overflow:auto}.project-review-card button{margin:8px 8px 0 0}.project-review-card iframe{width:100%;height:310px;border:1px solid #748a9b;border-radius:10px}.project-review-card .check-label{display:flex}.project-review-card input[type=checkbox]{flex-shrink:0}
#workspace[data-variables=true][data-layout=play] #variables-stage{min-height:50vh}
@media(max-width:820px){#variables-stage,#variables-frame{min-height:330px}}

/*
 * Viewport contract
 * -----------------
 * The active story owns the dynamic viewport. The header, optional banners and
 * lesson dock are normal flex rows; the workspace receives only the remaining
 * space. Every panel then either contains a scaled stage or owns its scrolling.
 */
html{min-height:100%;min-height:100dvh}
body:has(#workspace:not([hidden])){height:100dvh;min-height:0;display:flex;flex-direction:column;overflow:hidden}
body:has(#workspace:not([hidden]))>.navbar,
body:has(#workspace:not([hidden]))>#teacher-preview-banner,
body:has(#workspace:not([hidden]))>#save-warning{flex:0 0 auto}
body:has(#workspace:not([hidden]))>main{display:flex;flex:1 1 auto;min-height:0;min-width:0;flex-direction:column;overflow:hidden}
#workspace:not([hidden]){flex:1 1 auto;height:auto!important;min-height:0!important;grid-template-rows:minmax(0,1fr);padding-bottom:18px}
#workspace>.card{height:100%;min-height:0}

/* Text can grow without pushing another panel or its controls off screen. */
#workspace>.instructions{overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
#workspace>.instructions::-webkit-scrollbar,#editable-lines::-webkit-scrollbar,#chapter-editor::-webkit-scrollbar,#variables-editor::-webkit-scrollbar,dialog::-webkit-scrollbar{width:12px;height:12px}
#workspace>.instructions::-webkit-scrollbar-track,#editable-lines::-webkit-scrollbar-track,#chapter-editor::-webkit-scrollbar-track,#variables-editor::-webkit-scrollbar-track,dialog::-webkit-scrollbar-track{background:#e6ddcc;border-radius:6px}
#workspace>.instructions::-webkit-scrollbar-thumb,#editable-lines::-webkit-scrollbar-thumb,#chapter-editor::-webkit-scrollbar-thumb,#variables-editor::-webkit-scrollbar-thumb,dialog::-webkit-scrollbar-thumb{background:#287666;border:2px solid #e6ddcc;border-radius:6px}
#workspace>.code{min-height:0;overflow:hidden}
#workspace>.code>.panel-heading,
#workspace>.code>.stop-code,
#workspace>.code>.code-actions,
#workspace>.code>.error-link,
#workspace>.code>.code-bottom,
#workspace>.code>#lesson-console{flex:0 0 auto}
#editable-lines{flex:1 1 auto;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
#chapter-editor,#variables-editor{overscroll-behavior:contain;scrollbar-gutter:stable}
#lesson-console[open]{max-height:min(34dvh,260px);overflow:auto}

/* The play panel reserves rows for its heading/actions and contains the stage. */
#workspace>.play{min-height:0;overflow:hidden}
#workspace>.play>.panel-heading,
#workspace>.play>.stop-code,
#workspace>.play>.room-controls,
#workspace>.play>#chapter-controls,
#workspace>.play>#chapter-result,
#workspace>.play>#variables-actions,
#workspace>.play>#variables-walk,
#workspace>.play>#variables-bubble{flex:0 0 auto}
#workspace>.play>.room-stage,
#workspace>.play>.portrait-stage,
#workspace>.play>#chapter-stage,
#workspace>.play>#variables-stage{flex:1 1 auto;min-height:0;max-height:100%;align-self:center}
#workspace>.play>.room-stage{width:auto;max-width:100%;min-width:0;aspect-ratio:16/9;margin:auto}
#room-canvas{width:100%;height:auto;max-height:100%;object-fit:contain}
.room-controls{max-height:30%;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
#workspace>.play>.portrait-stage{width:auto;max-width:100%;aspect-ratio:480/420}
#portrait-frame{min-height:0!important;aspect-ratio:auto}
#chapter-stage,#chapter-frame,#variables-stage,#variables-frame{min-height:0!important}
#workspace>.play>#chapter-stage,#workspace>.play>#variables-stage{width:100%;min-width:0}

/* Full-panel modes use exactly the same bounded rows as the three-panel view. */
#workspace[data-layout=instructions]>.instructions,
#workspace[data-layout=code]>.code,
#workspace[data-layout=play]>.play{height:100%;min-height:0;width:min(100%,1200px);margin:auto}
#workspace[data-layout=instructions]>.instructions{width:min(1100px,100%)}
#workspace[data-layout=code]>.code{width:min(1100px,100%)}
#workspace[data-layout=play] #portrait-frame{height:100%;min-height:0}
#workspace[data-chapter=true][data-layout=play] #chapter-stage,
#workspace[data-variables=true][data-layout=play] #variables-stage{min-height:0}

/* Lesson actions are a reserved footer row, never an overlay on game content. */
#lesson-dock{position:static;inset:auto;z-index:8;flex:0 0 auto;max-height:32dvh;overflow:auto;padding:10px 24px}
#lesson-complete{top:50%;transform:translate(-50%,-50%);max-height:calc(100dvh - 32px);overflow:auto;overscroll-behavior:contain}
dialog{max-height:calc(100dvh - 32px);overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable}

@media(max-width:820px){
  body:has(#workspace:not([hidden])){height:auto;min-height:100dvh;overflow:auto}
  body:has(#workspace:not([hidden]))>main{display:block;overflow:visible}
  #workspace:not([hidden]){height:auto!important;min-height:calc(100dvh - 180px)!important;grid-template-rows:auto;padding-bottom:10px}
  #workspace>.card{height:auto}
  #workspace[data-layout=split]>.play{min-height:480px}
  #lesson-dock{position:sticky;bottom:0;max-height:42dvh}
}

/* Shared activity runner stays inside Story and its viewport contract. */
body:has(#workspace[data-pilot="true"]:not([hidden])){height:100dvh;min-height:0;overflow:hidden}
body:has(#workspace[data-pilot="true"]:not([hidden]))>main{display:flex;flex-direction:column;overflow:hidden;min-height:0}
#workspace[data-pilot="true"]:not([hidden]){min-height:0!important}
#workspace[data-pilot="true"]{display:block;overflow:auto;overflow-anchor:none;padding:1rem;}
#workspace[data-pilot="true"] > :not(#pilot-studio){display:none!important;}
#pilot-studio{width:100%;max-width:1500px;margin:auto;}
#pilot-studio .studio-controls{position:sticky;top:0;z-index:2;background:var(--panel);padding:.5rem;border-bottom:1px solid var(--line)}
.pilot-navigation{position:sticky;bottom:0;z-index:2;display:flex;gap:.6rem;align-items:center;flex-wrap:wrap;background:var(--panel);padding:.65rem;border-top:1px solid var(--line)}
.pilot-navigation p{flex:1;margin:0;min-width:12rem;font-size:.9rem}
.pilot-navigation>button:last-child{background:var(--mint);color:#132d2a}
body:not([data-theme="charcoal"]) .eyebrow{color:#634180;}

.practice-dialog{width:95vw;max-width:1400px;max-height:94dvh;overflow:auto}.practice-dialog>label{max-width:24rem}#pilot-studio{min-width:0;padding:1rem}#arcade-dialog{max-height:94dvh;overflow:auto}#arcade-dialog h2{margin:.25rem 0}#arcade-dialog p{margin:.45rem 0}#arcade-dialog button{margin:.2rem}
/* Household presentation stays outside student-drawn canvases. */
.world-bar{display:flex;align-items:center;gap:14px;padding:7px 22px;border-bottom:3px solid var(--zone-color,#dfb768);background:#26323c;color:#fff4dd;flex:0 0 auto;font-size:14px;min-width:0}
.world-bar strong{white-space:nowrap}.world-bar>span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.world-bar button{font-size:13px;min-height:34px;padding:6px 10px;white-space:nowrap;background:#3e4a53;color:#fff4dd;border:1px solid #72818a}
body[data-zone] #play-panel{box-shadow:inset 0 4px var(--zone-color)}
body[data-zone] #pilot-activity{border-top:4px solid var(--zone-color)}
.world-picture{overflow:hidden;border-radius:12px;line-height:0}.world-picture svg{display:block;width:100%;height:auto}
.world-arrival{padding:14px;margin:0 0 22px;border:1px solid #c6b8a2;border-radius:12px;background:#f5eddc;color:#303744;font-size:15px}
.world-arrival .world-picture{margin:-3px -3px 12px}.world-arrival .eyebrow{font-size:10px;margin:10px 0 4px!important;color:#65576d}.world-arrival h3{font-size:20px;margin:6px 0 12px}.world-arrival .story-line{font-size:15px;line-height:1.5;margin:9px 0!important}.world-arrival .story-dismiss{margin-top:10px;font-size:14px;background:#dce7dd!important;color:#273c36!important;border:1px solid #b2c8bc}
#challenges-dialog{width:min(1100px,96vw);max-width:1100px;max-height:94dvh;padding:26px;background:#f7f0e1;color:#303744;border:2px solid #bea784;border-radius:20px}
#challenges-dialog h2{font-family:Georgia,serif;font-size:30px;margin:0 0 4px}#challenges-dialog>p{margin:6px 0 12px;max-width:80ch}#challenges-close{float:right;margin-top:-52px;background:#e5ddcd;color:#34404a;border:1px solid #beaf99}
#challenges-dialog>label{display:block;font-size:14px;margin:12px 0 5px}#challenges-dialog input[type=search]{width:min(550px,100%);background:#fffaf0;color:#303744;border-color:#b7a98e}#challenges-dialog .check-label{display:flex;align-items:center;gap:8px}
.house-hero{display:grid;grid-template-columns:1fr 1fr;gap:22px;margin:20px 0;align-items:center}.house-hero h3{font-family:Georgia,serif;font-size:29px;margin:8px 0 15px}.house-hero .eyebrow{color:#766044;font-size:11px;letter-spacing:1.6px}.house-hero .house-next{font-size:14px;line-height:1.4;color:#535663}.house-hero .primary{background:#326d5d;color:#fff9e9}.house-hero .world-picture{border:5px solid #d5bd99;box-shadow:0 4px #b69c7c}
.house-layout{display:grid;grid-template-columns:180px 1fr;gap:20px;border-top:1px solid #d6c8af;border-bottom:1px solid #d6c8af;padding:16px 0}.house-elevator{display:flex;flex-direction:column;gap:7px;background:#e6ddcc;padding:13px;border:1px solid #c7b69c;border-radius:13px;align-self:start}.house-elevator h3{margin:0 0 7px;font-size:16px}.house-elevator button{width:100%;text-align:left;font-size:13px;padding:10px;background:#f7f1e6;color:#394149;border:1px solid #c4b69d}.house-elevator button[aria-pressed=true]{background:#364b50;color:#fff5de;border-color:#364b50}.house-elevator p{font-size:12px;margin:6px 0;line-height:1.5}.house-wing>h3{font-size:15px;margin:0 0 12px;color:#63583f}
.house-doors{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px}.house-door{display:flex;flex-direction:column;align-items:center;gap:8px;background:#ece4d5;color:#303b43;padding:14px 9px;border:2px solid transparent;border-radius:12px;min-height:238px}.house-door[aria-pressed=true]{border-color:#536861;background:#fff9ed}.house-door strong{font-size:15px;line-height:1.3}.house-door>span:not(.door-shape){font-size:12px;line-height:1.3}.house-door small{font-size:11px;color:#65615c;font-weight:400}.door-shape{position:relative;display:grid;place-items:center;width:70px;height:104px;margin:3px 0 5px;border:7px solid #aa9478;border-bottom:0;border-radius:35px 35px 0 0;background:var(--door-color);box-shadow:inset 0 0 0 3px #ffffff55,0 5px #897154}.door-shape:after{content:'';position:absolute;width:7px;height:7px;background:#4f493e;right:5px;top:60px;border-radius:50%}.door-shape>span{font-size:24px;color:#394248}
.house-shortcuts{margin:14px 0;gap:7px}.house-shortcuts button{font-size:13px;background:#e4e5d8;color:#394647;border:1px solid #c3c6b5}.house-objective{padding:13px 16px;background:#e8e8d9;border-left:4px solid #7a9787;border-radius:0 8px 8px 0;color:#3b4a43}
#challenge-list .house-lesson{margin:7px 0;padding:0;border:1px solid #d6cbb8;border-radius:9px;background:#fffbf2}#challenge-list .house-lesson button{display:block;text-align:left;width:100%;margin:0;background:transparent;color:#334149;line-height:1.4;font-size:14px}#challenge-list .house-lesson button:disabled{opacity:1;color:#716b61}#challenge-list .house-lesson small{display:block;padding:0 15px 12px;font-size:12px;color:#67645c}#challenge-list .house-lesson[data-status=completed]{border-left:4px solid #6e9d83}#challenge-list .house-lesson[data-status=submitted]{border-left:4px solid #b78650}#challenge-list .house-lesson[data-status=progress]{border-left:4px solid #727fa8}.house-practice{margin:22px 0;padding:15px;border:1px solid #cbbfa9;border-radius:10px}.house-practice summary{cursor:pointer;font-weight:700}.house-practice button{background:#e6e7dc!important;color:#394447!important;font-size:13px}
.story-journal{width:min(930px,94vw);max-width:930px;max-height:92dvh;padding:25px;background:#f5eddd;color:#323942;border:2px solid #bda37d;border-radius:18px}.story-journal>h2{font-family:Georgia,serif;font-size:30px;margin:0 0 12px}.story-journal>button{background:#dce4d9;color:#34473e}.journal-tabs{display:flex;gap:6px;flex-wrap:wrap;max-height:140px;overflow:auto;margin:18px 0}.journal-tabs button{background:#e5ddcd;color:#464351;border:1px solid #cebea6;font-size:12px;min-height:34px;padding:7px 10px}.journal-tabs button[aria-pressed=true]{background:#455f59;color:#fff7e7}.story-scene{background:#fff9ed;padding:16px;border:1px solid #dbccb5;border-radius:12px}.story-scene .world-picture{margin-bottom:18px}.story-scene .eyebrow{color:#756047}.story-scene h3{font-family:Georgia,serif;font-size:26px;margin:8px 0 18px}.story-line{line-height:1.65;margin:12px 0}.story-rewards{padding:8px 10px}.story-rewards p{margin:6px 0;color:#3b6554}
@media(max-width:800px){.world-bar{padding:7px 12px;gap:9px}.world-bar>span{display:none}.world-bar strong{flex:1;font-size:12px;white-space:normal}.house-layout{grid-template-columns:130px 1fr;gap:10px}.house-hero{gap:12px}.house-hero h3{font-size:24px}.house-door{min-height:222px}.house-elevator{padding:9px}.house-elevator button{font-size:12px}.house-doors{grid-template-columns:repeat(auto-fit,minmax(130px,1fr))}#challenges-close{float:none;margin:0}}
@media(max-width:520px){#challenges-dialog{padding:16px}.house-hero{grid-template-columns:1fr}.house-hero .world-picture{display:none}.house-layout{grid-template-columns:1fr}.house-elevator{display:grid;grid-template-columns:1fr 1fr}.house-elevator h3,.house-elevator p{grid-column:1/-1}.house-door{min-height:210px}.story-journal{padding:14px}.world-arrival{padding:10px}.world-bar button{font-size:12px}}
.arcade-creations{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:7px;padding:8px;border-top:1px solid #b9ab92}.arcade-creations strong{font-size:13px}.arcade-creations button{font-size:12px;padding:7px 10px;min-height:34px}
#challenges-dialog:has(#house-hub:not([hidden])) #challenge-list{max-height:none;overflow:visible}
.world-vignette{flex:0 0 108px;border:1px solid var(--zone-color);border-radius:5px}.world-vignette svg{height:36px;width:108px}.world-bar{background:var(--zone-ink,#26323c)}
@media(max-width:600px){.world-vignette{display:none}}
/* Keep selected doors readable under both workspace themes. */
#house-hub .house-door[aria-pressed=true]{background:#fff9ed;color:#303b43;border-color:#536861}
.story-journal[open]{display:grid;grid-template-columns:190px minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;gap:16px;width:min(1060px,94vw);max-width:1060px;height:min(820px,92dvh);overflow:hidden}
.story-journal>h2{grid-column:1/-1;grid-row:1;margin:0;padding-right:220px;font-size:27px}.story-journal>button{grid-column:1/-1;grid-row:1;justify-self:end;align-self:start;min-height:38px;padding:8px 12px;font-size:13px}
.story-journal .journal-tabs{grid-column:1;grid-row:2;display:flex;flex-direction:column;flex-wrap:nowrap;max-height:none;min-height:0;margin:0;padding-right:8px;overflow:auto}.story-journal .journal-tabs button{flex:0 0 auto;text-align:left;font-weight:500;line-height:1.4}
.journal-stage{grid-column:2;grid-row:2;min-height:0;overflow:auto}.journal-stage .story-scene{padding:14px}.journal-stage .world-picture svg{max-height:190px}.journal-stage .world-picture{background:#333642;margin-bottom:12px}.journal-stage .story-scene h3{font-size:25px;margin:6px 0 14px}.journal-stage .story-scene .eyebrow{font-size:10px;margin:8px 0}.journal-stage .story-line{font-size:15px;line-height:1.55;margin:11px 0}
.story-journal>.story-rewards{grid-column:1/-1;grid-row:3;margin:0;padding:10px 14px;border:1px solid #cebea6;border-radius:8px;max-height:180px;overflow:auto}.story-rewards summary{cursor:pointer;font-weight:700;font-size:14px}.story-rewards a{color:#315f53}
@media(max-width:700px){.story-journal[open]{grid-template-columns:1fr;grid-template-rows:auto 90px minmax(0,1fr) auto;gap:10px;padding:14px}.story-journal>h2{font-size:22px;padding-right:130px}.story-journal>button{max-width:125px;font-size:12px}.story-journal .journal-tabs{grid-column:1;grid-row:2;display:flex;flex-direction:row;flex-wrap:wrap;padding:0}.story-journal .journal-tabs button{font-size:11px;padding:6px 8px}.journal-stage{grid-column:1;grid-row:3}.story-journal>.story-rewards{grid-row:4}.journal-stage .world-picture svg{max-height:135px}}
/* Keep the first action visible; appearance is optional and remains in Settings. */
.title-screen{margin:12px auto;padding:16px 24px}.title-art{height:90px}.title-art canvas{width:90px;height:90px}.title-screen h1{font-size:clamp(34px,4vw,48px)}.title-screen .subtitle{font-size:17px;margin:10px auto;max-width:42ch}#start-form{margin:16px auto}.appearance-options{margin:14px 0;text-align:left}.appearance-options>summary{cursor:pointer;font-size:14px}
/* Arrival art supports the conversation without pushing its action out of view. */
.world-arrival .world-picture{max-height:110px;overflow:hidden}.world-arrival .world-picture svg{width:100%;height:110px}.world-arrival .story-dismiss{position:sticky;bottom:0;box-shadow:0 -5px 12px #f5eddc}
.coordinate-example{margin:18px 0;padding:12px;border:1px solid #c6b8a2;border-radius:10px}.coordinate-example svg{width:100%;max-height:210px}.coordinate-example figcaption{font-size:16px;line-height:1.5}

/* Dedicated click-through story scenes: lesson instructions stay behind the dialog. */
.story-cutscene{width:min(960px,calc(100% - 24px));padding:22px;background:#fff7e9;color:#303744;max-height:96dvh;overflow:auto;border:2px solid #ad9474}
.story-cutscene h2{font-size:23px;margin:0 0 14px}.story-cutscene::backdrop{background:#101622ec}
.cutscene-stage{position:relative;isolation:isolate;min-height:380px;overflow:hidden;border-radius:14px;background:#2c3846}
.cutscene-stage>svg{position:absolute;inset:0;width:100%;height:100%;object-fit:cover}
.cutscene-actors{position:relative;display:flex;justify-content:space-between;padding:24px 7% 0;gap:10px}
.cutscene-actors canvas{width:160px;height:180px;object-fit:contain;filter:brightness(.8) saturate(.8)}
.cutscene-actors canvas.speaking{opacity:1;filter:none}
.cutscene-bubble{position:relative;margin:18px 28px 24px;padding:18px 24px;min-height:122px;border-radius:18px;background:#fff9ed;color:#29334a;box-shadow:0 4px 15px #0003}
.cutscene-bubble:before{content:'';position:absolute;top:-17px;left:60px;border-bottom:19px solid #fff9ed;border-right:19px solid transparent}
.cutscene-bubble[data-side=right]:before{left:auto;right:60px;border-right:0;border-left:19px solid transparent}
.cutscene-bubble strong{color:#73523d}.cutscene-line{font-size:20px;line-height:1.45;margin:8px 0 0}
.cutscene-controls{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:16px}.cutscene-controls button{min-width:120px}
.story-cutscene button:not(.primary){background:#e7dfd0;color:#303744;border-color:#ad9474}.story-cutscene .cutscene-skip{display:block;margin:10px 0 0 auto;background:transparent;font-size:14px;min-height:36px;padding:5px 12px}
@media(max-height:650px){.story-cutscene{padding:14px}.cutscene-stage{min-height:280px}.cutscene-actors{padding-top:8px}.cutscene-actors canvas{width:105px;height:118px}.cutscene-bubble{min-height:100px;margin:12px 20px 16px;padding:12px 18px}.cutscene-line{font-size:18px}.cutscene-controls{margin-top:10px}}
@media(max-width:520px){.story-cutscene h2{font-size:19px}.cutscene-actors canvas{width:100px;height:112px}.cutscene-bubble{margin:16px 12px;padding:14px}.cutscene-line{font-size:17px}.cutscene-controls button{min-width:0}}

#variables-memory{margin:0 0 16px;padding:10px 12px;border:1px solid #9d9e8f;border-radius:8px}#variables-memory summary{cursor:pointer;font-size:14px;font-weight:600}#variables-values{max-height:115px;overflow:auto;margin:8px 0}

#teacher-preview-banner select{min-width:140px;max-width:320px;flex:1;padding:8px;font:inherit}#teacher-preview-banner>strong{font-size:13px}
.plan-inspector{margin-top:10px;text-align:left}.plan-inspector summary{cursor:pointer;font-weight:600}.plan-inspector select{font:inherit;max-width:100%;padding:6px}.plan-inspector output{display:block;margin-top:10px;font-weight:600}#chapter-plan:focus-visible{outline:3px solid var(--accent);outline-offset:3px}

#lesson-attempt-feedback{margin:0 0 8px;white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px}#lesson-attempt-feedback[data-error=true],body:not([data-theme="charcoal"]) #input-error{color:#963141}
body[data-theme="charcoal"] #lesson-attempt-feedback[data-error=true]{color:#ffb7be}
