/* ===== 全站共用樣式：手機優先，畫面變大時再調整排版 ===== */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #5d6677;
  --line: #dde1e8;
  --accent: #e0791b;     /* 橘色：機器人「以為的」 */
  --accent-2: #1f7ae0;   /* 藍色：真實的 */
  --ok: #1a8f4c;
  --warn: #c48a00;
  --bad: #c7382f;
  --radius: 12px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --card: #1b2029;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --line: #2c3340;
    --accent: #f2913a;
    --accent-2: #5aa2f5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--accent-2); }

/* ----- 頂部導覽列 ----- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.topbar .brand { font-weight: 700; margin-right: auto; white-space: nowrap; }
.topbar a.nav {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.topbar a.nav.active { background: var(--accent); color: #fff; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ----- 卡片 ----- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.card h3 { margin: 16px 0 8px; font-size: 1rem; }
.hint { color: var(--muted); font-size: 0.9rem; }

/* ----- 表單 ----- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label.field .value { color: var(--text); font-weight: 600; }
select, input[type="number"], input[type="text"] {
  font: inherit;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
input[type="range"] { width: 100%; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, .button {
  font: inherit;
  padding: 10px 16px;
  min-height: 44px;            /* 手指好按 */
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ----- 自己擺放（可展開的設定區） ----- */
details.editor {
  margin-top: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}
details.editor summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
details.editor h3 { font-size: 0.95rem; }

/* ----- 數字指標 ----- */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.metric {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
}
.metric .label { font-size: 0.8rem; color: var(--muted); }
.metric .num { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .unit { font-size: 0.8rem; color: var(--muted); margin-left: 2px; }

/* ----- 3D 與俯視圖 ----- */
.view3d {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #0d1117;
  touch-action: none;           /* 讓手指可以旋轉 3D，不會捲動整頁 */
}
.topview { width: 100%; height: auto; border-radius: 8px; background: #0d1117; display: block; touch-action: manipulation; }
.chart-box { position: relative; width: 100%; height: 240px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  background: var(--c);
}
.toggles { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.9rem; margin-top: 8px; }
.toggles label { display: inline-flex; align-items: center; gap: 4px; }

/* ----- 狀態標籤 ----- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--line);
}
.badge.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.badge.bad { background: var(--bad); color: #fff; border-color: var(--bad); }
.badge.warn { background: var(--warn); color: #fff; border-color: var(--warn); }

/* ----- 表格（窄螢幕可以左右捲動） ----- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td input[type="number"] { padding: 6px; min-width: 80px; }

/* ----- 訊息紀錄 ----- */
.log {
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.85rem;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
}
.log div.error { color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: #222a;
  backdrop-filter: blur(6px);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  max-width: calc(100% - 32px);
  z-index: 50;
}

/* ----- 介紹頁 ----- */
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: 1.5rem; line-height: 1.35; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0; }
.steps { padding-left: 1.2em; }
.steps li { margin-bottom: 6px; }
.cards-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }

/* ----- 畫面變寬（平板、電腦）時的排版 ----- */
@media (min-width: 720px) {
  .form-grid { grid-template-columns: repeat(3, 1fr); }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .cards-2 { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 2rem; }
}
@media (min-width: 1024px) {
  .layout-2col { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
}
