:root {
  color-scheme: dark;
  --bg: #070b14; --card: rgb(18 26 42 / .62); --text: #e8f0fa; --muted: #8a9ab0; --line: rgb(130 160 200 / .16);
  --haram: #ff5470; --doubtful: #ffb020; --ok: #94a3b8; --halal: #34d399; --accent: #5eead4; --accent2: #818cf8;
  --haram-bg: rgb(255 84 112 / .14); --doubtful-bg: rgb(255 176 32 / .14); --ok-bg: rgb(148 163 184 / .12); --halal-bg: rgb(52 211 153 / .14);
  --grad: linear-gradient(135deg, #5eead4, #818cf8);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; color: var(--text); min-height: 100vh;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(600px 360px at 85% -5%, rgb(129 140 248 / .22), transparent 70%),
    radial-gradient(520px 340px at -10% 8%, rgb(94 234 212 / .16), transparent 70%),
    linear-gradient(rgb(94 234 212 / .035) 1px, transparent 1px) 0 0 / 36px 36px,
    linear-gradient(90deg, rgb(94 234 212 / .035) 1px, transparent 1px) 0 0 / 36px 36px,
    var(--bg);
  background-attachment: fixed;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 10px; max-width: 560px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 19px; letter-spacing: .02em; }
.brand b { font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 0 18px rgb(94 234 212 / .35); }
nav { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.tab { border: 0; background: none; color: var(--muted); padding: 6px 15px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 600; letter-spacing: .03em; transition: .2s; }
.tab.on { background: var(--grad); color: #04121a; box-shadow: 0 0 14px rgb(94 234 212 / .4); }
main, footer { max-width: 560px; margin: 0 auto; padding: 0 18px; }
footer { color: var(--muted); font-size: 12px; text-align: center; padding: 28px 18px 40px; }
footer a { color: var(--accent); }
h2 { font-size: 12px; margin: 8px 0 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; }

/* scanner */
.scanner { position: relative; width: min(320px, 100%); height: 180px; margin: 12px auto 16px; border-radius: 22px; overflow: hidden; background: #02050a;
  border: 1px solid rgb(94 234 212 / .35); box-shadow: 0 0 0 4px rgb(94 234 212 / .05), 0 0 40px rgb(94 234 212 / .18), inset 0 0 30px rgb(0 0 0 / .6); }
#reader { width: 100%; height: 100%; }
#reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner::before { content: ""; position: absolute; inset: 14px; z-index: 2; pointer-events: none; --c: var(--accent);
  background:
    linear-gradient(var(--c), var(--c)) top left / 22px 2px, linear-gradient(var(--c), var(--c)) top left / 2px 22px,
    linear-gradient(var(--c), var(--c)) top right / 22px 2px, linear-gradient(var(--c), var(--c)) top right / 2px 22px,
    linear-gradient(var(--c), var(--c)) bottom left / 22px 2px, linear-gradient(var(--c), var(--c)) bottom left / 2px 22px,
    linear-gradient(var(--c), var(--c)) bottom right / 22px 2px, linear-gradient(var(--c), var(--c)) bottom right / 2px 22px;
  background-repeat: no-repeat; filter: drop-shadow(0 0 4px var(--accent)); }
.idle { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); font-size: 13px; letter-spacing: .04em;
  background: radial-gradient(circle at 50% 50%, rgb(94 234 212 / .1), transparent 65%), #060a12; }
.idle p { margin: 0; }
.scanner.live .idle { display: none; }
.frame { width: 200px; height: 70px; border-radius: 6px; background: repeating-linear-gradient(90deg, rgb(94 234 212 / .5) 0 2px, transparent 2px 6px, rgb(94 234 212 / .3) 6px 7px, transparent 7px 12px); opacity: .55; }
.scanner.live::after { content: ""; position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; z-index: 3; background: linear-gradient(90deg, transparent, #ff5470, transparent); box-shadow: 0 0 14px 2px #ff5470; animation: sweep 1.5s ease-in-out infinite alternate; }
@keyframes sweep { from { transform: translateY(-62px); } to { transform: translateY(62px); } }

.controls { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
button { font: inherit; cursor: pointer; transition: transform .1s, box-shadow .2s; }
button:active { transform: scale(.97); }
.primary { background: var(--grad); color: #04121a; border: 0; padding: 12px 26px; border-radius: 14px; font-weight: 700; letter-spacing: .02em; box-shadow: 0 0 22px rgb(94 234 212 / .35); }
.ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px; font-weight: 600; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
#manual { display: flex; gap: 8px; margin-bottom: 22px; }
#manual input, .read textarea, .mine input, #pname { background: rgb(8 12 22 / .7); color: var(--text); border: 1px solid var(--line); font: inherit; outline: none; transition: border-color .2s, box-shadow .2s; }
#manual input:focus, .read textarea:focus, .mine input:focus, #pname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(94 234 212 / .15); }
#manual input { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* result */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; margin-bottom: 16px; backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 10px 40px rgb(0 0 0 / .35); animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.banner { padding: 20px 20px; position: relative; border-bottom: 1px solid var(--line); }
.banner::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: currentColor; box-shadow: 0 0 18px currentColor; }
.banner .big { font-size: 23px; font-weight: 800; letter-spacing: -.01em; }
.banner .sub { font-size: 13px; opacity: .8; margin-top: 2px; }
.banner.haram { background: var(--haram-bg); color: var(--haram); }
.banner.doubtful { background: var(--doubtful-bg); color: var(--doubtful); }
.banner.nothing_flagged { background: var(--ok-bg); color: var(--accent); }
.banner.halal { background: var(--halal-bg); color: var(--halal); }
.banner .sub, .banner .big { color: inherit; }
.product { display: flex; gap: 14px; padding: 16px 20px; align-items: center; border-bottom: 1px solid var(--line); }
.product img { width: 66px; height: 66px; object-fit: contain; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.product .ph { width: 66px; height: 66px; border-radius: 14px; background: var(--ok-bg); display: grid; place-content: center; font-size: 26px; }
.product h3 { margin: 0; font-size: 17px; line-height: 1.25; }
.product small { color: var(--muted); display: block; }
.product small:last-child { font-family: ui-monospace, Menlo, monospace; font-size: 12px; letter-spacing: .05em; }
.sec { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec h4 { margin: 0 0 12px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; }
.reason { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.reason:first-of-type { border-top: 0; padding-top: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 8px; flex: none; box-shadow: 0 0 10px currentColor; }
.dot.haram { background: var(--haram); color: var(--haram); } .dot.doubtful { background: var(--doubtful); color: var(--doubtful); }
.dot.halal { background: var(--halal); color: var(--halal); } .dot.watch { background: var(--ok); color: var(--ok); }
.reason b { display: block; text-transform: capitalize; }
.reason span { color: var(--muted); font-size: 14px; }
.tag { display: inline-block; background: var(--halal-bg); color: var(--halal); font-weight: 700; font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid rgb(52 211 153 / .35); }
.warn { color: var(--muted); font-size: 14px; margin: 0; }
details summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); }
.ing { margin-top: 10px; font-size: 14px; color: var(--muted); }
mark { background: var(--doubtful-bg); color: var(--doubtful); border-radius: 4px; padding: 0 3px; }
mark.haram { background: var(--haram-bg); color: var(--haram); }
mark.watch { background: var(--ok-bg); color: var(--text); }
.mine { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mine button { padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line); background: rgb(8 12 22 / .5); color: var(--text); font-size: 13px; font-weight: 600; }
.mine button.on { border-color: var(--accent); box-shadow: 0 0 14px rgb(94 234 212 / .4); color: var(--accent); }
.mine input { grid-column: 1 / -1; padding: 11px 13px; border-radius: 12px; font-size: 14px; }
.next { width: 100%; margin-top: 4px; }
.read { display: grid; gap: 10px; }
.read textarea { width: 100%; min-height: 110px; padding: 12px; border-radius: 14px; font-size: 14px; resize: vertical; }
.read .row { display: flex; gap: 8px; }
.read .row > * { flex: 1; text-align: center; }
label.ghost { display: block; text-align: center; }

/* history */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list li { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 13px 15px; cursor: pointer; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: border-color .2s; }
.list li:active { border-color: var(--accent); }
.list .t { flex: 1; min-width: 0; }
.list .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .t small { color: var(--muted); }
.chip { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; letter-spacing: .05em; text-transform: uppercase; }
.chip.haram { background: var(--haram-bg); color: var(--haram); }
.chip.doubtful { background: var(--doubtful-bg); color: var(--doubtful); }
.chip.nothing_flagged { background: var(--ok-bg); color: var(--ok); }
.chip.halal { background: var(--halal-bg); color: var(--halal); }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

.banner.halal_certified, .banner.likely_halal { background: var(--halal-bg); color: var(--halal); }
.banner.likely_halal { color: #6ee7b7; }
.chip.halal_certified { background: var(--halal-bg); color: var(--halal); }
.chip.likely_halal { background: var(--halal-bg); color: #6ee7b7; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-i { border: 1px solid var(--line); background: rgb(8 12 22 / .5); color: var(--text); border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.chip-i.fixed { border-color: var(--accent); color: var(--accent); }
.chip-i.part, .chip-i.unknown { border-style: dashed; color: var(--muted); }
.chip-i em { font-style: normal; color: var(--accent); }
.prev { width: 100%; max-height: 180px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
label.lang { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.lang select { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgb(8 12 22 / .7); color: var(--text); font: inherit; font-size: 14px; }

/* gentle glow on a halal result */
@keyframes glow { 0%, 100% { box-shadow: inset 0 0 0 rgb(52 211 153 / 0); } 50% { box-shadow: inset 0 0 40px rgb(52 211 153 / .28); } }
.banner.halal_certified, .banner.likely_halal, .banner.halal { animation: glow 2.4s ease-in-out 2; }
@media (prefers-reduced-motion: reduce) { .banner { animation: none !important; } }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
label.check input { margin-top: 4px; accent-color: var(--accent); }
label.check small { color: var(--muted); }

.banner.no_data { background: var(--ok-bg); color: var(--muted); }
.banner.no_data .big { color: var(--text); }
.chip.no_data { background: var(--ok-bg); color: var(--muted); border: 1px dashed var(--line); }
label.check span { flex: 1; }
label.check small { display: block; }

/* loading indicators */
.loader { height: 6px; border-radius: 999px; background: rgb(255 255 255 / .08); overflow: hidden; position: relative; }
.loader::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 38%; border-radius: inherit; background: var(--grad); box-shadow: 0 0 14px rgb(94 234 212 / .65); animation: slide 1.15s ease-in-out infinite; }
.loader.det::before { width: var(--p, 0%); animation: none; transition: width .25s ease; }
@keyframes slide { from { transform: translateX(-105%); } to { transform: translateX(265%); } }
.scanning { max-width: 320px; margin: -4px auto 14px; text-align: center; }
.scanning p { margin: 10px 0 0; font-size: 13px; color: var(--muted); min-height: 1.4em; transition: opacity .25s; }
.scanning p.fade { opacity: 0; }
.skel { border-radius: 10px; background: linear-gradient(90deg, rgb(255 255 255 / .05) 25%, rgb(255 255 255 / .13) 50%, rgb(255 255 255 / .05) 75%); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
#ocrload { margin-top: 2px; }
.qual { background: var(--doubtful-bg); color: var(--doubtful); font-size: 14px; }
@media (prefers-reduced-motion: reduce) { .loader::before, .skel { animation-duration: 3s; } }
#pname { padding: 11px 13px; border-radius: 12px; font-size: 14px; width: 100%; }

/* crop step */
.cropper { position: fixed; inset: 0; z-index: 998; background: rgb(4 7 12 / .96); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.croptip { margin: 0; color: var(--text); font-size: 14px; text-align: center; }
.cropstage { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.cropstage canvas { display: block; border-radius: 6px; }
.cropbox { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgb(0 0 0 / .55), 0 0 18px rgb(94 234 212 / .6); cursor: move; touch-action: none; }
.cropbox .h { position: absolute; width: 22px; height: 22px; background: var(--accent); border-radius: 50%; box-shadow: 0 0 10px rgb(94 234 212 / .8); touch-action: none; }
.cropbox .h::after { content: ""; position: absolute; inset: -14px; } /* bigger touch target than the dot */
.h[data-m="nw"] { left: -11px; top: -11px; } .h[data-m="ne"] { right: -11px; top: -11px; }
.h[data-m="sw"] { left: -11px; bottom: -11px; } .h[data-m="se"] { right: -11px; bottom: -11px; }
.cropbtns, .croptip { position: relative; z-index: 2; } /* above the frame's dark surround */
.cropbtns { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
