:root {
  color-scheme: light;
  --ff-ink: #22304a;
  --ff-cream: #fffaf0;
  --ff-paper: #fffdf8;
  --ff-pink: #f4b8cb;
  --ff-mint: #b8dfc7;
  --ff-blue: #b8d9ef;
  --ff-yellow: #f4dda1;
  --ff-lavender: #d8c5ea;
  --ff-peach: #f3c6a8;
  --ff-success: #387b58;
  --ff-attention: #945b20;
  --ff-error: #9b4040;
  --ff-border: #54617a;
  --ff-radius: 18px;
  --ff-outline: 3px;
  --shadow: 0 10px 25px rgb(34 48 74 / 14%);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  font-synthesis: none;
  color: var(--ff-ink);
  background: var(--ff-cream);
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; scroll-behavior: smooth; }
body { min-height: 100vh; min-height: 100svh; margin: 0; overflow-x: hidden; background: linear-gradient(#eaf6fb 0 22%, #f9edda 22% 100%); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 4px solid #254c79;
  outline-offset: 3px;
}
button:disabled { cursor: not-allowed; opacity: .5; }
h1, h2, p { overflow-wrap: anywhere; }
.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; top: 8px; left: 8px; z-index: 1000; padding: 10px 14px; border-radius: 10px; color: #fff; background: var(--ff-ink); transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.factory-backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.factory-backdrop::before { content: ""; position: absolute; inset: 22% 0 0; background:
  linear-gradient(90deg, transparent 48%, rgb(120 98 73 / 8%) 49% 51%, transparent 52%) 0 0 / 150px 100%,
  linear-gradient(#f3d8c8, #f5e7d6 65%, #caa983 65% 68%, #b89369 68%); }
.factory-window { position: absolute; top: 10%; left: 5%; width: 170px; height: 140px; border: 12px solid #fff5da; border-radius: 22px; background: linear-gradient(#a9d8ed 68%, #9fc58f 68%); box-shadow: 0 7px 0 #8c725a; }
.factory-window::before, .factory-window::after { content: ""; position: absolute; background: #fff5da; }
.factory-window::before { width: 8px; inset: 0 auto 0 50%; }
.factory-window::after { height: 8px; inset: 50% 0 auto; }
.factory-window span { position: absolute; bottom: 0; width: 55px; height: 40px; border-radius: 80% 80% 0 0; background: #79ad76; }
.factory-window span:last-child { right: 0; width: 75px; background: #6aa36d; }
.factory-pipe { position: absolute; border: 12px solid #83a9aa; opacity: .65; }
.pipe-one { top: 15%; right: -15px; width: 220px; height: 105px; border-left: 0; border-bottom: 0; border-radius: 0 0 0 40px; }
.pipe-two { bottom: 10%; left: -30px; width: 150px; height: 120px; border-right: 0; border-top: 0; border-radius: 0 0 40px; }
.factory-shelf { position: absolute; top: 23%; right: 3%; display: flex; align-items: end; gap: 12px; width: 180px; height: 70px; padding: 0 18px 10px; border-bottom: 10px solid #916c56; }
.factory-shelf i { width: 26px; height: 44px; border: 4px solid #54617a; border-radius: 8px 8px 3px 3px; background: var(--ff-pink); }
.factory-shelf i:nth-child(2) { height: 55px; background: var(--ff-mint); }
.factory-shelf i:nth-child(3) { height: 39px; background: var(--ff-yellow); }
.factory-shelf i:nth-child(4) { height: 50px; background: var(--ff-lavender); }
.factory-plant { position: absolute; right: 5%; bottom: 5%; width: 90px; height: 70px; border-radius: 10px 10px 28px 28px; background: #d98577; }
.factory-plant i, .factory-plant i::before, .factory-plant i::after { position: absolute; width: 42px; height: 75px; border-radius: 100% 0 100% 0; background: #689c6b; content: ""; }
.factory-plant i { left: 25px; bottom: 45px; transform: rotate(-12deg); }
.factory-plant i::before { left: -35px; top: 20px; transform: rotate(-45deg); }
.factory-plant i::after { left: 30px; top: 12px; transform: rotate(52deg); }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 68px; padding: max(8px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left)); border-bottom: 3px solid rgb(84 97 122 / 35%); background: rgb(255 250 240 / 92%); backdrop-filter: blur(10px); }
.brand-button, .tool-button { min-height: 46px; border: 0; border-radius: 14px; background: transparent; }
.brand-button { display: flex; align-items: center; gap: 10px; padding: 5px 10px; font-size: 1.05rem; }
.brand-button > span { display: grid; width: 38px; height: 38px; place-items: center; border: 3px solid var(--ff-ink); border-radius: 12px; background: var(--ff-yellow); font-size: 1.45rem; }
.toolbar-actions { display: flex; gap: 5px; }
.tool-button { display: flex; align-items: center; gap: 6px; padding: 7px 10px; font-size: .88rem; font-weight: 800; }
.tool-button:hover, .brand-button:hover { background: #fff; }

main { width: min(1500px, 100%); min-height: calc(100svh - 68px); margin: auto; padding: clamp(14px, 2.5vw, 36px); }
.screen[hidden] { display: none !important; }
.screen { animation: screen-in 240ms ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }
.eyebrow { margin: 0 0 6px; color: #765228; font-size: .78rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.screen-heading { max-width: 760px; margin: 0 auto 20px; text-align: center; }
.screen-heading h1, .play-heading h1, .entrance-copy h1, dialog h1 { margin: 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 1; letter-spacing: -.04em; }
.screen-heading p:last-child { margin: 10px auto; font-weight: 650; }

.entrance-screen { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(420px, 1.1fr); align-items: center; gap: clamp(20px, 4vw, 70px); min-height: calc(100svh - 120px); }
.entrance-copy { padding: clamp(8px, 3vw, 42px); }
.entrance-copy h1 { font-size: clamp(3rem, 7vw, 6.8rem); color: #344566; text-shadow: 0 4px #fff; }
.hero-line { max-width: 620px; margin: 15px 0 24px; font-size: clamp(1.1rem, 2vw, 1.45rem); font-weight: 750; line-height: 1.4; }
.entrance-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-card { display: grid; grid-template-columns: 55px 1fr; align-items: center; min-height: 100px; padding: 13px; border: 3px solid var(--ff-border); border-radius: 22px; text-align: left; box-shadow: var(--shadow); transition: transform 160ms ease, box-shadow 160ms ease; }
.choice-card:hover { transform: translateY(-3px); box-shadow: 0 15px 28px rgb(34 48 74 / 18%); }
.choice-explore { background: #e8f7ef; }
.choice-challenges { background: #e9f4fb; }
.choice-build { background: #fff1d2; }
.choice-notebook { background: #f4ebfb; }
.choice-icon { display: grid; width: 48px; height: 48px; place-items: center; border: 2px solid rgb(34 48 74 / 35%); border-radius: 14px; background: rgb(255 255 255 / 70%); font-size: 1.6rem; }
.choice-card strong, .choice-card small { display: block; }
.choice-card strong { font-size: 1.06rem; }
.choice-card small { margin-top: 4px; font-family: system-ui, sans-serif; font-weight: 600; line-height: 1.25; }
.secondary-actions { display: flex; flex-wrap: wrap; gap: 5px 15px; margin-top: 15px; }
.text-button { min-height: 44px; padding: 10px 3px; border: 0; color: #394c6d; background: transparent; font-family: system-ui, sans-serif; font-size: .84rem; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.attention-link { color: var(--ff-error); }
.entrance-art { position: relative; display: flex; flex-direction: column; justify-content: end; min-height: 570px; padding: 80px 15px 20px; border: 5px solid rgb(84 97 122 / 45%); border-radius: 60px 60px 25px 25px; background: linear-gradient(#f8dfc7 0 68%, #d5b38d 68%); box-shadow: var(--shadow), inset 0 0 60px rgb(255 255 255 / 55%); overflow: hidden; }
.entrance-art::before { content: ""; position: absolute; left: 8%; right: 8%; top: 8%; height: 56%; border: 9px solid #9a765e; border-radius: 15px; background: linear-gradient(90deg, transparent 49%, #fff6de 49% 52%, transparent 52%), linear-gradient(transparent 48%, #fff6de 48% 52%, transparent 52%), #9ed2e3; box-shadow: inset 0 -70px #80ad7a; }
.factory-sign { position: absolute; top: 20px; left: 50%; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 12px 18px; border: 4px solid var(--ff-ink); border-radius: 15px; background: var(--ff-paper); font-size: clamp(.7rem, 1vw, .9rem); font-weight: 900; transform: translateX(-50%); white-space: nowrap; }
.family-line { position: relative; z-index: 3; display: flex; align-items: end; justify-content: center; gap: 0; min-height: 310px; }
.family-line .character-sprite { margin: 0 -8px; filter: drop-shadow(0 8px 5px rgb(34 48 74 / 25%)); }

.panel { border: 3px solid rgb(84 97 122 / 68%); border-radius: var(--ff-radius); background: var(--ff-paper); box-shadow: var(--shadow); }
.screen-actions { display: flex; justify-content: center; padding: 20px; }
.button, .small-button { min-height: 44px; border: 3px solid var(--ff-border); border-radius: 13px; font-weight: 850; }
.button { padding: 10px 18px; }
.button.primary { color: #fff; border-color: #2e6748; background: var(--ff-success); }
.button.secondary { background: #fff; }
.button.attention { color: #fff; border-color: #783535; background: var(--ff-error); }
.button.compact { min-height: 42px; padding: 7px 12px; font-size: .85rem; }
.small-button { padding: 7px 10px; border-width: 2px; background: #f7f2e8; font-size: .8rem; }

.blueprint-wall { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px; margin: 18px auto 22px; }
.blueprint { min-width: 125px; padding: 9px 12px; border: 2px dashed #6b7181; border-radius: 12px; background: #dcecf3; font-size: .78rem; font-weight: 800; text-align: center; }
.blueprint.complete { border-style: solid; background: #cde8d7; }
.blueprint::before { content: "○ "; }
.blueprint.complete::before { content: "✓ "; color: var(--ff-success); }
.station-grid { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 15px; max-width: 1050px; margin: auto; }
.station-card { position: relative; min-height: 160px; padding: 20px; border: 3px solid var(--ff-border); border-radius: 22px; background: var(--ff-paper); text-align: left; box-shadow: var(--shadow); }
.station-card:not(:disabled):hover { transform: translateY(-2px); }
.station-card .station-number { display: grid; width: 38px; height: 38px; place-items: center; margin-bottom: 10px; border-radius: 12px; background: var(--ff-blue); font-weight: 900; }
.station-card strong, .station-card small { display: block; }
.station-card strong { font-size: 1.1rem; }
.station-card small { margin-top: 7px; font-family: system-ui, sans-serif; font-weight: 600; line-height: 1.35; }

.play-heading { display: flex; justify-content: space-between; align-items: end; gap: 15px; margin-bottom: 14px; }
.play-heading h1 { font-size: clamp(1.8rem, 3.3vw, 3rem); }
.play-heading-actions { display: flex; gap: 7px; }
.factory-floor { display: grid; grid-template-columns: minmax(180px, .7fr) minmax(440px, 1.65fr) minmax(300px, 1fr); align-items: start; gap: 16px; }
.guide-panel { position: sticky; top: 85px; padding: 15px; text-align: center; overflow: hidden; }
.guide-characters { position: relative; height: 245px; }
.guide-character { display: flex; height: 245px; align-items: end; justify-content: center; }
.guide-character .character-sprite { max-height: 235px; width: auto; filter: drop-shadow(0 7px 4px rgb(34 48 74 / 20%)); }
.creekside-factory-companion { position: absolute; right: -5px; bottom: -3px; width: 76px; height: 94px; pointer-events: none; }
.creekside-factory-companion img { width: 100%; height: 100%; object-fit: contain; object-position: bottom; }
.speech-card { position: relative; margin-top: 10px; padding: 13px; border: 3px solid var(--ff-border); border-radius: 18px; background: #fff8db; text-align: left; }
.speech-card::before { content: ""; position: absolute; top: -13px; left: 42%; width: 20px; height: 20px; border-top: 3px solid var(--ff-border); border-left: 3px solid var(--ff-border); background: #fff8db; transform: rotate(45deg); }
.speech-card h2 { margin: 0; font-size: 1.1rem; }
.speech-card p { margin: 5px 0 0; font-family: system-ui, sans-serif; font-weight: 620; line-height: 1.4; }
.machine-column { min-width: 0; }
.machine-stage { position: relative; display: grid; grid-template-columns: minmax(82px, 1fr) minmax(145px, 1.25fr) minmax(82px, 1fr); align-items: center; min-height: 290px; padding: 25px 10px 30px; border: 4px solid var(--ff-border); border-radius: 28px; background: linear-gradient(#f8e8cf 72%, #cfa47c 72%); box-shadow: var(--shadow); overflow: hidden; }
.input-station, .output-station { position: relative; z-index: 3; display: flex; flex-direction: column; align-items: center; }
.station-label { margin-bottom: 6px; padding: 3px 8px; border-radius: 7px; color: #fff; background: var(--ff-ink); font-size: .7rem; font-weight: 900; text-transform: uppercase; }
.number-card { display: grid; width: clamp(58px, 7vw, 76px); height: clamp(65px, 8vw, 86px); place-items: center; border: 4px solid var(--ff-ink); border-radius: 12px; background: #fff; box-shadow: 0 5px 0 rgb(34 48 74 / 25%); font-family: Georgia, serif; font-size: clamp(1.7rem, 3vw, 2.5rem); font-weight: 900; }
.conveyor { display: flex; gap: 5px; width: 100%; min-width: 80px; height: 24px; align-items: center; justify-content: center; border: 4px solid var(--ff-border); background: #767d8d; }
.conveyor i { width: 15px; height: 15px; border-radius: 50%; background: #cbd0d9; }
.conveyor-in { margin-left: 60%; }
.conveyor-out { margin-right: 60%; order: 2; }
.output-card { order: 3; }
.output-station .station-label { order: 1; }
.function-machine { position: relative; z-index: 4; display: grid; min-height: 210px; place-items: center; border: 6px solid var(--ff-ink); border-radius: 42px 42px 24px 24px; background: linear-gradient(135deg, #aacddd, #75a9bf); box-shadow: inset 0 0 0 7px rgb(255 255 255 / 25%), 0 11px 0 #526c7b; }
.machine-rule { position: relative; z-index: 5; min-width: 105px; max-width: 88%; padding: 15px 10px; border: 4px solid var(--ff-ink); border-radius: 14px; background: #fffdf4; font-size: clamp(1.1rem, 2.2vw, 1.75rem); font-weight: 900; text-align: center; }
.machine-light { position: absolute; top: -19px; width: 33px; height: 33px; border: 5px solid var(--ff-ink); border-radius: 50%; background: #f0c978; }
.gears { position: absolute; inset: auto 16px 15px auto; display: flex; align-items: center; }
.gears i { display: block; width: 40px; height: 40px; border: 9px dotted #d8ebed; border-radius: 50%; }
.gears i:last-child { width: 28px; height: 28px; margin-left: -6px; border-width: 7px; }
.machine-door { position: absolute; left: 15px; bottom: 17px; width: 37px; height: 47px; border: 4px solid var(--ff-ink); border-radius: 8px; background: #446d80; }
.machine-stage.running .input-card { animation: card-in 420ms ease-in forwards; }
.machine-stage.running .output-card { animation: card-out 380ms 520ms ease-out both; }
.machine-stage.running .gears i { animation: gear-turn 420ms linear 2; }
.machine-stage.running .machine-light { animation: light-pulse 250ms ease-in-out 3; }
.machine-stage.running .function-machine { animation: machine-wiggle 140ms ease-in-out 5; }
@keyframes card-in { to { transform: translateX(120%) scale(.55); opacity: .1; } }
@keyframes card-out { from { transform: translateX(-100%) scale(.55); opacity: .1; } }
@keyframes gear-turn { to { transform: rotate(180deg); } }
@keyframes light-pulse { 50% { background: #fff397; box-shadow: 0 0 22px #ffe77b; } }
@keyframes machine-wiggle { 50% { transform: translateY(-2px) rotate(.5deg); } }
.example-panel { margin-top: 14px; padding: 14px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-title-row h2 { margin: 0; font-size: 1rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; margin-top: 8px; border-collapse: collapse; font-family: system-ui, sans-serif; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border: 2px solid #788297; text-align: center; }
th { color: #fff; background: var(--ff-ink); }
td { background: #fff; font-weight: 750; }
.empty-row td { color: #687184; font-weight: 500; }
.challenge-panel { position: sticky; top: 85px; padding: 18px; }
.challenge-panel h2 { margin: 6px 0 10px; font-size: clamp(1.25rem, 2vw, 1.65rem); }
.question-number { min-height: 20px; color: #687184; font-size: .75rem; font-weight: 850; }
.equation-panel { padding: 14px; border: 3px solid #536177; border-radius: 14px; background: #fff; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.05rem, 2vw, 1.35rem); font-weight: 700; line-height: 1.5; text-align: center; }
.equation-panel .chain { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 7px; }
.equation-panel .chain span { padding: 6px 8px; border-radius: 8px; background: #edf5f8; }
.answer-actions { display: flex; gap: 8px; margin-top: 12px; }
.answer-actions .button { flex: 1; }
.number-entry { margin-top: 13px; }
.answer-input { width: 100%; min-height: 55px; padding: 8px 12px; border: 3px solid var(--ff-border); border-radius: 12px; background: #fff; font-size: 1.55rem; font-weight: 850; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.keypad button { min-height: 46px; border: 2px solid var(--ff-border); border-radius: 10px; background: #f7f2e8; font-weight: 900; }
.keypad .key-wide { grid-column: span 2; }
.choice-list { display: grid; gap: 8px; margin-top: 13px; }
.answer-choice { display: block; position: relative; }
.answer-choice input { position: absolute; opacity: 0; }
.answer-choice span { display: block; min-height: 52px; padding: 12px; border: 3px solid #707b90; border-radius: 12px; background: #fff; font-weight: 800; line-height: 1.3; }
.answer-choice input:checked + span { border-color: #255f83; background: #dceefa; box-shadow: inset 0 0 0 2px #255f83; }
.answer-choice input:focus-visible + span { outline: 4px solid #254c79; outline-offset: 3px; }
.support-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.feedback-panel { margin-top: 14px; padding: 13px; border: 3px solid var(--ff-success); border-radius: 14px; background: #eff9f2; }
.feedback-panel.incorrect { border-color: var(--ff-error); background: #fff2f0; }
.feedback-panel.hint { border-color: var(--ff-attention); background: #fff7e8; }
.feedback-panel p { margin: 0; font-family: system-ui, sans-serif; font-weight: 700; line-height: 1.45; }
#feedbackWork { margin-top: 7px; font-family: Georgia, serif; font-size: 1.08rem; font-weight: 700; }
.feedback-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

.rule-builder { margin-top: 12px; }
.rule-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; min-height: 58px; padding: 9px; border: 3px dashed #707b90; border-radius: 13px; background: #fff; }
.rule-token { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 44px; padding: 8px 10px; border: 2px solid #536177; border-radius: 10px; background: #e8f3f6; font-weight: 900; }
.step-order-controls { display: inline-flex; gap: 4px; }
.step-order-controls button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--ff-border);
  border-radius: 10px;
  color: var(--ff-ink);
  background: var(--ff-paper);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 900;
}
.function-graph { width: min(100%, 420px); margin: 0 auto; }
.function-graph svg { display: block; width: 100%; height: auto; border-radius: 14px; background: #fffef9; }
.function-graph rect { fill: #fffef9; stroke: #c7bfd3; stroke-width: 2; }
.function-graph .axis { stroke: var(--ff-ink); stroke-width: 2; }
.function-graph circle { fill: var(--ff-pink); stroke: var(--ff-ink); stroke-width: 2; }
.function-graph text { fill: var(--ff-ink); font-weight: 900; }
.function-graph figcaption { margin-top: 6px; color: #4b5870; font-size: .78rem; line-height: 1.5; text-align: center; }
.tile-groups { display: grid; gap: 9px; margin-top: 10px; }
.tile-group { display: flex; flex-wrap: wrap; gap: 6px; }
.tile-group strong { width: 100%; font-size: .75rem; }
.tile { min-width: 44px; min-height: 44px; border: 2px solid var(--ff-border); border-radius: 10px; background: #fff3cc; font-weight: 900; }

.notebook-screen { max-width: 1250px; margin: auto; }
.notebook-paper { min-height: 75svh; padding: clamp(18px, 3vw, 40px); border: 4px solid #8d765e; border-radius: 15px 30px 30px 15px; background:
  linear-gradient(90deg, transparent 72px, #efb2b9 72px 75px, transparent 75px),
  repeating-linear-gradient(#fffdf8 0 35px, #ccdfed 36px 37px);
  box-shadow: var(--shadow); }
.notebook-heading { margin-bottom: 15px; }
.notebook-toolbar { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.notebook-layout { display: grid; grid-template-columns: minmax(230px, .65fr) minmax(360px, 1.35fr); gap: 16px; }
.notebook-list { display: grid; align-content: start; gap: 8px; }
.notebook-list-card { width: 100%; padding: 12px; border: 3px solid #6d778b; border-radius: 13px; background: rgb(255 255 255 / 90%); text-align: left; }
.notebook-list-card.active { border-color: #315d7b; background: #dceefa; }
.notebook-list-card strong, .notebook-list-card small { display: block; }
.notebook-list-card small { margin-top: 4px; font-family: system-ui, sans-serif; }
.notebook-detail { min-height: 360px; padding: 23px; border: 3px solid #6d778b; border-radius: 16px; background: rgb(255 255 255 / 92%); }
.empty-notebook { display: grid; min-height: 300px; place-items: center; align-content: center; text-align: center; }
.empty-notebook > span { font-size: 3rem; }
.empty-notebook h2 { margin: 8px; }
.notebook-entry-head { display: flex; justify-content: space-between; gap: 12px; }
.notebook-entry-head h2 { margin: 0; }
.notebook-meta { color: #5e687c; font-family: system-ui, sans-serif; font-size: .82rem; }
.notebook-section { margin: 17px 0; }
.notebook-section h3 { margin: 0 0 6px; font-size: .85rem; text-transform: uppercase; letter-spacing: .07em; }
.notebook-field { width: 100%; padding: 10px; border: 2px solid #6d778b; border-radius: 10px; background: #fff; font-family: system-ui, sans-serif; }
textarea.notebook-field { min-height: 100px; resize: vertical; }

dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100svh - 24px); padding: 0; border: 0; border-radius: 23px; color: var(--ff-ink); background: transparent; overflow: auto; }
dialog::backdrop { background: rgb(27 38 57 / 65%); backdrop-filter: blur(3px); }
.dialog-card { position: relative; padding: clamp(20px, 4vw, 38px); border: 4px solid var(--ff-border); border-radius: 23px; background: var(--ff-paper); box-shadow: 0 20px 50px rgb(0 0 0 / 25%); }
.dialog-card > h1 { margin-bottom: 12px; font-size: clamp(1.8rem, 4vw, 2.8rem); }
.dialog-close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 2px solid #6d778b; border-radius: 50%; background: #fff; font-size: 1.7rem; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.help-grid section { padding: 13px; border: 2px solid #737e92; border-radius: 13px; background: #f8f5ec; }
.help-grid h2 { margin: 0; font-size: 1rem; }
.help-grid p { margin: 5px 0 0; font-family: system-ui, sans-serif; line-height: 1.4; }
.help-grid .wide { grid-column: 1 / -1; }
.mini-flow { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 8px; }
.mini-flow > * { padding: 5px 7px; border-radius: 7px; background: #fff; font-style: normal; }
.dialog-done { margin-top: 18px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 70px; padding: 12px 0; border-bottom: 2px solid #d1d5dc; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { margin-top: 4px; font-family: system-ui, sans-serif; }
.switch-row input { width: 28px; height: 28px; }
.advanced-drawer { margin-top: 18px; padding: 14px; border: 2px dashed #7a6a88; border-radius: 13px; background: #f3edf7; }
.advanced-drawer p { margin-bottom: 0; font-family: system-ui, sans-serif; }
.confirmation-card { text-align: center; }
.dialog-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.toast { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 100; max-width: min(390px, calc(100% - 36px)); padding: 13px 17px; border: 3px solid var(--ff-ink); border-radius: 13px; color: #fff; background: var(--ff-ink); box-shadow: var(--shadow); font-family: system-ui, sans-serif; font-weight: 750; }

.character-sprite { display: block; height: auto; object-fit: contain; object-position: center bottom; user-select: none; }
.character-placeholder { display: grid; place-items: center; border: 3px solid var(--ff-border); border-radius: 50%; background: var(--ff-lavender); font-weight: 900; }

@media (max-width: 1050px) {
  .entrance-screen { grid-template-columns: 1fr 1fr; }
  .factory-floor { grid-template-columns: minmax(180px, .7fr) minmax(430px, 1.5fr); }
  .challenge-panel { position: static; grid-column: 1 / -1; }
  .guide-panel { top: 82px; }
  .station-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

@media (max-width: 760px) {
  .topbar { min-height: 60px; padding: max(6px, env(safe-area-inset-top)) 9px 6px; }
  .brand-button strong, .tool-button span:last-child { display: none; }
  .tool-button { min-width: 44px; justify-content: center; font-size: 1.1rem; }
  main { min-height: calc(100svh - 60px); padding: 12px; }
  .entrance-screen { display: flex; min-height: auto; flex-direction: column; }
  .entrance-copy { width: 100%; padding: 10px 2px; text-align: center; }
  .entrance-copy h1 { font-size: clamp(3rem, 15vw, 5rem); }
  .hero-line { margin-right: auto; margin-left: auto; }
  .entrance-actions { grid-template-columns: 1fr; }
  .choice-card { min-height: 83px; }
  .secondary-actions { justify-content: center; }
  .entrance-art { width: 100%; min-height: 390px; padding-top: 65px; }
  .family-line { min-height: 220px; }
  .family-line .character-sprite { max-width: 23%; height: auto !important; }
  .station-grid { grid-template-columns: 1fr; }
  .play-heading { align-items: start; }
  .play-heading-actions { flex-direction: column; }
  .factory-floor { display: flex; flex-direction: column; }
  .guide-panel { position: static; display: grid; grid-template-columns: 100px 1fr; align-items: center; width: 100%; padding: 10px; }
  .guide-characters { height: 130px; }
  .guide-character { height: 130px; }
  .guide-character .character-sprite { max-height: 125px; }
  .creekside-factory-companion { right: -9px; bottom: -4px; width: 48px; height: 61px; }
  .speech-card { margin: 0; }
  .speech-card::before { top: 42%; left: -12px; border-top: 0; border-bottom: 3px solid var(--ff-border); transform: rotate(45deg); }
  .machine-column, .challenge-panel { width: 100%; }
  .machine-stage { min-height: 245px; padding-right: 5px; padding-left: 5px; }
  .function-machine { min-height: 175px; border-width: 5px; }
  .machine-rule { min-width: 80px; padding: 10px 5px; font-size: 1rem; }
  .number-card { width: 52px; height: 64px; font-size: 1.55rem; }
  .conveyor { min-width: 55px; }
  .notebook-layout { grid-template-columns: 1fr; }
  .notebook-paper { padding: 16px 12px 16px 28px; background:
    linear-gradient(90deg, transparent 19px, #efb2b9 19px 21px, transparent 21px),
    repeating-linear-gradient(#fffdf8 0 35px, #ccdfed 36px 37px); }
  .help-grid { grid-template-columns: 1fr; }
  .help-grid .wide { grid-column: auto; }
}

@media (max-width: 430px) {
  .screen-heading h1 { font-size: 2.35rem; }
  .machine-stage { grid-template-columns: 70px minmax(118px, 1fr) 70px; }
  .conveyor i:nth-child(3) { display: none; }
  .machine-door, .gears { transform: scale(.75); transform-origin: bottom; }
  .keypad { grid-template-columns: repeat(3, 1fr); }
  .keypad .key-wide { grid-column: span 1; }
  .rule-token { width: 100%; justify-content: space-between; }
  .step-order-controls { margin-left: auto; }
  .three-actions { flex-direction: column; }
}

@media (max-height: 540px) and (orientation: landscape) {
  .topbar { position: relative; }
  main { padding: 8px 14px; }
  .entrance-screen { display: grid; grid-template-columns: 1.1fr .9fr; gap: 10px; }
  .entrance-copy { padding: 0; text-align: left; }
  .entrance-copy h1 { font-size: clamp(2.5rem, 8vw, 4rem); }
  .hero-line { margin: 6px 0 9px; font-size: 1rem; }
  .entrance-actions { grid-template-columns: 1fr 1fr; gap: 6px; }
  .choice-card { grid-template-columns: 40px 1fr; min-height: 63px; padding: 6px; border-radius: 14px; }
  .choice-icon { width: 37px; height: 37px; font-size: 1.2rem; }
  .choice-card small { display: none; }
  .secondary-actions { margin-top: 2px; }
  .text-button { min-height: 35px; padding: 5px 2px; }
  .entrance-art { min-height: 340px; }
}

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

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

@media print {
  body { background: #fff; }
  .factory-backdrop, .topbar, .notebook-toolbar, .screen-actions, .dialog-close { display: none !important; }
  main { width: 100%; padding: 0; }
  .screen:not(.notebook-screen) { display: none !important; }
  .notebook-screen, .notebook-paper { display: block !important; border: 0; box-shadow: none; background: #fff; }
  .notebook-layout { display: block; }
  .notebook-list { display: none; }
  .notebook-detail { border: 0; min-height: auto; padding: 0; }
}
