/* FlyBrain 遙控網站：B 科學筆記本（方格紙、手寫標題、紅筆、螢光筆）
   ＋ E 學術圖表（圖號、座標軸、等寬數字）。 */
:root {
  --paper: #f4f7f9;
  --grid: #dbe6ee;
  --card: #ffffffd9;
  --ink: #1e3658;
  --ink-soft: #4b5f7c;
  --red: #c8423b;
  --blue: #2457b3;
  --hl: #fff27a;
  --ok: #2f7d4f;
  --line: #9fb3c8;
  --hand: "LXGW WenKai TC", "Kaiti TC", "DFKai-SB", "BiauKai", serif;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 14px 14px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
}
.page { max-width: 560px; margin: 0 auto; padding: 16px 16px 40px; counter-reset: fig; }

.masthead { padding: 8px 0 4px; }
.kicker { margin: 0; font-size: 13px; color: var(--ink-soft); letter-spacing: .04em; }
h1 {
  font-family: var(--hand); font-weight: 700; font-size: 30px; line-height: 1.25;
  margin: 4px 0 8px;
}
.nowrap { white-space: nowrap; }
.status-line { margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--ink-soft); font-size: 14px; }

.pill {
  font-family: var(--hand); font-size: 17px; padding: 0 10px;
  border-radius: 3px; border: 1.5px solid currentColor;
}
.pill-on { color: var(--ok); background: linear-gradient(transparent 55%, #c9f2d6 55%); }
.pill-off { color: var(--red); }

/* ---- 圖（E）：每個區塊有「圖 N」編號 ---- */
.fig {
  background: var(--card); border: 1px solid var(--line); border-radius: 4px;
  padding: 14px 14px 10px; margin: 16px 0;
}
.fig h2 {
  font-family: var(--hand); font-size: 21px; font-weight: 700; margin: 0 0 10px;
  color: var(--red); text-decoration: underline wavy var(--red) 1px; text-underline-offset: 5px;
}
.fig h2:not(.no-num)::before {
  counter-increment: fig; content: "圖 " counter(fig) "　";
  font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--blue);
  text-decoration: none; display: inline-block;
}
.caption { margin: 8px 0 0; font-size: 13px; color: var(--ink-soft); border-top: 1px dashed var(--line); padding-top: 6px; }
.note { font-size: 14px; color: var(--ink-soft); margin: 6px 0; }
mark { background: linear-gradient(transparent 50%, var(--hl) 50%); color: inherit; padding: 0 2px; }
code { font-family: var(--mono); font-size: 13px; background: #e8eef4; padding: 0 4px; border-radius: 3px; }

/* ---- 圖 1：昆蟲 ---- */
.bug-fig { display: grid; grid-template-columns: 130px 1fr; gap: 12px; align-items: center; }
#bug-svg { width: 100%; height: auto; }
#bug-svg .body { fill: #fff; stroke: var(--ink); stroke-width: 2; }
#bug-svg .head { fill: #fff; stroke: var(--ink); stroke-width: 2; }
#bug-svg .leg { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
#bug-svg .leg.groupB { stroke: var(--blue); }
#bug-svg .svg-note { font-size: 9px; fill: var(--ink-soft); font-family: var(--sans); }
.readings { margin: 0; display: grid; gap: 4px; }
.readings div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px dotted var(--line); }
.readings dt { color: var(--ink-soft); font-size: 14px; }
.readings dd { margin: 0; font-family: var(--mono); font-size: 15px; text-align: right; }

/* ---- 遙控面板 ---- */
.login label { font-family: var(--hand); font-size: 18px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1; min-width: 0; font-size: 16px; padding: 10px 12px;
  border: 1.5px solid var(--ink); border-radius: 4px; background: #fff; color: var(--ink);
}
.who { font-family: var(--hand); font-size: 18px; margin: 4px 0 10px; }
.who .you { background: linear-gradient(transparent 50%, var(--hl) 50%); }
.who button { margin-left: 8px; }

.btn {
  font-family: var(--hand); font-size: 19px; color: var(--ink);
  background: #fff; border: 2px solid var(--ink); border-radius: 6px;
  padding: 10px 14px; box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.btn:active, .btn.pressed { transform: translate(2px, 2px); box-shadow: none; background: var(--hl); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 8px; }
.pad-btn { min-height: 72px; font-size: 22px; touch-action: none; }
.pad-stop { font-size: 18px; color: var(--ink-soft); }
.pad-extra { display: grid; }
.pad-extra .pad-btn { min-height: 52px; }
.pad[aria-disabled="true"] .pad-btn, .control.locked .pad-extra .pad-btn { opacity: .35; pointer-events: none; }
.hint { text-align: center; }

.btn-danger {
  width: 100%; margin: 10px 0 4px; min-height: 60px; font-size: 24px; font-weight: 700;
  color: #fff; background: var(--red); border-color: #7d211c; box-shadow: 3px 3px 0 #7d211c;
}
.btn-danger:active { background: #a8322c; }

.assemble { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 8px; }
.assemble summary { font-family: var(--hand); font-size: 18px; cursor: pointer; padding: 4px 0; }
.steps { padding-left: 22px; font-size: 14px; }
.steps li { margin: 4px 0; }
.legs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.legs-grid .btn { font-size: 17px; display: flex; justify-content: space-between; align-items: baseline; }
.legs-grid small { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }

/* ---- 圖 2：延遲 ---- */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 64px; gap: 8px; align-items: center; font-size: 14px; }
.bar {
  height: 14px; border: 1px solid var(--ink); position: relative;
  background-image: repeating-linear-gradient(90deg, transparent 0 19px, var(--grid) 19px 20px);
}
.bar i {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: repeating-linear-gradient(45deg, var(--blue) 0 3px, #8fb0e6 3px 6px);
  transition: width .4s;
}
.total .bar i { background: repeating-linear-gradient(45deg, var(--red) 0 3px, #eaa29c 3px 6px); }
.num { font-family: var(--mono); text-align: right; }
.spark { width: 100%; height: 90px; margin-top: 12px; border-left: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); }
.spark polyline { fill: none; stroke: var(--red); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark .axis line { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .axis text { font-family: var(--mono); font-size: 9px; fill: var(--ink-soft); }
.axis-label { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

.foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 20px; font-size: 14px; }
.foot a { color: var(--blue); font-family: var(--hand); font-size: 18px; }

/* 研究說明頁 */
.prose p, .prose li { font-size: 16px; }
.prose h2 { margin-top: 4px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; vertical-align: top; }
.prose th { font-family: var(--hand); font-size: 16px; }
.flow { font-family: var(--mono); font-size: 13px; white-space: pre; overflow-x: auto; background: #fff; border: 1px dashed var(--line); padding: 10px; }

@media (max-width: 380px) {
  h1 { font-size: 26px; }
  .bug-fig { grid-template-columns: 100px 1fr; }
  .bar-row { grid-template-columns: 84px 1fr 56px; }
  .pad-btn { min-height: 64px; font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .bar i { transition: none; }
}

/* ---- 韌體產生器 ---- */
.callout {
  margin: 0 0 12px; padding: 8px 10px; font-size: 14px;
  background: linear-gradient(transparent 0, #fffbd1 0); border-left: 3px solid var(--red);
}
.group { border: 1px dashed var(--line); border-radius: 4px; padding: 8px 12px 12px; margin: 0 0 12px; }
.group legend, details.group > summary { font-family: var(--hand); font-size: 18px; padding: 0 4px; }
details.group > summary { cursor: pointer; padding: 4px 0; }
.fields { display: grid; gap: 8px; margin-top: 6px; }
.fields.two { grid-template-columns: 1fr 96px; }
.group label:not(.radio) { display: grid; gap: 2px; font-size: 14px; color: var(--ink-soft); margin-top: 6px; }
.group input[type=text], .group input[type=password], .group input[type=number], .group select {
  width: 100%; min-width: 0; font-size: 16px; padding: 8px 10px; color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 4px; background: #fff; font-family: var(--mono);
}
.radio { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; margin: 4px 0; }
.radio input { margin-top: 5px; }
.legs-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.legs-table th { font-family: var(--hand); font-weight: 400; text-align: left; border-bottom: 1px solid var(--ink); }
.legs-table td { padding: 4px 4px 4px 0; border-bottom: 1px dotted var(--line); }
.legs-table td:nth-child(3), .legs-table td:nth-child(4) { width: 84px; }
.mono { font-family: var(--mono); }
.errors { color: var(--red); white-space: pre-line; margin: 0; font-size: 14px; }
.copy-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-big { flex: 1; min-height: 56px; font-size: 22px; font-weight: 700; background: var(--hl); }
.code {
  width: 100%; height: 280px; margin-top: 8px; padding: 8px; resize: vertical;
  font-family: var(--mono); font-size: 12px; line-height: 1.45; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
}
.screen-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.screen-table th { font-family: var(--hand); font-weight: 400; text-align: left; border-bottom: 1px solid var(--ink); }
.screen-table td:first-child, .screen-table th:first-child { white-space: nowrap; padding-right: 10px; }
.screen-table td { padding: 4px 4px 4px 0; border-bottom: 1px dotted var(--line); vertical-align: top; }

/* ---- 遙控面板的觸角燈 ---- */
.manual-ant { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 4px; margin: 6px 0 2px; font-size: 15px; }
.manual-ant > span:first-child { font-family: var(--hand); font-size: 17px; }
.manual-ant .ant { font-size: 17px; }
.switch { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-soft); }
.switch input { width: 18px; height: 18px; }

/* ---- 觸角測試 ---- */
.sub { font-family: var(--hand); font-size: 18px; margin: 16px 0 4px; border-top: 1px dashed var(--line); padding-top: 10px; }
.ant-test { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.ant-box { border: 2px solid var(--ink); border-radius: 10px; padding: 12px; text-align: center; background: #fff; transition: background .08s; }
.ant-box b { display: block; font-family: var(--hand); font-size: 20px; }
.ant-box small { font-family: var(--mono); color: var(--ink-soft); }
.ant-box .count { display: block; font-family: var(--mono); font-size: 14px; margin-top: 4px; }
.ant-box.on { background: var(--red); border-color: #7d211c; color: #fff; }
.ant-box.on small { color: #ffe1de; }

/* ---- 自動避障 ---- */
.models { display: grid; gap: 6px; margin: 10px 0; }
.model { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.model:has(input:checked) { border-color: var(--ink); background: linear-gradient(transparent 0, #fffbd1 0); }
.model input { margin-top: 6px; }
.model b { font-family: var(--hand); font-size: 18px; display: block; }
.model small { color: var(--ink-soft); font-size: 13px; }
.auto-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.auto-row .btn { min-height: 54px; }
.btn-go { background: #c9f2d6; font-weight: 700; }
.auto-panel.locked .auto-row .btn:not(#runs-csv), .auto-panel.locked .models { opacity: .4; pointer-events: none; }
.auto-readings { margin-top: 10px; }
.ant { display: inline-block; min-width: 2.4em; text-align: center; margin-left: 6px; padding: 0 6px; border: 1.5px solid var(--line); border-radius: 12px; font-family: var(--hand); }
.ant.on { background: var(--red); border-color: var(--red); color: #fff; }
.chart { width: 100%; height: 140px; border-left: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); background: #fff; }
.chart polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .line-a { stroke: var(--ink); }
.chart .line-b { stroke: var(--blue); }
.chart .line-c { stroke: var(--ink); stroke-dasharray: 4 3; opacity: .6; }
.chart .line-d { stroke: var(--blue); stroke-dasharray: 4 3; opacity: .6; }
.chart #chart-grid line { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart #chart-touch rect { fill: var(--red); opacity: .25; }
.legend { font-size: 13px; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 4px; }
.legend .dash { border-top-style: dashed; }
.table-wrap { overflow-x: auto; }
.runs { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.runs th { font-family: var(--hand); font-weight: 400; text-align: left; border-bottom: 1.5px solid var(--ink); padding: 4px 6px 4px 0; }
.runs td { border-bottom: 1px dotted var(--line); padding: 4px 6px 4px 0; font-family: var(--mono); font-size: 13px; }
.runs td.model-cell { font-family: var(--sans); }
