:root {
  --green: #0b7a4b;
  --green-dark: #095f3b;
  --gold: #d9a400;
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #15201b;
  --muted: #6b7a72;
  --line: #e3e8e5;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Ethiopic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  /* App-like feel on touch devices */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
}

/* ===== App shell =====
   The whole app fills the screen as a fixed-height column: top bar, scrollable
   content (#main), and a bottom nav that is ALWAYS pinned to the bottom. Only
   #main scrolls — the page/body never does — so short pages leave calm app
   background above the nav instead of a blank, rubber-banding gap after it. */
.phone {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
#main { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Tablet band (640–699px): keep the app a comfortable phone width, centred,
   before the desktop phone-frame kicks in at 700px. The shell still handles
   vertical layout; here we only cap width and centre. */
@media (min-width: 640px) and (max-width: 699.98px) {
  body { background: #e9eceb; }
  .topbar, #main, .bottomnav, .install-banner {
    max-width: 480px; margin-left: auto; margin-right: auto; }
  .topbar { border-radius: 0 0 14px 14px; }
  .install-banner { border-radius: 0 0 12px 12px; }
  .bottomnav { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 16px calc(12px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--green);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 15px; line-height: 1.1; }
.tagline { font-size: 11px; opacity: .85; }
.lang-btn {
  background: rgba(255,255,255,.18); color: #fff; border: 0;
  border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 13px;
}

main { max-width: 560px; margin: 0 auto; padding: 16px 16px 20px; }
.view { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }

/* Guard against runaway page height / blank space on mobile.
   NOTE: deliberately no `overflow-x: hidden` on html/body — on iOS Safari it
   combines with position:sticky to break touch scrolling. Media max-width +
   word-wrap below already prevent horizontal overflow. */
[hidden] { display: none !important; }          /* the hidden attribute always wins */
img, video, canvas { max-width: 100%; }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px;
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.hero { background: linear-gradient(135deg, var(--green), var(--green-dark)); color: #fff; }
.hero p { margin: 0; opacity: .95; font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: #fafcfb;
}
input:focus { outline: 2px solid var(--green); border-color: var(--green); }

button { cursor: pointer; font-family: inherit; }
.primary {
  width: 100%; margin-top: 18px; padding: 14px; border: 0;
  background: var(--green); color: #fff; font-size: 16px; font-weight: 700;
  border-radius: 12px;
}
.primary:active { background: var(--green-dark); }
.secondary {
  width: 100%; margin-top: 12px; padding: 12px; font-size: 15px; font-weight: 600;
  background: #eef4f1; color: var(--green-dark); border: 1px solid var(--line); border-radius: 12px;
}
.ghost { width: 100%; padding: 12px; background: transparent; color: var(--danger);
  border: 1px solid var(--line); border-radius: 12px; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Photo */
.photo-row { margin-top: 8px; }
.photo-box {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 150px; border: 2px dashed var(--line);
  border-radius: 12px; background: #fafcfb; color: var(--muted); font-weight: 600;
  overflow: hidden;
}
.photo-box img { width: 100%; height: auto; max-height: 44vh; object-fit: contain; display: block; }
.photo-actions { display: flex; gap: 10px; margin-top: 10px; }
.photo-actions .secondary { flex: 1; margin-top: 0; }
/* Cap the live camera scanner so it can't blow the page height up on phones */
#scanner { margin-top: 12px; border-radius: 12px; overflow: hidden; max-height: 60vh; }
#scanner video { max-height: 60vh; object-fit: cover; }
.chip {
  margin-top: 10px; display: inline-block; background: #eef9f2; color: var(--green-dark);
  border: 1px solid #cdeede; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  word-break: break-all;
}

.msg { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; overflow-wrap: anywhere; }
.msg.ok { background: #eafaf0; color: var(--green-dark); }
.msg.err { background: #fdecea; color: var(--danger); }

/* Stats card */
.stat-card { display: flex; justify-content: space-around; text-align: center; }
.stat-card .big, .big { font-size: 26px; font-weight: 800; display: block; color: var(--green); }
.stat-card small { color: var(--muted); font-size: 12px; }

/* Personal standing (privacy-safe ranking) */
.stand-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stand-row:last-child { border-bottom: 0; }
.stand-row b { font-size: 18px; color: var(--green); }

/* VAT summary */
.vat-card { text-align: center; }
.vat-big { font-size: 30px; font-weight: 800; color: var(--green); margin-bottom: 4px; }
.vat-cur { font-size: 15px; font-weight: 700; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.item .thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: #eee; flex: none; }
.item .grow { flex: 1; min-width: 0; }
.item .vname { font-weight: 700; font-size: 14px; }
.item .meta { font-size: 12px; color: var(--muted); }
.status { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.status.pending { background: #fff4d6; color: #96710a; }
.status.verified { background: #e3f7ea; color: var(--green-dark); }
.status.rejected { background: #fdecea; color: var(--danger); }

/* Leaderboard rows */
.rank { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; background: #eef4f1; color: var(--green-dark); flex: none; }
.rank.r1 { background: var(--gold); color: #fff; }
.rank.r2 { background: #b8c2bd; color: #fff; }
.rank.r3 { background: #cd853f; color: #fff; }
.reward-tag { font-size: 10px; background: var(--gold); color:#fff; padding:2px 7px; border-radius:999px; font-weight:700; }

.bullets { margin: 0; padding-left: 18px; }
.bullets li { margin-bottom: 10px; font-size: 14px; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats-grid .box { background:#fafcfb; border:1px solid var(--line); border-radius:10px; padding:12px; }
.stats-grid .box b { display:block; font-size:20px; color: var(--green); }
.stats-grid .box span { font-size:12px; color: var(--muted); }

/* Bottom nav */
.bottomnav {
  /* Static: last child of the flex shell, so it is always pinned to the
     bottom of the screen without position:fixed (no scroll-past blank). */
  position: static; flex: none; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav button {
  flex: 1; border: 0; background: transparent; padding: 9px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px;
}
.bottomnav button span { font-size: 20px; }
.bottomnav button.active { color: var(--green); font-weight: 700; }

.bottomnav button { min-height: 56px; }  /* comfortable thumb target */

/* html5-qrcode cleanup */
#scanner video { width: 100% !important; border-radius: 12px; }
#scanner img[alt="Info icon"] { display: none; }

/* ---- Mobile touch ergonomics ---- */
.primary, .secondary, .ghost, .photo-box, .lang-btn { min-height: 48px; }
.primary:active, .secondary:active, .ghost:active,
.bottomnav button:active, .lang-btn:active { transform: scale(.98); }
.primary, .secondary, .ghost, .bottomnav button, .lang-btn { transition: transform .06s ease; }
input, button, textarea, select { font-size: 16px; }  /* stop iOS auto-zoom on focus */

/* ---- Install (add-to-home-screen) banner ---- */
.install-banner {
  position: static; z-index: 9;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: #063; color: #fff; font-size: 13px; font-weight: 600;
}
.install-banner #install-text { flex: 1; }
.install-banner #install-btn {
  background: #fff; color: var(--green-dark); border: 0;
  padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px;
}
.install-banner .x { background: transparent; border: 0; color: #fff; font-size: 15px; padding: 6px; }

/* ===== Desktop: present the app shell as a centered phone frame ===== */
@media (min-width: 700px) {
  body {
    background: radial-gradient(1100px 760px at 50% -18%, #0e6040, #06311f) fixed, #06311f;
    min-height: 100vh; margin: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 18px;
  }
  .phone {
    width: min(620px, 100%); height: calc(100vh - 36px); max-height: 1024px;
    background: var(--bg); border-radius: 26px; position: relative;
    box-shadow: 0 28px 70px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.3);
  }
  .topbar { max-width: none; margin: 0; border-radius: 0; }
  .install-banner { max-width: none; margin: 0; border-radius: 0; }
  #main { max-width: none; margin: 0; padding: 20px 22px 24px; }
  .bottomnav button { min-height: 62px; }
  .bottomnav { width: 100%; max-width: none; border-left: 0; border-right: 0; }
}
