:root {
  color-scheme: light dark;
  --bg: #f3f7f6;
  --surface: #ffffff;
  --text: #14312f;
  --muted: #647b78;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d7f1ee;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --border: #d8e4e2;
  --shadow: 0 10px 30px rgba(21, 55, 51, 0.10);
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #dff5f2 0, var(--bg) 360px);
  color: var(--text);
}
button, select, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.app-header {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.eyebrow { margin: 0 0 2px; color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.55rem, 5vw, 2.15rem); }
h2 { margin: 0 0 12px; font-size: 1.05rem; }

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 10px 16px calc(40px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
.card, .counter-card, .camera-card {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.counter-card {
  padding: 20px;
  text-align: center;
  background: linear-gradient(145deg, #ffffff, #ecfaf8);
}
.counter-label { color: var(--muted); font-weight: 700; }
.counter-number { font-size: clamp(4rem, 20vw, 7.5rem); line-height: 1; font-weight: 900; letter-spacing: -.06em; margin: 4px 0 12px; }
.status-pill {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 750;
  background: #e9efee;
  color: var(--muted);
}
.status-pill.ready { background: var(--accent-soft); color: var(--accent-strong); }
.status-pill.raised { background: #fff1c2; color: #7a4e00; transform: scale(1.04); }
.status-pill.error { background: var(--danger-soft); color: var(--danger); }
.subcounts {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.subcounts div { background: rgba(255,255,255,.72); border: 1px solid var(--border); border-radius: 14px; padding: 10px; }
.subcounts span { display: block; color: var(--muted); font-size: .85rem; }
.subcounts strong { font-size: 1.5rem; }

.camera-card { overflow: hidden; }
.camera-wrap {
  position: relative;
  min-height: 280px;
  aspect-ratio: 3 / 4;
  background: #13201f;
  overflow: hidden;
}
video, canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
canvas { pointer-events: none; }
.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: #e7f6f4;
  padding: 22px;
  background: linear-gradient(160deg, #1b3431, #0e1c1a);
}
.camera-placeholder p { max-width: 290px; margin: 0; color: #bdd0cd; }
.hand-icon { font-size: 4.2rem; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }

button {
  min-height: 46px;
  border-radius: 13px;
  padding: 10px 14px;
  border: 1px solid transparent;
  font-weight: 800;
}
.primary { background: var(--accent); color: white; }
.primary:hover { background: var(--accent-strong); }
.secondary { background: #edf5f4; color: var(--text); border-color: var(--border); }
.ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.danger { background: var(--danger-soft); color: var(--danger); border-color: #f9c8c3; }
.hidden { display: none !important; }

.quick-actions, .settings-card, .history-card, .tips { padding: 16px; }
.button-grid { display: grid; grid-template-columns: .8fr 1.2fr 1fr; gap: 8px; }
details summary { font-weight: 850; cursor: pointer; }
.setting-list { display: grid; gap: 16px; padding-top: 18px; }
.setting-list label { display: grid; gap: 8px; color: var(--muted); font-size: .93rem; }
.setting-list select { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.setting-list input[type="range"] { width: 100%; accent-color: var(--accent); }
.toggle-row { grid-template-columns: 1fr auto !important; align-items: center; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--accent); }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin-bottom: 3px; }
.section-heading p { margin: 0; color: var(--muted); font-size: .85rem; }
.history-list { margin: 14px 0 0; padding-left: 24px; max-height: 260px; overflow: auto; }
.history-list li { padding: 9px 5px; border-bottom: 1px dashed var(--border); }
.history-list li:last-child { border-bottom: 0; }
.history-empty { list-style: none; margin-left: -24px; color: var(--muted); }
.event-meta { color: var(--muted); font-size: .82rem; margin-left: 6px; }
.tips p { margin: 8px 0; color: var(--muted); line-height: 1.65; }
.privacy-note { font-size: .88rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: #102523;
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: .22s ease;
  z-index: 30;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  main { grid-template-columns: 1fr 1fr; align-items: start; }
  .counter-card, .camera-card { grid-column: span 1; }
  .camera-wrap { aspect-ratio: 4 / 5; }
  .history-card, .tips { grid-column: span 2; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #091513;
    --surface: #10201e;
    --text: #e9f5f3;
    --muted: #9ab2ae;
    --accent: #45c2b5;
    --accent-strong: #71d8ce;
    --accent-soft: #143c38;
    --border: #27413e;
    --danger-soft: #3a1f1c;
    --shadow: 0 12px 32px rgba(0,0,0,.28);
  }
  body { background: radial-gradient(circle at top, #143b36 0, var(--bg) 380px); }
  .counter-card { background: linear-gradient(145deg, #142b28, #0e1c1a); }
  .subcounts div { background: rgba(255,255,255,.03); }
  .secondary { background: #162b28; }
}
