:root {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --text: #1f2a22;
  --muted: #5f6f63;
  --border: #dde5da;
  --primary: #2f7d4f;
  --primary-hover: #276a43;
  --primary-soft: #e3f1e7;
  --good: #2f7d4f;
  --good-soft: #e3f1e7;
  --warn: #a86400;
  --warn-soft: #fff4dd;
  --bad: #b3261e;
  --bad-soft: #fdeceb;
  --info: #1f5fa8;
  --info-soft: #e8f0fb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1b221d;
    --text: #e6ede7;
    --muted: #9aab9e;
    --border: #2c3830;
    --primary: #5cb882;
    --primary-hover: #74c895;
    --primary-soft: #1f3327;
    --good: #5cb882;
    --good-soft: #1f3327;
    --warn: #f0b04a;
    --warn-soft: #362a14;
    --bad: #f2827a;
    --bad-soft: #3a1d1b;
    --info: #7fb2ef;
    --info-soft: #182637;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; margin-top: 1rem; }
ul, ol { padding-left: 1.25rem; margin: .5rem 0; }
li { margin: .3rem 0; }
.small { font-size: .875rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ── Layout ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .6rem 1rem;
}
.brand {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-weight: 700; font-size: 1.1rem; color: var(--primary);
}
main { max-width: 720px; margin: 0 auto; padding: 1rem 1rem 6rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  margin: 1rem 0;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--primary); color: #fff;
  border: 1px solid transparent; border-radius: 999px;
  padding: .65rem 1.2rem; font: inherit; font-weight: 600;
  cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(.98); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover { background: var(--primary-soft); }
.btn-big { width: 100%; padding: 1rem; font-size: 1.1rem; }
.btn-small { padding: .35rem .85rem; font-size: .875rem; }
@media (prefers-color-scheme: dark) { .btn:not(.btn-secondary) { color: #0d1a12; } }

/* ── Home ── */
.hero { text-align: center; padding: 1.5rem .5rem .5rem; }
.hero-emoji { font-size: 3.5rem; }
.hero p { color: var(--muted); max-width: 32rem; margin: .5rem auto 0; }
.dropzone {
  display: grid; gap: .75rem;
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-top: 1.25rem; text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone p { margin: 0; }
@media (pointer: coarse) { .hide-touch { display: none; } }
.privacy { text-align: center; }

/* ── Check view ── */
.preview-card { display: flex; flex-direction: column; align-items: center; gap: .75rem; }
#preview { max-width: 100%; max-height: 320px; border-radius: 10px; object-fit: contain; }

.question { border: 0; padding: 0; margin: 1.25rem 0 0; }
.question legend { font-weight: 600; margin-bottom: .5rem; padding: 0; }
.options { display: flex; flex-wrap: wrap; gap: .5rem; }
.option { position: relative; cursor: pointer; }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option span {
  display: inline-block;
  border: 1px solid var(--border); border-radius: 999px;
  padding: .45rem .9rem; font-size: .925rem;
  background: var(--surface);
  transition: background .1s, border-color .1s;
  user-select: none;
}
.option:hover span { border-color: var(--primary); }
.option input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.option input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.sticky-actions {
  position: sticky; bottom: 0;
  padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* ── Analyzing ── */
.analyzing { text-align: center; padding: 4rem 1rem; }
.spinner {
  width: 56px; height: 56px; margin: 0 auto 1.25rem;
  border: 5px solid var(--primary-soft); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; margin-top: .75rem; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.analyzing .progress { max-width: 320px; margin: 1rem auto 0; }

.model-status {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  width: min(92vw, 420px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .12);
  padding: .6rem .9rem; font-size: .85rem; z-index: 20;
}
.model-status .progress { margin-top: .4rem; }

/* ── Results ── */
.plant-card { display: grid; grid-template-columns: 140px 1fr; gap: 1.1rem; align-items: start; }
@media (max-width: 520px) { .plant-card { grid-template-columns: 1fr; } }
.result-photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.scientific { font-style: italic; color: var(--muted); margin-bottom: .5rem; }
.candidates { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.candidates .small { width: 100%; }
.plant-search { display: block; margin-top: .9rem; font-size: .875rem; color: var(--muted); }
.plant-search input {
  display: block; width: 100%; margin-top: .3rem;
  padding: .55rem .7rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.plant-search input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.search-msg { display: block; margin-top: .3rem; color: var(--warn); }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; vertical-align: middle; }
.badge-high, .badge-user { background: var(--good-soft); color: var(--good); }
.badge-medium { background: var(--warn-soft); color: var(--warn); }
.badge-low { background: var(--bad-soft); color: var(--bad); }

.status { border-left-width: 6px; }
.status-good { border-left-color: var(--good); }
.status-warn { border-left-color: var(--warn); }
.status-bad { border-left-color: var(--bad); }
.status-head { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: .5rem; }
.status-icon { font-size: 1.8rem; line-height: 1; }
.status-label { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.status-good .status-label { color: var(--good); }
.status-warn .status-label { color: var(--warn); }
.status-bad .status-label { color: var(--bad); }
.status h2 { margin: .1rem 0; }

.alternatives { margin-top: .75rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.alternatives .small { width: 100%; }
.chip {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: .3rem .8rem; font: inherit; font-size: .85rem; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }

.notice { border-radius: 10px; padding: .7rem .9rem; margin: .75rem 0; font-size: .925rem; }
.notice .btn { margin-top: .5rem; display: flex; }
.notice-info { background: var(--info-soft); }
.notice-warn { background: var(--warn-soft); }
.notice-bad { background: var(--bad-soft); }

.steps li { padding-left: .25rem; margin: .5rem 0; }

.tier { border-top: 1px solid var(--border); padding-top: .5rem; margin-top: .75rem; }
.tier h4 { margin: .5rem 0 .2rem; }
.tier-organic h4 { color: var(--good); }
.tier-supplement h4 { color: var(--info); }
.tier-chemical h4 { color: var(--warn); }
.treatment { background: var(--bg); border-radius: 10px; padding: .7rem .85rem; margin: .5rem 0; font-size: .925rem; }
.treatment > div + div { margin-top: .3rem; }
.treatment-name { font-weight: 700; }
.precaution { color: var(--muted); }

.care-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem 1.25rem; margin: .5rem 0 0; }
.care-grid dt { font-weight: 600; }
.care-grid dd { margin: .15rem 0 0; color: var(--muted); font-size: .925rem; }

.disclaimer { font-size: .8rem; color: var(--muted); text-align: center; margin: 1.5rem .5rem; }
.actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

/* ── Camera ── */
.camera-dialog {
  border: 0; padding: 0; background: #000; border-radius: 16px;
  width: min(92vw, 720px); overflow: hidden;
}
.camera-dialog::backdrop { background: rgba(0, 0, 0, .7); }
#camera-video { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #000; }
.camera-actions { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; }
.btn-shutter {
  width: 64px; height: 64px; border-radius: 50%; padding: 0;
  background: #fff; border: 5px solid #8fd1a8;
}
.btn-shutter:hover { background: #eee; }
