@import url('https://fonts.googleapis.com/css2?family=M+PLUS+1+Code:wght@500;700&family=M+PLUS+Rounded+1c:wght@700;800;900&display=swap');

:root {
  --ink: #1d2a4d;
  --blue: #3d56d6;
  --pink: #f65c93;
  --yellow: #ffc53d;
  --green: #1fb971;
  --paper: #ffffff;
  --soft: #edf0f6;
  --workspace: #f1f4fc;
  --muted: #8b96b5;
  --shell-scale: 1;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body {
  color: var(--ink);
  background-color: var(--soft);
  background-image:
    linear-gradient(#dfe3ee 1px, transparent 1px),
    linear-gradient(90deg, #dfe3ee 1px, transparent 1px);
  background-size: 24px 24px;
  font-family: 'M PLUS 1 Code', monospace;
}
button, a { font: inherit; }
button { color: inherit; }
ruby { ruby-position: over; ruby-align: center; ruby-overhang: auto; }
ruby rt {
  visibility: hidden;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 0;
  font-weight: 900;
  line-height: 0;
  white-space: nowrap;
}
[data-japanese-mode="hira"] ruby rt { visibility: visible; font-size: .56em; line-height: .82; }

.textbook-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1180px;
  height: 800px;
  transform: translate(-50%, -50%) scale(var(--shell-scale));
  transform-origin: center;
  overflow: hidden;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
}
.eyebrow { color: var(--blue); font-size: 11.5px; font-weight: 700; letter-spacing: 2px; }
.book-title { font: 900 17px 'M PLUS Rounded 1c', sans-serif; }
.level-pill, .mode-button, .map-button {
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  font-size: 12px;
  font-weight: 900;
}
.level-pill { padding: 3px 12px; background: linear-gradient(#f4f6fa, #c6cdda); box-shadow: none; }
.topbar-spacer { margin-left: auto; }
.mode-button, .map-button { padding: 7px 14px; background: #fff; cursor: pointer; }
.mode-button.is-on { color: #fff; background: var(--blue); }
.stamp-count { font-size: 12.5px; font-weight: 800; }

.screen-area { position: absolute; top: 64px; bottom: 104px; left: 0; right: 0; }
.step-screen {
  height: 100%;
  display: grid;
  grid-template-columns: 470px minmax(0, 1fr);
  gap: 22px;
  padding: 20px 28px 10px;
}
.code-card, .cover-card, .play-card {
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 6px 0 var(--ink);
  overflow: hidden;
}
.step-info { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.step-info.has-try-layout { gap: 10px; }
.step-heading { display: flex; align-items: center; gap: 10px; }
.step-badge {
  min-width: 0;
  height: auto;
  padding: 6px 12px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  color: #fff;
  background: var(--pink);
  box-shadow: 0 3px 0 var(--ink);
  font: 900 13px 'M PLUS Rounded 1c', sans-serif;
}
.step-action-pill { min-height: 32px; padding: 3px 12px 3px 6px; display: inline-flex; align-items: center; gap: 7px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; font-size: 12px; font-weight: 900; line-height: 1.2; }
[data-japanese-mode="hira"] .step-action-pill { min-height: 38px; padding-top: 8px; padding-bottom: 4px; }
.step-action-text { min-width: 0; white-space: nowrap; }
.target-icon { width: 28px; height: 28px; padding: 2px; border: 2px solid var(--ink); border-radius: 50%; background: #fff; object-fit: contain; }
.step-action-pill .target-icon { width: 22px; height: 22px; padding: 0; border: 0; }
.step-title { margin: 0; font: 900 26px/1.35 'M PLUS Rounded 1c', sans-serif; }
.outcome { margin: 0; font-size: 14px; line-height: 1.75; }
.step-info .outcome { font-size: 15px; }
.instruction-card {
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  background: #fff;
  overflow: hidden;
}
.instruction-head { min-height: 34px; display: flex; align-items: center; gap: 8px; padding: 7px 12px; color: #fff; background: var(--blue); border-bottom: 2.5px solid var(--ink); }
.instruction-head b { font-size: 13.5px; }
.instruction-head span { margin-left: auto; font-size: 10px; letter-spacing: 1px; opacity: .85; }
.instruction-card ol { margin: 0; padding: 10px 12px; display: grid; gap: 8px; list-style: none; counter-reset: instruction-step; background: #f7f8fc; }
.instruction-card li { counter-increment: instruction-step; display: flex; gap: 9px; align-items: flex-start; font-size: 12.4px; line-height: 1.48; font-weight: 700; }
.instruction-text { min-width: 0; flex: 1; }
.instruction-card li::before { content: counter(instruction-step); width: 22px; height: 22px; flex: none; display: grid; place-items: center; color: #fff; background: var(--blue); border-radius: 50%; font-size: 12px; font-weight: 900; }
.step-info.has-long-steps .instruction-card ol { padding: 8px 10px; gap: 5px; }
.step-info.has-long-steps .instruction-card li { gap: 7px; font-size: 11.7px; line-height: 1.38; }
.step-info.has-long-steps .instruction-card li::before { width: 20px; height: 20px; font-size: 11px; }
.instruction-card a { color: var(--blue); font-weight: 900; }
.point, .try-card {
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  font-size: 12.5px;
  line-height: 1.55;
  font-weight: 700;
}
[data-japanese-mode="hira"] .point, [data-japanese-mode="hira"] .try-card { padding-top: 14px; line-height: 1.72; }
.point .card-text, .try-card .card-text { min-width: 0; flex: 1; }
.point { background: #fff3d1; }
.try-card { margin-top: auto; background: #fff; box-shadow: 0 4px 0 var(--ink); }
.tag { display: inline-block; flex: none; margin-right: 0; padding: 2px 9px; border: 2px solid var(--ink); border-radius: 999px; font-size: 10.5px; font-weight: 900; line-height: 1.35; }
.point .tag { background: var(--yellow); }
.try-card .tag { color: #fff; background: var(--green); }

.code-card { background: #fff; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.code-head { min-height: 48px; display: flex; align-items: center; gap: 9px; padding: 8px 16px; color: #fff; background: var(--blue); border-bottom: 3px solid var(--ink); }
.code-head img { width: 28px; height: 28px; padding: 2px; object-fit: contain; background: #fff; border-radius: 50%; }
.code-head strong { font-size: 14px; }
.code-head small { margin-left: auto; font-size: 10px; letter-spacing: 1px; opacity: .85; }
.program-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  scrollbar-gutter: stable;
  background-color: var(--workspace);
  background-image: radial-gradient(#cdd5e8 1px, transparent 1px);
  background-size: 18px 18px;
}
.program-workspace { width: max-content; min-width: 100%; min-height: 100%; display: flex; gap: 70px; align-items: flex-start; padding: 24px 84px 90px 54px; }
.program-panel { flex: none; width: max-content; min-width: 300px; position: relative; }
.program-panel.is-previous { filter: grayscale(1) saturate(.24); opacity: .54; }
.program-panel.is-whole-new { padding: 12px 24px 18px 12px; border: 3px dashed var(--pink); border-radius: 16px; background: rgba(246,92,147,.07); box-shadow: 0 0 0 4px rgba(246,92,147,.12); }
.program-label { display: inline-flex; margin: 0 0 12px 8px; padding: 4px 11px; border: 2px solid var(--ink); border-radius: 999px; background: #fff3d1; font: 900 11.5px 'M PLUS Rounded 1c', sans-serif; }
.is-previous .program-label { color: #556070; border-color: #7a86a8; background: #fff; }
.scratch-source { margin: 0; white-space: pre; font-size: 15px; }
.program-panel svg { display: block; max-width: none; overflow: visible; }
.block-dim { opacity: .46; filter: grayscale(1) saturate(.25); }
.scratch-ruby-text { fill: #fff; stroke: rgba(29,42,77,.78); stroke-width: 1.25px; paint-order: stroke; font: 900 6.4px 'M PLUS Rounded 1c', sans-serif; text-anchor: middle; pointer-events: none; }
.block-outline { fill: rgba(246,92,147,.06); stroke: var(--pink); stroke-width: 3; stroke-dasharray: 7 5; pointer-events: none; }
.block-outline-label { fill: var(--pink); font: 900 12px 'M PLUS Rounded 1c', sans-serif; pointer-events: none; }
.full-button { margin-left: auto; margin-right: 4px; padding: 5px 10px; border: 2px solid #fff; border-radius: 999px; color: #fff; background: transparent; font-size: 10.5px; font-weight: 900; cursor: pointer; }

.program-split { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; background: var(--workspace); }
.program-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.overview-pane { border-right: 3px solid var(--ink); }
.detail-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: 1fr 1fr; }
.detail-pane + .detail-pane { border-top: 3px solid var(--ink); }
.split-pane-head { min-height: 37px; padding: 7px 11px; display: flex; align-items: center; gap: 8px; color: var(--ink); background: #fff3d1; border-bottom: 2px solid var(--ink); }
.split-pane-head b { font: 900 12.5px 'M PLUS Rounded 1c', sans-serif; }
.split-pane-head span { margin-left: auto; color: #59627d; font-size: 9.5px; font-weight: 900; }
.split-scroll { flex: 1; }
.split-scroll .program-workspace { padding: 16px 52px 52px 24px; }
.overview-pane .program-workspace { justify-content: center; padding: 14px 24px 34px; }
.is-split-code .program-label:empty { display: none; }
.is-split-code .program-panel { min-width: 0; }

.stage-preview { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 220px; overflow: hidden; border: 2.5px solid var(--ink); border-radius: 13px; background: #fff; }
.stage-preview.is-main { min-height: 190px; max-height: 220px; flex: 1 1 190px; }
.stage-preview.has-movement-guide { min-height: 170px; max-height: 190px; flex: 1 0 170px; }
.step-info.has-try-layout .stage-preview:not(.is-main) { min-height: 90px; max-height: 125px; flex: 1 1 125px; }
.step-info.has-choice-layout .stage-preview { min-height: 90px; max-height: 125px; flex: 1 1 125px; }
.step-info.has-point-layout .stage-preview { min-height: 85px; max-height: 110px; flex: 1 1 110px; }
.step-info.has-try-layout.has-long-steps .stage-preview { min-height: 60px; max-height: 80px; flex: 1 1 80px; }
.stage-preview.is-scratch-ratio { width: 100%; min-height: 0 !important; max-height: none !important; flex: none !important; aspect-ratio: 4 / 3; align-self: center; }
.step-screen[data-page-type="setup"] .stage-preview.is-scratch-ratio { width: 82%; }
.step-screen[data-page-type="setup-test"] .stage-preview.is-scratch-ratio { width: 64%; }
.step-screen[data-page-type="choice"] .stage-preview.is-scratch-ratio { width: 70%; }
.step-screen .stage-preview.is-scratch-ratio.is-ratio-full { width: 100%; }
.step-screen .stage-preview.is-scratch-ratio.is-ratio-compact { width: 55%; }
.step-screen .stage-preview.is-scratch-ratio.is-ratio-tiny { width: 46%; }
.stage-preview img.backdrop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage-grid { position: absolute; inset: 0; background-image: linear-gradient(#dfe3ee 1px,transparent 1px),linear-gradient(90deg,#dfe3ee 1px,transparent 1px); background-size: 24px 24px; }
.scene-sprite { position: absolute; object-fit: contain; transform: translate(-50%, -50%); filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.scene-focus-ring { position: absolute; z-index: 1; aspect-ratio: 1; transform: translate(-50%, -50%); border: 4px solid #ff3b66; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255,255,255,.88); pointer-events: none; }
.preview-caption { position: absolute; left: 8px; top: 8px; padding: 3px 8px; color: #fff; background: rgba(29,42,77,.88); border-radius: 999px; font-size: 9.5px; font-weight: 900; }
.coordinate-label, .move-note { position: absolute; z-index: 2; padding: 4px 10px; border: 2px solid var(--ink); border-radius: 999px; color: var(--ink); background: #fff; box-shadow: 0 2px 0 var(--ink); font: 900 11.5px 'M PLUS Rounded 1c', sans-serif; }
.coordinate-label { right: 12px; bottom: 12px; }
.movement-guide { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.move-note { color: var(--blue); border-color: var(--blue); box-shadow: 0 2px 0 var(--blue); }
.move-left { left: 8%; top: 48%; }
.move-right { right: 8%; top: 48%; }
.move-up { left: 50%; top: 12%; transform: translateX(-50%); }
.move-down { left: 50%; bottom: 8%; transform: translateX(-50%); }

.drawing-info { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.drawing-info .outcome { font-size: 15px; line-height: 1.75; }
.drawing-instructions { flex: none; }
.editor-cue { position: relative; min-height: 132px; margin-top: auto; padding: 12px 14px; border: 2.5px solid #b9c4dc; border-radius: 14px; background: #e7ecf7; overflow: hidden; }
.editor-cue-title { color: #7a86a8; font-size: 10.5px; font-weight: 900; letter-spacing: 1px; }
.editor-sprites { display: flex; gap: 10px; margin-top: 10px; }
.editor-sprite { width: 58px; height: 58px; display: grid; place-items: center; border: 2px solid #b9c4dc; border-radius: 10px; background: #fff; }
.editor-sprite img { width: 42px; height: 42px; object-fit: contain; }
.editor-plus { position: absolute; right: 14px; bottom: 14px; width: 52px; height: 52px; display: grid; place-items: center; border: 2.5px solid var(--ink); border-radius: 50%; color: #fff; background: #4d97ff; font-size: 28px; font-weight: 900; }
.editor-click { position: absolute; right: 73px; bottom: 28px; padding: 2px 10px; border: 2px solid var(--ink); border-radius: 999px; background: var(--yellow); font-size: 11px; font-weight: 900; }
.draw-result-card { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink); background: #fff; }
.draw-result-head { min-height: 48px; padding: 10px 16px; display: flex; align-items: center; gap: 8px; color: #fff; background: var(--green); border-bottom: 3px solid var(--ink); }
.draw-result-head strong { font-size: 14px; }
.draw-result-head small { margin-left: auto; font-size: 11px; letter-spacing: 1px; opacity: .9; }
.draw-result-body { flex: 1; min-height: 0; padding: 18px; display: grid; grid-template-rows: auto 1fr auto; gap: 12px; background: var(--workspace); }
.draw-result-meta { min-height: 30px; display: flex; align-items: center; gap: 10px; }
.draw-result-meta span { padding: 4px 12px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; font-size: 12.5px; font-weight: 900; }
.draw-result-meta b { margin-left: auto; color: #5566a0; font-size: 11.5px; }
.draw-canvas { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; border: 2.5px solid #b9c4dc; border-radius: 16px; background-color: #fff; }
.draw-canvas.is-sprite { background-image: conic-gradient(#e4ebf5 25%,#fff 0 50%,#e4ebf5 0 75%,#fff 0); background-size: 30px 30px; }
.draw-canvas > img { width: var(--drawing-width); max-width: 86%; max-height: 82%; object-fit: contain; filter: drop-shadow(0 3px 0 rgba(29,42,77,.16)); }
.draw-canvas.is-backdrop > img { width: 92%; height: auto; max-width: 92%; max-height: 90%; aspect-ratio: 4 / 3; object-fit: contain; border: 2px solid var(--ink); border-radius: 10px; filter: none; }
.draw-canvas-badge { position: absolute; z-index: 1; top: 14px; right: 14px; padding: 3px 10px; border: 2px solid var(--ink); border-radius: 999px; background: #fff3d1; font-size: 11px; font-weight: 900; }
.draw-finish { padding: 8px 12px; display: flex; align-items: center; justify-content: center; gap: 9px; border: 2px solid #9ad8b9; border-radius: 12px; color: #176b48; background: #e4f8ee; }
.draw-finish span { padding: 2px 10px; border-radius: 999px; color: #fff; background: var(--green); font-size: 11px; font-weight: 900; }
.draw-finish b { font-size: 12.5px; }

.cover-screen { height: 100%; display: grid; grid-template-columns: 1fr 520px; gap: 24px; padding: 20px 28px 10px; }
.cover-card { position: relative; display: flex; flex-direction: column; gap: 13px; padding: 34px 36px; color: #fff; background-color: var(--blue); background-image: radial-gradient(rgba(255,255,255,.14) 2px,transparent 2px); background-size: 22px 22px; }
.cover-kicker { color: var(--yellow); font-size: 12px; letter-spacing: 3px; font-weight: 700; }
.cover-card h1 { margin: 0; font: 900 48px/1.16 'M PLUS Rounded 1c', sans-serif; text-shadow: 3px 3px 0 var(--ink); }
.cover-card h1 span { color: var(--yellow); }
.cover-card p { margin: 0; font-size: 15px; line-height: 1.85; font-weight: 700; }
.cover-tags { display: flex; gap: 10px; }
.cover-tags span { padding: 3px 13px; border: 2px solid #fff; border-radius: 999px; background: rgba(255,255,255,.15); font-size: 11.5px; font-weight: 800; }
.start-button { margin-top: auto; width: fit-content; padding: 13px 38px; border: 3px solid var(--ink); border-radius: 999px; background: var(--yellow); box-shadow: 0 5px 0 var(--ink); font: 900 19px 'M PLUS Rounded 1c', sans-serif; cursor: pointer; }
.cover-hero { position: absolute; right: 26px; bottom: 18px; width: 100px; }
.play-card { display: flex; flex-direction: column; background: #fff; }
.play-head { padding: 10px 18px; color: #fff; background: var(--pink); border-bottom: 3px solid var(--ink); font-size: 14px; font-weight: 900; }
.play-frame { flex: 1; display: grid; place-items: center; padding: 10px; background: var(--workspace); }
.play-frame iframe { width: 485px; height: 402px; max-width: 100%; border: 0; border-radius: 8px; }
.play-note { padding: 10px 18px; border-top: 2px dashed #c6cdda; font-size: 12.5px; font-weight: 800; }

.mission-screen { height: 100%; padding: 20px 28px 10px; }
.mission-card { height: 100%; padding: 26px; border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 6px 0 var(--ink); background: #fff; overflow: auto; }
.mission-card h1 { margin: 0 0 7px; font: 900 29px 'M PLUS Rounded 1c', sans-serif; }
.mission-card > p { margin: 0 0 18px; font-size: 13px; }
.mission-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.mission-item { padding: 16px; border: 2.5px solid var(--ink); border-radius: 16px; background: #fff3d1; }
.mission-item b { display: block; margin-bottom: 7px; font: 900 17px 'M PLUS Rounded 1c', sans-serif; }
.mission-item p { margin: 0; font-size: 12px; line-height: 1.6; }

.footer { position: absolute; left: 0; right: 0; bottom: 0; height: 104px; display: grid; grid-template-columns: 140px 1fr 116px 140px; align-items: center; gap: 10px; padding: 10px 28px 16px; }
.nav-button, .done-button { min-height: 44px; border: 2.5px solid var(--ink); border-radius: 999px; box-shadow: 0 4px 0 var(--ink); font-weight: 900; cursor: pointer; background: #fff; }
.nav-button:disabled { opacity: .35; cursor: default; }
.done-button { color: var(--ink); background: var(--yellow); }
.done-button.is-done { color: #fff; background: var(--pink); }
.step-rail { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; }
.step-dot { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border: 2px dashed #9aa5c0; border-radius: 50%; background: #fff; color: var(--muted); font-size: 10px; font-weight: 900; cursor: pointer; }
.step-dot.is-current { color: var(--pink); border: 2px solid var(--pink); }
.step-dot.is-done { color: #fff; border: 2px solid var(--ink); background: var(--pink); }
.step-dot.is-choice { width: 34px; border-radius: 12px; font-size: 9px; }
.step-dot.is-substep { border-radius: 11px; }
.step-rail.is-dense { gap: 3px; }
.step-rail.is-dense .step-dot { width: 26px; height: 26px; font-size: 8.5px; }
.step-rail.is-dense .step-dot.is-choice,
.step-rail.is-dense .step-dot.is-substep { width: 30px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(29,42,77,.56); }
.modal { width: min(920px, calc(100vw - 48px)); max-height: min(690px, calc(100vh - 48px)); display: flex; flex-direction: column; overflow: hidden; border: 3px solid var(--ink); border-radius: 24px; background: #fff; box-shadow: 0 8px 0 var(--ink); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 3px solid var(--ink); background: #fff3d1; }
.modal-head h2 { margin: 0; font: 900 20px 'M PLUS Rounded 1c', sans-serif; }
.modal-close { margin-left: auto; width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 50%; background: #fff; font-weight: 900; cursor: pointer; }
.map-grid { padding: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; overflow: auto; }
.map-item { min-height: 66px; padding: 10px; display: flex; gap: 10px; align-items: center; border: 2px solid var(--ink); border-radius: 14px; background: #fff; text-align: left; font-size: 11.5px; font-weight: 800; cursor: pointer; }
.map-item.is-current { background: #fff3d1; }
.map-tag { min-width: 34px; height: 30px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 999px; background: #fff; font-size: 10px; }
.map-item.is-done .map-tag { color: #fff; background: var(--pink); }
.full-programs { padding: 20px; display: flex; gap: 56px; overflow: auto; background: var(--workspace); }

@media (max-height: 690px) {
  .step-info { gap: 9px; }
  .stage-preview { max-height: 180px; }
}
