:root {
  --green: #0F7B5F;
  --green-dark: #0B5E49;
  --teal: #14B8A6;
  --teal-soft: #CCF3EE;
  --white: #FFFFFF;
  --bg: #F3FAF8;
  --ink: #0B2B26;
  --grey: #6B7C79;
  --line: #E1EEEA;
  --danger: #B42318;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(11, 43, 38, .04), 0 8px 24px rgba(15, 123, 95, .08);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
[hidden] { display: none !important; }
h1 { font-size: 28px; line-height: 1.15; margin: 4px 0 6px; letter-spacing: -.02em; }
h2 { font-size: 22px; margin: 18px 0 6px; letter-spacing: -.01em; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--grey); margin: 22px 4px 8px; }
.lead { color: var(--grey); margin: 0 0 18px; }
.muted { color: var(--grey); }
.small { font-size: 13px; }
.note { color: var(--grey); font-size: 13px; margin: 10px 4px 0; }

.shell { max-width: 480px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- header */
.top {
  position: sticky; top: 0; z-index: 5;
  background: rgba(243, 250, 248, .92); backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 20px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 10px; }
.wordmark { font-weight: 800; font-size: 22px; letter-spacing: -.02em; color: var(--green-dark); }
.stepper { list-style: none; display: flex; gap: 6px; margin: 12px 0 0; padding: 0; }
.stepper li { flex: 1; display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--grey); font-weight: 600; }
.stepper i { display: block; height: 5px; border-radius: 99px; background: var(--line); transition: background .3s; }
.stepper li.done i { background: var(--teal); }
.stepper li.now i { background: var(--green); }
.stepper li.now { color: var(--green-dark); }

/* ---------------------------------------------------------------- screens */
main { flex: 1; padding: 8px 20px 0; }
.screen { display: none; padding-bottom: calc(120px + var(--safe-b)); animation: rise .35s ease both; }
.screen.active { display: block; }
.screen.center { text-align: center; padding-top: 8vh; }
@keyframes rise { from { transform: translateY(8px); } to { transform: none; } }

.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }

/* size inputs */
.field + .field { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.field label { display: block; font-weight: 700; margin-bottom: 8px; }
.stepper-input { display: flex; align-items: center; gap: 12px; }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: 0; flex: none;
  background: var(--teal-soft); color: var(--green-dark); font-size: 26px; font-weight: 600; cursor: pointer;
}
.round:active { transform: scale(.94); }
.num { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.num input {
  width: 100%; max-width: 140px; text-align: center; border: 0; background: transparent; color: var(--ink);
  font-family: inherit; font-weight: 700; font-size: 40px; line-height: 1; letter-spacing: -.02em; padding: 0; -moz-appearance: textfield;
}
.num input::-webkit-outer-spin-button, .num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num input:focus { outline: none; }
.num span { color: var(--grey); font-weight: 600; }

.plan-card { display: flex; align-items: center; gap: 16px; }
.plan-card svg { width: 112px; height: 112px; flex: none; }
.plan-text { display: flex; flex-direction: column; gap: 2px; color: var(--grey); }
.plan-text strong { color: var(--ink); font-size: 20px; }

.link { display: block; margin: 6px auto 0; background: none; border: 0; color: var(--green); font-family: inherit; font-weight: 600; font-size: 16px; padding: 12px; cursor: pointer; }

/* ---------------------------------------------------------------- busy */
.spinner { width: 56px; height: 56px; margin: 0 auto; border-radius: 50%; border: 5px solid var(--teal-soft); border-top-color: var(--teal); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- scanning */
.lane-head { display: flex; justify-content: space-between; align-items: center; margin: 6px 0 4px; }
.pill { display: inline-block; padding: 6px 12px; border-radius: 99px; background: var(--green); color: #fff; font-weight: 700; font-size: 14px; }
.pill.soft { background: var(--teal-soft); color: var(--green-dark); }
.pill.on-dark { background: rgba(255, 255, 255, .18); color: #fff; margin-top: 12px; }
.ring-wrap { position: relative; width: min(72vw, 270px); aspect-ratio: 1; margin: 12px auto 4px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 14; }
.ring-bg { stroke: var(--teal-soft); }
.ring-fg { stroke: var(--teal); stroke-linecap: round; stroke-dasharray: 553; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.big { font-size: 76px; font-weight: 800; letter-spacing: -.04em; line-height: 1; color: var(--green-dark); font-variant-numeric: tabular-nums; }
.ring-center .muted { font-size: 14px; max-width: 150px; text-align: center; }
.cue { text-align: center; font-weight: 700; font-size: 19px; margin: 10px 0 14px; }
.mini { display: flex; gap: 14px; align-items: center; padding: 12px; }
.mini svg { width: 92px; height: 92px; flex: none; }
.mini-side { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.mini-side img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 12px; background: var(--line); }

/* ---------------------------------------------------------------- confirm / detect */
.badge-ok { width: 76px; height: 76px; margin: 0 auto 6px; border-radius: 50%; background: var(--teal-soft); color: var(--green); display: grid; place-items: center; }
.badge-ok svg { width: 40px; height: 40px; }
.bar { height: 10px; border-radius: 99px; background: var(--teal-soft); overflow: hidden; margin: 18px 10px 0; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--teal)); border-radius: 99px; transition: width .4s ease; }
.scanline { width: 120px; height: 90px; margin: 0 auto; border-radius: 16px; background: var(--white); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.scanline div { position: absolute; left: 0; right: 0; height: 3px; background: var(--teal); box-shadow: 0 0 12px var(--teal); animation: sweep 1.6s ease-in-out infinite alternate; }
@keyframes sweep { from { top: 8px; } to { top: 80px; } }

/* ---------------------------------------------------------------- map */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.map-card { padding: 8px; position: relative; }
#map { width: 100%; display: block; border-radius: 14px; background: #E6F4F0; touch-action: manipulation; }
.robot-hud { position: absolute; left: 18px; right: 18px; bottom: 18px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.robot-hud span { background: rgba(11, 43, 38, .78); color: #fff; padding: 6px 10px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 14px; }
.chip { display: inline-flex; align-items: center; gap: 7px; background: var(--white); border-radius: 99px; padding: 7px 12px 7px 9px; box-shadow: var(--shadow); font-size: 14px; font-weight: 600; }
.chip i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.chip b { color: var(--ink); }
.chip.dashed i { background: transparent !important; border: 2px dashed var(--grey); }
.seg { display: flex; background: var(--white); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); margin: 6px 0 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 10px; font-family: inherit; font-weight: 600; font-size: 15px; color: var(--grey); cursor: pointer; }
.seg button.on { background: var(--green); color: #fff; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat .v { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.stat .k { color: var(--grey); font-size: 13px; }
.stat .d { font-size: 13px; font-weight: 700; color: var(--green); }
.stat .d.worse { color: var(--grey); }

/* ---------------------------------------------------------------- report */
.hero { background: linear-gradient(135deg, var(--green), var(--teal)); color: #fff; border-radius: 24px; padding: 26px 20px; text-align: center; box-shadow: var(--shadow); margin: 6px 0 14px; }
.hero-num { font-size: 72px; font-weight: 800; line-height: 1; letter-spacing: -.04em; }
.hero-text { font-size: 18px; opacity: .95; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .card { margin: 0; padding: 14px 16px; }
.list { padding: 4px 18px; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row i { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.row span { flex: 1; }
.row b { font-variant-numeric: tabular-nums; }
.row small { color: var(--grey); }

/* ---------------------------------------------------------------- actions */
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 14px 20px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, rgba(243, 250, 248, 0));
  display: flex; flex-direction: column; gap: 8px; max-width: 480px; margin: 0 auto;
}
/* while scanning, Stop stays reachable above the countdown and turn screens */
body.scanning .actions { z-index: 25; background: none; }
.btn {
  width: 100%; height: 56px; border-radius: 16px; border: 0; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 18px; letter-spacing: -.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--green); color: #fff; box-shadow: 0 8px 20px rgba(15, 123, 95, .28); }
.btn.secondary { background: var(--white); color: var(--green-dark); box-shadow: inset 0 0 0 2px var(--line); }
.btn.stop { background: var(--white); color: var(--danger); box-shadow: inset 0 0 0 2px #F5D0CC; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 22px; height: 22px; }

/* ---------------------------------------------------------------- overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 30px; }
.countdown { background: linear-gradient(160deg, var(--green), var(--teal)); }
.countdown div { font-size: 160px; font-weight: 800; line-height: 1; animation: pop .9s ease both; }
.countdown p { font-size: 20px; font-weight: 600; opacity: .9; }
.turn { background: var(--teal); }
.turn svg { width: 140px; height: 140px; }
.turn svg.left { transform: scaleX(-1); }
.turn-title { font-size: 46px; font-weight: 800; letter-spacing: -.02em; margin-top: 10px; }
.turn p { font-size: 19px; font-weight: 600; max-width: 300px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

.scrim { position: fixed; inset: 0; background: rgba(11, 43, 38, .4); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 480px; margin: 0 auto;
  background: var(--white); border-radius: 24px 24px 0 0; padding: 10px 20px calc(20px + var(--safe-b));
  max-height: 82vh; overflow: auto; animation: up .25s ease both;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.grab { width: 42px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 14px; }
.detail-img { position: relative; border-radius: 14px; overflow: hidden; background: var(--line); }
.detail-img img { width: 100%; display: block; }
.detail-img svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.detail-head { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; }
.detail-head i { width: 14px; height: 14px; border-radius: 50%; }
.detail-head h2 { margin: 0; }
.scan-item { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; padding: 14px 4px; border: 0; background: none; border-top: 1px solid var(--line); font: inherit; color: inherit; cursor: pointer; }
.scan-item:first-of-type { border-top: 0; }
.scan-item .ico { width: 42px; height: 42px; border-radius: 12px; background: var(--teal-soft); display: grid; place-items: center; color: var(--green); flex: none; }
.scan-item span { flex: 1; display: flex; flex-direction: column; }
.scan-item small { color: var(--grey); }

.toast {
  position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 12px); z-index: 40;
  max-width: 448px; margin: 0 auto; background: var(--ink); color: #fff; border-radius: 16px; padding: 14px 16px;
  font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); animation: up .25s ease both;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
