:root {
  --bg: #f2f4f3; --card: #fff; --text: #17201d; --muted: #5d6b66; --line: #e3e8e6;
  --brand: #0f766e; --brand-2: #14a08c; --brand-ink: #fff; --brand-soft: #e3f3f0;
  --danger: #b42318; --danger-bg: #fdecea;
  --caution: #a15c07; --caution-bg: #fef4e2;
  --safe: #067647; --safe-bg: #e7f6ee;
  --unknown: #475467; --unknown-bg: #eef1f4;
  --bar: rgba(255, 255, 255, 0.88);
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 4px 16px rgba(16, 24, 20, 0.06);
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  --appbar-h: 58px; --tabbar-h: 64px; --oryxun: #05aeec;
  color-scheme: light;
}
/* Dark palette: used when the phone is in dark mode (unless the user picked Light),
   or when the user picked Dark. The two blocks must stay identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b100e; --card: #161e1b; --text: #e7ecea; --muted: #94a39e; --line: #26302c;
    --brand: #2dd4bf; --brand-2: #14a08c; --brand-ink: #062b27; --brand-soft: #0f2a26;
    --danger: #f97066; --danger-bg: #3a1714;
    --caution: #fdb022; --caution-bg: #33260c;
    --safe: #47cd89; --safe-bg: #0f2b1d;
    --unknown: #b0bac5; --unknown-bg: #222a30;
    --bar: rgba(22, 30, 27, 0.88);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b100e; --card: #161e1b; --text: #e7ecea; --muted: #94a39e; --line: #26302c;
  --brand: #2dd4bf; --brand-2: #14a08c; --brand-ink: #062b27; --brand-soft: #0f2a26;
  --danger: #f97066; --danger-bg: #3a1714;
  --caution: #fdb022; --caution-bg: #33260c;
  --safe: #47cd89; --safe-bg: #0f2b1d;
  --unknown: #b0bac5; --unknown-bg: #222a30;
  --bar: rgba(22, 30, 27, 0.88);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- app bar ---------- */
.appbar {
  position: fixed; inset: 0 0 auto; z-index: 20;
  height: calc(var(--appbar-h) + var(--top)); padding: var(--top) 12px 0;
  display: flex; align-items: center; gap: 8px;
  background: var(--bar); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; flex: 1; padding-left: 4px; }
.brand > img { border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.wordmark { font-size: 21px; font-weight: 700; letter-spacing: -0.5px; }
.wordmark b { color: var(--brand); }
.byline {
  display: flex; align-items: center; gap: 4px; margin-top: 3px;
  font-size: 9.5px; font-weight: 600; letter-spacing: 1.6px; color: var(--muted); text-transform: uppercase;
}
.byline img { margin: 0 1px; }
.byline b { color: var(--oryxun); font-weight: 800; }
.made-by { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 8px 0 4px; }
.made-by span { font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
/* The ORYXUN wordmark is light-grey outline text drawn for white: always sit it on a white plate. */
.made-by img {
  width: 240px; height: auto; max-width: 72%; background: #fff; border-radius: 14px; padding: 8px 14px;
  box-shadow: var(--shadow);
}
.appbar-title { flex: 1; margin: 0; font-size: 18px; font-weight: 650; }
.icon-btn, .avatar {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active, .avatar:active { background: var(--line); }
.avatar { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.avatar svg { width: 22px; height: 22px; }

/* ---------- views ---------- */
main {
  padding: calc(var(--appbar-h) + var(--top) + 12px) 16px calc(var(--tabbar-h) + var(--bottom) + 24px);
  max-width: 600px; margin: 0 auto;
}
.view { animation: view-in 0.22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.greeting { margin: 4px 0 0; color: var(--muted); }
.headline { margin: 0 0 16px; font-size: 26px; letter-spacing: -0.5px; }
.section-label { margin: 22px 4px 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.fineprint { font-size: 12px; color: var(--muted); text-align: center; margin: 20px 8px; }

.card { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 16px; }
.card-head a { font-size: 14px; font-weight: 600; }

.hero {
  display: flex; align-items: center; gap: 14px; padding: 20px; margin-bottom: 12px; border-radius: 20px;
  background: linear-gradient(135deg, var(--brand-2), #0b5e57); color: #fff;
  box-shadow: 0 8px 24px rgba(15, 118, 110, 0.3); transition: transform 0.12s;
}
.hero:active { transform: scale(0.98); }
.hero-icon { width: 52px; height: 52px; border-radius: 16px; background: rgba(255, 255, 255, 0.18); display: grid; place-items: center; }
.hero-icon svg { width: 30px; height: 30px; }
.hero b { display: block; font-size: 18px; }
.hero small { opacity: 0.85; font-size: 14px; }
.hero .chev { margin-left: auto; opacity: 0.8; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; border: 0; border-radius: 18px;
  background: var(--card); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; cursor: pointer; text-align: left;
  transition: transform 0.12s;
}
.tile:active { transform: scale(0.97); }
.tile svg { color: var(--brand); background: var(--brand-soft); padding: 8px; width: 40px; height: 40px; border-radius: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border-radius: 999px; padding: 5px 12px; font-size: 14px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chips .empty { color: var(--muted); font-size: 14px; }

/* ---------- lists / rows ---------- */
.list { list-style: none; margin: 0 0 14px; padding: 4px 0; }
.list > li, .row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 16px;
  border: 0; background: none; text-align: left; cursor: pointer; color: var(--text);
}
.list > * + * { border-top: 1px solid var(--line); }
.list > li:active, .row:active { background: var(--bg); }
.row span { flex: 1; min-width: 0; }
.row b { display: block; font-weight: 600; }
.row small { display: block; color: var(--muted); font-size: 13px; }
.row .chev { color: var(--muted); width: 20px; height: 20px; }
.row-icon { color: var(--brand); }
.row.danger, .row.danger .row-icon { color: var(--danger); }
.row-details summary { list-style: none; }
.row-details summary::-webkit-details-marker { display: none; }
.row-details[open] .chev { transform: rotate(90deg); }
.details-body { padding: 0 16px 12px 52px; font-size: 14px; color: var(--muted); }
.details-body p { margin: 0 0 10px; }

.h-main { flex: 1; min-width: 0; }
.h-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-date { font-size: 12px; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.danger { background: var(--danger); } .dot.caution { background: var(--caution); }
.dot.safe { background: var(--safe); } .dot.unknown { background: var(--unknown); }
.list .empty-row { color: var(--muted); font-size: 14px; cursor: default; justify-content: center; }

/* iOS-style switch */
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 51px; height: 31px; margin: 0;
  border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.switch:checked { background: var(--brand-2); }
.switch:checked::after { transform: translateX(20px); }
.switch-row { cursor: pointer; }

/* ---------- segmented / forms / buttons ---------- */
.segmented { display: flex; background: var(--line); padding: 3px; border-radius: 12px; margin-bottom: 14px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button[aria-selected="true"], .segmented button[aria-checked="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input:not([type="checkbox"]), textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input:disabled { opacity: 0.7; }
.form-error { margin: 0; color: var(--danger); font-size: 14px; }

.primary-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; border: 0; border-radius: 14px;
  padding: 14px; font-weight: 650; font-size: 16px; background: var(--brand); color: var(--brand-ink); cursor: pointer;
  transition: transform 0.12s, opacity 0.12s;
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.6; }
.danger-btn { background: var(--danger); color: #fff; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(255, 255, 255, 0.4); background: rgba(255, 255, 255, 0.12);
  color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; cursor: pointer;
}
.text-btn { display: block; margin: 0 auto; border: 0; background: none; font-weight: 600; padding: 10px; cursor: pointer; }
.text-btn.danger { color: var(--danger); }

/* ---------- account ---------- */
.auth-hero { text-align: center; padding: 8px 12px 18px; }
.auth-hero img { border-radius: 16px; box-shadow: var(--shadow); }
.auth-hero h2 { margin: 12px 0 4px; font-size: 22px; }
.auth-hero p { margin: 0; }
.profile { display: flex; align-items: center; gap: 14px; padding: 4px 4px 6px; }
.profile-avatar {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 700;
  background: linear-gradient(135deg, var(--brand-2), #0b5e57); color: #fff;
}
.profile b { font-size: 19px; }
.about { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 26px 0 6px; font-size: 13px; text-align: left; }
.about img { border-radius: 9px; }

/* ---------- scan ---------- */
body.scanning { background: #000; }
body.scanning .appbar { background: rgba(0, 0, 0, 0.55); border-color: transparent; color: #fff; }
.view-scan { position: fixed; inset: 0; background: #000; }
.camera { position: absolute; inset: 0; }
.camera video { width: 100%; height: 100%; object-fit: cover; }
.reticle {
  position: absolute; left: 50%; top: 42%; width: min(78vw, 340px); height: min(46vw, 200px); transform: translate(-50%, -50%);
  border-radius: 20px; border: 3px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.5);
}
.reticle span { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: #ff4d4d; box-shadow: 0 0 12px #ff4d4d; animation: laser 1.8s ease-in-out infinite; }
@keyframes laser { 0%, 100% { transform: translateY(-60px); } 50% { transform: translateY(60px); } }
.camera-hint { position: absolute; left: 0; right: 0; top: calc(42% + min(23vw, 100px) + 20px); text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 4px #000; padding: 0 24px; margin: 0; }
.scan-actions { position: absolute; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--bottom) + 24px); text-align: center; }
.scan-actions svg { width: 20px; height: 20px; }

/* ---------- result ---------- */
.verdict { border-radius: 20px; padding: 20px; margin-bottom: 14px; text-align: center; }
.verdict .v-icon { font-size: 40px; line-height: 1; }
.verdict b { display: block; font-size: 22px; margin-top: 6px; }
.verdict small { font-size: 14px; }
.verdict.danger { background: var(--danger-bg); color: var(--danger); }
.verdict.caution { background: var(--caution-bg); color: var(--caution); }
.verdict.safe { background: var(--safe-bg); color: var(--safe); }
.verdict.unknown { background: var(--unknown-bg); color: var(--unknown); }
.product { display: flex; gap: 14px; align-items: center; }
.product img { width: 64px; height: 64px; object-fit: contain; border-radius: 12px; background: #fff; }
.product .p-name { font-weight: 650; font-size: 17px; }
.detected .row { cursor: default; min-height: 48px; }
.detected .row:active { background: none; }
.badge { flex: none; font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 999px; }
.badge.contains { background: var(--danger-bg); color: var(--danger); }
.badge.may_contain { background: var(--caution-bg); color: var(--caution); }
.badge.none { background: var(--unknown-bg); color: var(--muted); font-weight: 500; }
.yours { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; padding: 2px 6px; border-radius: 6px; background: var(--danger); color: #fff; vertical-align: 2px; }
.ingredients summary { cursor: pointer; font-weight: 600; }
.ingredients p { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.ad { border: 1px dashed var(--line); box-shadow: none; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; inset: auto 0 0; z-index: 20; display: flex; justify-content: space-around; align-items: flex-end;
  height: calc(var(--tabbar-h) + var(--bottom)); padding: 0 6px var(--bottom);
  background: var(--bar); backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--line); user-select: none; -webkit-user-select: none;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 8px;
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.tabbar a[aria-current="page"] { color: var(--brand); }
.tabbar a:active svg { transform: scale(0.9); }
.tab-scan span {
  width: 58px; height: 58px; margin-top: -26px; margin-bottom: 1px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-2), #0b5e57); color: #fff;
  box-shadow: 0 6px 18px rgba(15, 118, 110, 0.45), 0 0 0 5px var(--bg); transition: transform 0.12s;
}
.tab-scan:active span { transform: scale(0.94); }
.tab-scan span svg { width: 28px; height: 28px; }
body.scanning .tabbar { background: rgba(0, 0, 0, 0.6); border-color: transparent; }
body.scanning .tab-scan span { box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.6); }

/* ---------- sheets / overlays ---------- */
.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 90vh;
  background: var(--card); color: var(--text); border-radius: 22px 22px 0 0;
}
@media (min-width: 640px) { .sheet { margin: auto; max-width: 480px; border-radius: 22px; } }
.sheet[open] { animation: sheet-up 0.25s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet-body { display: flex; flex-direction: column; gap: 12px; padding: 10px 20px calc(20px + var(--bottom)); }
.sheet-body h3 { margin: 4px 0 0; font-size: 19px; }
.sheet-body p { margin: 0; font-size: 14px; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 6px; }

.loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 8px;
  background: rgba(0, 0, 0, 0.35); color: #fff; font-weight: 600;
}
.loading p { margin: 0; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--bottom) + 16px); z-index: 60; transform: translateX(-50%);
  max-width: calc(100% - 32px); background: #17201d; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--danger); }

/* ---------- gates: welcome / paywall ---------- */
body.gated main { padding-bottom: calc(var(--bottom) + 24px); }
.view-gate .auth-hero { padding-top: 16px; }
.view-gate .auth-hero img { border-radius: 20px; }
.trial-pill {
  display: inline-block; margin: 12px 0 0; padding: 6px 14px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 650; font-size: 14px;
}
.hint { margin: -4px 0 0; font-size: 13px; color: var(--muted); }
.small { font-size: 13px; }
.paywall-card { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 22px 18px; }
.paywall-card p { margin: 0; }
.paywall-icon { width: 40px; height: 40px; color: var(--caution); }
.paywall-card #paywall-info { font-size: 17px; font-weight: 600; }

/* ---------- subscription ---------- */
.banner {
  display: block; margin-bottom: 14px; padding: 12px 16px; border-radius: 14px;
  background: var(--caution-bg); color: var(--caution); font-weight: 600; font-size: 14px;
}
.sub-card p { margin: 6px 0 0; }
.sub-line { font-size: 17px; font-weight: 650; }
.sub-pill, .pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.pill-active { background: var(--safe-bg); color: var(--safe); }
.pill-trial { background: var(--brand-soft); color: var(--brand); }
.pill-expired { background: var(--danger-bg); color: var(--danger); }
.pill-disabled { background: var(--unknown-bg); color: var(--muted); }
.pill-admin { background: #ede9fe; color: #6d28d9; }

/* ---------- admin ---------- */
.admin-entry { display: flex; align-items: center; gap: 12px; color: var(--text); }
.admin-entry > svg:first-child { color: #6d28d9; background: #ede9fe; padding: 8px; width: 40px; height: 40px; border-radius: 12px; }
.admin-entry span { flex: 1; }
.admin-entry b { display: block; }
.admin-entry small { color: var(--muted); font-size: 13px; }
.admin-entry .chev { color: var(--muted); width: 20px; height: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: 14px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 14px; padding: 0 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.search svg { color: var(--muted); width: 20px; height: 20px; }
.search input { border: 0; background: transparent; padding: 12px 0; box-shadow: none !important; }
.small-seg button { font-size: 13px; padding: 7px 4px; }
.u-main { flex: 1; min-width: 0; }
.u-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.au-head { display: flex; align-items: center; gap: 12px; }
.au-head .profile-avatar { width: 48px; height: 48px; font-size: 20px; flex: none; }
.au-head b { display: block; font-size: 17px; }
.au-status { background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.au-status p { margin: 4px 0 0; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.secondary-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 14px;
  padding: 12px; font-weight: 600; cursor: pointer;
}
.secondary-btn:active { background: var(--bg); }
.secondary-btn.danger { color: var(--danger); }
.big-btn { padding: 16px; font-size: 17px; }
.au-devices { font-size: 13px; color: var(--muted); }
.au-devices div { padding: 2px 0; }
.temp-pw {
  font: 700 24px/1.2 ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: 1px; text-align: center;
  background: var(--brand-soft); color: var(--brand); border-radius: 14px; padding: 14px; user-select: all;
}
.sheet .field textarea { min-height: 70px; }
.sheet-body h3.section-label { margin: 10px 0 0; font-size: 13px; }
.stats.single { grid-template-columns: 1fr; }
.guest-hide { display: none !important; }
