/* Weed Detection: Apple-style interface (system font, large titles, grouped lists,
   translucent bars, light and dark). No inline styles anywhere: the CSP forbids them. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --text: #1c1c1e;
  --muted: #5a5a62;
  --line: rgba(60, 60, 67, 0.2);
  --accent: #1b7a3a;
  --accent-press: #14602d;
  --on-accent: #ffffff;
  --tint: rgba(27, 122, 58, 0.12);
  --danger: #c0261c;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --warn-line: #d49a00;
  --focus: #0a64d6;
  --glass: rgba(249, 249, 252, 0.74);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius-card: 20px;
  --radius-control: 14px;
  --radius-field: 12px;
  --bar-height: 3.25rem;
  --tab-height: 3.5rem;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #a3a3ab;
    --line: rgba(235, 235, 245, 0.2);
    --accent: #34c76a;
    --accent-press: #2aa957;
    --on-accent: #04210f;
    --tint: rgba(52, 199, 106, 0.16);
    --danger: #ff6b61;
    --warn-bg: #3a2e08;
    --warn-text: #ffd978;
    --warn-line: #d49a00;
    --focus: #64a8ff;
    --glass: rgba(28, 28, 30, 0.74);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text",
    "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.47;
  letter-spacing: -0.011em;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.visually-hidden, .picker {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -5rem;
  z-index: 30;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.skip-link:focus { top: 0.75rem; }

a { color: var(--accent); text-underline-offset: 0.15em; }
a:focus-visible, button:focus-visible, .input:focus-visible,
.picker:focus-visible + .viewfinder, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.icon { flex: none; display: block; }

/* ---------- top bar (translucent, content scrolls beneath it) ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 44rem;
  min-height: var(--bar-height);
  margin: 0 auto;
  padding: 0 max(1rem, env(safe-area-inset-left));
}
.brand, .top-link, .link-button { white-space: nowrap; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand .icon { color: var(--accent); }
.inline-form { display: inline; margin: 0; }
.link-button {
  min-height: 2.75rem;
  padding: 0 0.25rem;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.link-button:active { opacity: 0.55; }

.top-nav { display: none; }
.top-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding: 0 0.85rem;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.top-link .icon { width: 20px; height: 20px; }
.top-link:hover { background: var(--tint); color: var(--text); }
.top-link[aria-current="page"] { background: var(--tint); color: var(--accent); }

/* ---------- bottom tab bar (phones) ---------- */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tab-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: var(--tab-height);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: transform 120ms var(--ease), color 160ms var(--ease);
}
.tab-link:active { transform: scale(0.94); }
.tab-link[aria-current="page"] { color: var(--accent); }

/* ---------- page ---------- */
main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-left)) calc(var(--tab-height) + 2.5rem + env(safe-area-inset-bottom));
}
h1 {
  margin: 1rem 0 0.35rem;
  font-size: clamp(1.9rem, 6vw, 2.5rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.026em;
  text-wrap: balance;
}
h2 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.022em;
}
.lede { margin: 0 0 1.5rem; color: var(--muted); max-width: 34rem; }
.hint { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.875rem; letter-spacing: 0; }
.aside { margin: 1.25rem 0 0; text-align: center; color: var(--muted); }
.scientific { margin: 0.2rem 0 0; color: var(--muted); font-size: 1.0625rem; }

.stack > * + * { margin-top: 1rem; }
.stack > .field + .field { margin-top: 1rem; }
.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}
form.card { padding: 1.25rem; }

/* ---------- controls ---------- */
.field { margin: 0; }
.field label {
  display: block;
  margin: 0 0 0.4rem 0.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0;
}
.input {
  display: block;
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-field);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  letter-spacing: -0.011em;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.input:focus { border-color: var(--accent); background: var(--surface); }
.input[aria-invalid="true"] { border-color: var(--danger); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.6rem 1.4rem;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  letter-spacing: -0.011em;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms var(--ease), background-color 160ms var(--ease), opacity 160ms var(--ease);
}
.button:hover { background: var(--accent-press); }
.button:active { transform: scale(0.97); }
.button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.button.block { display: flex; width: 100%; }
.button.secondary { background: var(--tint); color: var(--accent); }
.button.secondary:hover { background: var(--tint); opacity: 0.8; }
.button.danger { background: transparent; color: var(--danger); }
.button.danger:hover { background: transparent; opacity: 0.7; }

.error { margin: 0.4rem 0 0 0.25rem; color: var(--danger); font-size: 0.9375rem; font-weight: 500; letter-spacing: 0; }
.auth > .error {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-control);
  background: var(--surface);
}
.flash {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-control);
  background: var(--tint);
  color: var(--text);
  font-weight: 500;
}
.flash.error { color: var(--danger); background: var(--surface); }
.status { min-height: 1.5rem; margin: 0; color: var(--muted); font-size: 0.9375rem; letter-spacing: 0; }
.status.error { color: var(--danger); font-weight: 500; }
.notice {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--warn-line);
  border-radius: 0 var(--radius-field) var(--radius-field) 0;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-weight: 600;
  letter-spacing: 0;
}
.disclaimer { margin: 1rem 0 0; color: var(--muted); font-size: 0.875rem; letter-spacing: 0; }

/* ---------- upload: the viewfinder ---------- */
.capture { margin: 0; }
.capture .viewfinder {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  margin: 0;
  overflow: hidden;
  border: 2px dashed var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  transition: transform 120ms var(--ease), border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.capture .viewfinder:hover { border-color: var(--accent); background: var(--tint); }
.capture .viewfinder:active { transform: scale(0.985); }
.viewfinder-prompt { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; padding: 1rem; text-align: center; }
.viewfinder-prompt .icon { width: 44px; height: 44px; }
.viewfinder-title { color: var(--text); font-size: 1.0625rem; font-weight: 600; }
.preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.has-photo .capture .viewfinder { border-style: solid; border-color: transparent; }
.has-photo .viewfinder-prompt {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  flex-direction: row;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  transform: translateX(-50%);
  white-space: nowrap;
}
.has-photo .viewfinder-prompt .icon { width: 20px; height: 20px; }
.has-photo .viewfinder-title { font-size: 0.9375rem; }

progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
}
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; transition: width 200ms var(--ease); }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
progress.low::-webkit-progress-value { background: var(--warn-line); }
progress.low::-moz-progress-bar { background: var(--warn-line); }

.disclosure { margin-top: 1.5rem; padding: 0 1.25rem 0 2.25rem; }
.disclosure summary {
  min-height: 3rem;
  padding: 0.75rem 0;
  font-weight: 600;
  cursor: pointer;
  list-style-position: outside;
}
.disclosure[open] summary { border-bottom: 1px solid var(--line); }
.plain-list { margin: 0; padding: 0; list-style: none; }
.plain-list li { padding: 0.65rem 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: 0; }
.disclosure .hint { padding-bottom: 1rem; }

/* ---------- result ---------- */
.result { margin-top: 1rem; }
.result-figure { margin: 0 0 1rem; }
.result-image {
  display: block;
  width: 100%;
  max-height: 26rem;
  object-fit: cover;
  border-radius: var(--radius-card);
  background: var(--surface);
}
.result-figure figcaption { margin: 0.5rem 0.25rem 0; color: var(--muted); font-size: 0.875rem; letter-spacing: 0; }
.verdict { padding: 1.25rem; }
.confidence { margin-top: 1.25rem; }
.confidence-line { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 0.5rem; color: var(--muted); }
.confidence-line strong { color: var(--text); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.meter { height: 0.6rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }
.actions .button { flex: 1 1 11rem; }
.danger-zone { margin: 1.5rem 0 0; text-align: center; }

/* ---------- grouped lists (history, account) ---------- */
.list { margin: 0; padding: 0; list-style: none; overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); margin-left: 1rem; }
.list li + li .row { margin-left: -1rem; padding-left: 1rem; }
.row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-height: 4rem;
  padding: 0.6rem 1rem;
  color: var(--text);
  text-decoration: none;
  transition: background-color 120ms var(--ease);
}
.row:hover { background: var(--tint); }
.row:active { background: var(--tint); transition-duration: 0ms; }
.row > .icon:last-child { width: 18px; height: 18px; color: var(--muted); }
.row-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.row-title { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 0.875rem; letter-spacing: 0; }
.row-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.row-icon {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  background: var(--tint);
  color: var(--accent);
}
.row-icon .icon { width: 20px; height: 20px; }
.thumb { flex: none; width: 56px; height: 56px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin: 1.25rem 0; }
.pager .button { min-height: 2.75rem; padding: 0.4rem 1.1rem; }
.pager-info { color: var(--muted); font-size: 0.9375rem; }

.empty { padding: 3rem 1rem; text-align: center; }
.empty-icon { display: inline-grid; place-items: center; width: 4rem; height: 4rem; margin-bottom: 0.75rem; border-radius: 50%; background: var(--tint); color: var(--accent); }
.empty-icon .icon { width: 30px; height: 30px; }
.empty-title { margin: 0; font-size: 1.25rem; font-weight: 650; letter-spacing: -0.02em; }
.empty .lede { margin: 0.25rem auto 1.25rem; }

.auth { max-width: 26rem; margin: 0 auto; padding-top: 1rem; }
.centered { max-width: 28rem; margin: 4rem auto 0; text-align: center; }
.centered .lede { margin-inline: auto; }

/* ---------- arrival: one calm moment, on the result only ---------- */
@keyframes arrive {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.result { animation: arrive 420ms var(--ease) both; }

/* ---------- wide screens: tabs move into the top bar ---------- */
@media (min-width: 48rem) {
  .top-nav { display: flex; gap: 0.25rem; }
  .tab-bar { display: none; }
  main { padding-bottom: 3rem; }
  .actions .button { flex: 0 1 auto; }
  .viewfinder { aspect-ratio: 16 / 9; }
}

/* ---------- accessibility preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .button:active, .tab-link:active, .capture .viewfinder:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .site-header, .tab-bar, .has-photo .viewfinder-prompt {
    background: var(--surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(60, 60, 67, 0.6); --muted: #3a3a40; }
  .card, .input, .viewfinder { border: 1px solid var(--line); }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root { --line: rgba(235, 235, 245, 0.6); --muted: #d1d1d6; }
}