:root {
  --bg: #f4f2ed;
  --surface: #ffffff;
  --ink: #15202b;
  --muted: #56606d;
  --line: #e4e0d7;
  --primary: #0b5d52;
  --primary-2: #0e7a6b;
  --primary-soft: #e3f1ee;
  --gold: #c8932f;
  --green: #146c43;
  --green-bg: #e2f4e9;
  --amber: #8a4b00;
  --amber-bg: #fff0d9;
  --red: #b42318;
  --red-bg: #fde8e6;
  --radius: 22px;
  --shadow-sm: 0 1px 2px rgba(21, 32, 43, .06), 0 2px 8px rgba(21, 32, 43, .05);
  --shadow-md: 0 2px 6px rgba(21, 32, 43, .06), 0 12px 32px rgba(21, 32, 43, .09);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, #e5efe9 0%, rgba(229, 239, 233, 0) 60%),
    var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Devanagari", "Mangal", sans-serif;
  font-size: 20px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.has-actions { padding-bottom: calc(120px + var(--safe-b)); }

svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(244, 242, 237, .82);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid rgba(21, 32, 43, .06);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--primary-2), var(--primary));
  color: #fff;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(11, 93, 82, .3);
}
.brand-name { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }

.lang-toggle {
  display: flex;
  padding: 4px;
  background: #e8e4da;
  border-radius: 999px;
}
.lang-toggle button {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s;
}
.lang-toggle button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------ layout */

main { width: 100%; max-width: 560px; margin: 0 auto; padding: 8px 18px 24px; }
.screen { animation: rise .35s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.title { margin: 16px 0 6px; font-size: 30px; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; }
.hint { margin: 0 0 20px; color: var(--muted); font-size: 19px; }

/* ------------------------------------------------------------ start */

.scan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 34px 20px 30px;
  border-radius: 28px;
  background: linear-gradient(160deg, #11806f 0%, var(--primary) 55%, #084a41 100%);
  color: #fff;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 18px 40px -12px rgba(11, 93, 82, .55);
  overflow: hidden;
  transition: transform .15s ease;
  user-select: none;
}
.scan-card::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 70%);
}
.scan-card:active { transform: scale(.98); }
.scan-card:focus-within { outline: 4px solid var(--gold); outline-offset: 4px; }

.scan-orb {
  position: relative;
  display: grid; place-items: center;
  width: 116px; height: 116px;
  margin-bottom: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  border: 2px solid rgba(255, 255, 255, .35);
  font-size: 54px;
}
.scan-orb::after {
  content: "";
  position: absolute; inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .25);
  animation: ring 2.4s ease-out infinite;
}
@keyframes ring { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
.scan-title { font-size: 30px; font-weight: 800; line-height: 1.2; }
.scan-sub { font-size: 18px; opacity: .85; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 12px 18px;
  border: 0;
  border-radius: 18px;
  font: inherit;
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: transform .12s ease, background .2s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
.btn .ic { font-size: 26px; }

.btn-ghost {
  margin-top: 14px;
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.btn-primary {
  background: linear-gradient(160deg, var(--primary-2), var(--primary));
  color: #fff;
  box-shadow: 0 10px 24px -8px rgba(11, 93, 82, .6);
}
.btn-secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }

.tips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}
.tips li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 6px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}
.tip-ic {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 24px;
}

/* ------------------------------------------------------------ scanning */

.scanning { padding-top: 16px; }
.photo {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #0d1418;
  box-shadow: var(--shadow-md);
}
#preview { display: block; width: 100%; max-height: 52vh; object-fit: contain; }
.scanline {
  position: absolute; left: 0; right: 0; top: 0;
  height: 30%;
  background: linear-gradient(180deg, rgba(46, 211, 183, 0) 0%, rgba(46, 211, 183, .28) 85%, rgba(120, 255, 230, .95) 100%);
  border-bottom: 2px solid #7fffe6;
  animation: sweep 1.8s cubic-bezier(.45, 0, .55, 1) infinite alternate;
}
@keyframes sweep { from { transform: translateY(-100%); } to { transform: translateY(240%); } }

.loading {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.loading strong { display: block; font-size: 23px; }
.loading span { color: var(--muted); font-size: 17px; }
.spinner {
  width: 42px; height: 42px; flex: none;
  border-radius: 50%;
  border: 5px solid var(--primary-soft);
  border-top-color: var(--primary);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ error */

.error-card {
  margin-top: 24px;
  padding: 30px 22px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.error-ic {
  display: inline-grid; place-items: center;
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--red-bg);
  color: var(--red);
  font-size: 36px;
}
.error-card h2 { margin: 14px 0 6px; font-size: 25px; }
.error-card p { margin: 0; color: var(--muted); }

/* ------------------------------------------------------------ result */

.result { padding-top: 12px; display: grid; gap: 14px; }

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius);
  font-weight: 700;
}
.status strong { display: block; font-size: 23px; line-height: 1.25; }
.status span:not(.status-ic) { font-size: 17px; font-weight: 600; opacity: .85; }
.status-ic {
  display: grid; place-items: center;
  width: 52px; height: 52px; flex: none;
  border-radius: 16px;
  font-size: 30px;
  background: rgba(255, 255, 255, .6);
}
.status.valid { background: var(--green-bg); color: var(--green); }
.status.expiring_soon { background: var(--amber-bg); color: var(--amber); }
.status.expired {
  background: linear-gradient(160deg, #d0342a, var(--red));
  color: #fff;
  box-shadow: 0 12px 28px -10px rgba(180, 35, 24, .6);
  animation: rise .35s ease-out both, nudge .5s .4s ease-in-out 2;
}
.status.expired .status-ic { background: rgba(255, 255, 255, .2); }
.status.expired strong { font-size: 25px; }
.status.unknown { background: #ebe8e1; color: var(--muted); }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.card {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.hero { display: flex; align-items: center; gap: 16px; }
.thumb {
  width: 76px; height: 76px; flex: none;
  object-fit: cover;
  border-radius: 16px;
  background: #e8e4da;
}
.hero-text { min-width: 0; }
.eyebrow { font-size: 15px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .04em; }
.hero h2 { margin: 2px 0 0; font-size: 29px; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; }
.brand-line { margin: 2px 0 0; color: var(--muted); font-size: 18px; font-weight: 600; }

.notice { display: flex; gap: 14px; align-items: flex-start; background: var(--amber-bg); color: var(--amber); box-shadow: none; }
.notice-ic { font-size: 30px; line-height: 1; padding-top: 2px; }
.notice p { margin: 0; font-weight: 600; }

.rows { padding: 6px 18px; }
.row { display: flex; gap: 14px; padding: 14px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row-ic {
  display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 22px;
}
.row-label { font-size: 16px; font-weight: 700; color: var(--muted); }
.row p { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.4; }

.caution { background: #fff8ec; border: 1.5px solid #f2d9a8; box-shadow: none; }
.caution-head { display: flex; align-items: center; gap: 8px; color: var(--amber); font-weight: 800; font-size: 18px; }
.caution-head svg { font-size: 24px; }
.caution p { margin: 6px 0 0; font-size: 20px; line-height: 1.45; }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.meta-item { padding: 14px 16px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-sm); min-width: 0; }
.meta:has(#batch-item[hidden]) { grid-template-columns: 1fr; }
.meta-label { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; color: var(--muted); }
.meta-item strong { display: block; margin-top: 2px; font-size: 23px; overflow-wrap: anywhere; }

.raw { border-radius: 18px; background: rgba(255, 255, 255, .55); color: var(--muted); font-size: 17px; }
.raw summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 54px; padding: 0 16px;
  cursor: pointer; list-style: none; font-weight: 600;
}
.raw summary::-webkit-details-marker { display: none; }
.raw summary svg { font-size: 20px; transition: transform .2s; }
.raw[open] summary svg { transform: rotate(90deg); }
.raw pre { margin: 0 12px 12px; padding: 12px; border-radius: 12px; background: #fff; font-size: 15px; white-space: pre-wrap; word-break: break-word; }

.audio-note {
  margin: 14px 0 0;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

.disclaimer { margin: 28px 8px 0; font-size: 15px; color: var(--muted); text-align: center; }

/* ------------------------------------------------------------ action bar */

.actions {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 18px calc(12px + var(--safe-b));
  background: rgba(244, 242, 237, .88);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid rgba(21, 32, 43, .07);
}
@media (min-width: 560px) { .actions { border-radius: 24px 24px 0 0; } }
.actions.single { grid-template-columns: 1fr; }
.actions .btn { min-height: 68px; padding: 12px 10px; gap: 8px; white-space: nowrap; }

.listen-ic { display: inline-grid; }
.listen-ic .ic { grid-area: 1 / 1; }
.ic-stop { opacity: 0; }
.wave { display: none; align-items: center; gap: 3px; height: 22px; }
.wave i { width: 4px; height: 100%; border-radius: 2px; background: currentColor; animation: wave 1s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: -.25s; }
.wave i:nth-child(3) { animation-delay: -.5s; }
.wave i:nth-child(4) { animation-delay: -.75s; }
@keyframes wave { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

#btn-listen.speaking { background: linear-gradient(160deg, #1d2a36, var(--ink)); box-shadow: 0 10px 24px -8px rgba(21, 32, 43, .5); }
#btn-listen.speaking .ic-speaker { opacity: 0; }
#btn-listen.speaking .ic-stop { opacity: 1; }
#btn-listen.speaking .wave { display: inline-flex; }
#btn-listen.pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(14, 122, 107, .25); } }

[hidden] { display: none !important; }

@media (max-width: 360px) {
  body { font-size: 18px; }
  .title { font-size: 26px; }
  .scan-title { font-size: 26px; }
  .tips li { font-size: 14px; }
  .actions .btn { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .scanline { display: none; }
}
