:root {
  --ts-ink: #26334d;
  --ts-cream: #fff9ec;
  --ts-paper: #fffef9;
  --ts-pink: #f2bfd0;
  --ts-mint: #bde3cf;
  --ts-aqua: #b9dfec;
  --ts-yellow: #f3dfa4;
  --ts-lavender: #d9c8eb;
  --ts-peach: #f2c8ad;
  --ts-green: #6b9876;
  --ts-error: #974949;
  --ts-warning: #8b6328;
  --ts-focus: #245e9c;
  --ts-radius: 18px;
  --ts-outline: 3px;
  --shadow: 0 7px 18px rgba(51, 56, 78, 0.13);
  color-scheme: light;
  font-family: ui-rounded, "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
  color: var(--ts-ink);
  background: var(--ts-cream);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--ts-cream); }
button, input, select { font: inherit; color: inherit; }
button, select, input[type="checkbox"] { min-width: 44px; min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: var(--ts-outline) solid var(--ts-focus);
  outline-offset: 3px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { line-height: 1.08; }
.visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}
.skip-link {
  position: fixed; z-index: 1000; left: 12px; top: -80px; padding: 12px 18px;
  border-radius: 10px; background: var(--ts-ink); color: #fff;
}
.skip-link:focus { top: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 60; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; min-height: 62px;
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: rgba(255, 249, 236, 0.96); border-bottom: 1px solid #e5d9c5;
  backdrop-filter: blur(10px);
}
.topbar nav { display: flex; gap: 6px; }
.brand-button, .top-tool {
  border: 0; background: transparent; border-radius: 12px; padding: 8px 12px;
}
.brand-button { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.mini-shell {
  display: grid; place-items: center; width: 34px; height: 28px; color: #719274;
  background: var(--ts-mint); border: 3px solid #68856c; border-radius: 50%;
}
.screen { min-height: calc(100vh - 62px); padding: clamp(20px, 3vw, 44px); }
.screen[hidden] { display: none !important; }
.screen-heading { max-width: 760px; margin: 0 auto 28px; text-align: center; }
.screen-heading h1 { margin-bottom: 8px; font-size: clamp(2rem, 5vw, 3.3rem); }
.eyebrow {
  margin-bottom: 8px; color: #64718b; font-size: 0.78rem;
  font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase;
}
.panel {
  border: 1px solid rgba(74, 77, 95, 0.12);
  border-radius: var(--ts-radius); background: rgba(255, 254, 249, 0.96);
  box-shadow: var(--shadow);
}
.button, .small-button, .run-bar button {
  border: 2px solid rgba(38, 51, 77, 0.18); border-radius: 13px;
  padding: 10px 16px; font-weight: 800; background: #fff;
  box-shadow: 0 3px 0 rgba(38, 51, 77, 0.12);
}
.button.primary, .run-button { background: var(--ts-green); border-color: #547b5e; color: #fff; }
.button.secondary { background: var(--ts-paper); }
.button.attention { color: var(--ts-error); border-color: #d5a9a9; background: #fff7f4; }
.button.compact, .small-button { padding: 7px 12px; min-height: 44px; }
.text-button {
  border: 0; background: transparent; padding: 10px; color: #365d7c;
  font-weight: 700; text-decoration: underline; text-underline-offset: 3px;
}

/* Entrance */
.entrance-screen {
  position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(320px, 680px) minmax(300px, 540px);
  place-content: center; gap: clamp(25px, 5vw, 80px);
  background: linear-gradient(180deg, #fff9ec 0 68%, #e4c99e 68% 70%, #d9b582 70%);
}
.hero-copy { position: relative; z-index: 2; }
.hero-copy h1 { margin-bottom: 8px; font-size: clamp(3rem, 8vw, 6.6rem); letter-spacing: -0.05em; color: #374462; }
.tagline { font-size: clamp(1.2rem, 2.3vw, 1.75rem); font-weight: 800; color: #6a5a80; }
.intro-quote {
  max-width: 600px; padding: 16px 18px; border-left: 5px solid var(--ts-mint);
  background: rgba(255,255,255,0.72); border-radius: 5px 15px 15px 5px; line-height: 1.55;
}
.entrance-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice-card {
  min-height: 104px; display: flex; align-items: center; gap: 14px; padding: 16px;
  text-align: left; border: 2px solid rgba(38, 51, 77, 0.14); border-radius: 20px;
  box-shadow: 0 5px 0 rgba(57, 59, 72, 0.14), var(--shadow);
}
.choice-card strong, .choice-card small { display: block; }
.choice-card strong { margin-bottom: 4px; font-size: 1.2rem; }
.choice-card small { line-height: 1.3; }
.choice-mark { display: grid; place-items: center; flex: 0 0 48px; height: 48px; border-radius: 14px; background: rgba(255,255,255,0.6); font-size: 1.5rem; }
.create-choice { background: var(--ts-mint); }
.challenge-choice { background: var(--ts-lavender); }
.pattern-choice { background: var(--ts-yellow); }
.gallery-choice { background: var(--ts-pink); }
.secondary-actions { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 14px; }
.hero-characters { position: relative; align-self: end; height: 540px; }
.theo-portrait { position: absolute; z-index: 3; width: 260px; height: 190px; left: 50%; bottom: 76px; transform: translateX(-50%); }
.theo-portrait img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 14px 8px rgba(35,48,43,0.2)); }
.crayon-portrait { position: absolute; left: 50%; bottom: 12%; width: 13px; height: 62px; background: #77529a; border: 3px solid #523f67; border-radius: 6px; transform: rotate(8deg); }
.cast-character { position: absolute; bottom: 0; object-fit: contain; filter: drop-shadow(0 12px 6px rgba(61,45,53,0.16)); }
.elle-character { height: 300px; left: 0; }
.jay-character { height: 270px; right: 0; }
.kay-character { height: 185px; right: 24%; }
.room-decor > * { position: absolute; opacity: 0.75; }
.window { width: 200px; height: 210px; right: 5%; top: 8%; border: 14px solid #e8c7a1; border-radius: 100px 100px 14px 14px; background: #cce8ef; }
.window:before, .window:after { content: ""; position: absolute; background: #e8c7a1; }
.window:before { width: 10px; top: 0; bottom: 0; left: 50%; }
.window:after { height: 10px; left: 0; right: 0; top: 52%; }
.shelf { left: 4%; top: 12%; width: 220px; height: 18px; background: #b8865c; border-radius: 8px; }
.shelf i { display: inline-block; width: 28px; height: 50px; margin: -50px 8px 0; background: var(--ts-pink); border-radius: 7px 7px 2px 2px; }
.shelf i:nth-child(2) { background: var(--ts-aqua); height: 42px; }
.shelf i:nth-child(3) { background: var(--ts-yellow); }
.shelf i:nth-child(4) { background: var(--ts-lavender); height: 36px; }
.frame { width: 78px; height: 78px; border: 8px solid #ba8d65; background: #fffdf6; top: 34%; }
.frame-square { left: 2%; box-shadow: inset 0 0 0 18px var(--ts-lavender); }
.frame-triangle { right: 1%; clip-path: polygon(50% 0, 100% 100%, 0 100%); background: var(--ts-mint); }

/* Maps, patterns and gallery */
.map-screen, .patterns-screen, .gallery-screen { background: linear-gradient(#fff9ec, #f5ead9); }
.opening-card { max-width: 930px; margin: 0 auto 24px; padding: 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; background: linear-gradient(135deg, #fff, var(--ts-mint)); }
.opening-card h2 { margin-bottom: 5px; }
.room-grid, .pattern-grid, .gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 18px;
  max-width: 1220px; margin: 0 auto 28px;
}
.room-card, .pattern-card, .project-card {
  border: 2px solid rgba(38,51,77,0.12); border-radius: 21px; padding: 18px;
  background: var(--ts-paper); box-shadow: var(--shadow); text-align: left;
}
.room-card { min-height: 190px; }
.room-card:nth-child(4n+1) { background: #f1fbf5; }
.room-card:nth-child(4n+2) { background: #f8f3fc; }
.room-card:nth-child(4n+3) { background: #fff9e8; }
.room-card:nth-child(4n) { background: #fff2f5; }
.room-card strong, .pattern-card strong { display: block; margin-bottom: 8px; font-size: 1.2rem; }
.room-card small, .pattern-card small { display: block; line-height: 1.4; }
.room-progress { display: block; margin-top: 18px; font-weight: 800; color: #5f6d87; }
.pattern-card { min-height: 150px; }
.pattern-concepts { margin-top: 12px; color: #60708a; }
.pattern-controls { max-width: 760px; margin: 0 auto 22px; padding: 18px; display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.pattern-controls label { display: grid; gap: 6px; font-weight: 800; }
.gallery-toolbar { max-width: 1220px; margin: -8px auto 22px; display: flex; gap: 10px; justify-content: center; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.project-preview {
  width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border: 1px solid #e7dfd2;
  border-radius: 13px; background: #fff; margin-bottom: 14px;
}
.project-preview svg { width: 100%; height: 100%; display: block; }
.project-meta { color: #62708a; font-size: 0.85rem; }
.card-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.card-actions button { min-height: 40px; border: 1px solid #ccd1d8; border-radius: 10px; background: #fff; font-weight: 700; }
.empty-gallery { grid-column: 1 / -1; padding: 50px 24px; text-align: center; border: 2px dashed #cfc4b4; border-radius: 22px; }

/* Studio */
.studio-screen { padding: 18px clamp(10px, 2vw, 28px) 104px; background: #f4eadb; }
.studio-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.studio-heading h1 { margin-bottom: 0; font-size: clamp(1.5rem, 3vw, 2.25rem); }
.project-tools { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.challenge-banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px;
  padding: 13px 16px; margin-bottom: 12px;
}
.challenge-banner h2, .challenge-banner p { margin-bottom: 4px; }
.guide-mini img { width: 52px; height: 67px; object-fit: contain; }
.challenge-banner-actions { display: flex; gap: 8px; }
.studio-layout { display: grid; grid-template-columns: minmax(210px, 0.8fr) minmax(260px, 1.1fr) minmax(440px, 2.2fr); gap: 12px; align-items: start; }
.studio-panel { min-height: 640px; max-height: calc(100vh - 190px); overflow: auto; border-radius: var(--ts-radius); background: var(--ts-paper); box-shadow: var(--shadow); }
.panel-heading { position: sticky; top: 0; z-index: 4; display: flex; justify-content: space-between; align-items: center; min-height: 56px; padding: 10px 14px; background: var(--ts-paper); border-bottom: 1px solid #e8e1d4; }
.panel-heading h2 { margin: 0; font-size: 1.15rem; }
.panel-heading span { font-size: 0.82rem; color: #68748a; }
.palette-group { padding: 10px 12px 4px; }
.palette-group h3 { margin-bottom: 8px; font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; }
.palette-choices { display: grid; gap: 8px; }
.palette-block {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 9px 12px;
  border: 2px solid rgba(38,51,77,0.12); border-radius: 13px; text-align: left;
}
.palette-block span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,0.65); }
.block-motion { background: var(--ts-aqua); }
.block-drawing { background: var(--ts-pink); }
.block-control { background: var(--ts-yellow); }
.block-variables { background: var(--ts-mint); }
.block-procedures { background: var(--ts-lavender); }
.block-numbers { background: var(--ts-peach); }
.palette-help { margin: -3px 0 9px; color: #68748a; font-size: 0.78rem; line-height: 1.35; }
.expression-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.history-controls { display: flex; gap: 5px; }
.history-controls button { width: 42px; border: 1px solid #d6d4cf; border-radius: 9px; background: #fff; font-size: 1.25rem; }
.program-empty { margin: 18px; padding: 18px; border: 2px dashed #d2c8b9; border-radius: 14px; line-height: 1.5; }
.program-workspace { padding: 12px; }
.program-block {
  position: relative; margin: 0 0 10px; border: 3px solid transparent; border-radius: 15px;
  box-shadow: 0 3px 0 rgba(38,51,77,0.13); overflow: hidden;
}
.program-block.selected { border-color: var(--ts-focus); }
.program-block.executing { border-color: #cf6d20; box-shadow: 0 0 0 4px rgba(243, 223, 164, 0.9); }
.program-block.loop-active { outline: 3px dashed #8a6a24; outline-offset: 3px; }
.block-head { min-height: 58px; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; padding: 8px 9px; }
.reorder-buttons { display: flex; gap: 4px; margin-left: auto; }
.reorder-buttons button {
  min-width: 44px; min-height: 44px; border: 2px solid rgba(38,51,77,0.2);
  border-radius: 11px; background: rgba(255,255,255,0.9); font-size: 1.15rem; font-weight: 900;
}
.block-number { display: grid; place-items: center; width: 25px; height: 25px; background: rgba(255,255,255,0.72); border-radius: 50%; font-size: 0.75rem; }
.block-icon { font-size: 1.2rem; }
.block-fields { display: flex; flex: 1 1 100%; flex-wrap: wrap; gap: 6px; padding-left: 28px; }
.field-control { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.field-control > button, .field-presets button {
  min-width: 44px; min-height: 44px; border: 1px solid rgba(38,51,77,0.2); border-radius: 9px; background: rgba(255,255,255,0.8); font-weight: 800;
}
.field-control input { width: 70px; min-height: 44px; border: 2px solid rgba(38,51,77,0.2); border-radius: 9px; text-align: center; font-weight: 800; background: #fff; }
.field-expression input, .field-condition input, .field-text input { width: min(210px, 100%); text-align: left; padding: 6px 9px; }
.field-control select { width: 120px; min-height: 40px; border: 2px solid rgba(38,51,77,0.2); border-radius: 9px; background: var(--swatch, #fff); font-weight: 800; }
.field-presets { display: flex; flex-wrap: wrap; gap: 3px; width: 100%; }
.field-presets button { min-height: 44px; min-width: 44px; font-size: 0.76rem; }
.block-actions { display: none; flex-wrap: wrap; gap: 4px; padding: 5px 8px 8px; background: rgba(255,255,255,0.36); }
.program-block.selected > .block-actions, .program-block:focus-within > .block-actions { display: flex; }
.block-actions button { min-width: 44px; min-height: 44px; border: 1px solid rgba(38,51,77,0.2); border-radius: 9px; background: #fff; }
.repeat-body { margin: 0 8px 9px 26px; padding: 8px; min-height: 52px; border-left: 5px solid rgba(116,87,33,0.33); border-radius: 8px; background: rgba(255,255,255,0.48); }
.repeat-empty { margin: 5px; color: #766a53; font-size: 0.82rem; }
.nested-block { margin-bottom: 7px; }
.code-preview { margin: 18px 12px; padding: 12px; border: 1px solid #ded8cd; border-radius: 12px; background: #f8f7f3; }
.code-preview summary { min-height: 38px; font-weight: 800; cursor: pointer; }
.code-preview > label { display: block; margin: 10px 0 6px; font-size: 0.82rem; font-weight: 800; }
.code-preview textarea {
  width: 100%; min-height: 240px; resize: vertical; padding: 12px; border: 2px solid #aeb9c8;
  border-radius: 10px; background: #fff; color: #283750; font: 0.9rem/1.5 ui-monospace, Consolas, monospace;
  text-transform: none;
}
.code-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.code-error { min-height: 1.2em; margin: 7px 0 0; color: var(--ts-error); font-size: 0.82rem; font-weight: 800; }
.drawing-column { min-width: 0; }
.drawing-toolbar { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-bottom: 8px; }
.drawing-toolbar h2 { margin: 0 auto 0 0; font-size: 1.15rem; }
.drawing-toolbar label { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 800; }
.drawing-toolbar select { min-height: 40px; border: 1px solid #cfd1d4; border-radius: 9px; background: #fff; }
.zoom-control { display: none; min-width: 44px; padding-inline: 10px; font-size: 1.2rem; }
body.unlimited-paper .zoom-control { display: inline-block; }
.toggle-label input { width: 26px; height: 26px; }
.drawing-stage {
  position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden;
  border: 10px solid #d1a979; border-radius: 22px; background: #fffef9;
  box-shadow: inset 0 0 20px rgba(69,53,38,0.06), var(--shadow); touch-action: none;
}
.drawing-stage svg { display: block; width: 100%; height: 100%; }
.paper-graph { background-color: #fff; background-image: linear-gradient(#b9ddec55 1px, transparent 1px), linear-gradient(90deg, #b9ddec55 1px, transparent 1px); background-size: 5% 6.67%; }
.paper-studio { background: linear-gradient(rgba(255,255,255,0.84), rgba(255,255,255,0.84)), repeating-linear-gradient(90deg, #d9bd91 0 60px, #cba978 60px 63px); }
.paper-garden { background: linear-gradient(rgba(255,255,255,0.82), rgba(255,255,255,0.82)), radial-gradient(circle at 20% 20%, #acd8ad 0 16%, transparent 17%), linear-gradient(100deg, #d6c3a0, #aacb9c); }
.grid-line { stroke: #8aa7b7; stroke-width: 1; opacity: 0.28; }
.grid-axis { stroke: #536f82; stroke-width: 2; opacity: 0.45; }
.grid-label { fill: #536f82; font: 11px ui-monospace, monospace; opacity: 0.72; }
.theo-layer {
  position: absolute; left: 0; top: 0; z-index: 5; width: 102px; height: 72px;
  pointer-events: none; transform-origin: center center; transition-property: transform;
  transition-timing-function: ease-in-out; will-change: transform;
}
.theo-layer img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 5px 3px rgba(38,51,50,0.18)); }
.theo-crayon {
  position: absolute; z-index: -1; left: 47px; top: 39px; width: 8px; height: 30px;
  border: 2px solid #59406e; border-radius: 4px; background: #8e69a9;
  transform: rotate(0deg); transform-origin: top; transition: transform 180ms;
}
.theo-crayon.raised { transform: translate(18px, -15px) rotate(-65deg); }
.theo-walking img { animation: theo-walk 260ms ease-in-out infinite alternate; }
.theo-turning-left img { animation: lean-left 380ms ease; }
.theo-turning-right img { animation: lean-right 380ms ease; }
.theo-celebrating img { animation: celebrate 500ms ease 2; }
.theo-thinking:after, .theo-surprised:after {
  position: absolute; left: 75%; top: -22px; display: grid; place-items: center; width: 32px; height: 32px;
  border: 2px solid #667084; border-radius: 50%; background: #fff; font-weight: 900;
}
.theo-thinking:after { content: "?"; }
.theo-surprised:after { content: "!"; color: var(--ts-warning); }
.debug-anchor, .debug-heading { display: none; position: absolute; }
.debug-stage .debug-anchor { display: block; left: 48px; top: 34px; width: 8px; height: 8px; border-radius: 50%; background: red; }
.debug-stage .debug-heading { display: block; left: 50px; top: -10px; width: 2px; height: 46px; background: red; }
.target-guide { position: absolute; inset: 0; display: none; pointer-events: none; }
.target-guide.target-l { display: block; background: linear-gradient(90deg, transparent 49.7%, #647fa533 49.7% 50.3%, transparent 50.3%), linear-gradient(90deg, transparent 50%, #647fa533 50% 70%, transparent 70%); }
.stage-status { display: flex; justify-content: space-between; gap: 14px; margin-top: 8px; padding: 10px 13px; font-size: 0.86rem; }
.stage-status p { margin: 0; }
.feedback-card { margin-top: 8px; padding: 13px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.feedback-card[hidden] { display: none; }
#feedbackCharacter img { width: 52px; height: 66px; object-fit: contain; }
.feedback-card h2, .feedback-card p { margin-bottom: 4px; }
.feedback-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.run-bar {
  position: fixed; z-index: 50; left: 50%; bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; align-items: center; gap: 7px;
  width: min(760px, calc(100% - 20px)); padding: 9px; border: 1px solid #d7cdbc;
  border-radius: 18px; background: rgba(255,252,246,0.98); box-shadow: 0 10px 30px rgba(34,39,52,0.22);
}
.run-bar button { flex: 1; padding: 8px 11px; }
.run-bar label { display: flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 800; }
.run-bar select { min-height: 42px; border: 1px solid #ccd1d8; border-radius: 9px; background: #fff; }
.phone-tabs { display: none; }

/* Dialogs */
dialog {
  width: min(720px, calc(100% - 24px)); max-height: calc(100vh - 24px);
  border: 0; border-radius: 22px; padding: 0; box-shadow: 0 24px 80px rgba(28,34,45,0.35);
}
dialog::backdrop { background: rgba(28,34,45,0.54); backdrop-filter: blur(3px); }
.dialog-card { position: relative; display: grid; gap: 14px; padding: clamp(22px, 4vw, 38px); overflow: auto; }
.dialog-card h1 { margin-bottom: 0; }
.dialog-close { position: absolute; right: 10px; top: 10px; width: 46px; border: 0; border-radius: 50%; background: #f2eee5; font-size: 1.5rem; }
.dialog-done { justify-self: end; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 13px; border: 1px solid #e2ddd4; border-radius: 13px; }
.setting-row span, .setting-row strong, .setting-row small { display: block; }
.setting-row small { margin-top: 4px; color: #667088; }
.setting-row input[type="checkbox"] { width: 30px; height: 30px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.help-search { display: grid; gap: 7px; font-weight: 800; }
.help-search input { min-height: 48px; border: 2px solid #b8c2ce; border-radius: 11px; padding: 8px 12px; }
.help-topics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.help-topic { padding: 14px; border-radius: 13px; background: #f6f3ec; }
.help-topic h2 { margin-bottom: 7px; font-size: 1rem; }
.help-topic p, .help-topic pre { margin-bottom: 7px; font-size: 0.86rem; }
.help-topic pre { padding: 8px; overflow: auto; border-radius: 8px; background: #fff; }
.toast {
  position: fixed; z-index: 100; left: 50%; bottom: 94px; transform: translateX(-50%);
  max-width: min(520px, calc(100% - 24px)); padding: 13px 18px; border-radius: 12px;
  background: var(--ts-ink); color: #fff; box-shadow: var(--shadow); text-align: center; font-weight: 800;
}

@keyframes theo-walk { to { transform: translateY(-4px) rotate(2deg); } }
@keyframes lean-left { 50% { transform: rotate(-9deg); } }
@keyframes lean-right { 50% { transform: rotate(9deg); } }
@keyframes celebrate { 50% { transform: translateY(-10px) scale(1.04); } }

@media (max-width: 1050px) {
  .entrance-screen { grid-template-columns: 1fr; }
  .hero-characters { display: none; }
  .studio-layout { grid-template-columns: minmax(260px, 1fr) minmax(420px, 1.65fr); }
  .command-panel { grid-column: 1 / -1; min-height: 0; max-height: none; }
  .command-panel .palette-choices { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .topbar { min-height: 56px; }
  .brand-button strong { display: none; }
  .top-tool { padding: 7px 8px; font-size: 0.82rem; }
  .screen { padding: 20px 12px; min-height: calc(100vh - 56px); }
  .entrance-screen { display: block; padding-top: 42px; background: linear-gradient(#fff9ec 0 91%, #d9b582 91%); }
  .hero-copy h1 { font-size: clamp(3rem, 16vw, 4.6rem); }
  .entrance-actions { grid-template-columns: 1fr; }
  .choice-card { min-height: 82px; }
  .secondary-actions { justify-content: center; }
  .opening-card { align-items: stretch; flex-direction: column; }
  .room-grid, .pattern-grid, .gallery-grid { grid-template-columns: 1fr; }
  .help-topics { grid-template-columns: 1fr; }
  .studio-screen { padding: 10px 8px 98px; }
  .studio-heading { align-items: flex-start; }
  .studio-heading .eyebrow { display: none; }
  .studio-heading h1 { font-size: 1.15rem; }
  .project-tools .button:nth-child(1), .project-tools .button:nth-child(3) { display: none; }
  .challenge-banner { grid-template-columns: auto 1fr; }
  .challenge-banner-actions { grid-column: 1 / -1; }
  .phone-tabs {
    position: sticky; top: 56px; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
    margin-bottom: 8px; padding: 4px; border-radius: 13px; background: #e2d5c2;
  }
  .phone-tabs button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 800; }
  .phone-tabs button[aria-selected="true"] { background: #fff; box-shadow: 0 2px 7px rgba(50,53,61,0.15); }
  .studio-layout { display: block; }
  [data-studio-pane] { display: none; }
  [data-studio-pane].phone-active { display: block; }
  .studio-panel { min-height: calc(100vh - 230px); max-height: none; }
  .command-panel .palette-choices { grid-template-columns: repeat(2, 1fr); }
  .reorder-buttons { display: grid; grid-template-columns: repeat(2, 48px); }
  .reorder-buttons button { min-width: 48px; min-height: 48px; font-size: 1.3rem; }
  .drawing-column.phone-active { display: block; }
  .drawing-toolbar { padding: 0 3px; }
  .drawing-toolbar h2 { width: 100%; }
  .drawing-stage { border-width: 6px; border-radius: 14px; }
  .stage-status { display: block; }
  .stage-status p + p { margin-top: 5px; }
  .feedback-card { grid-template-columns: auto 1fr; }
  .feedback-actions { grid-column: 1 / -1; }
  .run-bar { bottom: max(5px, env(safe-area-inset-bottom)); gap: 4px; padding: 6px; }
  .run-bar button { min-width: 0; padding: 7px 4px; font-size: 0.78rem; }
  .run-bar label { display: none; }
  .field-presets { display: grid; grid-template-columns: repeat(6, 1fr); }
  .field-presets button { min-width: 0; }
}

@media (max-width: 390px) {
  .command-panel .palette-choices { grid-template-columns: 1fr; }
  .project-tools .button { padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

body.reduced-motion *, body.reduced-motion *::before, body.reduced-motion *::after {
  animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important;
}

@media print {
  .topbar, .studio-heading, .challenge-banner, .phone-tabs, .command-panel, .program-panel, .drawing-toolbar, .run-bar, .stage-status, .feedback-card { display: none !important; }
  body, .studio-screen { background: #fff; }
  .studio-layout, .drawing-column { display: block !important; }
  .drawing-stage { border: 0; box-shadow: none; max-width: 800px; margin: 30px auto; }
}
