:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #16202a;
  --muted: #5b6875;
  --line: #d6dde4;
  --primary: #1a5fd0;
  --primary-hover: #154ea9;
  --danger: #c0262d;
  --danger-bg: #fdecec;
  --ok: #1d7a3a;
  --ok-bg: #e7f5ec;
  --warn-bg: #fff5d6;
  --video-bg: #0e1319;
  --radius: 10px;
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; font-size: 17px; line-height: 1.5; }
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---- 按鈕、表單 ---- */
button, .btn {
  font: inherit; font-size: 18px; font-weight: 600;
  padding: 10px 22px; border-radius: 8px; border: 1px solid transparent;
  background: var(--primary); color: #fff; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px;
}
button:hover:not(:disabled), .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.secondary:hover:not(:disabled) { background: #eef1f4; }
button.danger { background: var(--danger); }

label { display: block; font-weight: 600; margin: 14px 0 6px; }
input, select {
  font: inherit; font-size: 18px; width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 3px solid rgba(26, 95, 208, .25); border-color: var(--primary); }
.field-hint { color: var(--muted); font-size: 15px; margin-top: 4px; }

.msg { padding: 12px 14px; border-radius: 8px; margin: 14px 0; font-size: 17px; }
.msg.error { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: #6b4e00; }

/* ---- 登入、註冊 ---- */
.auth-page { display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 28px 24px;
}
.auth-card h1 { font-size: 24px; margin: 0 0 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 8px; }
.auth-card button[type=submit] { width: 100%; margin-top: 22px; }
.auth-card .alt { text-align: center; margin-top: 18px; }
#licenseCode { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 2px; text-transform: uppercase; }

/* ---- 頂部列 ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 18px; margin-right: auto; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--text); }
.topbar nav a.active { background: #e6eefb; color: var(--primary); font-weight: 600; }
.topbar .who { color: var(--muted); font-size: 15px; }
.topbar button { min-height: 36px; padding: 4px 14px; font-size: 15px; }

/* ---- 主控台：左 2/3 鏡頭、右 1/3 數據、下方控制列 ---- */
.console {
  display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr auto;
  gap: 12px; padding: 12px; height: calc(100vh - 57px); min-height: 520px;
}
.stage {
  position: relative; background: var(--video-bg); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 0;
}
.stage canvas { max-width: 100%; max-height: 100%; display: block; }
.stage video { display: none; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  color: #fff; font-size: 34px; font-weight: 700; pointer-events: none;
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
}
.overlay.dim { background: rgba(14, 19, 25, .72); pointer-events: auto; }
.overlay .detail { font-size: 19px; font-weight: 400; max-width: 560px; margin-top: 12px; line-height: 1.6; }
.overlay button { margin-top: 20px; }
.stage-status {
  position: absolute; left: 10px; bottom: 8px; color: #cfd6de; font-size: 13px;
  background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 4px;
}
.stage-notice {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--warn-bg); color: #6b4e00; padding: 6px 14px; border-radius: 6px; font-size: 15px;
}

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 0;
}
.metric { border-bottom: 1px solid #edf0f3; padding: 4px 0 6px; }
.metric:last-child { border-bottom: 0; }
.metric .label { color: var(--muted); font-size: 16px; display: flex; justify-content: space-between; }
.metric .value { font-size: 36px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.metric .value small { font-size: 18px; font-weight: 500; color: var(--muted); margin-left: 4px; }
/* 規格：次數與動作判定至少 48px */
.metric.big .value { font-size: 64px; }
.metric.pose .value { font-size: 48px; }
.metric .side { font-size: 14px; color: var(--muted); }
.metric .value.na { color: #a3adb7; }
.angle-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.angle-name { font-size: 16px; color: var(--muted); }
.metric.angles .value { font-size: 34px; }

.controls {
  grid-column: 1 / -1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.controls .group { display: flex; align-items: center; gap: 8px; }
.controls label { margin: 0; font-weight: 600; white-space: nowrap; }
.controls select { width: auto; min-width: 150px; }
.controls input[type=range] { width: 180px; padding: 0; }
.controls .spacer { flex: 1; }

@media (max-width: 900px) {
  .console { grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; }
  .stage { aspect-ratio: 4 / 3; }
  .metric.big .value { font-size: 56px; }
}
