/* =========================================================
   Answer Library — 真實 Scratch 網站樣式
   配色 / 卡片 / 按鈕 / 表單 全部照 scratch.mit.edu CSS
   ========================================================= */

* { box-sizing: border-box; }

html, body, #app {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--scr-page-bg);
  color: var(--scr-text);
  font-family: "Helvetica Neue", "Helvetica", Arial, "Hiragino Sans", "Noto Sans TC", "Noto Sans SC", sans-serif;
  font-weight: normal;
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

::selection { background-color: var(--scr-selection-bg); }
button, input, textarea, select { font: inherit; color: var(--scr-text); }

a {
  color: var(--primary);
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
}
a:hover { color: var(--primary-hover); }

h1, h2, h3, h4, h5 {
  margin: 0;
  color: var(--scr-text);
  font-weight: bold;
  line-height: 1.5em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
h5 {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 0.85rem;
}

/* ================================================================
   覆寫 ui-master tokens（讓 .ui.button / .ui.field 也對齊）
   ================================================================ */
:root {
  --field-border-radius: 0.5rem;
  --field-height-base: 2.4;
  --field-border-width: 1px;
  --field-font-size: 0.875rem;
  --button-text-transform: none;
  /* 題名 — 解法名系列、Stage 頂列副文 */
  --answer-series-color: #0000ff;
}

/* ================================================================
   App shell — 固定 viewport
   ================================================================ */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  background: var(--scr-page-bg);
  overflow: hidden;
}

/* ================================================================
   Topbar — 真實 Scratch nav (#navigation 樣式)
   ================================================================ */
.app-topbar {
  flex: 0 0 auto;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1rem;
  background: linear-gradient(180deg, var(--scr-vars) 0%, var(--scr-vars-dark) 100%);
  color: #fff;
  border-bottom: 1px solid var(--scr-line);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.25);
  z-index: 10;
  position: relative;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  margin-right: 10px;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.25);
  margin: 0 12px;
}

.topbar-tabs { display: flex; gap: 0; height: 100%; }

.topbar-tab {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 0.85rem;
  font-weight: bold;
  padding: 0 15px;
  cursor: pointer;
  height: 100%;
  display: inline-flex;
  align-items: center;
}
.topbar-tab:hover { background-color: rgba(0, 0, 0, 0.1); }
.topbar-tab.active { background-color: rgba(0, 0, 0, 0.15); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 100%;
}

/* Topbar「🤖 Spec」— 版型對齊 palette-item；#e04e19 系；常駐淡外陰影（hover 不加重，見 a/spec/design-rules.md §2） */
.topbar-spec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border: 1px solid #b83a14;
  border-radius: 0.5rem;
  background: #e04e19;
  color: #fff;
  cursor: pointer;
  padding: 7px 11px;
  font-size: 0.8125rem;
  font-weight: bold;
  line-height: 1.3;
  text-align: center;
  font-family: inherit;
  transition: none;
  /* 破例：常駐淡淡外陰影（hover 與否皆同，不疊加更重陰影） */
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
}
.topbar-spec-btn:hover:not(:disabled) {
  background: #c84315;
  border-color: #9a3010;
  text-shadow: 0 1px 2px rgb(0 0 0 / 32%);
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
}
.topbar-spec-btn:active:not(:disabled) {
  outline: none;
  background: #c84315;
  border-color: #9a3010;
  box-shadow:
    0 1px 4px rgb(0 0 0 / 18%),
    inset 0 1px 3px rgb(0 0 0 / 14%);
  text-shadow: 0 1px 2px rgb(0 0 0 / 20%);
}
.topbar-spec-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ================================================================
   按鈕系統 — 真實 Scratch .button（平的，.5rem 圓角）
   ================================================================ */
.scr-btn {
  display: inline-block;
  margin: 0;
  border: 0;
  border-radius: 0.5rem;
  background-color: var(--primary);
  cursor: pointer;
  padding: 0.55em 1rem;
  color: #fff;
  font-size: 0.8rem;
  font-weight: bold;
  line-height: 1.2;
  transition: background-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  text-align: center;
  user-select: none;
}
.scr-btn:hover:not(:disabled) { background-color: var(--primary-hover); }
.scr-btn:active:not(:disabled) { background-color: var(--primary-focus); }
.scr-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 變體（照真實 Scratch .button.white / .pass / .fail） */
.scr-btn.scr-white { background-color: #fff; color: var(--primary); border: 1px solid var(--scr-line); }
.scr-btn.scr-white:hover:not(:disabled) { background-color: hsl(0, 0%, 97%); }

.scr-btn.scr-green { background-color: var(--success-strong); }
.scr-btn.scr-green:hover:not(:disabled) { background-color: var(--success-strong-hover); }

.scr-btn.scr-red { background-color: var(--error); }
.scr-btn.scr-red:hover:not(:disabled) { background-color: #b53800; }

.scr-btn.scr-orange { background-color: var(--warning); }
.scr-btn.scr-orange:hover:not(:disabled) { background-color: hsl(38, 100%, 48%); }

.scr-btn.scr-blue { background-color: var(--info); }
.scr-btn.scr-blue:hover:not(:disabled) { background-color: hsl(215, 100%, 55%); }

.scr-btn.scr-pink { background-color: var(--scr-myblocks); }
.scr-btn.scr-pink:hover:not(:disabled) { background-color: var(--scr-myblocks-dark); }

.scr-btn.scr-transparent {
  background-color: transparent;
  color: var(--primary);
}
.scr-btn.scr-transparent:hover:not(:disabled) { background-color: rgba(0, 0, 0, 0.06); }

/* 尺寸 */
.scr-btn.scr-tiny { padding: 0.35em 0.7rem; font-size: 0.72rem; }
.scr-btn.scr-large { padding: 0.75rem 1.25rem 0.8125rem; font-size: 1rem; border-radius: 0.25rem; }
.scr-btn.scr-round {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
}
.scr-btn.scr-round.scr-tiny { width: 26px; height: 26px; font-size: 11px; }

/* 也覆寫 ui-master .ui.button */
.ui.button {
  border-radius: 0.5rem;
  font-weight: bold;
  text-transform: none;
  padding: 0.55em 1rem !important;
  cursor: pointer;
}

/* ================================================================
   App body — 左：分類條 | 右：可拖曳三欄（palette · scripts · stage）
   ================================================================ */
.app-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  min-height: 0;
  background: var(--scr-page-bg);
}

.workspace-panels {
  display: grid;
  grid-template-columns:
    var(--panel-palette-w, 252px)
    10px
    minmax(180px, 1fr)
    10px
    var(--panel-stage-w, 400px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.workspace-panels > .palette,
.workspace-panels > .scripts,
.workspace-panels > .stage {
  min-width: 0;
}

/* 拖曳分隔條：預設透明；hover／拖曳時 #fff587 緊貼「該條實際分界」— palette 條貼左（palette 側），stage 條貼右（stage 側），避免一側空白 */
.resize-gutter {
  position: relative;
  z-index: 2;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  background: transparent;
  border: none;
  margin: 0;
}
.resize-gutter--palette:hover,
html[data-panel-resize="palette"] .resize-gutter--palette {
  background: linear-gradient(to right, #fff587 0, #fff587 4px, transparent 4px);
  background-repeat: no-repeat;
}
.resize-gutter--stage:hover,
html[data-panel-resize="stage"] .resize-gutter--stage {
  background: linear-gradient(to left, #fff587 0, #fff587 4px, transparent 4px);
  background-repeat: no-repeat;
}

/* ================================================================
   Category strip
   ================================================================ */
.category-strip {
  background: var(--scr-page-bg);
  border-right: 1px solid var(--scr-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 20px;
  overflow-y: auto;
}

.cat-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--scr-line);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  position: relative;
  padding: 0;
  transition: none;
  box-shadow: none;
}
/* hover：僅鈕面略暗一點，無外陰影、無邊框變色、無放大 */
.cat-btn:hover {
  transform: none;
  box-shadow: none;
}
.cat-btn:not(.active):hover {
  background: hsl(0, 0%, 94%);
  border-color: var(--scr-line);
}
.cat-btn.cat-problems.active:hover {
  background: hsl(214, 100%, 58%);
  border-color: var(--scr-motion-dark);
  color: #fff;
}
.cat-btn.cat-concepts.active:hover {
  background: hsl(351, 90%, 62%);
  border-color: var(--scr-myblocks-dark);
  color: #fff;
}
.cat-btn .cat-label {
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: bold;
  color: var(--scr-text-soft);
  white-space: nowrap;
  letter-spacing: 0.4px;
}
.cat-btn.cat-problems.active {
  background: var(--scr-motion);
  border-color: var(--scr-motion-dark);
  color: #fff;
}
.cat-btn.cat-concepts.active {
  background: var(--scr-myblocks);
  border-color: var(--scr-myblocks-dark);
  color: #fff;
}

/* ================================================================
   Palette — 保留積木感（這算 block editor）
   ================================================================ */
.palette {
  background: hsla(215, 100%, 65%, 0.04);
  border-right: 1px solid var(--scr-line);
  overflow-y: auto;
  padding: 12px 10px 30px;
}

.palette-title {
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--scr-text-soft);
  padding: 4px 4px 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--scr-line);
}

.palette-list { display: flex; flex-direction: column; gap: 5px; }

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  background: var(--scr-motion);
  color: #fff;
  border: 1px solid var(--scr-motion-dark);
  border-radius: 0.5rem;
  padding: 7px 11px;
  cursor: pointer;
  text-align: left;
  transition: none;
  box-shadow: none;
}
.palette-item:hover {
  background: var(--scr-motion-dark);
  box-shadow: 0 3px 10px rgb(0 0 0 / 22%);
}
.palette-item:hover .palette-item-title {
  text-shadow: 0 1px 2px rgb(0 0 0 / 32%);
}
.palette-item.active {
  outline: none;
  background: var(--scr-motion-dark);
  box-shadow: 0 2px 7px rgb(0 0 0 / 14%), inset 0 1px 3px rgb(0 0 0 / 14%);
}
.palette-item.active .palette-item-title {
  text-shadow: 0 1px 2px rgb(0 0 0 / 20%);
}
.palette-item.is-concept {
  background: var(--scr-myblocks);
  border-color: var(--scr-myblocks-dark);
}
.palette-item.is-concept:hover {
  background: var(--scr-myblocks-dark);
  box-shadow: 0 3px 10px rgb(0 0 0 / 22%);
}
.palette-item.is-concept:hover .palette-item-title {
  text-shadow: 0 1px 2px rgb(0 0 0 / 28%);
}
.palette-item.is-concept.active {
  outline: none;
  background: var(--scr-myblocks-dark);
  box-shadow: 0 2px 7px rgb(0 0 0 / 14%), inset 0 1px 3px rgb(0 0 0 / 16%);
}
.palette-item.is-concept.active .palette-item-title {
  text-shadow: 0 1px 2px rgb(0 0 0 / 18%);
}
.palette-item-title {
  font-weight: bold;
  font-size: 0.8125rem;
  line-height: 1.3;
}
.palette-item-meta {
  font-size: 0.625rem;
  color: hsla(0, 0%, 100%, 0.82);
  font-weight: 600;
  margin-top: 1px;
}

/* ================================================================
   Scripts area — 純向下滾動，不用 flex（避免子元素被 flex-shrink 壓扁）
   ================================================================ */
.scripts {
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  background: var(--scr-page-bg);
}
.scripts > * {
  margin-bottom: 1rem;
  flex-shrink: 0;
}
.scripts > *:last-child {
  margin-bottom: 0;
}

/* ================================================================
   Script block — 彩色 header strip + 白色 body（細邊、無 chunky shadow）
   ================================================================ */
.script-block {
  background-color: #fff;
  border: 1px solid var(--scr-callout-border);
  border-radius: var(--scr-callout-radius);
  padding: 0;
  overflow: visible;
}
.script-block-head {
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.72rem;
  font-weight: bold;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff;
  background-color: var(--block-head-color, var(--primary));
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--scr-callout-radius) var(--scr-callout-radius) 0 0;
}
.script-block-body {
  padding: 1.25rem;
  background-color: #fff;
  border-radius: 0 0 var(--scr-callout-radius) var(--scr-callout-radius);
}

/* === Hero：📘 Problem＝Motion 藍；💡 Card＝Concept（與左欄 CNCPT／紫卡統一 scr-myblocks）=== */
.hero-block--problem {
  --block-head-color: var(--scr-motion);
}
.hero-block--problem .script-block-head {
  color: #fff;
}
.hero-block--concept {
  --block-head-color: var(--scr-myblocks);
}
.hero-block--concept .script-block-head {
  color: #fff;
}
.hero-title {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 0 0.5rem;
  color: var(--scr-text);
  letter-spacing: -0.2px;
}
.hero-eyebrow {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ff0000;
  margin-bottom: 0.25rem;
}

/* === Examples（與原 One-liner 對調：Operators 綠系）=== */
.examples-block {
  --block-head-color: var(--success-strong);
  --examples-accent: var(--success-strong);
  --examples-label: hsl(144, 45%, 24%);
}
.examples-block .script-block-head {
  color: #fff;
}
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.625rem;
}
.example-card {
  background: #fff;
  border: 1px solid var(--scr-callout-border);
  border-left: 3px solid var(--examples-accent, var(--success-strong));
  border-radius: 0.375rem;
  padding: 0.625rem 0.75rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
}
.example-label {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: bold;
  font-size: 0.7rem;
  color: var(--examples-label, hsl(144, 45%, 24%));
  margin: 0 0 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.example-card p { margin: 0.25rem 0; }
.example-note {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 0.78rem;
  color: var(--scr-text-soft);
  border-top: 1px dashed var(--scr-line);
  padding-top: 0.375rem !important;
  margin-top: 0.375rem !important;
}

/* === Lead cards (PlainAsk / Intuition) === */
.lead-card {
  background: #fff;
  border: 1px solid var(--scr-callout-border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-top: 0.625rem;
  font-size: 0.9rem;
  line-height: 1.65;
}
.lead-card.plainask { border-left: 4px solid var(--scr-motion); }
.lead-card.intuition { border-left: 4px solid var(--scr-events); }
.lead-label {
  display: block;
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
  color: var(--scr-text-soft);
}
.lead-card.plainask .lead-label { color: var(--scr-motion-dark); }
.lead-card.intuition .lead-label { color: hsl(28, 80%, 38%); }

/* === Badges（題目 patterns／primary block；難度改見 .problem-difficulty-emoji）=== */
.badge-row { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.625rem; align-items: center; }
.badge-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 0.2rem 0.625rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.7);
  color: var(--scr-text);
  border: 1px solid var(--scr-callout-border);
  line-height: 1.4;
}
.badge-chip.primary-block {
  background: #ffadf8;
  color: hsl(312, 48%, 20%);
  border-color: #e078cf;
}

.problem-difficulty-emoji {
  font-size: 1.125rem;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
  cursor: default;
}

/* === Solution：依序 #00ddff / #00deb5 / #405cff（第四個起循環）=== */
.solution-block {
  --solution-head-base: var(--scr-looks);
  --block-head-color: var(--solution-head-base);
}
.solution-block--sol1 {
  --solution-head-base: #00ddff;
  --block-head-color: #00ddff;
}
.solution-block--sol2 {
  --solution-head-base: #00deb5;
  --block-head-color: #00deb5;
}
.solution-block--sol3 {
  --solution-head-base: #405cff;
  --block-head-color: #405cff;
}
.solution-block--sol1 .script-block-head,
.solution-block--sol2 .script-block-head {
  color: rgba(8, 22, 36, 0.94);
}
.solution-block--sol3 .script-block-head {
  color: #f0f7ff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.solution-block.is-active {
  border-color: var(--solution-head-base);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--solution-head-base) 35%, transparent);
}

.solution-pills {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 0.625rem;
  flex-wrap: wrap;
  align-items: center;
}
.solution-head-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.solution-tier-emoji {
  font-size: 1.125rem;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
  cursor: default;
}
.solution-tier-emoji--head {
  /* 標題列內仍為 tier 標記，略突出於旁邊大寫英文 */
  font-size: 1.2rem;
  line-height: 1;
}
.block-pill {
  display: inline-block;
  padding: 0.2rem 0.625rem;
  border-radius: 0.5rem;
  font-size: 0.7rem;
  font-weight: bold;
  line-height: 1.4;
  background: #ffadf8;
  color: hsl(312, 48%, 20%);
  border: 1px solid #e078cf;
}

.solution-set-active {
  margin-left: auto;
  display: inline-block;
  background-color: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 0.5rem;
  padding: 0.35em 0.75rem;
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.solution-set-active:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--solution-head-base, var(--primary)) 12%, #fff);
}
.solution-set-active.is-current {
  background-color: color-mix(in srgb, var(--solution-head-base, var(--success-strong)) 78%, #0a1620);
  color: #fff;
  border-color: color-mix(in srgb, var(--solution-head-base) 55%, #000000);
  cursor: default;
}

.solution-name {
  margin: 0 0 0.5rem;
  font-size: 1.0625rem;
  font-weight: bold;
  color: var(--answer-series-color);
}

.approach-text {
  background-color: hsla(35, 90%, 55%, 0.1);
  border: 1px solid var(--scr-callout-border);
  border-left: 3px solid var(--scr-events);
  border-radius: 0.375rem;
  padding: 0.625rem 0.875rem;
  margin: 0 0 0.875rem;
  font-size: 0.875rem;
  line-height: 1.6;
}
.approach-label {
  display: block;
  font-size: 0.7rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: hsl(28, 80%, 38%);
  margin-bottom: 0.25rem;
}

.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.module-block {
  background: #fff;
  border: 1px solid var(--scr-callout-border);
  border-left: 3px solid var(--scr-sensing);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.55;
}
.module-label {
  display: block;
  font-size: 0.7rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--scr-sensing-dark);
  margin-bottom: 0.25rem;
}

/* === Code block — 終端風深色底 + 高對比語法色 === */
.code-block {
  position: relative;
  margin-top: 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
  background: #1a1d23;
  color: #e6e9ef;
}
/* 右上角工具列：👁️（左）📋（右），無框無底；預設 60% / hover 90% / active 100% */
.code-block-tools {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 3;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
}
.code-block-tool-btn {
  margin: 0;
  padding: 2px;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
  transition: none;
  -webkit-tap-highlight-color: transparent;
}
.code-block-tool-btn:hover {
  opacity: 0.9;
}
.code-block-tool-btn:active {
  opacity: 1;
}
/* 隱藏註解模式開啟時：👁️ 維持完全不透明（標示狀態） */
.code-block.is-comments-hidden .code-block-toggle-comments.is-active,
.code-block.is-comments-hidden .code-block-toggle-comments.is-active:hover,
.code-block.is-comments-hidden .code-block-toggle-comments.is-active:active {
  opacity: 1;
}
.code-block-tool-btn:focus {
  outline: none;
}
.code-block-tool-btn:focus-visible {
  outline: 1px solid rgba(255, 255, 255, 0.35);
  outline-offset: 2px;
}
.code-block-pre {
  margin: 0;
  padding: 12px 14px;
  padding-right: 3.75rem;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}
.code-block-line {
  padding: 0 6px;
  white-space: pre;
}
.code-block-line.is-hl {
  background: rgba(255, 210, 72, 0.2);
  box-shadow: inset 3px 0 0 0 hsl(48, 100%, 54%);
}

/* Stage 內 code block 取消 margin-top（讓 stage-body 的 gap 接管） */
.stage-body > .code-block {
  margin-top: 0;
}

/* === 語法染色 tokens（終端／高對比；# 註解含「關鍵一行」等皆竹綠） ===
   CodeBlock 與 Mini IDE（Scratch Pad）共用選擇器，避免 overlay 無法繼承 .code-block 規則 */
.code-block .tok-keyword,
.mini-ide .tok-keyword  { color: hsl(277, 78%, 80%); font-weight: 700; }
.code-block .tok-builtin,
.mini-ide .tok-builtin  { color: hsl(191, 82%, 64%); }
.code-block .tok-type,
.mini-ide .tok-type     { color: hsl(46, 95%, 66%); font-weight: 600; }
.code-block .tok-string,
.mini-ide .tok-string   { color: hsl(100, 58%, 66%); }
.code-block .tok-number,
.mini-ide .tok-number   { color: hsl(24, 92%, 66%); }
.code-block .tok-comment,
.mini-ide .tok-comment  { color: hsl(152, 38%, 46%); font-style: italic; }
.code-block .tok-operator,
.mini-ide .tok-operator { color: hsl(350, 88%, 76%); }

/* 隱藏註解模式：不顯示 # 註解區塊（仍保留換行與縮排前的空白） */
.code-block.is-comments-hidden .tok-comment {
  display: none;
}

.complexity-row {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  margin-top: 0.625rem;
}
.complexity-pill {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 0.2rem 0.625rem;
  border-radius: 0.375rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--scr-callout-border);
  color: var(--scr-text-soft);
}

/* === Notes：🧠 Memory＝#ffb88a／⚠️ Mistakes＝#ff5b29 === */
.notes-twocol {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.notes-memory {
  --block-head-color: #ffb88a;
  --memory-accent: #ffb88a;
}
.notes-memory .script-block-head {
  color: hsl(18, 88%, 20%);
}
.notes-mistakes {
  --block-head-color: #ff5b29;
  --mistakes-accent: #ff5b29;
}
.notes-mistakes .script-block-head {
  color: #fff;
}

.note-line {
  background: #fff;
  border: 1px solid var(--scr-callout-border);
  border-left: 3px solid var(--scr-callout-border);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 0.375rem 0;
}
.notes-memory .note-line {
  border-left-color: var(--memory-accent, #ffb88a);
}
.notes-mistakes .note-line.is-mistake {
  border-left-color: var(--mistakes-accent, #ff5b29);
}

/* === One-liner（與原 Examples 對調：#ccff00 系）=== */
.oneliner-bar {
  background-color: hsla(72, 100%, 50%, 0.14);
  border: 1px solid var(--scr-callout-border);
  border-left: 4px solid #ccff00;
  border-radius: 0.5rem;
  padding: 0.875rem 1.125rem;
  display: flex;
  gap: 0.875rem;
  align-items: center;
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--scr-text);
  flex-wrap: wrap;
}
.oneliner-label {
  background: #ccff00;
  color: hsl(0, 0%, 12%);
  border-radius: 0.375rem;
  padding: 0.2rem 0.625rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* --- 區塊 hover：約 3% 壓暗底色（無 transition、無外／內陰影） --- */
.script-block:hover .script-block-head {
  background-color: color-mix(in srgb, var(--block-head-color, var(--primary)) 97%, #000000 3%);
}
.script-block:hover .script-block-body {
  background-color: color-mix(in srgb, #ffffff 97%, #000000 3%);
}

.lead-card:hover,
.example-card:hover,
.module-block:hover,
.note-line:hover,
.tracer-counter:hover {
  background-color: color-mix(in srgb, #ffffff 97%, #000000 3%);
}

.complexity-pill:hover {
  background-color: color-mix(in srgb, rgba(255, 255, 255, 0.7) 97%, #000000 3%);
}

.oneliner-bar:hover {
  background-color: color-mix(in srgb, hsla(72, 100%, 50%, 0.14) 97%, #000000 3%);
}

.approach-text:hover {
  background-color: color-mix(in srgb, hsla(35, 90%, 55%, 0.1) 97%, #000000 3%);
}

.tracer-controls:hover {
  background-color: color-mix(in srgb, var(--scr-callout-bg) 97%, #000000 3%);
}

.tracer-label:hover {
  background-color: color-mix(in srgb, var(--scr-events) 97%, #000000 3%);
}

.tracer-state:hover {
  background-color: color-mix(in srgb, var(--scr-callout-bg) 97%, #000000 3%);
}
.tracer-state:hover .tracer-state-head {
  background-color: color-mix(in srgb, var(--tracer-state-head-bg, #2ae600) 92%, #000000 8%);
}
.tracer-state:hover .tracer-state-body {
  background-color: color-mix(in srgb, #ffffff 97%, #000000 3%);
}

.tracer-action:hover {
  background-color: color-mix(in srgb, hsla(196, 60%, 60%, 0.18) 97%, #000000 3%);
}

.tracer-note:hover {
  background-color: color-mix(in srgb, hsla(35, 90%, 55%, 0.1) 97%, #000000 3%);
}

.badge-chip:hover {
  background-color: color-mix(in srgb, rgba(255, 255, 255, 0.7) 97%, #000000 3%);
}
.badge-chip.primary-block:hover {
  background-color: color-mix(in srgb, #ffadf8 97%, #000000 3%);
}

.block-pill:hover {
  background-color: color-mix(in srgb, #ffadf8 97%, #000000 3%);
}

.code-block:hover {
  background-color: color-mix(in srgb, #1a1d23 97%, #000000 3%);
}

/* ================================================================
   Stage
   ================================================================ */
.stage {
  /* Step Tracer 與頂列標題用：略偏靛的藍字，避開中欄 sol3 #405cff 與純 #00f */
  --stage-series-color: hsl(228, 100%, 34%);
  background: #fff;
  border-left: 1px solid var(--scr-line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* 為 viewport 固定的 .stage-headline-bar 預留垂直空間（長標題換行） */
  padding-top: 5.5rem;
}

/* 🎬 + 題名 — 解法名：自橘色全寬條改為獨立懸浮列，固定於視窗頂（topbar 下）、寬度對齊 Stage 欄 */
.stage-headline-bar {
  position: fixed;
  top: 50px;
  right: 0;
  width: var(--panel-stage-w, 400px);
  max-width: 100vw;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  z-index: 9;
  background: hsla(0, 0%, 100%, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--scr-line);
  border-left: 1px solid var(--scr-line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.stage-headline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  row-gap: 0.25rem;
}
.stage-headline-icon {
  font-size: 1.85rem;
  line-height: 1;
  flex-shrink: 0;
}
.stage-headline-text {
  font-size: 0.925rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--stage-series-color, var(--answer-series-color));
  letter-spacing: -0.02em;
  min-width: 0;
}
.stage-empty {
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--scr-text-soft);
  font-size: 0.875rem;
  line-height: 1.65;
}
.stage-empty:hover {
  background-color: color-mix(in srgb, var(--scr-page-bg) 97%, #000000 3%);
}

.stage-body {
  flex: 1 1 auto;
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tracer-controls {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
  padding: 0.625rem;
  background-color: var(--scr-callout-bg);
  border: 1px solid var(--scr-callout-border);
  border-radius: 0.5rem;
}

/* Stage Step Tracer：emoji 控制鈕（無框、略大於 code-block 工具鈕） */
.tracer-ctrl-btn {
  margin: 0;
  padding: 0px 4px 0px 0px;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  color: inherit;
  opacity: 0.72;
  transition: none;
  -webkit-tap-highlight-color: transparent;
}
.tracer-ctrl-btn:hover:not(:disabled) {
  opacity: 0.95;
}
.tracer-ctrl-btn:active:not(:disabled) {
  opacity: 1;
}
.tracer-ctrl-btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}
.tracer-ctrl-btn.is-playing {
  opacity: 1;
}
.tracer-ctrl-btn:focus {
  outline: none;
}
.tracer-ctrl-btn:focus-visible {
  outline: 1px solid rgba(0, 0, 0, 0.28);
  outline-offset: 2px;
  border-radius: 0.25rem;
}

.tracer-progress {
  flex: 1 1 100%;
  order: 99;
  min-width: 0;
  padding: 0 0.25rem;
}
.tracer-slider {
  width: 100%;
  accent-color: var(--primary);
}
.tracer-counter {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
  background: #fff;
  border: 1px solid var(--scr-callout-border);
  color: var(--scr-text);
}

.tracer-label {
  background: var(--scr-events);
  color: hsl(28, 90%, 22%);
  border: 1px solid hsl(45, 100%, 40%);
  border-radius: 0.5rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-weight: bold;
}


.tracer-state {
  --tracer-state-head-bg: #2ae600;
  --tracer-state-key: hsl(118, 90%, 22%);
  background-color: var(--scr-callout-bg);
  border: 1px solid var(--scr-callout-border);
  border-radius: 0.5rem;
  padding: 0;
  overflow: hidden;
}
.tracer-state-head {
  padding: 0.4rem 0.875rem;
  background-color: var(--tracer-state-head-bg);
  color: #fff;
  font-size: 0.65rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.tracer-state-body {
  background: #fff;
  padding: 0.5rem 0.875rem;
}
.tracer-state table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
}
.tracer-state td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px dashed var(--scr-line);
  vertical-align: top;
}
.tracer-state tr:last-child td { border-bottom: 0; }
.tracer-state td:first-child {
  color: var(--tracer-state-key);
  font-weight: bold;
  white-space: nowrap;
  max-width: 130px;
}
.tracer-state td:last-child { word-break: break-word; color: var(--scr-text); }

.tracer-action {
  background-color: hsla(196, 60%, 60%, 0.18);
  color: var(--scr-text);
  border: 1px solid var(--scr-callout-border);
  border-left: 4px solid var(--scr-sensing);
  border-radius: 0.5rem;
  padding: 0.625rem 0.875rem;
  font-weight: bold;
  font-size: 0.875rem;
  line-height: 1.55;
}

.tracer-note {
  background-color: hsla(35, 90%, 55%, 0.1);
  border: 1px solid var(--scr-callout-border);
  border-radius: 0.5rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.83rem;
  line-height: 1.65;
}
.tracer-note::before { content: "💡 "; margin-right: 2px; }

/* Stage 內 tracer：色票略偏移，避免與左欄 Motion 藍、中欄 Events 黃／Approach 淺橘／解法 sol1–3 過度重疊 */
.stage .tracer-controls {
  background-color: hsla(218, 72%, 58%, 0.09);
  border-color: hsla(218, 35%, 48%, 0.16);
}
.stage .tracer-slider {
  accent-color: hsl(201, 78%, 40%);
}
.stage .tracer-label {
  background: hsl(48, 100%, 52%);
  color: hsl(26, 92%, 20%);
  border-color: hsl(36, 92%, 42%);
}
.stage .tracer-state-head {
  background-color: var(--tracer-state-head-bg, #2ae600);
  color: #fff;
}
.stage .tracer-state td:first-child {
  color: var(--tracer-state-key, hsl(118, 90%, 22%));
}
.stage .tracer-action {
  background-color: hsla(203, 55%, 52%, 0.14);
  border-left-color: hsl(203, 58%, 46%);
}
.stage .tracer-note {
  background-color: hsla(28, 82%, 54%, 0.09);
  border-color: hsla(28, 40%, 45%, 0.14);
}

/* ================================================================
   Spec Modal — 外殼對齊 Scratch Pad；內容區為白底 + 藍系字（非代碼框終端風）
   ================================================================ */
.spec-modal-backdrop {
    position: fixed;
  inset: 0;
  background-color: hsla(215, 100%, 65%, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 510;
}
.spec-modal {
  position: relative;
  margin: 0;
  border-radius: 0.6rem;
  border: 2px solid var(--scr-vars, hsl(28, 100%, 55%));
  box-shadow: 0 14px 40px rgb(0 0 0 / 22%);
  background-color: var(--scr-page-bg, #fff);
  padding: 0;
  width: min(52rem, 100%);
  max-height: min(90vh, 940px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  transition: none;
}
.spec-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
  padding: 6px 10px;
  background: linear-gradient(
    180deg,
    var(--scr-vars, hsl(28, 100%, 55%)) 0%,
    var(--scr-vars-dark, hsl(28, 100%, 43%)) 100%
  );
  color: #fff;
  border-radius: 0.55rem 0.55rem 0 0;
  border-bottom: 1px solid hsl(28, 100%, 40%);
  user-select: none;
}
.spec-modal-title {
  flex: 1 1 auto;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #fff;
  text-shadow: 0 1px 0 rgb(0 0 0 / 18%);
}
.spec-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}
/* Spec Modal：↩️／📋 懸浮於白底編輯區右上角（不佔流、不擠壓 textarea 換行寬） */
.spec-modal-editor {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.spec-modal-editor .code-block-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  z-index: 4;
  margin: 0;
}
/* 白底上略調字色／focus ring，其餘同 .code-block-tool-btn */
.spec-modal-editor .code-block-tool-btn {
  color: hsl(240, 55%, 38%);
  opacity: 0.65;
}
.spec-modal-editor .code-block-tool-btn:hover {
  opacity: 0.95;
}
.spec-modal-editor .code-block-tool-btn:active {
  opacity: 1;
}
.spec-modal-editor .code-block-tool-btn:focus-visible {
  outline: 1px solid rgba(0, 0, 255, 0.4);
  outline-offset: 2px;
}
.spec-textarea {
  flex: 1 1 auto;
  box-sizing: border-box;
  width: 100%;
  min-height: min(52vh, 480px);
  margin: 0;
  padding: 12px 14px;
  /* 工具列懸浮頂右：預留頂高即可；勿用大 padding-right 否則窄螢 pre-wrap 會被擠成細欄 */
  padding-top: 2.75rem;
  resize: vertical;
  background: #fff;
  border: 0;
  border-radius: 0;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  letter-spacing: 0;
  color: #0000ff;
  caret-color: #0000dd;
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre;
  overflow: auto;
}
.spec-textarea:focus {
  outline: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 255, 0.28);
}
.spec-textarea::selection {
  background: rgba(0, 0, 255, 0.16);
}

/* ================================================================
   Input (真實 Scratch .input)
   ================================================================ */
.scr-input {
  border: 1px solid var(--scr-callout-border);
  border-radius: var(--scr-input-radius);
  background-color: var(--scr-input-bg);
  padding: 0 1rem;
  height: 3rem;
  color: var(--scr-text);
  font-size: 0.875rem;
  transition: border 0.25s ease;
}
.scr-input:focus { outline: none; border: 1px solid var(--primary); }

/* ================================================================
   Mobile
   ================================================================ */
.mobile-tabs { display: none; }

@media (max-width: 1120px) and (min-width: 961px) {
  .workspace-panels {
    grid-template-columns: var(--panel-palette-w, 220px) 10px minmax(0, 1fr);
  }
  .resize-gutter--stage,
  .workspace-panels > .stage {
    display: none !important;
  }
}

@media (max-width: 960px) {
  /* 視窗高度含行動瀏覽器 UI；避免整頁被裁切 */
  .app-shell {
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
  }
  .app-shell--mobile .app-topbar {
    padding-left: max(0.625rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.625rem, env(safe-area-inset-right, 0px));
  }

  .app-topbar { height: 44px; padding: 0 0.625rem; gap: 0.375rem; flex-shrink: 0; }
  .topbar-tab { font-size: 0.72rem; padding: 0 0.625rem; }
  .topbar-sep { margin: 0 8px; }
  .topbar-right {
    min-width: 0;
    flex-shrink: 1;
    gap: 6px;
  }
  /* 移動版禁用 Pad（按鈕仍由 JS 不渲染；此為保險） */
  .topbar-pad-btn {
    display: none !important;
  }

  /* 行動 Stage：標題 sticky（捲動區頂）；避免 fixed + top 含 safe-area 與 44px topbar 錯位造成空白 */
  .stage.mobile-open .stage-headline-bar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    border-left: none;
    border-bottom: none;
    box-shadow: none;
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  }

  .app-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  .workspace-panels {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
  }

  .workspace-panels .resize-gutter {
    display: none !important;
  }

  .category-strip,
  .workspace-panels .palette,
  .workspace-panels .scripts,
  .workspace-panels .stage {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    height: 100%;
    border: 0;
    border-top: 1px solid var(--scr-line);
    display: none;
  }
  /* Read／Stage：直向堆疊 + 單欄捲動，避免誤用預設 flex-row 造成區塊橫排溢出 */
  .workspace-panels .scripts.mobile-open,
  .workspace-panels .stage.mobile-open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(3.35rem + env(safe-area-inset-bottom, 0px));
  }

  /* 行動 Stage：標題改 sticky 佔排版高度，勿再沿用桌機為 fixed 預留的 5.5rem */
  .workspace-panels .stage.mobile-open {
    padding-top: 0;
  }

  .workspace-panels .palette.mobile-open {
    display: block;
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.625rem 0.5rem;
    padding-bottom: calc(3.35rem + env(safe-area-inset-bottom, 0px));
    /* List 分頁：緊貼上方 PROBS／CNPT 列，不要多一道頂線 */
    border-top: none;
  }

  /* List（行動）：兩顆圓鈕橫排置中；列底不畫線、不投影（題單緊貼其下） */
  .category-strip.mobile-open {
    flex-direction: row;
    height: auto;
    padding: 0.625rem 0.75rem 1.125rem;
    gap: 1.375rem;
    flex: 0 0 auto;
    overflow-x: auto;
    overflow-y: visible;
    justify-content: center;
    align-items: flex-start;
    display: flex;
    width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
  }

  .category-strip.mobile-open .cat-btn {
    flex-shrink: 0;
  }

  .mobile-tabs {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    flex: 0 0 auto;
    /* 與桌機拖曳 gutter 同色 #fff587，約 80% 透明度 */
    background: rgba(255, 245, 135, 0.8);
    background: color-mix(in srgb, #fff587 80%, transparent);
    border-top: 1px solid rgba(180, 150, 40, 0.45);
    border-top: 1px solid color-mix(in srgb, #c9a400 55%, transparent);
    box-shadow: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translate3d(0, 0, 0);
    transition: transform 0.14s ease-out;
    will-change: transform;
  }
  .mobile-tabs.mobile-tabs--hidden {
    transform: translate3d(0, calc(100% + 2px), 0);
    pointer-events: none;
  }
  .mobile-tab {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: transparent;
    border: 0;
    border-top: 3px solid transparent;
    padding: 0.55rem 0.35rem;
    font-size: 0;
    font-weight: bold;
    color: hsla(26, 30%, 26%, 0.88);
    cursor: pointer;
    min-width: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-tab.active {
    border-top-color: hsl(28, 100%, 38%);
    color: hsl(28, 100%, 32%);
  }
  .mobile-tab .mobile-tab-icon {
    display: block;
    font-size: 1.85rem;
    line-height: 1;
    margin: 0;
  }

  .hero-title { font-size: 1.25rem; }
  .notes-twocol { grid-template-columns: 1fr; }
  .modules-grid { grid-template-columns: 1fr; }
  .examples-grid { grid-template-columns: 1fr; }
  .scripts {
    padding: 0.625rem;
    gap: 0.625rem;
    max-width: 100%;
  }
  .scripts.mobile-open .script-block {
    min-width: 0;
    max-width: 100%;
  }
  .scripts.mobile-open .script-block-body {
    min-width: 0;
    overflow-x: auto;
  }

  /* 行動版：題解 Read／Stage 內等寬代碼字級略縮（不影響桌機） */
  .scripts.mobile-open .code-block-pre,
  .scripts.mobile-open .example-card,
  .stage.mobile-open .code-block-pre,
  .stage.mobile-open .tracer-state table {
    font-size: 0.72rem;
  }
  .scripts.mobile-open .code-block-tool-btn,
  .stage.mobile-open .code-block-tool-btn {
    font-size: 0.9rem;
  }
  .stage.mobile-open .tracer-counter {
    font-size: 0.65rem;
  }
  .stage.mobile-open .tracer-label {
    font-size: 0.78rem;
  }
  .stage.mobile-open .tracer-action {
    font-size: 0.8rem;
  }
  .stage.mobile-open .tracer-note {
    font-size: 0.76rem;
  }
  .stage.mobile-open .tracer-state-head {
    font-size: 0.6rem;
  }

  /* 行動版：教練 Prompt 白板可換行，避免長行／無空白字串撐出橫向 overflow */
  .spec-modal {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .spec-modal-body,
  .spec-modal-editor {
    min-width: 0;
  }
  .spec-textarea {
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-wrap: break-word;
    max-width: 100%;
    min-width: 0;
    padding-top: 2.5rem;
  }
}

/* =========================================================
   Topbar「🛠️ Pad」按鈕（Scratch Pad 觸發）
   對齊 design-rules：transition: none、常駐淡淡外陰影、.5rem 圓角
   ========================================================= */
.topbar-pad-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid hsl(120, 50%, 30%);
  background: var(--scr-operators, hsl(120, 45%, 56%));
  color: #fff;
  font-weight: bold;
  font-size: 0.78rem;
  padding: 7px 11px;
  border-radius: 0.5rem;
  cursor: pointer;
  user-select: none;
  margin-right: 6px;
  transition: none;
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
}
.topbar-pad-btn:hover {
  background: hsl(120, 45%, 45%);
  border-color: hsl(120, 50%, 25%);
  text-shadow: 0 1px 0 rgb(0 0 0 / 20%);
}
.topbar-pad-btn:active,
.topbar-pad-btn.is-active {
  background: hsl(120, 45%, 38%);
  border-color: hsl(120, 50%, 22%);
  box-shadow:
    0 1px 4px rgb(0 0 0 / 18%),
    inset 0 1px 2px rgb(0 0 0 / 35%);
}

/* =========================================================
   Floating Scratch Pad — 可拖曳 / resize / 收合 浮動視窗
   ========================================================= */
.scratchpad-window {
    position: fixed;
  z-index: 80;
  display: flex;
  flex-direction: column;
  min-width: 300px;
  min-height: 64px;
  max-width: 95vw;
  max-height: 95vh;
  background: var(--scr-page-bg, #fff);
  border: 2px solid var(--scr-vars, hsl(28, 100%, 55%));
  border-radius: 0.6rem;
  box-shadow: 0 14px 40px rgb(0 0 0 / 22%);
  overflow: hidden;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  /* drag 應立刻反應，整個 window 不要任何 transition */
  transition: none;
}
.scratchpad-window.is-minimized {
  height: auto !important;
}

.scratchpad-header {
    display: flex;
    align-items: center;
  gap: 8px;
  background: linear-gradient(
    180deg,
    var(--scr-vars, hsl(28, 100%, 55%)) 0%,
    var(--scr-vars-dark, hsl(28, 100%, 43%)) 100%
  );
  color: #fff;
  padding: 6px 10px;
  cursor: move;
  user-select: none;
  border-bottom: 1px solid hsl(28, 100%, 40%);
  transition: none;
  flex: 0 0 auto;
}
.scratchpad-grip {
  font-size: 0.95rem;
  opacity: 0.85;
  letter-spacing: -1px;
  cursor: move;
}
.scratchpad-title {
  flex: 1 1 auto;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 0 rgb(0 0 0 / 18%);
}

.scratchpad-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgb(0 0 0 / 22%);
  background: rgb(255 255 255 / 22%);
  color: #fff;
  border-radius: 0.4rem;
  font-size: 0.7rem;
  font-weight: bold;
  cursor: pointer;
  transition: none;
  padding: 0;
}
.scratchpad-header-btn:hover {
  background: rgb(255 255 255 / 35%);
}
.scratchpad-header-btn:active {
  background: rgb(0 0 0 / 18%);
  border-color: rgb(0 0 0 / 32%);
}
.scratchpad-header-btn.scratchpad-close:hover {
  background: var(--scr-lists, hsl(20, 100%, 55%));
  border-color: hsl(20, 100%, 38%);
}

.scratchpad-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #282c34;
  position: relative; /* 讓 .scratchpad-tools 用 absolute 定位 */
}

/* 編輯器工具列：右上 🧹🔫、左下對角 📸⏱️（6px／8px 與原右上角相同，僅錨點對調）
   對齊 .code-block-tools 的設計：無框透明、opacity 0.6→0.9→1.0、transition: none */
.scratchpad-tools {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  pointer-events: none; /* 整個容器不擋 editor 滑鼠事件 */
}
.scratchpad-tools--tr {
  top: 6px;
  right: 8px;
}
.scratchpad-tools--bl {
  bottom: 6px;
  left: 8px;
}
.scratchpad-tool-btn {
  margin: 0;
  padding: 2px;
  border: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
  transition: none;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto; /* 只有按鈕本身收 click */
}
.scratchpad-tool-btn:hover {
  opacity: 0.9;
}
.scratchpad-tool-btn:active {
  opacity: 1;
}
.scratchpad-tool-btn:focus {
  outline: none;
}
.scratchpad-tool-btn:focus-visible {
  outline: 1px solid rgba(255, 255, 255, 0.35);
  outline-offset: 2px;
}

/* ===========================================================
   Mini-IDE：textarea + 同步染色 overlay
   兩層位置 / 字體 / padding / line-height 必須完全對齊
   =========================================================== */
.mini-ide {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #282c34;
  color: #abb2bf;
}

/* 兩層共用的字體 / 間距規格 — 不要在子層覆寫 */
.mini-ide-overlay,
.mini-ide-textarea {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  box-sizing: border-box;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
  line-height: 1.55;
    letter-spacing: 0;
  white-space: pre;
  tab-size: 4;
  -moz-tab-size: 4;
  overflow: auto;
}

/* 染色 overlay：在下層、不收事件 */
.mini-ide-overlay {
  z-index: 1;
  color: #abb2bf;
  background: transparent;
  pointer-events: none;
}
.mini-ide-line {
  display: block;
  white-space: pre;
}
.mini-ide-empty {
  display: inline-block;
  width: 1px;
}

/* textarea：在上層、字色透明、caret 白色 */
.mini-ide-textarea {
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: #fff;
  -webkit-text-fill-color: transparent;
  outline: none;
  resize: none;
}
/* 選取色（看得到反白但又不蓋掉下層染色） */
.mini-ide-textarea::selection {
  background: rgba(255, 255, 255, 0.18);
}
.mini-ide-textarea::placeholder {
  color: hsl(220, 14%, 55%);
  -webkit-text-fill-color: hsl(220, 14%, 55%);
}
/* Firefox：上面的 -webkit-text-fill-color 失效時兜底 */
@-moz-document url-prefix() {
  .mini-ide-textarea {
    color: transparent;
  }
}

/* 右下角 resize 把手 — 用斜線視覺，不要 transition */
.scratchpad-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  background:
    linear-gradient(
      135deg,
      transparent 0%,
      transparent 35%,
      rgb(255 255 255 / 35%) 35%,
      rgb(255 255 255 / 35%) 42%,
      transparent 42%,
      transparent 55%,
      rgb(255 255 255 / 35%) 55%,
      rgb(255 255 255 / 35%) 62%,
      transparent 62%,
      transparent 75%,
      rgb(255 255 255 / 35%) 75%,
      rgb(255 255 255 / 35%) 82%,
      transparent 82%
    );
  transition: none;
}
.scratchpad-resize-handle:hover {
  background:
    linear-gradient(
      135deg,
      transparent 0%,
      transparent 35%,
      var(--scr-events, hsl(45, 100%, 50%)) 35%,
      var(--scr-events, hsl(45, 100%, 50%)) 42%,
      transparent 42%,
      transparent 55%,
      var(--scr-events, hsl(45, 100%, 50%)) 55%,
      var(--scr-events, hsl(45, 100%, 50%)) 62%,
      transparent 62%,
      transparent 75%,
      var(--scr-events, hsl(45, 100%, 50%)) 75%,
      var(--scr-events, hsl(45, 100%, 50%)) 82%,
      transparent 82%
    );
}

/* 收合狀態下不顯示 body 和 resize handle —— JS 已不 render，這裡 belt-and-suspenders */
.scratchpad-window.is-minimized .scratchpad-body,
.scratchpad-window.is-minimized .scratchpad-resize-handle {
    display: none;
  }

/* =========================================================
   先禁用、僅保留設計代碼：Scratch Pad 底欄分區（.scratchpad-status + counter + 底列 history 靠右 + tag 群）
   走 icon 流、頂部一排 emoji（📸 右側 ⏱️），故不再與底欄分區；開回時取消本段註解 + answerMain 內對應 JSX。
   =========================================================
.scratchpad-status {
  flex: 0 0 auto;
    display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #1f2329;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: hsl(220, 14%, 65%);
  font-size: 0.7rem;
  font-weight: 600;
  user-select: none;
}

.scratchpad-counter {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: hsl(220, 14%, 60%);
  letter-spacing: 0;
    white-space: nowrap;
}

.scratchpad-tool-btn.scratchpad-history-toggle {
  margin-left: auto;
}
.scratchpad-tool-btn.scratchpad-history-toggle.is-active {
  opacity: 1;
}

.scratchpad-tags {
  display: flex;
  align-items: center;
  gap: 2px;
}
.scratchpad-tag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 24px;
  border: 0;
  background: transparent;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 0.3rem;
  padding: 0;
  transition: none;
  opacity: 0.65;
  line-height: 1;
}
.scratchpad-tag-btn:hover:not(:disabled) {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}
.scratchpad-tag-btn:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
}
.scratchpad-tag-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
.scratchpad-tag-pass:hover:not(:disabled) {
  background: hsla(144, 45%, 36%, 0.3);
}
.scratchpad-tag-bug:hover:not(:disabled) {
  background: hsla(38, 100%, 55%, 0.28);
}
.scratchpad-tag-stuck:hover:not(:disabled) {
  background: hsla(0, 70%, 55%, 0.28);
}
   ========================================================= */

/* =========================================================
   Toast（右下角浮現 2.5s）
   - 不用 transform 動畫，避免拖曳/resize 時抖動感
   - 純色 + 邊框，符合 design-rules 即時感
   ========================================================= */
.scratchpad-toast {
  position: absolute;
  right: 12px;
  bottom: 10px; /* 底欄 .scratchpad-status 已關，無需再抬高 */
  z-index: 5;
  max-width: 80%;
  padding: 6px 10px;
  border-radius: 0.4rem;
  font-size: 0.72rem;
  font-weight: bold;
  background: #2f3640;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scratchpad-toast-ok {
  background: linear-gradient(180deg, hsl(144, 45%, 30%) 0%, hsl(144, 45%, 22%) 100%);
  border-color: hsl(144, 45%, 40%);
}
.scratchpad-toast-warn {
  background: linear-gradient(180deg, hsl(28, 80%, 36%) 0%, hsl(28, 80%, 28%) 100%);
  border-color: hsl(28, 80%, 50%);
}

/* =========================================================
   📸 History View — 快照列表
   ========================================================= */
.scratchpad-history {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #1a1d23;
  color: #d6dae0;
}
.scratchpad-history-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #232730;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: bold;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
}
.scratchpad-history-title {
  color: var(--scr-events, hsl(45, 100%, 60%));
}
/* 頂列 ↩️：無框 emoji，同 .scratchpad-tool-btn */
.scratchpad-history-head .scratchpad-tool-btn.scratchpad-history-back {
  flex-shrink: 0;
}

.scratchpad-history-empty {
  padding: 24px 16px;
  text-align: center;
  color: hsl(220, 14%, 55%);
  font-size: 0.78rem;
  line-height: 1.6;
}

.scratchpad-history-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.scratchpad-history-item {
  background: #262a33;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0.4rem;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
}
.scratchpad-history-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: hsl(220, 14%, 65%);
}
.scratchpad-history-time {
  font-weight: bold;
  color: #fff;
}
.scratchpad-history-tag {
  font-size: 0.62rem;
  padding: 1px 6px;
  border-radius: 0.3rem;
  letter-spacing: 0.3px;
  font-weight: bold;
}
.scratchpad-history-tag-auto {
  background: rgba(255, 187, 0, 0.18);
  color: var(--scr-events, hsl(45, 100%, 65%));
}
.scratchpad-history-tag-prob {
  background: rgba(76, 151, 255, 0.18);
  color: hsl(214, 90%, 75%);
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.scratchpad-history-size {
  margin-left: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.65rem;
  color: hsl(220, 14%, 50%);
}
.scratchpad-history-preview {
  margin: 0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: hsl(120, 30%, 70%);
  white-space: pre;
    overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 6px;
  background: #1a1d23;
  border-radius: 0.3rem;
}
.scratchpad-history-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.scratchpad-history-actions .scratchpad-history-delete {
  margin-left: auto;
}
