:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #64748b;
  --line: #dbe2ea;
  --brand: #ffbf00;
  --run: #19a974;
  --stop: #e5484d;
  --accent: #0090f5;
  --ok: #16a34a;
  --fail: #dc2626;
  --wait: #94a3b8;
  --warn: #d97706;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; overflow: hidden;
}
button, select, input { font: inherit; }
button {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 9px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, transform .05s;
}
button:hover:not(:disabled) { background: #f3f6fa; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
.spacer { flex: 1; }

/* ---- 頂部 ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; row-gap: 6px; flex-wrap: wrap; padding: 8px 16px;
  background: #1f2a37; color: #fff; flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.logo { font-size: 26px; background: var(--brand); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; }
.title { font-weight: 900; font-size: 17px; letter-spacing: .5px; }
.subtitle { font-size: 12px; color: #a9b6c6; }
.brand-logo { width: 50px; height: 50px; flex: none; background: #fff; border-radius: 50%; padding: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.brand .org { font-size: 12px; font-weight: 700; color: #ffd84d; letter-spacing: .5px; line-height: 1.3; }
.levels { display: flex; gap: 4px; background: #2c3a4b; padding: 4px; border-radius: 11px; }
.levels button { background: transparent; color: #cfd8e3; border: 0; padding: 6px 12px; white-space: nowrap; }
.levels button.on { background: var(--brand); color: #1f2a37; }
.levels button.locked { opacity: .5; }
.levels button .soon { font-size: 11px; margin-left: 4px; opacity: .8; }
.map-pick select { background: #2c3a4b; color: #fff; border: 1px solid #3c4d61; border-radius: 9px; padding: 7px 10px; font-weight: 600; }
.task-pick select { background: #2c3a4b; color: #fff; border: 1px solid #3c4d61; border-radius: 9px; padding: 7px 10px; font-weight: 600; min-width: 200px; max-width: 280px; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: #cfd8e3; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #3c4d61; display: grid; place-items: center; font-weight: 700; }

/* ---- 版面 ---- */
.layout { flex: 1; display: grid; grid-template-columns: minmax(380px, 44%) 1fr; gap: 10px; padding: 10px; min-height: 0; }
.code-pane, .sim-pane { min-height: 0; display: flex; flex-direction: column; }
.code-pane { background: var(--panel); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.pane-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pane-title { font-weight: 800; }
.ghost { border-color: transparent; background: transparent; font-size: 13px; color: var(--muted); }
.file-btn { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; }
.file-btn:hover { background: #f3f6fa; }
#blockly { flex: 1; min-height: 0; }

.sim-pane { gap: 10px; }
.viewer { position: relative; flex: 1; min-height: 260px; border-radius: var(--radius); overflow: hidden; background: #dfe7f1; border: 1px solid var(--line); }
.viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.toolbar, .viewbar {
  position: absolute; left: 10px; right: 10px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; pointer-events: none;
}
.toolbar > *, .viewbar > * { pointer-events: auto; }
.toolbar { top: 10px; }
.viewbar { top: 52px; }
.run { background: var(--run); color: #fff; border-color: var(--run); padding: 7px 18px; font-size: 15px; }
.run:hover:not(:disabled) { background: #148f62; }
.stop { background: var(--stop); color: #fff; border-color: var(--stop); }
.stop:hover:not(:disabled) { background: #c93b40; }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 10px; font-size: 13px; }
.seg button.on { background: var(--accent); color: #fff; }
.chk { background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 9px; padding: 4px 10px; font-size: 13px; font-weight: 600; display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.challenge { background: #fff7e0; border-color: #f5d27a; font-size: 13px; }
.challenge.on { background: var(--brand); }
.timer { background: #1f2a37; color: var(--brand); font-weight: 900; font-size: 18px; padding: 3px 12px; border-radius: 9px; font-variant-numeric: tabular-nums; }
.timer.low { color: #ff6b6b; }
/* 檢定倒數（TTRA 1 分鐘）：取代碼表 */
.exam-timer { display: inline-flex; align-items: baseline; gap: 6px; background: #1f2a37; color: #fff; font-weight: 800; font-size: 13px; padding: 3px 12px; border-radius: 9px; white-space: nowrap; }
.exam-timer[hidden], .stopwatch[hidden] { display: none; }
.exam-timer b { font-size: 18px; color: var(--brand); font-variant-numeric: tabular-nums; min-width: 3.6em; text-align: right; }
.exam-timer.going b { color: #5ee08f; }
.exam-timer.low b { color: #ff6b6b; }
.exam-timer.done b { color: #5ee08f; }
.exam-timer.timeup b { color: #ff6b6b; }
.challenge small { display: inline-block; margin-left: 6px; font-size: 10.5px; font-weight: 800; color: #9a6700; background: #ffe7a3; border-radius: 5px; padding: 0 5px; vertical-align: 1px; }
.challenge.on small { background: rgba(255,255,255,.55); }
.challenge[hidden] { display: none; }
/* 碼表：一排小工具列（計時／倒數、秒數、停止、歸零），拖曳秒數區可移動 */
.stopwatch { display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 3px; background: #fff; border: 1px solid var(--line); border-radius: 10px; user-select: none; white-space: nowrap; }
.stopwatch.moved { position: absolute; z-index: 4; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.sw-mode button { padding: 3px 8px; font-size: 12px; }
.sw-face { display: inline-flex; align-items: center; gap: 6px; padding: 0 4px; cursor: grab; touch-action: none; }
.stopwatch.dragging .sw-face { cursor: grabbing; }
.sw-read { display: flex; align-items: baseline; gap: 2px; font-weight: 800; color: #1f2a37; }
.sw-read b { min-width: 3.4em; text-align: right; font-size: 17px; font-variant-numeric: tabular-nums; }
.sw-read small { font-size: 11px; color: var(--muted); }
.stopwatch.going .sw-read b { color: #1a8f5a; }
.stopwatch.done .sw-read b, .stopwatch.timeup .sw-read b { color: #d6336c; }
.sw-set { font-size: 11px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 2px; }
.sw-set[hidden] { display: none; }
.sw-set input { width: 3.6em; font-size: 12px; padding: 1px 3px; border: 1px solid var(--line); border-radius: 5px; text-align: center; }
#swUp { display: inline-flex; gap: 3px; }
.sw-stop, .sw-zero { padding: 3px 8px; font-size: 12px; font-weight: 800; color: #fff; border: 0; border-radius: 7px; }
.sw-stop { background: #e5484d; }
.sw-stop:hover:not(:disabled) { background: #c92a2f; }
.sw-stop:disabled { opacity: .5; background: #e5484d; }
.sw-zero { background: #3c4d61; }
.sw-zero:hover { background: #52657c; }
#swUp[hidden] { display: none; }
.place-hint {
  position: absolute; left: 10px; bottom: 10px; background: rgba(31,42,55,.85); color: #fff; font-size: 12.5px;
  padding: 6px 10px; border-radius: 9px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; max-width: calc(100% - 20px);
}
.place-hint { cursor: move; user-select: none; touch-action: none; z-index: 2; }
.place-hint.dragging { box-shadow: 0 6px 20px rgba(0,0,0,.3); opacity: .92; }
.place-hint .drag-handle { font-size: 15px; line-height: 1; opacity: .7; margin-right: -2px; }
.place-hint kbd { background: #3c4d61; border-radius: 4px; padding: 0 5px; font-family: inherit; }
.place-hint .rot button { padding: 2px 8px; font-size: 14px; }
.place-hint .rot { display: inline-flex; align-items: center; gap: 4px; }
.place-hint .rot-ang { min-width: 52px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; background: #3c4d61; border-radius: 6px; padding: 2px 6px; }
.place-hint .rot-step { display: inline-flex; align-items: center; gap: 2px; font-size: 12.5px; opacity: .95; }
.place-hint .rot-step button { padding: 1px 6px; font-size: 12px; background: transparent; color: #cfd8e3; border: 1px solid #56687d; }
.place-hint .rot-step button.on { background: #ffbf00; color: #1f2a37; border-color: #ffbf00; font-weight: 800; }
.pose-badge { font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.pose-badge.good { background: var(--ok); }
.pose-badge.bad { background: var(--fail); }
.viewer.running .place-hint, .viewer.moved .place-hint { display: none; }
.banner {
  position: absolute; left: 50%; top: 96px; transform: translateX(-50%); max-width: 86%;
  background: #fff; border-radius: 12px; padding: 10px 18px; font-weight: 700; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  border-left: 6px solid var(--accent); font-size: 15px; text-align: center;
}
.banner.success { border-color: var(--ok); background: #effcf3; font-size: 18px; }
.banner.fail { border-color: var(--fail); background: #fff3f3; }

/* ---- 下方面板 ---- */
.panel { flex: none; height: 290px; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-radius: 9px 9px 0 0; background: transparent; color: var(--muted); }
.tabs button.on { background: #eef4fb; color: var(--ink); }
.tab-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px 14px; } /* min-height: 0 才捲得動（文字太多時） */
/* 面板上緣的拖曳把手：上下拉可以調整面板高度 */
.panel-resize { flex: none; height: 9px; cursor: ns-resize; touch-action: none; position: relative; }
.panel-resize::after { content: ''; position: absolute; left: 50%; top: 3px; width: 44px; height: 4px; margin-left: -22px; border-radius: 3px; background: #cdd6e1; }
.panel-resize:hover::after, .panel-resize.dragging::after { background: var(--accent); }
body.side-panel .panel-resize, .panel.collapsed .panel-resize { display: none; }
.task-wrap { display: grid; grid-template-columns: 1fr minmax(240px, 42%); gap: 14px; }
.task-text h2 { margin: 0 0 6px; font-size: 18px; }
.task-text .setup { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.task-text .goal { margin: 0 0 8px; font-weight: 700; font-size: 15px; }
.rules { margin: 0; padding-left: 20px; font-size: 13.5px; line-height: 1.65; }
.task-side h3 { margin: 0 0 6px; font-size: 14px; }
.checklist { list-style: none; margin: 0 0 10px; padding: 0; font-size: 13.5px; }
.checklist li { padding: 4px 0 4px 26px; position: relative; line-height: 1.4; }
.checklist li::before { position: absolute; left: 0; top: 3px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 900; color: #fff; }
.checklist li.ok::before { content: "✓"; background: var(--ok); }
.checklist li.fail::before { content: "✗"; background: var(--fail); }
.checklist li.wait::before { content: "…"; background: var(--wait); }
.checklist li.info::before { content: "i"; background: var(--accent); }
.checklist li.warn { color: var(--warn); }
.checklist li.warn::before { content: "!"; background: var(--warn); }
#taskImg { width: 100%; border-radius: 8px; border: 1px solid var(--line); }

/* ---- 車體檢視（蓋在模擬畫面上）---- */
.robot-view { position: absolute; inset: 0; z-index: 5; background: radial-gradient(ellipse at 50% 40%, #f7fafd, #dfe7f1); }
.robot-view[hidden] { display: none; }
.robot-view > canvas, .rv-labels { position: absolute; inset: 0; width: 100%; height: 100%; }
.rv-labels { touch-action: none; }
.rv-bar { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; z-index: 2; pointer-events: none; }
.rv-bar > * { pointer-events: auto; }
.rv-bar > button { padding: 5px 10px; font-size: 13px; }
.rv-bar > button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.rv-legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px; z-index: 2; max-width: calc(100% - 130px); }
.rv-legend button { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; background: rgba(255,255,255,.9); font-weight: 600; }
.rv-legend button i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.rv-legend button.on { border-color: #ff3b6b; color: #ff3b6b; }
.rv-tip { position: absolute; right: 10px; bottom: 12px; font-size: 11.5px; color: var(--muted); z-index: 2; pointer-events: none; }
/* 平常不顯示數字，只有正在調整或點選的那一項才顯示 */
.rv-label { display: none; background: #fff; border: 2px solid #ff3b6b; color: #1f2a37; border-radius: 8px; padding: 3px 9px; font-size: 13px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.15); pointer-events: none; }
.rv-label.hot { display: block; }
.rv-label b { color: #ff3b6b; font-size: 16px; }
.rv-label.up { margin-top: -26px; }
.rv-label.down { margin-top: 30px; }
.rv-label.right { margin-left: 70px; }
.rv-label.left { margin-left: -80px; }

/* ---- 「車體」「主機」分頁：模擬畫面在左、面板在右 ---- */
@media (min-width: 981px) {
  body.side-panel .layout { grid-template-columns: minmax(320px, 30%) 1fr; }
}
@media (min-width: 761px) {
  body.side-panel .sim-pane { flex-direction: row; }
  body.side-panel .viewer { min-height: 0; }
  body.side-panel .panel { height: auto; width: clamp(320px, 42%, 480px); }
  body.side-panel .tabs button { white-space: nowrap; padding: 6px 8px; }
  body.side-panel .robot-grid { grid-template-columns: 1fr; }
  body.side-panel .presets { grid-template-columns: 1fr 1fr; gap: 6px; }
  body.side-panel .preset { padding: 6px 10px; }
  body.side-panel .preset span { display: none; }
  body.side-panel .hub { flex-direction: column; }
  body.side-panel .readings { width: 100%; grid-template-columns: 1fr 1fr; }
}
.robot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.presets { display: grid; gap: 8px; }
.preset { text-align: left; border: 2px solid var(--line); border-radius: 10px; padding: 8px 12px; font-weight: 500; }
.preset b { display: block; font-size: 15px; }
.preset span { font-size: 12.5px; color: var(--muted); }
.preset.on { border-color: var(--accent); background: #eef6ff; }
.params { display: grid; gap: 8px; font-size: 13.5px; }
.params label { display: block; font-weight: 600; }
.params label input, .params label select { display: block; width: 100%; margin-top: 3px; }
.params select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); }
.preset.custom { border-style: dashed; }
.preset.custom.on { border-style: solid; }
.custom-box { display: grid; gap: 8px; border: 2px dashed var(--accent); border-radius: 10px; padding: 8px 10px; background: #f8fbff; }
.custom-box[hidden], .params [hidden] { display: none; }
.custom-box h4 { margin: 0; font-size: 14px; }
.cu-colors { display: grid; gap: 6px; }
.cu-color { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: grid; gap: 4px; }
.cu-head { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.cu-head select { width: auto; padding: 2px 6px; }
.cu-head button { margin-left: auto; padding: 1px 8px; }
.cu-size { font-size: 12.5px; line-height: 1.6; }
.cu-size .bad { color: #d6336c; font-weight: 700; }
.cu-size .good { color: #1a8f5a; font-weight: 700; }
.ports { font-size: 12.5px; color: var(--muted); background: #f6f8fb; border-radius: 8px; padding: 8px 10px; line-height: 1.6; }

.hub { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.matrix { width: 120px; height: 120px; background: #111; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 26px; border: 6px solid #ffd400; text-align: center; padding: 4px; word-break: break-all; }
.readings { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; flex: 1; }
.reading { background: #f6f8fb; border-radius: 9px; padding: 8px 10px; }
.reading .k { font-size: 12px; color: var(--muted); }
.reading .v { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1px solid #ccc; }

.log { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.log li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.log .t { color: var(--muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.log .warn { color: var(--warn); }
.log .err { color: var(--fail); }
.log .ok { color: var(--ok); font-weight: 700; }

/* Blockly 細節 */
.blocklyToolboxDiv { background: #fff !important; border-right: 1px solid var(--line); }
.blocklyTreeRow { border-radius: 8px; margin: 2px 6px !important; height: 34px !important; line-height: 34px !important; }
/* 移動方向圖示選單排成 2×2（仿 SPIKE） */
.blocklyDropDownDiv .blocklyMenu:has(img) { display: grid; grid-template-columns: repeat(2, auto); gap: 4px; padding: 4px; }
.blocklyDropDownDiv .blocklyMenu:has(img) .blocklyMenuItem { padding: 4px 6px; min-width: 0; margin: 0; border: 1px solid rgba(255,255,255,.6); border-radius: 6px; }
.blocklyDropDownDiv .blocklyMenu:has(img) .blocklyMenuItemCheckbox { display: none; }
.blocklyDropDownDiv .blocklyMenu:has(img) .blocklyMenuItemSelected { background: rgba(0,0,0,.2); }
.blocklyTreeLabel { font-family: "Noto Sans TC", sans-serif !important; font-weight: 700; font-size: 14px !important; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; }
  .code-pane { height: 70vh; }
  .viewer { min-height: 55vh; }
  .panel { height: auto; min-height: 280px; }
  .task-wrap, .robot-grid { grid-template-columns: 1fr; }
  .user { margin-left: 0; }
}

/* ---- 變化題 ---- */
.teacher-btn { background: var(--brand); border-color: var(--brand); color: #1f2a37; margin-left: auto; white-space: nowrap; }
.teacher-btn:hover:not(:disabled) { background: #ffd24d; }
a.teacher-btn { display: inline-flex; align-items: center; text-decoration: none; border: 1px solid var(--brand); border-radius: 10px; padding: 6px 12px; font-weight: 700; font-size: 14px; }
a.teacher-btn[hidden] { display: none; }
.sa-people { margin: 12px 18px 0; }
.teacher-btn:not([hidden]) ~ .user { margin-left: 4px; }
.teacher-btn:not([hidden]) ~ .teacher-btn { margin-left: 0; }
.task-text .from { margin: -2px 0 4px; font-size: 12px; color: var(--muted); }
.task-text .story { margin: 0 0 6px; background: #fff7e0; border-radius: 8px; padding: 6px 10px; font-size: 14px; }
dialog.teacher { width: min(1100px, 96vw); max-height: 92vh; border: 0; border-radius: 16px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink); }
dialog.teacher::backdrop { background: rgba(15,23,32,.55); }
.t-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); margin: 0; }
.t-head h2 { margin: 0; font-size: 19px; flex: 1; }
.t-head small { font-size: 12px; background: #eef4fb; color: var(--muted); border-radius: 6px; padding: 2px 8px; margin-left: 6px; vertical-align: 2px; }
.t-close { font-size: 18px; }
.t-body { display: grid; grid-template-columns: 330px 1fr; min-height: 0; max-height: calc(92vh - 60px); }
.t-opts { padding: 14px 18px; border-right: 1px solid var(--line); overflow: auto; }
.t-opts h3 { font-size: 14px; margin: 12px 0 6px; }
.t-opts h3:first-child { margin-top: 0; }
.t-tasks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; font-size: 14px; }
.t-row { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.t-wrap { flex-wrap: wrap; }
.t-opts label { cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.t-note { font-size: 12.5px; color: var(--muted); background: #f6f8fb; border-radius: 8px; padding: 6px 9px; margin: 6px 0 0; line-height: 1.55; }
#tCount { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }
.t-results { display: flex; flex-direction: column; min-height: 0; }
.t-tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--line); }
.t-tabs button { border: 0; border-radius: 9px 9px 0 0; background: transparent; color: var(--muted); }
.t-tabs button.on { background: #eef4fb; color: var(--ink); }
.t-list { overflow: auto; padding: 12px 14px; display: grid; gap: 10px; align-content: start; }
.t-empty { color: var(--muted); text-align: center; padding: 40px 0; }
.t-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: 13.5px; }
.t-card p { margin: 4px 0; line-height: 1.55; }
.t-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.t-card-head b { font-size: 15px; }
.t-id { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); }
.t-story { background: #fff7e0; border-radius: 8px; padding: 5px 9px; }
.t-k { display: inline-block; background: #eef4fb; color: var(--accent); font-weight: 700; font-size: 12px; border-radius: 5px; padding: 0 6px; margin-right: 6px; }
.t-meta { color: var(--muted); font-size: 12.5px; }
.t-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.t-actions button { font-size: 13px; padding: 5px 10px; }
@media (max-width: 760px) {
  .t-body { grid-template-columns: 1fr; max-height: none; overflow: auto; }
  .t-opts { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---- 會員 ---- */
.user .who { display: flex; flex-direction: column; line-height: 1.2; }
.user .who b { color: #fff; font-size: 13.5px; }
.user .who small { color: #a9b6c6; font-size: 11.5px; }
.user .logout { background: transparent; color: #cfd8e3; border-color: #3c4d61; padding: 4px 10px; font-size: 12.5px; }
.user .logout:hover { background: #2c3a4b; }
.user .help-btn { background: #2c3a4b; color: #fff; border-color: #3c4d61; padding: 5px 11px; font-size: 13px; white-space: nowrap; margin-right: 4px; }
.user .help-btn:hover { background: #3c4d61; }
.user a.help-btn { display: inline-flex; align-items: center; text-decoration: none; border: 1px solid #3c4d61; border-radius: 9px; font-weight: 600; }
/* ---- 題庫（變化題＋自訂題） ---- */
.lib-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-filter button { font-size: 13px; padding: 4px 12px; border-radius: 999px; color: var(--muted); }
.lib-filter button.on { background: #1f2a37; border-color: #1f2a37; color: #fff; }
.lib-group { margin: 8px 0 -2px; font-size: 14px; color: var(--ink); border-bottom: 2px solid var(--line); padding-bottom: 4px; }
.lib-none { margin: 0; color: var(--muted); font-size: 13px; }
.lib-badge { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-right: 8px; vertical-align: 2px; }
.lib-badge.custom { background: #fdecef; color: #c8174f; }
.lib-badge.variant { background: #e8f3ff; color: #0b6bcb; }
.lib-card.custom { border-left: 4px solid #f19bb0; }
.lib-card.variant { border-left: 4px solid #8cc4f7; }
/* ---- 第一次使用提醒 ---- */
.login-intro { margin: 14px auto 0; font-size: 13.5px; }
.login-admin { display: block; margin: 6px auto 0; font-size: 12.5px; color: #8b9bb0 !important; }
/* ---- 學生變化題練習區 ---- */
dialog.practice { width: min(760px, 96vw); }
.pr-body { padding: 8px 18px 18px; overflow: auto; max-height: calc(92vh - 70px); }
.pr-body h3 { font-size: 15px; margin: 12px 0 8px; }
.pr-tasks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pr-tasks button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border-radius: 12px; border: 2px solid var(--line); background: #f7f9fc; cursor: pointer; color: var(--ink); }
.pr-tasks button b { font-size: 17px; }
.pr-tasks button span { font-size: 13px; color: var(--muted); }
.pr-tasks button:hover { border-color: #9fb6d6; }
.pr-tasks button.on { border-color: #ffbf00; background: #fff8e1; box-shadow: 0 0 0 3px rgba(255,191,0,.25); }
.pr-hard { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 14px; }
@media (max-width: 560px) { .pr-tasks { grid-template-columns: repeat(2, 1fr); } }
/* ---- 程式區 Logo 浮水印 ---- */
.ws-watermark { opacity: .1; }
.ws-watermark text { font-weight: 900; fill: #1f2a37; letter-spacing: 2px; }
/* ---- 挑戰成功動畫 ---- */
.celebrate { position: absolute; inset: 0; z-index: 30; overflow: hidden; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 50%, rgba(255,240,170,.35), rgba(20,20,60,.35)); cursor: pointer; animation: cel-fade 4.6s ease forwards; }
.cel-rays { position: absolute; left: 50%; top: 50%; width: 900px; height: 900px; margin: -450px 0 0 -450px; border-radius: 50%; background: repeating-conic-gradient(rgba(255,220,90,.38) 0 10deg, rgba(255,255,255,0) 10deg 20deg); -webkit-mask: radial-gradient(circle, #000 0, #000 30%, transparent 68%); mask: radial-gradient(circle, #000 0, #000 30%, transparent 68%); animation: cel-rays 6s linear infinite; }
.celebrate i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation-name: cel-fall; animation-timing-function: linear; animation-fill-mode: both; }
.celebrate em { position: absolute; width: 7px; height: 7px; border-radius: 50%; opacity: 0; animation: cel-burst 1.1s cubic-bezier(.1,.7,.3,1) both; }
.celebrate u { position: absolute; font-size: 26px; text-decoration: none; transform: translate(-50%,-50%); opacity: 0; animation: cel-twinkle 1.2s ease-in-out infinite; }
.cel-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 38px 16px; border-radius: 22px; background: linear-gradient(160deg, #fff8d6, #ffe680); border: 4px solid #fff; box-shadow: 0 0 0 4px #ffbf00, 0 18px 50px rgba(0,0,0,.4), 0 0 60px rgba(255,200,0,.7); text-align: center; animation: cel-pop .7s cubic-bezier(.2,1.6,.4,1) both, cel-glow 1.4s ease-in-out .7s infinite; }
.cel-star { font-size: 72px; line-height: 1; animation: cel-spin 1.1s ease-out both, cel-bob 1s ease-in-out 1.1s infinite; }
.cel-card b { font-size: 38px; font-weight: 900; color: #e01e5a; letter-spacing: 3px; text-shadow: 2px 2px 0 #fff, 4px 4px 0 rgba(224,30,90,.25); }
.cel-card b s { display: inline-block; text-decoration: none; animation: cel-jump .7s cubic-bezier(.3,1.8,.5,1) both; }
.cel-card span { font-size: 16px; font-weight: 700; color: #1f2a37; }
.cel-card small { font-size: 14px; color: #6b4f00; font-weight: 700; }
@keyframes cel-fall { 0% { top: -20px; transform: translateX(0) rotate(0); } 100% { top: 110%; transform: translateX(var(--dx, 40px)) rotate(900deg); } }
@keyframes cel-burst { 0% { opacity: 1; transform: translate(0,0) scale(1.4); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--tx), calc(var(--ty) + 30px)) scale(.4); } }
@keyframes cel-twinkle { 0%, 100% { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(0); } 50% { opacity: 1; transform: translate(-50%,-50%) scale(1.2) rotate(30deg); } }
@keyframes cel-pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes cel-spin { from { transform: rotate(-340deg) scale(.2); } to { transform: rotate(0) scale(1); } }
@keyframes cel-bob { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-8px) scale(1.08); } }
@keyframes cel-jump { 0% { transform: translateY(30px) scale(.3); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes cel-glow { 0%, 100% { box-shadow: 0 0 0 4px #ffbf00, 0 18px 50px rgba(0,0,0,.4), 0 0 40px rgba(255,200,0,.5); } 50% { box-shadow: 0 0 0 4px #ffbf00, 0 18px 50px rgba(0,0,0,.4), 0 0 90px rgba(255,200,0,.95); } }
@keyframes cel-rays { to { transform: rotate(360deg); } }
@keyframes cel-fade { 0%, 82% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .celebrate i, .celebrate em, .celebrate u, .cel-rays { display: none; } .cel-card, .cel-star, .cel-card b s { animation: none; } }
/* ---- 管理者 ---- */
dialog.teacher.superadmin .sa-search { flex: 1; min-width: 160px; }
.sa-note { font-size: 13px; color: #6b4f00; background: #fff8e1; border-radius: 9px; padding: 7px 11px; margin: 0 0 10px; }
.sa-head { background: linear-gradient(120deg, #1f2a44, #3a2a6b); color: #fff; border-bottom: 0; border-radius: 16px 16px 0 0; }
.sa-head h2 { font-size: 21px; }
.sa-head h2 span { font-size: 14px; font-weight: 700; background: #ffbf00; color: #1f2a44; border-radius: 999px; padding: 3px 12px; margin-left: 8px; vertical-align: 3px; }
.sa-head .t-close { color: #fff; }
.sa-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 18px 4px; }
.sa-card.sa-settings.on { border-color: #ff8c1a; background: #fff4e6; box-shadow: 0 0 0 3px rgba(255,140,26,.18); }
.sa-set { max-width: 620px; }
.sa-set h3 { margin: 4px 0 8px; font-size: 18px; }
.sa-set p { font-size: 14px; line-height: 1.6; margin: 0 0 10px; }
.sa-set-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 10px; }
.sa-set-row input[type=range] { flex: 1; min-width: 200px; accent-color: #ff8c1a; }
.sa-set-row input[type=number] { width: 80px; font-size: 18px; font-weight: 700; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); }
.sa-set-hint { color: var(--muted); font-size: 13px !important; }
.sa-msg { font-size: 14px; font-weight: 700; color: #1d6b4a; }
.sa-card { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: #f7f9fc; cursor: pointer; color: var(--ink); }
.sa-card .sa-ic { font-size: 34px; line-height: 1; }
.sa-card .sa-txt { display: flex; flex-direction: column; }
.sa-card b { font-size: 26px; line-height: 1.1; }
.sa-card b small { font-size: 13px; font-weight: 600; color: var(--muted); }
.sa-card .sa-txt > span { font-size: 14px; font-weight: 700; color: var(--muted); }
.sa-card:hover { border-color: #9fb6d6; }
.sa-card.sa-teachers.on { border-color: #2e7dd7; background: #eaf3ff; box-shadow: 0 0 0 3px rgba(46,125,215,.18); }
.sa-card.sa-students.on { border-color: #2eb67d; background: #e9f9f1; box-shadow: 0 0 0 3px rgba(46,182,125,.18); }
.sa-card.sa-variants.on { border-color: #9a5cff; background: #f3edff; box-shadow: 0 0 0 3px rgba(154,92,255,.18); }
.sa-card.on .sa-txt > span { color: var(--ink); }
.sa-table tbody tr:hover td { background: #f5f8fc; }
.sa-table tr.sa-group td { background: #e9f9f1; color: #1d6b4a; font-weight: 800; font-size: 13.5px; padding-top: 9px; }
.a-acts .sa-del { color: #c62828; border-color: #f2c4c4; margin-left: 6px; }
.a-acts .sa-del:hover { background: #fdecec; }
.a-bar .sa-teacher { font-size: 14px; }
@media (max-width: 640px) { .sa-cards { grid-template-columns: 1fr; } }
dialog.intro { width: min(760px, 94vw); max-height: 92vh; overflow: auto; border: 0; border-radius: 18px; padding: 22px 26px 18px; box-shadow: 0 24px 60px rgba(0,0,0,.4); color: var(--ink); line-height: 1.7; font-size: 14.5px; }
dialog.intro.in-post { width: min(600px, 94vw); }
dialog.intro::backdrop { background: rgba(15,23,32,.6); }
dialog.intro h2 { margin: 0 0 4px; font-size: 20px; }
dialog.intro h3 { margin: 10px 0 2px; font-size: 15.5px; }
dialog.intro ol { margin: 4px 0; padding-left: 22px; }
dialog.intro p { margin: 6px 0; }
.in-head { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.in-head img { width: 64px; height: 64px; flex: none; }
.in-head small { color: #c8174f; font-weight: 700; }
.in-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.in-cols section { background: #f6f8fb; border-radius: 12px; padding: 4px 14px 8px; }
.in-cols section:last-child { background: #fff8e0; }
.in-tip { font-size: 13px; color: var(--muted); }
.in-note { text-align: center; color: var(--muted); font-size: 13px; }
.in-code { font-family: ui-monospace, monospace; font-size: 20px; font-weight: 800; letter-spacing: 2px; background: #fff3cd; border-radius: 6px; padding: 0 8px; }
.in-steps li { margin: 3px 0; }
.in-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
@media (max-width: 640px) {
  .in-cols { grid-template-columns: 1fr; }
  dialog.intro { padding: 16px; }
  .in-foot button { flex: 1 1 auto; }
}
/* ---- 使用說明 ---- */
dialog.help { width: min(980px, 96vw); height: 92vh; }
dialog.help[open] { display: flex; flex-direction: column; overflow: hidden; }
dialog.help .t-head { gap: 6px; }
.h-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.h-kinds { display: flex; gap: 4px; background: #eef4fb; padding: 3px; border-radius: 10px; }
.h-kinds button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; }
.h-kinds button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.h-search { flex: 1; min-width: 220px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14.5px; }
.h-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.h-quick { width: 100%; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.h-quick button.link { font-weight: 600; font-size: 13px; }
.h-body { display: grid; grid-template-columns: 210px 1fr; grid-template-rows: minmax(0, 1fr); flex: 1; min-height: 120px; }
.h-toc { border-right: 1px solid var(--line); overflow: auto; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.h-toc a { color: var(--ink); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.h-toc a:hover { background: #eef4fb; }
.h-content { overflow: auto; padding: 6px 22px 24px; font-size: 14.5px; line-height: 1.75; }
.h-content section { padding-bottom: 8px; border-bottom: 1px dashed var(--line); scroll-margin-top: 8px; }
.h-content section:last-child { border-bottom: 0; }
.h-content h3 { font-size: 17px; margin: 16px 0 4px; }
.h-content h4 { font-size: 14.5px; margin: 10px 0 0; }
.h-content ul, .h-content ol { margin: 4px 0; padding-left: 22px; }
.h-content p { margin: 6px 0; }
.h-content .tip { background: #eef8f2; border-radius: 8px; padding: 6px 10px; }
.h-content .warn { background: #fff4e5; border-radius: 8px; padding: 6px 10px; }
.h-content dt { font-weight: 700; margin-top: 8px; }
.h-content dd { margin: 0 0 0 18px; color: #334155; }
.h-content kbd { border: 1px solid #b8c2cf; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; background: #fff; }
.h-content mark { background: #ffe58a; border-radius: 3px; padding: 0 1px; }
.h-found { color: var(--muted); font-size: 13px; margin-top: 12px !important; }
@media (max-width: 760px) {
  .h-body { grid-template-columns: 1fr; }
  .h-toc { display: none; }
  .h-content { padding: 6px 16px 20px; }
}
.view-bar { display: flex; align-items: center; gap: 10px; background: #fff3cd; border-bottom: 1px solid #f5d27a; padding: 6px 12px; font-size: 13.5px; font-weight: 600; }
.view-bar span { flex: 1; }
.view-bar[hidden] { display: none; }

/* 登入頁：外層可捲動，卡片用 margin:auto 置中，畫面不夠高時從上方開始顯示，不會把 Logo 切掉 */
.boot-screen { position: fixed; inset: 0; z-index: 999; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #8b9bb0; font-size: 14px; background: radial-gradient(circle at 20% 10%, #2c3a4b, #141c26 70%); }
.boot-screen img { width: 96px; height: 96px; }
.login-screen { position: fixed; inset: 0; z-index: 1000; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 24px 16px; background: radial-gradient(circle at 20% 10%, #2c3a4b, #141c26 70%); }
.login-card { margin: auto 0 0; flex-shrink: 0; width: min(860px, 100%); display: grid; grid-template-columns: 340px 1fr; background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 24px 60px rgba(0,0,0,.45); }
.login-foot { flex-shrink: 0; margin: 16px 0 auto; color: #8b9bb0; font-size: 12px; text-align: center; }
.login-hero { background: linear-gradient(160deg, #fff8d6 0%, #ffe680 100%); padding: 32px 26px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.login-hero img { width: 190px; height: 190px; filter: drop-shadow(0 6px 14px rgba(224,30,90,.18)); }
.hero-text .org { font-size: 19px; font-weight: 900; color: #e01e5a; letter-spacing: 1px; }
.hero-text b { display: block; font-size: 22px; font-weight: 900; color: #1f2a37; margin-top: 4px; }
.hero-text span { display: block; font-size: 13px; color: #6b5a1e; margin-top: 4px; }
.hero-points { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13.5px; color: #4a3f17; text-align: left; display: grid; gap: 6px; }
.login-main { padding: 28px 30px; display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 760px) {
  .login-card { grid-template-columns: 1fr; }
  .login-hero { flex-direction: row; text-align: left; padding: 18px 20px; gap: 14px; }
  .login-hero img { width: 92px; height: 92px; flex: none; }
  .hero-text .org { font-size: 16px; }
  .hero-text b { font-size: 19px; }
  .hero-points { display: none; }
  .login-main { padding: 20px; }
}
@media (max-width: 420px) {
  .login-hero { flex-direction: column; text-align: center; }
}.demo-note { background: #fff7e0; border: 1px solid #f5d27a; border-radius: 10px; padding: 8px 11px; font-size: 12.5px; line-height: 1.6; margin-bottom: 12px; }
.demo-note code { background: #fff; border-radius: 4px; padding: 0 5px; font-weight: 700; }
.login-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #eef2f7; padding: 4px; border-radius: 11px; margin-bottom: 14px; }
.login-tabs button { border: 0; background: transparent; font-size: 13.5px; padding: 7px 4px; }
.login-tabs button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.login-form { display: grid; gap: 10px; }
.login-form[hidden] { display: none; }
.login-form label { display: grid; gap: 4px; font-size: 13.5px; font-weight: 700; }
.login-form input { border: 1.5px solid var(--line); border-radius: 9px; padding: 9px 11px; font-size: 16px; }
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-form .run { padding: 10px; font-size: 16px; margin-top: 4px; }
.login-form .hint { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.login-ok { margin: 10px 0 0; background: #eefaf3; color: #1d6b4a; border-radius: 9px; padding: 8px 11px; font-size: 13.5px; font-weight: 600; }
.login-forgot { justify-self: center; font-size: 13px; }
.login-reg { margin: 0; font-size: 14px; line-height: 1.7; background: #eef7ff; border: 1px solid #b9dcf7; border-radius: 10px; padding: 10px 12px; }
.login-reg-go { display: block; text-align: center; text-decoration: none; border-radius: 9px; }
.login-error { margin: 10px 0 0; background: #fff3f3; color: var(--fail); border-radius: 9px; padding: 8px 11px; font-size: 13.5px; font-weight: 600; }

dialog.admin .a-tabs { padding: 10px 18px 0; }
.a-body { padding: 14px 18px 18px; overflow: auto; max-height: calc(92vh - 110px); }
.a-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.a-bar select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }
.a-count { font-size: 13px; color: var(--muted); }
.a-err { color: var(--fail); }
.a-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.a-table th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 700; border-bottom: 2px solid var(--line); padding: 6px 8px; white-space: nowrap; }
.a-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; }
.a-table tr.bad td { background: #fff3f3; color: var(--fail); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.a-acts { text-align: right; white-space: nowrap; }
.a-acts button { font-size: 12.5px; padding: 4px 9px; }
.a-scroll { overflow: auto; }
.a-grid th, .a-grid td { text-align: center; }
.a-grid th small { display: block; font-weight: 500; font-size: 10.5px; }
.a-grid td.who { text-align: left; white-space: nowrap; }
.a-grid td.who small { display: block; color: var(--muted); font-size: 11.5px; }
.a-grid td.cell { cursor: pointer; min-width: 48px; }
.a-grid td.cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.a-grid td.pass { background: #effcf3; }
.a-grid td small { font-size: 10.5px; color: var(--muted); margin-left: 4px; }
.a-grid td.who small { margin-left: 0; }
.a-grid td.try { background: #fff7e0; }
.a-grid td.none { color: #c3ccd6; }
.a-grid tr.sum td { font-weight: 700; background: #f6f8fb; }
.a-help p { margin: 0 0 4px; font-size: 13.5px; }
.a-help .hint { color: var(--muted); font-size: 12.5px; }
.a-paste { width: 100%; min-height: 130px; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; margin: 8px 0; tab-size: 12; }
.a-preview { margin-top: 6px; }
.a-preview .a-bar { margin-top: 10px; }
.a-done h3 { margin: 0 0 6px; }
.a-warn { background: #fff7e0; border-radius: 8px; padding: 7px 10px; font-size: 13.5px; }
.a-me { text-align: center; padding: 20px 0; }
.a-code { font-family: ui-monospace, Consolas, monospace; font-size: 56px; font-weight: 900; letter-spacing: 10px; background: #1f2a37; color: var(--brand); display: inline-block; padding: 8px 24px; border-radius: 14px; margin: 6px 0 14px; }
.a-me .hint { color: var(--muted); font-size: 13.5px; line-height: 1.8; }
.a-codechg { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line); }
.a-codelock { margin-top: 16px; font-weight: 700; color: #6b7a8c; }
dialog.a-ask { border: 0; border-radius: 16px; padding: 22px 24px; width: min(460px, 92vw); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog.a-ask::backdrop { background: rgba(15,23,32,.5); }
.a-ask h3 { margin: 0 0 10px; font-size: 19px; }
.a-ask-body { font-size: 15px; line-height: 1.7; }
.a-ask-body ul { padding-left: 20px; margin: 4px 0; }
.a-ask-code { font-family: ui-monospace, Consolas, monospace; font-size: 18px; letter-spacing: 3px; background: #1f2a37; color: var(--brand); padding: 1px 8px; border-radius: 6px; }
.a-ask-input { width: 100%; margin-top: 10px; font: 700 22px ui-monospace, Consolas, monospace; letter-spacing: 6px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 10px; }
.a-ask-err { color: #b42318; font-size: 13.5px; min-height: 1.2em; margin-top: 4px; }
.a-ask-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.a-ask .run.danger { background: #e5484d; }
/* ---- 面板縮小 / 模擬放大 ---- */
.panel-toggle { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 4px 10px; margin-bottom: 2px; }
.panel.collapsed { height: auto !important; }
.panel.collapsed .tab-body { display: none; }
.panel.collapsed .tabs button.on { background: transparent; color: var(--muted); }
.maxbtn { background: rgba(255,255,255,.95); font-size: 13px; }
.site-foot {
  flex: none; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 6px;
  padding: 4px 16px 6px; font-size: 12px; color: var(--muted); text-align: center;
}
.site-foot .dot { opacity: .5; }
body.sim-max .layout { grid-template-columns: 1fr; }
/* 程式區大小（2026-10-31）：放大＝程式佔 65%；全畫面＝只留程式區 */
.code-size button { font-size: 12.5px; padding: 4px 9px; }
body.code-wide .layout { grid-template-columns: minmax(380px, 65%) 1fr; }
body.code-full .layout { grid-template-columns: 1fr; }
body.code-full .sim-pane { display: none; }
.robot-reset { justify-self: start; align-self: start; font-size: 13px; padding: 5px 12px; border-radius: 9px; background: #fff7e6; border: 1px solid #f5c26b; color: #8a5a00; font-weight: 700; cursor: pointer; }
.robot-reset:hover { background: #ffedc7; }
body.sim-max .code-pane, body.sim-max .panel { display: none; }
body.sim-max .maxbtn { background: var(--accent); color: #fff; border-color: var(--accent); }
.cursor-info { position: absolute; right: 10px; bottom: 10px; background: rgba(31,42,55,.85); color: #fff; font-size: 12.5px; padding: 5px 10px; border-radius: 8px; pointer-events: none; font-variant-numeric: tabular-nums; }
.cursor-info b { color: var(--brand); }
@media (max-width: 980px) {
  body.sim-max .viewer { min-height: calc(100vh - 140px); }
}

/* ---- 老師指派的題目（學生端） ---- */
.task-text .assign { margin: 0 0 6px; background: #e8f1ff; color: #1d4ed8; border-radius: 8px; padding: 5px 10px; font-size: 13.5px; font-weight: 700; }
.task-text .assign[hidden] { display: none; }

/* ---- 自訂題目 ---- */
.cu-body { grid-template-columns: 420px 1fr; }
.cu-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 14px; }
.cu-row input, .cu-row select, #cuDesc, #cuAddType { border: 1.5px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px; font-family: inherit; }
.cu-row input { flex: 1; min-width: 160px; }
#cuDesc { width: 100%; resize: vertical; margin-bottom: 6px; line-height: 1.6; }
#cuAddType { flex: 1; min-width: 0; }
.cu-items { display: grid; gap: 8px; margin-bottom: 8px; }
.cu-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbfcfe; }
.cu-item-head { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; }
.cu-item-head button { padding: 2px 8px; }
.cu-fields { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; }
.cu-fields label { display: grid; gap: 2px; font-size: 12.5px; cursor: default; }
.cu-fields input:not([type="checkbox"]), .cu-fields select { border: 1.5px solid var(--line); border-radius: 7px; padding: 5px 7px; font-size: 13.5px; width: 150px; }
.cu-fields input[type="number"] { width: 70px; }
.cu-fl { color: var(--muted); font-size: 12px; }
.cu-chk { display: inline-flex !important; grid-auto-flow: column; align-items: center; gap: 5px; font-size: 13.5px; cursor: pointer; }
.cu-err { background: #fff3f3; color: var(--fail); border-radius: 8px; padding: 6px 10px; margin: 0; font-size: 13.5px; font-weight: 600; }
.cu-warn { background: #fff7e0; border-radius: 8px; padding: 6px 10px; margin: 4px 0; font-size: 13px; }
.cu-rules { margin: 2px 0 4px; padding-left: 20px; line-height: 1.6; }

/* ---- 班級群組、派發題目 ---- */
.a-lv { line-height: 1.9; }
.a-name { white-space: nowrap; }
.a-perm { display: inline-flex; align-items: center; gap: 3px; margin-right: 10px; white-space: nowrap; }
.a-perm label { margin-right: 0; }
.a-exp { font-size: 11px; line-height: 1.5; padding: 0 6px; border-radius: 9px; border: 1px dashed #b8c4d2; background: #fff; color: #6b7a8c; cursor: pointer; }
.a-exp:hover { border-style: solid; border-color: var(--accent); color: var(--accent); }
.a-exp.set { border-style: solid; border-color: #9fd3b8; background: #eefaf3; color: #1d6b4a; }
.a-exp.over { border-style: solid; border-color: #f2b8b8; background: #fdecec; color: #c62828; font-weight: 700; }
.a-dur { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.a-muted { color: #8a97a6; }
.a-seen { white-space: nowrap; }
.a-exppop { position: fixed; z-index: 2000; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; width: 290px; font-size: 13px; }
.a-exptitle { font-weight: 700; }
.a-expbtns, .a-expdate { display: flex; gap: 6px; flex-wrap: wrap; }
.a-expbtns button, .a-expdate button { font-size: 12.5px; padding: 4px 9px; }
.a-exppop small { color: #6b7a8c; }
.a-lv label { white-space: nowrap; display: inline-flex; align-items: center; gap: 2px; margin-right: 8px; font-size: 13px; cursor: pointer; }
.a-lvbar { background: #f6f9fc; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.a-lvbar small { color: #6b7a8c; }
.a-gtags span { display: inline-block; background: #eef4fb; color: var(--accent); border-radius: 5px; padding: 0 6px; margin: 1px 3px 1px 0; font-size: 12px; }
.a-members { font-size: 12.5px; color: var(--muted); max-width: 420px; }
.a-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.a-pick label { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; cursor: pointer; font-size: 13.5px; }
.a-pick label:has(input:checked) { background: #effcf3; border-color: #9fdcb5; }
.a-pick small { display: block; color: var(--muted); font-size: 11.5px; }
/* 學習進度：勾選學生、題目 */
.pg-pick { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pg-box { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fbfcfe; }
.pg-box summary { cursor: pointer; font-weight: 800; font-size: 14.5px; }
.pg-box summary b { font-weight: 600; font-size: 13px; color: var(--muted); margin-left: 6px; }
.pg-box[open] summary { margin-bottom: 8px; }
.pg-box .a-pick { max-height: 240px; overflow: auto; }
.pg-group { margin: 0 0 8px; }
.pg-gh { display: inline-flex; align-items: center; gap: 4px; font-size: 13.5px; cursor: pointer; margin-bottom: 4px; }
.pg-gh small { color: var(--muted); }
.pg-tasks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px; padding-left: 18px; }
.pg-tasks label { display: flex; align-items: center; gap: 5px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 7px; cursor: pointer; background: #fff; }
.pg-tasks label small { margin-left: auto; color: #1a8f5a; font-size: 11px; white-space: nowrap; }
.pg-tasks label.pg-zero small { color: #b0b8c2; }
.pg-tasks label:has(input:checked) { background: #effcf3; border-color: #9fdcb5; }
.a-assign { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; background: #fbfcfe; }
.a-assign h3, .a-h3 { margin: 0 0 8px; font-size: 15px; }
.a-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; align-items: start; }
.a-form > label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; }
.a-form small { font-weight: 400; color: var(--muted); }
.a-form select, .a-form input:not([type]), .a-form input[type="date"] { border: 1.5px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13.5px; font-family: inherit; }
.as-task { grid-row: span 3; min-height: 150px; }
.as-who { display: grid; gap: 4px; font-size: 13px; }
.as-groups { display: grid; gap: 3px; padding-left: 20px; }
.as-groups[hidden] { display: none; }
button.link { border: 0; background: none; color: var(--accent); text-decoration: underline; padding: 0; font-weight: 700; }
.a-detail td { background: #f6f8fb; font-size: 13px; }
@media (max-width: 760px) {
  .cu-body { grid-template-columns: 1fr; }
  .a-form { grid-template-columns: 1fr; }
  .as-task { grid-row: auto; }
}

/* ---- 新增學生：直接輸入 ---- */
.a-modes { display: inline-flex; gap: 4px; background: #eef2f7; padding: 4px; border-radius: 11px; margin-bottom: 12px; }
.a-modes button { border: 0; background: transparent; font-size: 13.5px; }
.a-modes button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.a-add .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.a-entry td { padding: 4px; border-bottom: 0; }
.a-entry input { width: 100%; border: 1.5px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 14px; }
.a-entry input:focus { outline: none; border-color: var(--accent); }
.a-entry td:last-child { width: 40px; }

/* ---- 手機直立：所有登入元件都能縮到螢幕寬度，不會被裁切 ---- */
.login-card { max-width: 100%; }
.login-card, .login-hero, .login-main, .login-form, .login-form label { min-width: 0; }
.login-form input { width: 100%; min-width: 0; }
.login-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.login-tabs button { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero-text { min-width: 0; }
.hero-text span { white-space: normal; }
@media (max-width: 760px) {
  .login-card { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .login-screen { padding: 12px 10px; }
  .login-hero { padding: 16px 14px; gap: 8px; }
  .login-hero img { width: 84px; height: 84px; }
  .hero-text .org { font-size: 15px; }
  .hero-text b { font-size: 18px; }
  .hero-text span { font-size: 12px; }
  .login-main { padding: 16px 14px; }
  .login-tabs button { font-size: 12.5px; padding: 7px 2px; }
  .login-form input { font-size: 16px; padding: 9px 10px; }
}

/* ---- 我的積木：製作積木視窗（仿 SPIKE） ---- */
dialog.mb-dlg { width: min(860px, 96vw); border: 0; border-radius: 16px; padding: 0; background: #1e1e1e; color: #eee; box-shadow: 0 24px 60px rgba(0,0,0,.5); overflow: hidden; }
dialog.mb-dlg::backdrop { background: rgba(15,23,32,.6); }
.mb-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #333; }
.mb-head h2 { margin: 0; font-size: 24px; }
.mb-x { width: 40px; height: 40px; border-radius: 50%; border: 0; background: #111; color: #ccc; font-size: 20px; cursor: pointer; }
.mb-stage { position: relative; margin: 26px 20px 10px; min-height: 200px; background: #121212; display: flex; align-items: center; justify-content: center; padding: 50px 16px 30px; overflow-x: auto; }
.mb-block { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; background: #FF6680; border: 1.5px solid #e2506b; border-radius: 6px; padding: 8px 12px 8px 26px; min-height: 52px; max-width: 100%;
  clip-path: polygon(0 0, 18px 0, 24px 6px, 40px 6px, 46px 0, 100% 0, 100% 100%, 46px 100%, 40px calc(100% - 6px), 24px calc(100% - 6px), 18px 100%, 0 100%); }
.mb-item { font: 600 15px "Noto Sans TC", "Microsoft JhengHei", sans-serif; border: 0; outline: none; text-align: center; padding: 6px 8px; min-width: 2.5ch; }
.mb-item.label { background: #fff; color: #333; border-radius: 4px; }
.mb-item.num { background: #e2506b; color: #fff; border-radius: 999px; padding: 6px 12px; }
.mb-item.bool { background: #e2506b; color: #fff; padding: 6px 18px; clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 12px 100%, 0 50%); }
.mb-item:focus { box-shadow: 0 0 0 2px #fff inset; }
.mb-item.label:focus { box-shadow: 0 0 0 2px #FF6680 inset; background: #ffe9ee; }
.mb-trash { position: absolute; transform: translateX(-50%); border: 0; background: transparent; font-size: 22px; cursor: pointer; padding: 2px 6px; filter: drop-shadow(0 0 2px #000); }
.mb-adds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 8px 20px 4px; }
.mb-adds button { background: transparent; border: 0; color: #eee; font: 700 14px/1.3 "Noto Sans TC", "Microsoft JhengHei", sans-serif; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px; border-radius: 10px; }
.mb-adds button:hover { background: #2a2a2a; }
.mb-ico { width: 56px; height: 48px; background: #FF6680; border-radius: 4px; display: flex; align-items: center; justify-content: center; position: relative; color: #fff; font-size: 12px; font-weight: 700; }
.mb-ico.num::after { content: ''; width: 40px; height: 28px; border-radius: 999px; background: #e2506b; border: 1px solid #c9405a; }
.mb-ico.bool::after { content: ''; width: 42px; height: 30px; background: #e2506b; clip-path: polygon(12px 0, 30px 0, 100% 50%, 30px 100%, 12px 100%, 0 50%); }
.mb-msg { min-height: 1.4em; margin: 2px 20px; color: #ffb4c2; font-size: 14px; text-align: center; }
.mb-foot { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid #333; }
.mb-foot button { background: transparent; border: 0; color: #ddd; font: 700 16px "Noto Sans TC", "Microsoft JhengHei", sans-serif; padding: 16px; cursor: pointer; }
.mb-foot .mb-cancel { color: #999; }
.mb-foot .mb-save { color: #fff; border-left: 1px solid #333; }
.mb-foot button:hover { background: #2a2a2a; }

/* 積木車（2026-11-02） */
.brick-info { font-size: 13px; line-height: 1.7; margin-bottom: 6px; }
.brick-info .bad { color: #b45309; }
.brick-btns { display: flex; flex-wrap: wrap; gap: 6px; }
/* 發放機構車體（2026-11-03） */
.brick-shared h5 { margin: 6px 0 4px; font-size: 13px; }
.brick-list { display: grid; gap: 4px; max-height: 220px; overflow: auto; }
.brick-list .sub { font-size: 12px; color: #6b7785; }
.brick-item { display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #dde3ea; border-radius: 8px; padding: 4px 6px; font-size: 13px; }
.brick-item .nm { flex: 1; min-width: 0; line-height: 1.35; }
.brick-item .nm small { display: block; color: #6b7785; font-size: 11.5px; }
.brick-item button { white-space: nowrap; padding: 3px 8px; }
dialog.brick-send { width: min(440px, 94vw); border: 0; border-radius: 14px; padding: 16px 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink); }
dialog.brick-send::backdrop { background: rgba(15,23,32,.55); }
dialog.brick-send h3 { margin: 0 0 10px; }
dialog.brick-send label { display: block; margin: 6px 0; font-size: 14px; }
dialog.brick-send input[type=text] { width: 100%; box-sizing: border-box; padding: 6px 8px; }
dialog.brick-send .groups { display: grid; gap: 2px; padding-left: 22px; max-height: 160px; overflow: auto; }
dialog.brick-send .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
dialog.brick-send .acts .primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
#btnBrickSend { justify-self: start; }

/* Python 程式（2026-11-02） */
.lang-seg button { font-weight: 600; }
.py-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.py-pane[hidden], #blockly[hidden] { display: none; }
.py-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.py-bar button.on { background: #e0f0ff; }
.py-hint { font-size: 12px; color: #6b7785; margin-left: auto; }
.py-body { flex: 1; min-height: 0; display: flex; }
.py-host { flex: 1; min-width: 0; position: relative; }
.py-host .CodeMirror { position: absolute; inset: 0; height: auto; font: 14px/1.55 Consolas, "Cascadia Mono", ui-monospace, monospace; }
.py-run { background: #fff3b0 !important; }
.py-err { background: #ffd9d6 !important; }
.py-ref { width: 300px; flex: none; overflow-y: auto; border-left: 1px solid var(--line); padding: 6px 10px 12px; background: #fafcfd; }
.py-ref h4 { margin: 10px 0 4px; font-size: 13px; color: #44515e; }
.py-snip { display: block; width: 100%; text-align: left; border: 1px solid #e3e8ee; background: #fff; border-radius: 8px; padding: 5px 7px; margin-bottom: 4px; cursor: pointer; }
.py-snip:hover { border-color: #0090f5; }
.py-snip code { display: block; white-space: pre-wrap; font: 12px/1.45 Consolas, ui-monospace, monospace; color: #0b4f8a; }
.py-snip span { display: block; font-size: 11.5px; color: #6b7785; margin-top: 2px; }
@media (max-width: 900px) { .py-ref { width: 220px; } }

/* 轉向轉盤（blocks.js FieldSteer） */
.steerDial { padding: 6px 8px 4px; user-select: none; touch-action: none; }
.steerDial svg { display: block; margin: 0 auto; }
.steerRow { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; color: #fff; font-weight: 700; font-size: 16px; }
.steerRow button { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.7); background: transparent; color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.steerRow button:hover { background: rgba(255,255,255,.15); }

/* 接線選單（app.js syncRobotPanel、setWire） */
.ports .wire-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 700; margin-bottom: 6px; }
.ports .wire-head span { font-weight: 400; font-size: 12px; opacity: .75; }
.ports .wire-head button { margin-left: auto; font-size: 12px; padding: 2px 8px; }
.ports .wire-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; }
.ports .wire-grid label { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0; }
.ports .wire-grid select { width: auto; min-width: 52px; }
.ports .wire-note { margin-top: 6px; }
