:root {
  --bg: #f5f7fb; --card: #fff; --ink: #1b2333; --muted: #667085; --line: #e4e8f0;
  --brand: #2563eb; --brand-ink: #fff; --brand-soft: #e8efff;
  --ok: #12805c; --ok-soft: #e3f6ee; --warn: #b54708; --warn-soft: #fff4e5; --bad: #c0362c; --bad-soft: #fdecea;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.05);
  --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --card: #171e29; --ink: #e8ecf3; --muted: #97a1b3; --line: #273041;
    --brand: #5b8cff; --brand-soft: #1d2a47; --ok: #3fcf96; --ok-soft: #12291f; --warn: #f2a35b; --warn-soft: #2e2214;
    --bad: #ff7a6e; --bad-soft: #321a18; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); } .small { font-size: .875rem; } .center { text-align: center; }
.hidden { display: none !important; }

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
#app.full { max-width: none; padding: 0; }
#app.no-nav { padding-bottom: 32px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* cegah zoom iOS */ color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.field { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
}
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--bad); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .875rem; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

.banner { border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.banner.trial { background: var(--warn-soft); color: var(--warn); }
.banner.active { background: var(--ok-soft); color: var(--ok); }
.banner.expired { background: var(--bad-soft); color: var(--bad); }
.banner .btn { flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 12px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chip { flex: none; min-height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.books { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .books { grid-template-columns: repeat(3, 1fr); } }
.book { display: block; color: inherit; }
.cover { aspect-ratio: 3 / 4; border-radius: 10px; background: var(--brand-soft) center / cover no-repeat; border: 1px solid var(--line); display: flex; align-items: flex-end; padding: 8px; position: relative; overflow: hidden; }
.cover .ph { font-weight: 700; color: var(--brand); font-size: .85rem; }
.cover .tag { position: absolute; top: 6px; left: 6px; }
.book .t { font-weight: 600; font-size: .9rem; margin-top: 6px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .m { font-size: .78rem; color: var(--muted); }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); color: inherit; }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }

.plans { display: grid; gap: 10px; }
.plan { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; font: inherit; color: inherit; text-align: left; width: 100%; }
.plan.on { border-color: var(--brand); background: var(--brand-soft); }
.plan .p { font-weight: 800; font-size: 1.05rem; }
.banks { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.bank { min-height: 76px; border: 2px solid var(--line); border-radius: var(--radius); background: #fff; font: inherit; font-weight: 600; font-size: .78rem; color: #475467; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px; }
.bank.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); color: var(--brand); }

.va { font-family: ui-monospace, Consolas, monospace; font-size: 1.55rem; font-weight: 800; letter-spacing: .06em; word-break: break-all; }
.big-amount { font-size: 1.6rem; font-weight: 800; }
details { border-top: 1px solid var(--line); padding: 10px 0; }
details summary { font-weight: 600; cursor: pointer; min-height: 32px; }
details ol { padding-left: 20px; margin: 8px 0 0; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 20; }
.nav a { flex: 1; max-width: 187px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .75rem; font-weight: 600; }
.nav a.on { color: var(--brand); }
.nav svg { width: 24px; height: 24px; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.back { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; font-size: 1.3rem; cursor: pointer; flex: none; }

/* Pembaca PDF */
.reader-bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.reader-bar .ttl { flex: 1; min-width: 0; font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-bar .pg { font-variant-numeric: tabular-nums; font-size: .85rem; color: var(--muted); }
.pages { overflow-x: auto; padding: 10px 0 40px; background: #525659; min-height: calc(100dvh - 61px); }
.page { scroll-margin-top: 70px; margin: 0 auto 10px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); position: relative; }
.page canvas { display: block; width: 100%; height: 100%; }
.page .n { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #999; font-size: .9rem; }

/* Latihan */
.opt { display: block; width: 100%; text-align: left; font: inherit; color: inherit; padding: 14px; margin-bottom: 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); cursor: pointer; min-height: 52px; }
.opt.on { border-color: var(--brand); background: var(--brand-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.progress { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
.progress > i { display: block; height: 100%; background: var(--brand); transition: width .2s; }
.score { font-size: 3rem; font-weight: 800; text-align: center; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%); background: #1b2333; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.3rem; }
.logo img { width: 40px; height: 40px; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }

/* Admin (layar lebar) */
.admin #app { max-width: 1100px; padding-bottom: 32px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat .v { font-size: 1.5rem; font-weight: 800; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.modal > .card { width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto; margin: 0; border-radius: 18px 18px 0 0; }
@media (min-width: 700px) { .modal { align-items: center; } .modal > .card { border-radius: 18px; } }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.brand-logo { display: block; width: min(260px, 70%); height: auto; margin: 0 auto 4px; }
@media (prefers-color-scheme: dark) { .brand-logo { background: #fff; border-radius: 18px; padding: 10px 14px; } }

/* Bilah merek di layar utama siswa (warna mengikuti logo: biru tua + emas) */
.brand-bar { position: sticky; top: 0; z-index: 15; background: var(--card); border-bottom: 1px solid var(--line); }
.brand-link { max-width: 560px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; gap: 8px; color: inherit; }
.brand-link img { width: 36px; height: 36px; border-radius: 8px; }
.brand-name { font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em; }
.brand-name .k1 { color: #2b3f96; } .brand-name .k2 { color: #d4a72c; }
@media (prefers-color-scheme: dark) { .brand-name .k1 { color: #8ea2ff; } .brand-link img { background: #fff; } }

/* Halaman depan publik */
#app.landing { max-width: 960px; padding: 0 16px 40px; }
.lp-top { display: flex; align-items: center; gap: 8px; padding: 12px 0; }
.lp-hero { text-align: center; padding: 8px 0 24px; }
.lp-hero h1 { font-size: 1.6rem; margin: 8px 0; }
.lp-hero .brand-logo { width: min(240px, 60%); }
.lp-sec { margin-top: 28px; }
.lp-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.lp-grid .card { margin: 0; }
.lp-ic { font-size: 1.6rem; }
.lp-price { font-size: 1.5rem; font-weight: 800; color: var(--brand); }
.lp-steps { padding-left: 20px; }
.lp-steps li { margin-bottom: 8px; }
.lp-foot { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); text-align: center; font-size: .9rem; }
/* Halaman legal statis */
.legal { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
.legal h1 { font-size: 1.4rem; margin-top: 8px; }
.legal h2 { font-size: 1.05rem; margin-top: 22px; }
.legal p, .legal li { line-height: 1.65; }

/* Logo bank (latar putih juga di mode gelap supaya warna logo tetap benar) */
.bank-logo { height: 28px; max-width: 100%; object-fit: contain; display: block; }
.pay-bank { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: #fff; border-radius: 10px; border: 1px solid var(--line); color: #1b2333; }
.pay-bank .bank-logo { height: 26px; max-width: 110px; }
.bank-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.bank-chip { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; display: inline-flex; align-items: center; }
.bank-chip .bank-logo { height: 22px; max-width: 90px; }

.qr-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: center; }
.qr-box img { width: min(260px, 100%); height: auto; aspect-ratio: 1; display: block; margin: 0 auto 6px; image-rendering: pixelated; }
.qr-box .small { color: #475467; }

/* Progres, lencana, peringkat */
.prog-card .streak { font-size: 1.3rem; font-weight: 800; }
.badges { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.bdg { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 1.3rem; min-width: 64px; padding: 6px 4px; border-radius: 10px; background: var(--bg); filter: grayscale(1); opacity: .45; }
.bdg small { font-size: .62rem; text-align: center; line-height: 1.15; color: var(--muted); }
.bdg em { font-size: .6rem; font-style: normal; color: var(--muted); text-align: center; }
.bdg.got { filter: none; opacity: 1; background: var(--warn-soft); }
.badges.big { flex-wrap: wrap; } .badges.big .bdg { min-width: 92px; }
.list-item.me { background: var(--brand-soft); border-radius: 10px; padding-left: 8px; padding-right: 8px; }
.rank { width: 32px; text-align: center; font-weight: 800; }
/* Rangkuman & Tanya AI */
details.sum { border-top: 1px solid var(--line); padding: 8px 0; }
details.sum summary { font-weight: 600; cursor: pointer; }
.sum-text { white-space: pre-wrap; font-size: .92rem; line-height: 1.6; margin: 8px 0 12px; }
form.ask { background: var(--bg); border-radius: 12px; padding: 10px; }
form.ask label { margin-bottom: 6px; }
.qa { margin-top: 10px; font-size: .9rem; } .qa .q { font-weight: 600; } .qa .a { white-space: pre-wrap; margin-top: 4px; line-height: 1.55; }
/* Laporan orang tua */
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; } .grid3 .card { margin: 0 0 14px; padding: 12px 6px; }
.week { display: flex; gap: 6px; } .wd { flex: 1; text-align: center; padding: 10px 0; border-radius: 8px; background: var(--bg); font-size: .75rem; color: var(--muted); }
.wd.on { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
