:root {
  color-scheme: light;
  --ink: #1d2420;
  --muted: #5e675f;
  --paper: #fffdf8;
  --line: #e4d8c4;
  --red: #9d2c2c;
  --green: #2f6b45;
  --shadow: 0 16px 40px rgba(70, 48, 20, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "PingFang HK", "Noto Sans CJK TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(157, 44, 44, 0.08), transparent 28%),
    linear-gradient(180deg, #f7f1e4 0%, #efe4d0 100%);
}

button, input { font: inherit; }

button, .ghost {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  background: var(--ink);
  color: #f6f1e6;
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.top, main, .login {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 0 12px;
}

.brand { display: flex; gap: 16px; align-items: center; }

.mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 2px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  transform: rotate(-8deg);
  background: rgba(255, 253, 248, 0.86);
  font-family: "Songti TC", "PMingLiU", "Noto Serif TC", serif;
  font-size: 32px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--muted);
}

h1, h2 { font-family: "Iowan Old Style", "Palatino Linotype", "Songti TC", "PMingLiU", serif; }

h1 { margin: 0; font-size: 36px; font-weight: 650; }
h2 { margin: 0 0 8px; font-size: 26px; }

.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; }

.login { padding: 24px 0 64px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.stack { display: grid; gap: 14px; }
.stack > label:not(.check):not(.file-btn) { display: grid; gap: 8px; }

.panel[hidden] { display: none; }

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  width: auto;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}

.sr-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 18px;
}

.tabs button { background: transparent; color: var(--ink); border: 1px solid transparent; }
.tabs button.active { background: var(--red); color: white; }

.panel { display: grid; gap: 16px; padding-bottom: 48px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat span { display: block; font-size: 40px; font-family: "Iowan Old Style", Palatino, serif; }
.stat p { margin: 0; color: var(--muted); }

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

#scan-image, .thumb {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 12px;
  background: #1d2420;
}

body.camera-open { overflow: hidden; }

.camera-stage[hidden] { display: none; }

.camera-stage {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #111;
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #111;
}

.camera-hint {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  margin: 0;
  color: #f6f1e6;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.65);
}

.camera-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.62));
}

.camera-bar .ghost {
  min-height: 56px;
  min-width: 96px;
  color: #f6f1e6;
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
}

#stage-snap {
  min-height: 56px;
  min-width: 168px;
  background: var(--red);
  color: white;
  font-size: 18px;
}

.thumb { width: 72px; height: 72px; object-fit: cover; background: #efe7d8; }

.list { display: grid; gap: 10px; }
.list article, .person {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.person { align-items: start; }
.people { display: grid; gap: 12px; }
.person-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.matched { color: var(--green); }
.unknown { color: var(--red); }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  margin: 0;
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show { opacity: 1; }

@media (max-width: 720px) {
  h1 { font-size: 30px; }
  .stats { grid-template-columns: 1fr; }
  .top, main, .login { width: min(1040px, calc(100% - 20px)); }
}
