:root {
  color-scheme: light;
  --ink: #142520;
  --ink-soft: #4a5a54;
  --muted: #6b7a74;
  --green: #0d5a40;
  --green-soft: #dcefe6;
  --bg: #f3f6f4;
  --card: #ffffff;
  --line: #dfe6e2;
  --clear: #e0362c;
  --possible: #f0a020;
  --mud: #47769d;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: Inter, "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}
html[lang="th"] { font-family: "IBM Plex Sans Thai", Inter, system-ui, sans-serif; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 18px 0 6px; }
h2 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--clear); font-weight: 500; }

#app { min-height: 100%; max-width: 560px; margin: 0 auto; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* Passcode */
.lock { align-items: center; justify-content: center; text-align: center; padding: 24px 24px calc(24px + var(--safe-b)); gap: 4px; }
.lock-logo { width: 132px; height: 132px; }
.lock p { margin: 0 0 18px; max-width: 300px; line-height: 1.5; }
#lock-form { width: 100%; max-width: 320px; display: grid; gap: 12px; }
#lock-form input { font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); text-align: center; letter-spacing: .1em; }
#lock-form input:focus { outline: none; border-color: var(--green); }
.lock-lang { margin-top: 18px; }

/* Header + tabs */
.top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 5; }
.top img { width: 40px; height: 40px; background: #fff; border-radius: 10px; padding: 3px; }
.top-title { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.top-title strong { letter-spacing: .08em; font-size: 15px; }
.top-title span { font-size: 12px; color: #b9c6c0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang-switch { border: 1.5px solid currentColor; background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 36px; cursor: pointer; }
.lock .lang-switch { color: var(--ink-soft); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 12px 16px 0; padding: 4px; background: #e6ece9; border-radius: 12px; }
.tabs button { border: 0; background: transparent; border-radius: 9px; padding: 10px 6px; font-weight: 600; font-size: 14px; color: var(--ink-soft); min-height: 44px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 37, 32, .12); }
.tabs.locked button:not([aria-selected="true"]) { opacity: .45; }

#stage { flex: 1; padding: 14px 16px calc(110px + var(--safe-b)); }
.lead { margin: 0 0 14px; color: var(--ink-soft); line-height: 1.5; }

/* Photo slots */
.slots { display: grid; gap: 12px; }
.slots.two { grid-template-columns: 1fr 1fr; }
.slot { position: relative; border: 2px dashed #b9c6c0; border-radius: var(--radius); background: var(--card); aspect-ratio: 4 / 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--ink-soft); overflow: hidden; padding: 10px; text-align: center; cursor: pointer; }
.slots.two .slot { aspect-ratio: 3 / 4; }
.slot.filled { border-style: solid; border-color: transparent; padding: 0; }
.slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slot .slot-label { position: absolute; left: 8px; top: 8px; background: rgba(20, 37, 32, .82); color: #fff; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; z-index: 1; }
.slot .slot-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; }
.slot .slot-text { font-weight: 600; font-size: 15px; color: var(--ink); }
.slot .slot-sub { font-size: 12px; }
.slot-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; width: 100%; max-width: 280px; }
.slots.two .slot-actions { grid-template-columns: 1fr; }
.chip-btn { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 8px; font-size: 14px; font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; }
.chip-btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.slot-retake { position: absolute; right: 8px; bottom: 8px; z-index: 1; border: 0; background: rgba(255, 255, 255, .92); border-radius: 999px; padding: 8px 12px; font-size: 13px; font-weight: 600; min-height: 36px; }

/* Samples */
.samples { margin-top: 22px; }
.sample-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.sample { flex: 0 0 148px; scroll-snap-align: start; border: 0; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; text-align: left; box-shadow: 0 1px 3px rgba(20, 37, 32, .1); cursor: pointer; }
.sample .thumbs { display: flex; height: 96px; }
.sample .thumbs img { flex: 1; min-width: 0; height: 100%; object-fit: cover; }
.sample .thumbs img + img { border-left: 2px solid #fff; }
.sample span { display: block; padding: 8px 10px 10px; font-size: 13px; font-weight: 600; line-height: 1.3; }

/* Photo view */
.flip { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: #e6ece9; border-radius: 12px; margin-bottom: 10px; }
.flip button { border: 0; background: transparent; border-radius: 9px; padding: 8px; font-weight: 600; font-size: 14px; min-height: 40px; color: var(--ink-soft); }
.flip button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 37, 32, .12); }
.photo-frame { position: relative; border-radius: var(--radius); overflow: hidden; background: #0d1714; touch-action: none; }
.zoom { position: relative; transform-origin: 0 0; will-change: transform; }
.zoom img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
#boxes { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#boxes rect { fill: transparent; stroke-width: 3; vector-effect: non-scaling-stroke; transition: stroke-width .15s, fill .15s; }
#boxes rect.clear { stroke: var(--clear); }
#boxes rect.possible { stroke: var(--possible); stroke-dasharray: 7 5; }
#boxes rect.mud { stroke: var(--mud); stroke-dasharray: 3 4; }
#boxes rect.halo { stroke: rgba(255, 255, 255, .85); stroke-width: 5; stroke-dasharray: none; }
#boxes rect.active { stroke-width: 5; fill: rgba(255, 255, 255, .12); }
.badges { position: absolute; inset: 0; pointer-events: none; }
.badge { position: absolute; transform: translate(-50%, -50%) scale(var(--inv, 1)); width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center; pointer-events: auto; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); padding: 0; }
.badge.clear { background: var(--clear); }
.badge.possible { background: var(--possible); color: #1d1300; }
.badge.mud { background: var(--mud); }
.badge.active { transform: translate(-50%, -50%) scale(calc(var(--inv, 1) * 1.25)); }
.hide-boxes #boxes, .hide-boxes .badges { display: none; }
.zoom-hint { position: absolute; right: 8px; bottom: 8px; margin: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 12px; padding: 4px 10px; border-radius: 999px; pointer-events: none; }

.scan { position: absolute; inset: 0; background: rgba(13, 90, 64, .18); overflow: hidden; pointer-events: none; }
.scan::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255, 255, 255, .12) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .12) 1px, transparent 1px); background-size: 28px 28px; }
.scan-line { position: absolute; left: 0; right: 0; height: 90px; top: -90px; background: linear-gradient(to bottom, transparent, rgba(110, 231, 183, .55) 85%, #6ee7b7); animation: sweep 2.2s ease-in-out infinite; }
@keyframes sweep { 0% { top: -90px; } 100% { top: 100%; } }
@media (prefers-reduced-motion: reduce) { .scan-line { animation: none; top: 40%; } }

.checking { margin-top: 14px; }
.progress { height: 6px; background: #e1e8e4; border-radius: 999px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--green); border-radius: 999px; transition: width .4s linear; }
.checking p { margin: 10px 0 0; font-size: 14px; min-height: 1.5em; }

/* Result */
.result { margin-top: 14px; }
.verdict { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-size: 14px; font-weight: 600; background: var(--card); border: 1.5px solid var(--line); }
.pill i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.pill.ok { background: var(--green-soft); border-color: transparent; color: var(--green); }
.pill.warn { background: #fff4e0; border-color: transparent; color: #7a4b00; }
.summary { margin: 12px 0 14px; line-height: 1.55; color: var(--ink-soft); }
.findings { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.finding { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; background: var(--card); border-radius: 14px; padding: 12px; border: 1.5px solid transparent; box-shadow: 0 1px 3px rgba(20, 37, 32, .08); cursor: pointer; }
.finding.active { border-color: var(--ink); }
.finding .num { width: 30px; height: 30px; border-radius: 50%; color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px; }
.finding .num.clear { background: var(--clear); }
.finding .num.possible { background: var(--possible); color: #1d1300; }
.finding .num.mud { background: var(--mud); }
.finding h3 { margin: 2px 0 4px; font-size: 16px; }
.finding p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--ink-soft); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: #eef2f0; color: var(--ink-soft); }
.tag.sev-moderate { background: #ffe9d6; color: #8a3b00; }
.tag.sev-severe { background: #fde2e1; color: #9b1c14; }
.tag.cert-possible { background: #fff4e0; color: #7a4b00; }
.meta { margin: 16px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.banner { background: #fde8e7; padding: 12px 14px; border-radius: 12px; margin-top: 12px; }

/* Bottom bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(to top, var(--bg) 70%, rgba(243, 246, 244, 0)); display: flex; gap: 10px; max-width: 560px; margin: 0 auto; }
.bar:empty { display: none; }
.btn { flex: 1; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px 16px; font-size: 16px; font-weight: 600; min-height: 52px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn:disabled { opacity: .45; cursor: default; }

/* Detail sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 17, .45); z-index: 9; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 20px calc(18px + var(--safe-b)); box-shadow: 0 -8px 30px rgba(0, 0, 0, .2); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 6px; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.sheet .num { width: 32px; height: 32px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 15px; flex: none; }
.sheet .num.clear { background: var(--clear); }
.sheet .num.possible { background: var(--possible); color: #1d1300; }
.sheet .num.mud { background: var(--mud); }
.sheet .crop { width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; background: #0d1714 no-repeat; margin: 10px 0 12px; }
.sheet p { margin: 0 0 6px; line-height: 1.5; }
.sheet .other-lang { color: var(--muted); font-size: 14px; }
.sheet .btn { width: 100%; margin-top: 14px; }

@media (min-width: 600px) {
  #stage { padding-top: 18px; }
}
