:root {
  --bg-pure: #FFFFFF;
  --bg-soft: #FBF9F4;
  --bg-accent: #F2EDE4;
  --text-main: #5C524A;
  --text-muted: #8E8279;
  --primary: #8E7D70;
  --primary-light: #A89584;
  --accent: #B08D65;
  --accent-soft: rgba(176, 141, 101, 0.12);
  --white: #FFFFFF;
  --danger: #C45C4A;
  --ok: #5A8F6B;
  --warn: #C4A35A;
  --high: #C45C4A;
  --overlay: rgba(45, 38, 32, 0.72);
  --radius: 16px;
  --shadow: 0 12px 36px rgba(114, 97, 84, 0.12);
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--text-main);
  background: var(--bg-soft);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-height: 100vh;
  overflow: hidden;
  background: #1a1612;
}

/* Camera stage */
.stage {
  position: absolute;
  inset: 0;
  background: #0d0b09;
}

#webcam {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#outputCanvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Screens / panels */
.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(251, 249, 244, 0.92) 0%, rgba(242, 237, 228, 0.97) 45%, #F2EDE4 100%);
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

.screen-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.35rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(176, 141, 101, 0.18);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 0.35rem;
  line-height: 1.2;
}

.brand span {
  color: var(--accent);
}

.eyebrow {
  display: inline-block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.lead {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.notice {
  background: var(--accent-soft);
  border: 1px solid rgba(176, 141, 101, 0.28);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-main);
  margin-bottom: 1rem;
}

.notice strong {
  color: var(--primary);
}

.notice ul {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
}

.notice li {
  margin-bottom: 0.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
  min-height: 52px;
  padding: 0.85rem 1.1rem;
  border: none;
  border-radius: 14px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
}

.btn-secondary {
  background: var(--bg-accent);
  color: var(--text-main);
  border: 1px solid rgba(142, 125, 112, 0.25);
  margin-top: 0.6rem;
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(142, 125, 112, 0.3);
  margin-top: 0.6rem;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-muted);
  margin: 0.85rem 0 1rem;
}

.check-row input {
  margin-top: 0.15rem;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* HUD overlay during scan */
.hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.75rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

.hud > * {
  pointer-events: auto;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.hud-chip {
  background: rgba(251, 249, 244, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(176, 141, 101, 0.35);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.hud-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.hud-chip.ready .dot {
  background: var(--ok);
}

.hud-chip.error .dot {
  background: var(--danger);
}

.hud-bottom {
  background: rgba(251, 249, 244, 0.94);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(176, 141, 101, 0.3);
  border-radius: 18px;
  padding: 0.65rem 0.85rem 0.75rem;
  box-shadow: var(--shadow);
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  max-height: min(34vh, 280px);
  overflow: hidden;
}

.hud-bottom.compact {
  max-height: none;
}

.step-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.step-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin: 0 0 0.2rem;
  color: var(--text-main);
  line-height: 1.2;
}

.step-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.progress-bar {
  height: 5px;
  background: var(--bg-accent);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 0.55rem;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-light), var(--accent));
  transition: width 0.15s linear;
}

.zone-grid {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 0.15rem;
}

.zone-grid::-webkit-scrollbar {
  display: none;
}

.zone-btn {
  flex: 0 0 auto;
  min-width: 118px;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid rgba(142, 125, 112, 0.25);
  background: var(--white);
  color: var(--text-main);
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.zone-btn strong {
  font-size: 0.78rem;
}

.zone-btn span {
  font-size: 0.62rem;
  color: var(--text-muted);
  line-height: 1.25;
}

.zone-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.zone-btn.done {
  opacity: 0.72;
}

.zone-btn.done::after {
  content: " ✓";
  color: var(--ok);
}

.brand-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.brand-pill {
  flex: 1;
  min-width: 68px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(142, 125, 112, 0.3);
  background: var(--white);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.brand-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.legend {
  display: flex;
  gap: 0.55rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  font-size: 0.62rem;
  color: var(--text-muted);
  scrollbar-width: none;
  min-width: 0;
}

.legend::-webkit-scrollbar {
  display: none;
}

.intensity-row {
  margin-bottom: 0.65rem;
}

.intensity-row label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text-main);
}

.intensity-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.intensity-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.dose-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.dose-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
}

.legend i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.25rem;
}

.legend .low {
  background: var(--ok);
}
.legend .mid {
  background: var(--warn);
}
.legend .high {
  background: var(--high);
}

.actions-row {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.actions-row .btn {
  flex: 1;
  min-height: 48px;
  font-size: 0.9rem;
  margin-top: 0;
}

.actions-row .btn-secondary {
  min-height: 42px;
  font-size: 0.82rem;
}

.live-tier {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.45rem;
  background: var(--bg-accent);
  color: var(--text-main);
}

.live-tier.tier-low {
  background: rgba(90, 143, 107, 0.18);
  color: #3d6b4a;
}

.live-tier.tier-mid {
  background: rgba(196, 163, 90, 0.22);
  color: #8a6d2e;
}

.live-tier.tier-high {
  background: rgba(196, 92, 74, 0.18);
  color: #9a3f32;
}

.micro {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0.4rem 0 0;
  line-height: 1.3;
}

/* Lead form */
.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-main);
}

.form-group input {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(142, 125, 112, 0.3);
  padding: 0.7rem 0.9rem;
  background: var(--bg-soft);
  color: var(--text-main);
}

.form-group input:focus {
  outline: 2px solid rgba(176, 141, 101, 0.45);
  border-color: var(--accent);
}

.summary-box {
  background: var(--bg-accent);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font-size: 0.8rem;
  margin-bottom: 0.85rem;
  line-height: 1.45;
}

.summary-box strong {
  color: var(--primary);
}

.points-list {
  margin: 0.4rem 0 0.55rem;
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.75rem;
  line-height: 1.45;
  padding: 0.45rem 0.55rem;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 8px;
}

.camera-error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(26, 22, 18, 0.92);
  color: #fff;
  text-align: center;
}

.camera-error h3 {
  font-family: var(--font-display);
  margin: 0 0 0.5rem;
}

.camera-error p {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.face-guide {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  width: min(72vw, 280px);
  aspect-ratio: 3 / 4;
  border: 3px dashed rgba(240, 220, 180, 0.95);
  box-shadow: 0 0 0 1px rgba(45, 38, 32, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  border-radius: 50% / 42%;
  pointer-events: none;
  z-index: 25;
  opacity: 1;
}

@media (min-width: 768px) {
  .screen {
    justify-content: center;
  }

  .hud-bottom {
    margin-bottom: 1rem;
    max-height: min(32vh, 300px);
  }

  .face-guide {
    top: 38%;
  }
}
