:root {
  --blue: #4c97ff;
  --deep: #3373cc;
  --bg: #e5f0ff;
  --panel: #e9f1fc;
  --line: #d9e3f2;
  --ink: #575e75;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    17px/1.55 system-ui,
    -apple-system,
    "Noto Sans TC",
    sans-serif;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
.file-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #bac8db;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 3px solid #ffab19;
  outline-offset: 2px;
}
button:active {
  transform: translateY(1px);
}
button[aria-pressed="true"] {
  border: 2px solid var(--blue);
  background: var(--bg);
  color: #214e8a;
}
.primary {
  background: var(--blue);
  border-color: var(--deep);
  color: white;
}
.green {
  color: #207c43;
  font-weight: 700;
}
.red {
  color: #c5364c;
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--blue);
  color: white;
  padding: 8px 16px;
}
header a {
  color: white;
  font-size: 25px;
  text-decoration: none;
  min-width: 44px;
}
header strong {
  flex: 1;
}
header button {
  background: #ffffff22;
  color: white;
  border-color: #ffffff55;
}
.chapterbar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid #bac8db;
}
.chapterbar select {
  min-height: 44px;
  max-width: 48vw;
  border: 1px solid #bac8db;
  border-radius: 6px;
  color: var(--ink);
  padding: 4px;
  background: white;
}
#progress {
  margin-left: auto;
  font-size: 14px;
}
main {
  max-width: 1300px;
  padding: 14px;
  margin: auto;
  padding-bottom: 88px;
}
.task,
.review,
#teacher-panel {
  padding: 16px;
  background: white;
  border: 1px solid #bac8db;
  border-radius: 8px;
  margin-bottom: 12px;
}
h1 {
  font-size: 27px;
  margin: 5px 0 10px;
}
h2 {
  font-size: 21px;
  margin: 4px 0 10px;
}
p {
  margin: 8px 0 12px;
}
.eyebrow {
  color: var(--deep);
  font-size: 14px;
  font-weight: 700;
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.mission {
  font-weight: 600;
}
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--panel);
  border-bottom: 1px solid #bac8db;
}
.tabs span {
  margin-left: auto;
  font-size: 14px;
}
#workbench {
  border: 1px solid #bac8db;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.desk {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  grid-template-areas: "editor stage";
}
.stage-panel {
  grid-area: stage;
  min-width: 0;
  border-left: 1px solid #bac8db;
}
.editor-panel {
  grid-area: editor;
  min-width: 0;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  padding: 6px;
  background: #f5f8ff;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.toolbar strong {
  margin-right: auto;
}
.toolbar button {
  padding: 7px 9px;
}
.stage-wrap {
  position: relative;
  background: white;
  aspect-ratio: 4/3;
}
canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}
#stage-status,
#touch-status {
  position: absolute;
  pointer-events: none;
  background: #ffffffec;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 3px 7px;
  font-size: 13px;
}
#stage-status {
  top: 8px;
  left: 8px;
}
#touch-status {
  bottom: 8px;
  right: 8px;
}
.stage-meta,
.sprites,
.star-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.stage-meta {
  font-size: 14px;
}
.stage-meta button {
  margin-left: auto;
}
.sprites span,
.star-controls span {
  font-size: 14px;
}
#editor {
  height: 490px;
  width: 100%;
  background: #f9f9fc;
}
.edit-tools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.editor-tip {
  font-size: 13px;
  padding: 0 10px;
}
.concepts {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 10px;
  scrollbar-width: thin;
}
.concepts button {
  flex-shrink: 0;
}
.demoheading {
  padding: 10px 16px;
  background: #f5f8ff;
  border-bottom: 1px solid var(--line);
}
#feedback {
  margin: 12px 0;
  padding: 14px;
  background: white;
  border: 1px solid #bac8db;
  border-left: 5px solid var(--blue);
  border-radius: 6px;
  min-height: 64px;
}
.review {
  margin-top: 12px;
}
#hint {
  padding: 12px;
  background: #fff4d2;
  border-radius: 6px;
  margin-top: 10px;
}
.lesson-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: #f5f8fff5;
  border-top: 1px solid #bac8db;
  font-size: 15px;
  min-height: 58px;
}
#save-status {
  font-size: 12px;
  max-width: 120px;
}
dialog {
  border: 1px solid #bac8db;
  border-radius: 12px;
  width: 560px;
  max-width: calc(100vw - 20px);
  max-height: 85dvh;
  color: var(--ink);
  padding: 16px;
}
dialog::backdrop {
  background: #273d6677;
}
.dialoghead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
#palette-list {
  display: grid;
  gap: 10px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  text-align: left;
  background: #f5f8ff;
  min-height: 92px;
}
.palette-item svg {
  flex: 0 0 170px;
  width: 170px;
  max-height: 115px;
}
.palette-item span {
  font-size: 14px;
}
#connection-list {
  display: grid;
  gap: 8px;
}
.settings-grid {
  display: grid;
  gap: 10px;
}
.file-button {
  display: block;
}
input[type="file"] {
  display: block;
  max-width: 100%;
  font-size: 14px;
}
textarea {
  width: 100%;
  border: 1px solid #bac8db;
  border-radius: 6px;
  padding: 8px;
  margin-top: 8px;
}
footer {
  font-size: 13px;
  padding: 10px;
}
#teacher-panel label {
  display: block;
  margin-top: 10px;
}
.projection #editor {
  height: 560px;
}
.projection {
  font-size: 21px;
}
.editing {
  overflow: hidden;
}
.editing header,
.editing .chapterbar,
.editing .task,
.editing .review,
.editing .lesson-controls,
.editing footer,
.editing #teacher-panel {
  display: none;
}
.editing main {
  padding: 0;
  height: 100dvh;
  max-width: none;
}
.editing #workbench {
  border-radius: 0;
  border: 0;
  height: 100dvh;
  overflow: auto;
}
.editing .desk {
  min-height: calc(100dvh - 62px);
}
.editing #feedback {
  margin: 0;
  padding: 8px;
  font-size: 14px;
}
.stage-focus .editor-panel {
  display: none;
}
.stage-focus .desk {
  display: block;
}
.stage-focus .stage-wrap {
  max-height: 75dvh;
  aspect-ratio: 4/3;
  margin: auto;
}
.stage-focus canvas {
  object-fit: contain;
}
.stage-focus .stage-panel {
  max-width: 800px;
  margin: auto;
}
#connection-list button {
  text-align: left;
}
#reflection {
  padding-top: 10px;
}
#reflection button {
  margin: 4px;
}
.blocklyText {
  font-family: system-ui, sans-serif !important;
}
.blocklyMainBackground {
  stroke: none !important;
}
[hidden] {
  display: none !important;
}
@media (max-width: 700px) {
  body {
    font-size: 16px;
  }
  header {
    padding: 6px 8px;
    gap: 4px;
  }
  header strong span {
    display: none;
  }
  header button {
    font-size: 14px;
  }
  .chapterbar {
    padding: 6px 8px;
    gap: 6px;
  }
  .chapterbar label {
    display: none;
  }
  .chapterbar select {
    max-width: 56vw;
    font-size: 14px;
  }
  #progress {
    display: none;
  }
  #teacher-toggle {
    margin-left: auto;
    font-size: 13px;
  }
  main {
    padding: 8px;
    padding-bottom: 80px;
  }
  h1 {
    font-size: 23px;
  }
  .task {
    padding: 12px;
  }
  .desk {
    display: flex;
    flex-direction: column;
  }
  .stage-panel {
    border-left: 0;
    border-bottom: 1px solid #bac8db;
  }
  .tabs {
    flex-wrap: wrap;
  }
  .tabs span {
    font-size: 12px;
  }
  .stage-wrap {
    aspect-ratio: 480/270;
  }
  #editor {
    height: 340px;
  }
  .toolbar {
    font-size: 13px;
  }
  .toolbar button {
    font-size: 13px;
  }
  .stage-meta {
    padding: 4px 8px;
  }
  .stage-meta button {
    font-size: 13px;
  }
  .sprites,
  .star-controls {
    padding: 5px 8px;
  }
  .sprites button {
    padding: 6px 12px;
  }
  .star-controls button {
    padding: 5px 12px;
  }
  .editor-tip {
    margin: 4px 0 8px;
  }
  .editing .desk {
    display: flex;
    min-height: 0;
  }
  .editing .stage-wrap {
    height: clamp(130px, 25dvh, 230px);
    aspect-ratio: auto;
  }
  .editing .stage-wrap canvas {
    object-fit: contain;
  }
  .editing #editor {
    height: clamp(230px, 37dvh, 550px);
  }
  .editing .star-controls,
  .editing .editor-tip {
    display: none;
  }
  .editing .stage-meta {
    display: none;
  }
  .editing .toolbar {
    padding: 4px;
  }
  .code-focus .stage-wrap {
    height: 125px;
  }
  .code-focus #editor {
    height: 48dvh;
  }
  .stage-focus .stage-wrap {
    height: 65dvh;
  }
  .palette-item {
    gap: 6px;
  }
  .palette-item svg {
    flex-basis: 155px;
    width: 155px;
  }
  .palette-item span {
    font-size: 13px;
  }
  .lesson-controls {
    gap: 10px;
  }
  #save-status {
    max-width: 95px;
  }
  .editing #feedback {
    display: none;
  }
}
@media (max-width: 380px) {
  .toolbar {
    gap: 3px;
  }
  .toolbar button {
    padding: 6px;
  }
  .tabs span {
    display: none;
  }
  .edit-tools button {
    font-size: 14px;
    padding: 6px 9px;
  }
  .palette-item svg {
    flex-basis: 135px;
    width: 135px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
@media print {
  header,
  .chapterbar,
  #workbench,
  .lesson-controls,
  .task,
  .review,
  #feedback,
  footer {
    display: none !important;
  }
  #teacher-panel {
    display: block !important;
    border: 0;
  }
  #teacher-panel button {
    display: none;
  }
  textarea {
    height: 120px;
  }
}

.blocklyInputField .blocklyText {
  fill: #575e75 !important;
}
.blocklyFieldRect {
  rx: 18px;
  ry: 18px;
}
.stage-wrap {
  aspect-ratio: 4/3;
}
.editing .stage-wrap canvas,
.stage-focus .stage-wrap canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
  margin: auto;
}
.editing .editor-tip {
  display: block;
  font-size: 13px;
  max-height: 70px;
  overflow: auto;
}
.editing #editor {
  height: clamp(220px, 34dvh, 550px);
}

#guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
.editing #guide {
  display: none;
}
.code-focus #guide {
  display: none;
}
.stage-focus #guide {
  display: none;
}
/* Guided course shell: the full editor opens only for a purposeful exercise. */
#guide-copy {
  padding: 14px;
  background: #f5f8ff;
  border: 1px solid #d9e3f2;
  border-radius: 10px;
  margin: 12px 0;
}
#guide-label {
  font-size: 14px;
  color: #3373cc;
  font-weight: 700;
}
#guide-text {
  font-size: 19px;
  min-height: 64px;
  line-height: 1.8;
}
.course-guided:not(.editing) #workbench {
  display: none;
}
.course-guided:not(.editing)[data-phase="1"] #workbench {
  display: block;
}
.course-guided:not(.editing) .review {
  display: none;
}
.course-guided:not(.editing)[data-phase="3"] .review {
  display: block;
}
.course-guided:not(.editing) #workbench .tabs,
.course-guided:not(.editing) #workbench .edit-tools,
.course-guided:not(.editing) #workbench .sprites,
.course-guided:not(.editing) #workbench .stage-meta,
.course-guided:not(.editing) #workbench .star-controls,
.course-guided:not(.editing) #workbench .editor-tip,
.course-guided:not(.editing) #workbench .editor-panel > .toolbar {
  display: none;
}
.course-guided:not(.editing) #stage-focus {
  display: none;
}
.course-guided:not(.editing) #editor {
  height: 340px;
}
.course-guided:not(.editing) #workbench .desk {
  grid-template-columns: 1fr 1fr;
}
.course-guided:not(.editing) #feedback {
  font-size: 16px;
}
.editing .task {
  display: block;
  padding: 8px 12px;
  margin: 0;
  border-radius: 0;
}
.editing .task > * {
  display: none;
}
.editing .task #mission {
  display: block;
  margin: 0;
  font-size: 14px;
}
.editing #workbench {
  height: calc(100dvh - 68px);
}
.editing .lesson-controls {
  display: none;
}
.course-guided .lesson-controls #count {
  font-size: 12px;
}
.course-guided .lesson-controls #next {
  font-size: 14px;
}
.course-guided .lesson-controls #save-status {
  display: none;
}
@media (max-width: 700px) {
  .course-guided:not(.editing) #editor {
    height: 285px;
  }
  .course-guided:not(.editing) .demoheading {
    padding: 10px;
  }
  .course-guided:not(.editing) .task {
    margin-top: 8px;
  }
  #guide-text {
    font-size: 18px;
  }
  .editing #workbench {
    height: calc(100dvh - 80px);
  }
}
/* Keep the characters visible throughout the lesson; only the editor is gated. */
.course-guided:not(.editing) #workbench {
  display: block;
}
.course-guided:not(.editing):not([data-phase="1"]) #workbench {
  max-width: 600px;
  margin: 12px auto;
}
.course-guided:not(.editing):not([data-phase="1"]) #workbench .desk {
  display: block;
}
.course-guided:not(.editing):not([data-phase="1"]) #workbench .editor-panel,
.course-guided:not(.editing):not([data-phase="1"])
  #workbench
  .stage-panel
  > .toolbar {
  display: none;
}
.course-guided:not(.editing):not([data-phase="1"]) #workbench .stage-panel {
  border: 0;
}
.course-guided:not(.editing):not([data-phase="1"]) #workbench .stage-wrap {
  width: min(100%, 480px);
  margin: auto;
  aspect-ratio: 4/3;
}
/* v4.2: continuous lesson cards with an embedded Scratch practice block. */
.course-vertical {
  background: #f8f7f5;
  color: #303332;
}
.course-vertical main {
  max-width: 820px;
  padding-top: 28px;
}
.course-vertical header {
  background: #fff;
  color: #303332;
  border-bottom: 1px solid #e5e3df;
}
.course-vertical header a {
  color: #303332;
}
.course-vertical header button {
  color: #303332;
  border-color: #ddd;
}
.course-vertical .chapterbar {
  background: #f8f7f5;
}
.course-vertical .task,
.course-vertical .review,
.learning-card,
.course-vertical #workbench {
  background: white;
  border: 1px solid #e7e5e1;
  border-radius: 20px;
  padding: 24px;
  margin: 0 0 24px;
  box-shadow: 0 2px 4px #00000006;
}
.learning-card h2 {
  font-size: 23px;
  margin-top: 8px;
}
.learning-card p {
  line-height: 1.9;
}
.local-demo {
  padding: 20px;
  border-radius: 14px;
  background: #f8f8f8;
}
.block-preview {
  display: block;
  min-width: 220px;
  max-width: 100%;
  margin: auto;
  padding: 16px;
  border: 2px solid #d9e3f2;
}
.block-preview svg {
  display: block;
  width: 210px;
  max-width: 100%;
  height: 110px;
}
.block-preview[aria-expanded="true"] {
  border-color: #4c97ff;
}
.local-result svg {
  display: block;
  width: 100%;
  background: #eef5fb;
  border-radius: 12px;
  margin-top: 18px;
}
.local-caption {
  min-height: 70px;
  background: #eaf2ff;
  padding: 12px;
  border-radius: 10px;
}
.click-prompt {
  text-align: center;
  font-size: 15px;
}
.workbench-heading {
  padding: 4px 0 14px;
}
.course-vertical #workbench {
  padding: 18px;
  scroll-margin-top: 80px;
}
.course-vertical .desk {
  grid-template-columns: 1fr;
}
.course-vertical #editor {
  height: 360px;
}
.course-vertical .stage-wrap {
  max-width: 480px;
  margin: auto;
}
.course-vertical .lesson-controls {
  background: #fffffff2;
  border-top: 1px solid #e5e3df;
  padding: 8px;
}
.course-vertical #save-status {
  font-size: 12px;
}
.course-vertical [hidden] {
  display: none !important;
}
@media (max-width: 700px) {
  .course-vertical main {
    padding: 12px 10px 88px;
  }
  .course-vertical .task,
  .course-vertical .review,
  .learning-card {
    padding: 18px;
    border-radius: 16px;
  }
  .local-demo {
    padding: 12px;
  }
  .course-vertical #workbench {
    padding: 8px;
  }
  .course-vertical .chapterbar {
    flex-wrap: wrap;
  }
  .course-vertical #save-status {
    display: none;
  }
}
/* Native numeric inputs: Scratch white fields with dark text. */
.course-number-field > rect,
.course-number-field .blocklyFieldRect {
  fill: #ffffff !important;
  fill-opacity: 1 !important;
  stroke: #3373cc !important;
}
.course-number-field > text,
.course-number-field .blocklyText {
  fill: #575e75 !important;
}
.course-vertical .block-preview {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: 0;
  margin-bottom: 12px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #d9e3f2;
  border-radius: 10px;
}
.course-vertical .block-preview svg {
  width: 100%;
  height: 100%;
  max-width: none;
}
.course-vertical .block-preview .blocklySvg {
  position: absolute;
  inset: 0;
}
.field-help,
.pointer-help {
  font-size: 14px;
  color: #575e75;
}
#pointer-marker {
  position: absolute;
  left: 70%;
  top: 32%;
  width: 28px;
  height: 28px;
  margin: -14px;
  line-height: 28px;
  text-align: center;
  color: #172b35;
  background: #ffbf00;
  border: 2px solid white;
  border-radius: 50%;
  pointer-events: none;
}
#stage {
  touch-action: pan-y;
}
#audio-status {
  font-size: 14px;
  padding: 6px 10px;
  background: #f5e9f7;
  color: #663166;
}
.handoff {
  border-left: 4px solid #4c97ff;
}
.migration-banner {
  background: #fff3d2;
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
}
@media (max-width: 700px) {
  .course-vertical .local-demo {
    padding: 10px;
  }
  .course-vertical #prediction {
    flex-wrap: wrap;
  }
  .course-vertical #prediction button {
    max-width: 100%;
  }
}
/* Blockly computes dropdown coordinates in document space on a scrolling lesson. */
.blocklyDropDownDiv {
  position: absolute !important;
}
/* v5.1: local practice, compact controls and accessible task support */
.start-help {padding:16px;background:#eef5ff;border:1px solid #b8c9e5;border-radius:12px;margin-bottom:16px}
.start-help p {margin:5px 0 12px}
#challenges textarea {display:block;width:100%;box-sizing:border-box;font:inherit;margin:12px 0}
#challenge-select {max-width:100%;font:inherit;padding:12px}
#mission {display:none}
.field-help {font-size:14px}
.learning-card .replay {display:none}
.learning-card .pause-demo {font-size:14px;padding:8px}
#quick-play {margin:8px 0}
#locate-issue {margin:10px 0}
@media(min-width:761px){#compact-stage{display:none}}
@media(max-width:760px){
body.compact-practice #workbench .stage-panel {position:sticky;top:0;z-index:12;background:#fff;padding:8px;border-bottom:2px solid #b8c9e5}
body.compact-practice #workbench .stage-wrap {width:160px;margin:auto}
body.compact-practice #workbench .stage-panel .toolbar {gap:4px;flex-wrap:wrap}
body.compact-practice #workbench .stage-panel .toolbar button {padding:6px;min-height:36px;font-size:14px}
body.compact-practice #workbench .pointer-help,body.compact-practice #workbench .stage-meta,body.compact-practice #workbench .star-controls,body.compact-practice #workbench #audio-status {display:none}
body.compact-practice #workbench .stage-panel .sprites {margin:4px 0}
body.compact-practice #workbench .desk {overflow:visible;display:block}
body.compact-practice #workbench .editor-panel {position:relative}
.start-help button {margin-bottom:8px}
}

/* Learning routes and optional transfer challenge. */
.learning-start{margin:18px 0;padding:18px;border:1px solid #b8cbe0;border-radius:12px;background:#f4f8ff;color:#19344f;scroll-margin-top:100px}
.learning-start summary{cursor:pointer;min-height:44px;font-weight:700}
.learning-start p{line-height:1.8}.learning-start a{display:inline-block;min-height:44px;padding:8px 4px;color:#244f8a;text-underline-offset:4px}
.learning-start label{display:block;font-weight:650;margin-block:12px 8px}.learning-start textarea{box-sizing:border-box;width:100%;max-width:100%;font:inherit;padding:12px;color:#19344f;background:#fff;border:1px solid #6b85a0;border-radius:8px}
.learning-start :focus-visible{outline:3px solid #285eaa;outline-offset:3px}
@media print{#learning-start{display:none}.learning-start{break-inside:avoid;background:white;color:black}}

#teacher-note{white-space:pre-line}
