:root {
  --bg: #0f1216; --card: #171c22; --line: #2a323c; --text: #e6e9ee; --muted: #8a94a3;
  --accent: #f0b429; --good: #3fb950; --bad: #f85149; --warn: #d29922;
  --c1: #ff6b6b; --c2: #4dd4ac; --c3: #5aa9ff;
  --web: rgba(200,210,225,.28); --grid: rgba(200,210,225,.12);   /* 畫布：蛛網線、波形格線 */
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); display: flex; flex-direction: column;
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif; font-size: 13px; }

/* ---------- 單頁儀表板：整個畫面不捲動 ---------- */
header { display: flex; align-items: center; gap: 16px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
main { flex: 1; min-height: 0; display: grid; gap: 10px; padding: 10px;
  grid-template-columns: minmax(320px, 1fr) minmax(400px, 1.25fr) minmax(330px, 1fr); }
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.grow { flex: 1 1 0; }
.dev-card { flex: 0 1 auto; max-height: 42%; }
.log-card { flex: 0 0 22%; }
.scroll { overflow: auto; min-height: 0; flex: 1 1 auto; }
.canvas-wrap { position: relative; flex: 1 1 0; min-height: 80px; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

h2 { font-size: 14px; margin: 0 0 6px; display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
.tools, .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row { margin-top: 6px; }
.row input[type=range] { width: 140px; vertical-align: middle; }
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, Menlo, monospace; }

button, .btn { background: #232a33; color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font: inherit; text-decoration: none; text-align: center; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button.mini { padding: 2px 8px; font-size: 12px; }
button.icon { padding: 2px 5px; }
.devtable .sub { color: var(--muted); font-size: 11px; line-height: 1.2; }
.pill { padding: 2px 9px; border-radius: 99px; font-size: 12px; background: #232a33; white-space: nowrap; }
.pill:empty { display: none; }
.pill.good { background: rgba(63,185,80,.18); color: var(--good); }
.pill.bad { background: rgba(248,81,73,.18); color: var(--bad); }
.pill.warn { background: rgba(210,153,34,.2); color: var(--warn); }
.switch { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }
.switch.small input { width: 14px; height: 14px; }

/* 蛛網與結果 */
.pred-box { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 4px 0 6px; }
.pred-name { font-size: 26px; font-weight: 700; color: var(--accent); }
.proba { display: grid; grid-template-columns: repeat(3, 34px 1fr 30px); gap: 3px 6px; align-items: center; font-size: 12px; }
.proba .bar { height: 8px; background: #232a33; border-radius: 4px; overflow: hidden; }
.proba .bar i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* 裝置 */
.devtable { width: 100%; border-collapse: collapse; font-size: 12px; }
.devtable th { position: sticky; top: 0; background: var(--card); }
.devtable th, .devtable td { padding: 4px 3px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.devtable select { background: #232a33; color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 1px; font-size: 12px; }
.lvl { width: 46px; height: 7px; background: #232a33; border-radius: 4px; overflow: hidden; }
.lvl i { display: block; height: 100%; background: var(--c2); }

/* 資料收集 */
.collect { display: flex; gap: 10px; align-items: stretch; }
.label-grid { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.label-grid button { padding: 5px 2px; font-size: 13px; line-height: 1.25; }
.label-grid button small { display: block; color: var(--muted); font-size: 11px; }
.label-grid button.sel { border-color: var(--accent); background: rgba(240,180,41,.15); }
.label-grid button.sel small { color: var(--accent); }
.collect-btns { display: flex; flex-direction: column; gap: 5px; width: 112px; }
.pair-btns { display: flex; gap: 5px; }
.pair-btns > * { flex: 1; padding-left: 4px; padding-right: 4px; }

/* 機器人遙控 */
.robot-card { flex: 0 0 auto; }
/* 方形遙控器：外殼是正方形，九宮格每一格也是正方形 */
.robot-pad { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 8px;
  width: min(100%, 210px); aspect-ratio: 1; margin: 2px auto 8px; padding: 10px;
  background: color-mix(in srgb, var(--text) 6%, transparent); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.25); }
.robot-pad button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 0; border-radius: 10px; font-size: 11px; aspect-ratio: 1; box-shadow: 0 2px 0 var(--line); }
.robot-pad button b { font-size: 20px; line-height: 1; }
.robot-pad button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.robot-pad button.stop { color: var(--bad); border-color: var(--bad); }
.robot-card .muted { text-align: center; }

/* 模型 */
.confusion { border-collapse: collapse; margin-top: 6px; font-size: 11px; }
.confusion td, .confusion th { border: 1px solid var(--line); padding: 2px 4px; text-align: center; min-width: 26px; }

.legend { display: flex; gap: 14px; margin-top: 4px; font-size: 11px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; background: var(--c); margin-right: 4px; vertical-align: middle; }
.log { font-size: 12px; line-height: 1.6; }
.log div span { color: var(--muted); margin-right: 6px; font-family: ui-monospace, Menlo, monospace; }

/* 窄螢幕（手機、平板直式）放不下單頁，改為可捲動的單欄 */
@media (max-width: 1100px) {
  body { height: auto; display: block; }
  header { flex-wrap: wrap; }
  #srvInfo { order: 3; width: 100%; }
  main { grid-template-columns: 1fr; }
  .card, .grow, .dev-card, .log-card { flex: none; max-height: none; }
  .web-card .canvas-wrap { flex: none; height: min(92vw, 460px); }
  .canvas-wrap { flex: none; height: 240px; }
  .log-card .scroll, .model-card .scroll { max-height: 220px; }
}
