:root {
  --ink: #1c1914;
  --muted: #5f584e;
  --paper: #f4efe4;
  --card: #fffdf8;
  --line: #e3d8c6;
  --header: #1b2e26;
  --gold: #8d6a2f;
  --pass: #0c7a34;
  --fail: #c4232a;
  --warn: #8a5a10;
  --shadow: 0 12px 28px rgba(48, 36, 16, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "WenQuanYi Micro Hei", sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.7), transparent 42%),
    var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.wrap {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 16px 16px 108px;
}
.top {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--header);
  color: #f4efe4;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.brand-name { margin: 0; font-weight: 800; }
.brand-sub { margin: 0; color: var(--muted); font-size: 13px; }
h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 22px; margin: 28px 0 8px; }
h3 { margin: 0 0 6px; font-size: 20px; }
.kicker {
  margin: 0 0 4px;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0.04em;
}
.en, .code-role small { color: var(--muted); font-weight: 600; font-size: 12px; }
.lead { margin: 0 0 14px; }
.section-note, .meta, .fine, .camera-msg { color: var(--muted); }
.mono, .code-text { font-family: ui-monospace, "SFMono-Regular", "Source Code Pro", Menlo, Consolas, monospace; }
.screen { display: flex; flex-direction: column; gap: 12px; }

.steps {
  margin: 0;
  padding: 12px 12px 12px 32px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.steps li { margin: 6px 0; }

.jump, .row, .card-actions, .code-actions, .mini-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn, .bottom-nav button, .code-actions button, .bound-row button, .text-btn, .mini {
  border-radius: 12px;
  border: 1px solid transparent;
  min-height: 48px;
  padding: 10px 14px;
  font-weight: 800;
  background: #fff;
}
.btn-primary { background: var(--header); color: #f6f1e6; }
.btn-pass { background: var(--pass); color: white; }
.btn-fail { background: white; color: var(--fail); border-color: #f0b4b4; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn.light { background: transparent; color: white; border-color: rgba(255,255,255,.7); }
.text-btn, .code-actions button, .mini, .bound-row button {
  min-height: 40px;
  background: transparent;
  border-color: var(--line);
  font-weight: 700;
}
.mini.match { border-color: #b7dfc4; }
.mini.mismatch { border-color: #f0b4b4; color: var(--fail); }

.map, .stack { display: flex; flex-direction: column; gap: 8px; }
.map-row, .bound-row {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.color-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; }
.color-name small { color: var(--muted); font-weight: 650; }
.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  display: inline-block;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.28);
  flex: none;
}
.swatch.dry { background: linear-gradient(90deg, #c4b49a 0 34%, #2f62d6 34% 67%, #f7f4ee 67% 100%); }
.swatch.navy { background: linear-gradient(90deg, #16356f 0 72%, #d5e2f5 72% 100%); }
.swatch.char { background: #2a2a2a; }
.swatch.unknown { background: repeating-linear-gradient(45deg, #ddd, #ddd 4px, #bdb7ae 4px, #bdb7ae 8px); }
h1 .swatch { width: 28px; height: 22px; vertical-align: -3px; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  scroll-margin-top: 12px;
  scroll-margin-bottom: 96px;
}
.card.match { border-color: #8fcea4; }
.card.mismatch { border-color: #f0a8a8; }
.expect { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: 0.04em; }
.card.match .expect { color: var(--pass); }
.card.mismatch .expect { color: var(--fail); }
.card-head p { margin: 0 0 8px; }

.code-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.code-cell {
  background: #fbf7f0;
  border-radius: 12px;
  padding: 8px;
  min-width: 0;
  overflow: hidden;
}
.code-cell .color-name {
  display: flex;
  flex-wrap: wrap;
  max-width: 100%;
  font-size: 13px;
  line-height: 1.25;
}
.code-cell .color-name small {
  flex-basis: 100%;
  font-size: 10px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.code-role { font-size: 13px; font-weight: 800; margin-bottom: 4px; }
.code-role span {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--header);
  color: white;
  font-size: 12px;
}
.code-text { margin: 6px 0; font-size: 12px; word-break: break-all; }
.code-text.xl { font-size: 18px; text-align: center; }
.code-actions { display: flex; flex-direction: column; }
.code-actions button { padding: 8px 4px; font-size: 13px; min-height: 36px; }
.card-actions .btn { flex: 1; }
.qr {
  background: white;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.qr img, .qr canvas { width: 100% !important; height: auto !important; }
.qr.xl { width: min(100%, 320px); margin: 0 auto; padding: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
input {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #d9d0c2;
  padding: 10px 12px;
  background: white;
  font-size: 16px;
}
.slot {
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: white;
}
.slot header { display: flex; gap: 8px; align-items: center; }
.slot header div { flex: 1; }
.slot header button { min-height: 40px; }
.slot.is-active { border-color: var(--header); }
.slot.good { border-color: var(--pass); background: #f3fbf6; }
.slot.bad { border-color: var(--fail); background: #fff6f6; }
.step {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--header);
  color: white;
  font-weight: 800;
}
.chip-row { min-height: 28px; margin: 8px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 750;
  background: #f3efe6;
}
.chip.ok, .chip.good { background: #e5f6ea; color: #0d5c2c; }
.chip.bad { background: #fde8e6; color: #9f1d24; }
.chip.wait { color: var(--muted); }

.equation {
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.eq-item {
  flex: 1;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.eq-item b { font-size: 13px; }
.eq-item small { color: var(--muted); }
.eq-item.good { border-color: var(--pass); }
.eq-item.bad { border-color: var(--fail); background: #fff6f6; }
.plus { align-self: center; font-weight: 800; color: var(--muted); }
.verdict {
  border-radius: 18px;
  padding: 16px;
}
.verdict .big { font-size: 56px; line-height: 1; margin: 0; font-weight: 900; letter-spacing: 0.08em; }
.en-strong { margin: 0; font-weight: 800; letter-spacing: 0.14em; }
.verdict.pass { background: var(--pass); color: white; }
.verdict.fail { background: var(--fail); color: white; }
.verdict.pending { background: #fff6e4; color: var(--warn); border: 2px solid #e7c88a; }
.verdict.empty { background: white; color: var(--muted); border: 2px dashed var(--line); }
.verdict ul { margin: 8px 0; padding-left: 18px; }
.verdict p { margin: 6px 0; }

.banner, .badge {
  border-radius: 14px;
  padding: 12px;
  margin: 0;
}
.banner.good, .badge.good { background: #e7f6ec; color: #0d5c2c; }
.banner.bad, .badge.bad { background: #fdeceb; color: #9f1d24; }
.banner.warn, .badge.warn { background: #fff4df; color: var(--warn); }
.badge { display: inline-block; font-weight: 800; }

.camera-panel { display: flex; flex-direction: column; gap: 8px; }
#reader { border-radius: 12px; overflow: hidden; background: #111; }
#reader:empty { display: none; }
#file-reader { position: absolute; left: -9999px; width: 320px; height: 240px; }
.file-btn input { display: none; }
.note {
  background: #fff;
  border-left: 4px solid var(--gold);
  padding: 10px 12px;
  border-radius: 10px;
}
.note p { margin: 4px 0; }

.search { display: flex; gap: 8px; }
.search input { flex: 1; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.facts div { background: white; border-radius: 12px; padding: 8px 10px; border: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 750; word-break: break-word; }
.photo { margin: 0; }
.photo img { border-radius: 14px; border: 1px solid var(--line); }
.photo figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.bound { display: flex; flex-direction: column; gap: 8px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  margin: 0;
  padding: 0 0 16px 18px;
  border-left: 2px solid #e4d9c8;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pass);
  box-shadow: 0 0 0 3px var(--paper);
}
.timeline li.fail::before { background: var(--fail); }
.timeline li.wait::before { background: #c8b48a; }
.timeline .when { color: var(--muted); font-size: 13px; }
.timeline p { margin: 2px 0; }

.table-wrap { overflow-x: auto; background: white; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); }

.foot { color: var(--muted); font-size: 12px; margin-top: 18px; }
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: #fffdf8;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  min-height: 58px;
}
.bottom-nav button small { display: block; font-weight: 600; font-size: 11px; }
.bottom-nav button.active { color: var(--header); box-shadow: inset 0 3px 0 var(--gold); }

@media (max-width: 380px) {
  h1 { font-size: 24px; }
  .verdict .big { font-size: 44px; }
  .facts { grid-template-columns: 1fr; }
}

/* Hangtag / barcode / guide / print */
.hangtag-thumb, .print-photo {
  margin: 0 0 10px;
}
.hangtag-thumb img, .print-photo img {
  border-radius: 12px;
  border: 1px solid var(--line);
  max-height: 220px;
  width: 100%;
  object-fit: cover;
  object-position: center;
}
.hangtag-thumb figcaption, .print-photo figcaption {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}
.barcode-wrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 4px 2px;
  overflow: hidden;
}
.barcode-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}
.barcode-wrap.xl {
  width: min(100%, 360px);
  margin: 0 auto;
  padding: 12px;
}
.barcode-wrap.wide { padding: 10px; }

.checklist {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.checklist li {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  counter-increment: step;
}
.checklist {
  counter-reset: step;
}
.checklist li::before {
  content: counter(step);
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--header);
  color: #fff;
  font-weight: 800;
  margin-right: 8px;
  vertical-align: middle;
}
.pass-word { color: var(--pass); font-weight: 800; }
.fail-word { color: var(--fail); font-weight: 800; }

.print-sheet {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 16px;
  break-inside: avoid;
  page-break-inside: avoid;
}
.print-codes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.print-cell {
  background: #fbf7f0;
  border-radius: 12px;
  padding: 8px;
  min-width: 0;
}

.bottom-nav {
  grid-template-columns: repeat(5, 1fr);
}
.bottom-nav button {
  font-size: 13px;
  padding: 8px 4px;
  min-height: 58px;
}

@media (max-width: 420px) {
  .print-codes { grid-template-columns: 1fr; }
  .code-grid { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .top, .foot, .bottom-nav, .no-print, .jump.no-print { display: none !important; }
  .wrap { width: 100%; padding: 0; margin: 0; }
  .print-sheet {
    border: 1px solid #999;
    box-shadow: none;
    page-break-after: always;
  }
  .print-sheet:last-child { page-break-after: auto; }
  .barcode-wrap, .qr { break-inside: avoid; }
}
