@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@600;700;800&family=Be+Vietnam+Pro:wght@400;500;600;700&display=swap');

:root {
  --red: #D9231C;
  --red-dark: #B01A14;
  --red-soft: #FFDAD8;
  --red-tint: #FFF0EF;
  --purple: #7C4CD1;
  --purple-dark: #4A2A8C;
  --purple-soft: #EDE4FB;
  --green: #3AAA35;
  --green-dark: #23801D;
  --green-soft: #E2F5D8;
  --cyan-dark: #0D6878;
  --cyan-soft: #D2F2F7;
  --orange-dark: #B23D0A;
  --orange-soft: #FFE4D4;
  --gold: #FDB000;
  --gold-soft: #FCE7A8;
  --gold-text: #5A4100;
  --silver-soft: #E6E8EC;
  --silver-text: #3F4650;
  --diamond-soft: #D9E8FB;
  --diamond-text: #1E4C86;
  --ink: #2A2522;
  --muted: #655446;
  --line: #F4E3BE;
  --line-soft: #F8EEDB;
  --cream: #FFF7E6;
  --white: #FFFFFF;
  --radius: 20px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-display: 'Baloo 2', 'Be Vietnam Pro', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
a { color: var(--red-dark); }
.hidden { display: none !important; }

/* Layout */
.app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--white); border-bottom: 2px solid var(--line);
}
.topbar img { width: 44px; height: 44px; border-radius: 50%; }
.topbar .brand { flex: 1; display: flex; flex-direction: column; }
.topbar .brand b { font-family: var(--font-display); font-weight: 800; font-size: 20px; line-height: 1.1; }
.topbar .brand span { font-size: 12px; color: var(--muted); }
.who { padding: 6px 12px; border-radius: 999px; background: var(--purple-soft); color: var(--purple-dark); font-size: 13px; font-weight: 600; white-space: nowrap; }
main { flex: 1; padding: 16px 16px 96px; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: center; background: var(--white); border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottomnav .inner { width: 100%; max-width: 720px; display: flex; }
.bottomnav button {
  flex: 1; border: none; background: none; padding: 10px 4px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.bottomnav button svg { width: 22px; height: 22px; }
.bottomnav button.active { color: var(--red); }

/* Typography */
h1, h2, h3 { margin: 0; }
.h-display { font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1.15; }
.h-section { font-weight: 700; font-size: 15px; margin: 4px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* Cards */
.card { background: var(--white); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.soft { background: #FFF3D1; border-color: transparent; }
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-title b { font-size: 15px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.divider { border-top: 1.5px dashed var(--line); margin: 6px 0; }

/* Forms */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 50px; border-radius: 16px; border: 2px solid #F5C66B;
  padding: 0 14px; background: var(--white); font-size: 16px; color: var(--ink);
}
textarea.input { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input:focus { outline: 3px solid var(--red-soft); border-color: var(--red); }
.searchbar { display: flex; gap: 8px; }
.searchbar .input { flex: 1; font-size: 18px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--muted); }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--red); }

/* Buttons */
.btn {
  min-height: 48px; border-radius: 16px; border: 2px solid transparent; padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 15px; background: var(--white);
}
.btn-primary { background: var(--red); color: var(--white); }
.btn-primary:active { background: var(--red-dark); }
.btn-big { min-height: 62px; border-radius: 22px; font-family: var(--font-display); font-weight: 800; font-size: 21px; width: 100%; }
.btn-outline { border-color: var(--purple); color: var(--purple-dark); }
.btn-ghost { border-color: var(--line); color: var(--ink); }
.btn-green { background: var(--green-dark); color: var(--white); }
.btn-danger { border-color: var(--red); color: var(--red-dark); }
.btn-block { width: 100%; }
.btn-icon { width: 50px; min-height: 50px; padding: 0; border-radius: 16px; background: var(--red); color: var(--white); border: none; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon svg { width: 22px; height: 22px; }
.link-btn { border: none; background: none; color: var(--red-dark); font-weight: 700; font-size: 13px; padding: 4px; }

/* Chips & badges */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--white); color: var(--muted); font-size: 13px; font-weight: 600; }
.chip.active { border-color: var(--red); background: var(--red-soft); color: var(--red-dark); }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.tier-bac { background: var(--silver-soft); color: var(--silver-text); }
.tier-vang { background: var(--gold-soft); color: var(--gold-text); }
.tier-kc { background: var(--diamond-soft); color: var(--diamond-text); }
.pill-stat { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.pill-stat b { padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 17px; }
.pill-stat span { font-size: 11px; color: var(--muted); }
.p-red b { background: var(--red-soft); color: var(--red-dark); }
.p-purple b { background: var(--purple-soft); color: var(--purple-dark); }
.p-cyan b { background: var(--cyan-soft); color: var(--cyan-dark); }
.p-green b { background: var(--green-soft); color: var(--green-dark); }

/* Kid rows */
.kid {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 18px; background: var(--white); border: 2px solid var(--line);
}
.kid.selected { border-color: var(--red); }
.avatar {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
}
.av-0 { background: var(--red-soft); color: var(--red-dark); }
.av-1 { background: var(--cyan-soft); color: var(--cyan-dark); }
.av-2 { background: var(--purple-soft); color: var(--purple-dark); }
.av-3 { background: var(--green-soft); color: var(--green-dark); }
.av-4 { background: var(--orange-soft); color: var(--orange-dark); }
.kid .info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.kid .info b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.parent-block { background: #FFF3D1; border-radius: 22px; padding: 14px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }

/* Ledger */
.ledger-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1.5px solid var(--line-soft); }
.ledger-item:last-child { border-bottom: none; }
.plus { color: var(--green-dark); font-weight: 700; }
.minus { color: var(--red-dark); font-weight: 700; }

/* Profile header */
.profile-head { background: #FFE7AE; border-bottom: 6px solid #F5A623; border-radius: var(--radius) var(--radius) 0 0; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.profile-head .avatar { width: 80px; height: 80px; font-size: 38px; background: var(--white); border: 4px solid var(--red); color: var(--red-dark); }
.points-big { font-family: var(--font-display); font-weight: 800; font-size: 46px; line-height: 1.05; color: var(--red-dark); }
.progress { width: 100%; height: 12px; border-radius: 999px; background: var(--white); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--purple); }

/* Rewards */
.gift { text-align: left; padding: 12px; border-radius: 18px; background: var(--white); border: 2px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.gift b.cost { font-family: var(--font-display); font-weight: 800; font-size: 17px; color: var(--red-dark); }
.gift.selected { border: 2.5px solid var(--red); background: var(--red-tint); }
.gift.disabled { opacity: .45; }

/* Toggle switch */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #D9D3CB; transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: var(--white); transition: transform .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--red-soft); }

/* Chart */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .bar i { display: block; width: 100%; border-radius: 8px 8px 4px 4px; background: #FFC9C5; min-height: 4px; }
.bars .bar i.hi { background: var(--red); }
.bars .bar span { font-size: 11px; color: var(--muted); }
.bars .bar em { font-style: normal; font-size: 11px; font-weight: 700; }

/* Sheet / modal */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(42, 37, 34, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 720px; max-height: 92vh; overflow: auto; background: var(--cream); border-radius: 26px 26px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom, 0px)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-close { width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--white); font-size: 22px; line-height: 1; }
@media (min-width: 760px) { .overlay { align-items: center; } .sheet { border-radius: 26px; } }

/* Toast */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: 88px; z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; max-width: 520px; background: var(--ink); color: var(--white); padding: 12px 16px; border-radius: 16px; font-weight: 600; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.toast.ok { background: var(--green-dark); }
.toast.err { background: var(--red-dark); }
.toast button { border: 1.5px solid rgba(255,255,255,.7); background: transparent; color: var(--white); border-radius: 10px; padding: 4px 10px; font-weight: 700; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 420px; background: var(--white); border: 2px solid var(--line); border-radius: 28px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login .box img { width: 120px; height: 120px; align-self: center; }

/* Scanner */
#reader { width: 100%; border-radius: 22px; overflow: hidden; background: var(--ink); min-height: 280px; }
#reader video { border-radius: 22px; }

/* QR */
.qr-box { background: var(--white); border-radius: 18px; padding: 12px; display: inline-flex; }
.qr-box img, .qr-box svg { display: block; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 4px solid var(--red-soft); border-top-color: var(--red); animation: spin .8s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple td { padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
table.simple td:last-child { text-align: right; font-weight: 700; }

/* Quay số */
.stage { position: fixed; inset: 0; z-index: 70; background: var(--cream); overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 24px 12px; }
.stage-inner { width: 100%; max-width: 1100px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.stage-logo { width: 96px; height: 96px; border-radius: 50%; }
.stage-title { font-weight: 700; font-size: 18px; color: var(--muted); }
.stage-prize { font-family: var(--font-display); font-weight: 800; font-size: clamp(30px, 6vw, 54px); line-height: 1.05; color: var(--red); }
.reel { position: relative; width: 100%; height: 150px; overflow: hidden; border-radius: 26px; background: var(--white); border: 3px solid #F5A623; }
.reel .pointer { position: absolute; left: 50%; top: 0; bottom: 0; width: 0; z-index: 2; }
.reel .pointer::before, .reel .pointer::after { content: ""; position: absolute; left: 50%; transform: translateX(-50%); border: 12px solid transparent; }
.reel .pointer::before { top: 0; border-top-color: var(--red); }
.reel .pointer::after { bottom: 0; border-bottom-color: var(--red); }
.track { display: flex; gap: 12px; padding: 21px 0; transition: transform 6s cubic-bezier(.12, .8, .15, 1); will-change: transform; }
.reel-card { flex: none; width: 180px; height: 108px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0 10px; }
.reel-card b { font-family: var(--font-display); font-weight: 800; font-size: 22px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.reel-card span { font-size: 12px; opacity: .85; }
.reel-card.win { outline: 4px solid var(--red); transform: scale(1.06); transition: transform .3s; }
.stage-result { min-height: 130px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stage-congrats { font-weight: 700; font-size: 20px; color: var(--purple-dark); }
.stage-winner { font-family: var(--font-display); font-weight: 800; font-size: clamp(40px, 8vw, 72px); line-height: 1.05; color: var(--red-dark); }
.stage-sub { font-size: 15px; color: var(--muted); }
.stage-close { min-width: 160px; }
.confetti { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation-name: fall; animation-timing-function: linear; animation-fill-mode: forwards; pointer-events: none; }
@keyframes fall { to { top: 110vh; transform: rotate(720deg) translateX(40px); } }
@media (prefers-reduced-motion: reduce) { .track { transition-duration: .8s; } .confetti { display: none; } }
