:root {
  --bg: #0f172a;
  --panel: #1b2a4a;
  --line: #2f4269;
  --text: #f1f5f9;
  --muted: #9fb0cc;
  --pass: #15803d;
  --pass-bright: #22c55e;
  --fail: #b91c1c;
  --fail-bright: #ef4444;
  --accent: #3b82f6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* 標題列 */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 19px; letter-spacing: .5px; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 15px;
  font-family: inherit;
}

/* 步驟 */
main { flex: 1; padding: 16px; overflow-y: auto; }

.steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 12px; }

.step {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  opacity: .55;
}
.step.current { opacity: 1; border-color: var(--accent); }
.step.done { opacity: 1; border-color: var(--pass-bright); }

.step-head { display: flex; align-items: center; gap: 10px; }

.num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
}
.step.done .num { background: var(--pass-bright); color: #06220f; }
.step .label { font-size: 16px; font-weight: 600; }

.value {
  margin-top: 10px;
  font-size: 20px;
  font-weight: 700;
  word-break: break-all;
  min-height: 26px;
}
.step:not(.done) .value { color: var(--muted); font-weight: 400; font-size: 16px; }

.meta { margin-top: 6px; font-size: 13px; color: var(--muted); word-break: break-all; }

/* 輸入 */
.manual { display: block; margin-bottom: 16px; }
.manual span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#scan-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 17px;
  font-family: inherit;
  color: var(--text);
  background: #16233f;
  border: 1px solid var(--line);
  border-radius: 10px;
}
#scan-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.actions { display: flex; gap: 10px; }
.ghost, .primary {
  flex: 1;
  padding: 14px;
  font-size: 16px;
  font-family: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}
.primary { background: #ffffff; color: #111827; border: none; font-weight: 700; }

/* 結果橫幅（與掃描步驟同頁） */
.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 20px;
  margin-bottom: 18px;
  border-radius: 14px;
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--line);
  transition: background-color .12s linear, border-color .12s linear;
}
.result.idle { background: var(--panel); }
.result.pass { background: var(--pass); border-color: var(--pass-bright); }
.result.fail { background: var(--fail); border-color: var(--fail-bright); }

.verdict { font-size: 19vw; line-height: 1.05; font-weight: 900; letter-spacing: 3px; }
.result.idle .verdict { font-size: 30px; color: var(--muted); letter-spacing: 1px; }
.verdict-sub { font-size: 19px; font-weight: 600; }
.result.idle .verdict-sub { font-size: 15px; color: var(--muted); font-weight: 400; }

.detail {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  background: rgba(0, 0, 0, .22);
  border-radius: 10px;
  overflow: hidden;
}
.detail td { padding: 9px 12px; border-bottom: 1px solid rgba(255, 255, 255, .16); text-align: left; word-break: break-all; }
.detail tr:last-child td { border-bottom: none; }
.detail td.k { width: 108px; color: rgba(255, 255, 255, .8); }
.detail td.bad { font-weight: 700; }

.warnings { font-size: 13px; color: rgba(255, 255, 255, .9); line-height: 1.6; }
.warnings:empty { display: none; }

/* 面板 */
.panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  overflow-y: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 19px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 16px;
}
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }
.num-row { justify-content: space-between; }
.num-row input {
  width: 84px; padding: 8px; font-size: 16px; font-family: inherit;
  color: var(--text); background: #16233f;
  border: 1px solid var(--line); border-radius: 8px;
}
.hint { font-size: 13px; color: var(--muted); line-height: 1.7; }

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.tag { padding: 3px 10px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.tag.pass { background: var(--pass-bright); color: #06220f; }
.tag.fail { background: var(--fail-bright); color: #2b0606; }
.history-list .sn { flex: 1; word-break: break-all; }
.history-list .time { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 16px 4px; }

@media (min-width: 520px) {
  .verdict { font-size: 104px; }
  .result.idle .verdict { font-size: 34px; }
}

.group {
  margin: 22px 0 2px;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: .5px;
}
.group:first-of-type { margin-top: 6px; }
.num-row input[type="text"] { width: 150px; }

.bar-actions { display: flex; align-items: center; gap: 8px; }

/* 相機掃描 */
.wide { width: 100%; flex: none; }
.camera-btn { margin-bottom: 14px; padding: 16px; font-size: 17px; }

.camera {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
}
.camera video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 取景框：中央方框，四周壓暗 */
.cam-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(72vw, 320px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, .95);
  border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5);
}

.cam-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, .65), transparent);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}
.cam-top .icon-btn { color: #fff; border-color: rgba(255, 255, 255, .5); }

.cam-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(28px + env(safe-area-inset-bottom));
  text-align: center;
  color: #fff;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.5;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
  padding: 0 24px;
}
