* {
  -webkit-tap-highlight-color: transparent;
}

:root {
    --card: #fff;
    --text: #0f172a;
    --muted: #64748b;
    --radius: 18px;
}

/* Themes */
body.mode-pre {
    --bg: #f6f9ff;
    --brand: #2563eb;
    --brand2: #0ea5e9;
    --chipBg: rgba(37, 99, 235, .10);
}

body.mode-pro {
    --bg: #fff7ed;
    --brand: #ea580c;
    --brand2: #f59e0b;
    --chipBg: rgba(234, 88, 12, .12);
}

body.mode-school {
    --bg: #f0fdf4;
    --brand: #16a34a;
    --brand2: #22c55e;
    --chipBg: rgba(34, 197, 94, .12);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
    background: var(--bg);
    color: var(--text);
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: linear-gradient(180deg, #ffffff, #ffffffcc);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(15, 23, 42, .06);
    padding: 12px 14px 10px;
}

.topbarRow {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
    font-weight: 1000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, .12);
}

.brandName {
    font-weight: 1000;
}

.brandSub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.topBtns {
    display: flex;
    gap: 10px;
}

.iconBtn {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    border: 1px solid rgba(15, 23, 42, .08);
    background: #fff;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .06);
}

.iconBtn:active {
    transform: scale(.98);
}

.backBtn {
    display: grid;
    place-items: center;
    text-decoration: none;
    color: inherit;
}

/* user row */
.userRow {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

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

.userName {
    font-size: 16px;
    font-weight: 1000;
    margin-top: 2px;
}

.pill {
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--chipBg);
    color: var(--brand);
    font-weight: 900;
    font-size: 12px;
}

.segHint {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    font-weight: 800;
}

/* Layout */
.page {
    padding: 12px;
}

.section {
    margin-top: 12px;
}

.sectionCard {
    background: var(--card);
    border: 1px solid rgba(15, 23, 42, .06);
    box-shadow: 0 10px 25px rgba(15, 23, 42, .05);
    border-radius: var(--radius);
    padding: 12px;
}

.secHead {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.secTitle {
    font-weight: 1000;
    font-size: 16px;
}

.secSub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.iconPill {
    border: none;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    padding: 9px 10px;
    border-radius: 999px;
    font-weight: 1000;
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(15, 23, 42, .06);
}

/* KPIs */
.kpiRow {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.kpiRow4 {
    grid-template-columns: repeat(4, 1fr);
}

@media(max-width:740px) {
    .kpiRow4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.kpiMini {
    border: 1px solid rgba(15, 23, 42, .06);
    background: #fff;
    border-radius: 18px;
    padding: 12px;
}

.kminiTop {
    display: flex;
    gap: 10px;
    align-items: center;
}

.kminiIco {
    width: 34px;
    height: 34px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--chipBg);
}

.kminiLbl {
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
}

.kminiVal {
    margin-top: 8px;
    font-weight: 1000;
    font-size: 16px;
}

.kminiSub {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted);
}

.kminiClick {
    cursor: pointer;
}

/* Invite cards */
/* Invite section (compact) */
.inviteGrid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media(max-width:740px) {
    .inviteGrid {
        grid-template-columns: 1fr;
    }
}

/* smaller card */
.invCard {
    border: 1px solid rgba(15, 23, 42, .06);
    border-radius: 16px;
    background: linear-gradient(135deg, var(--chipBg), rgba(255, 255, 255, .92));
    padding: 10px;
}

.invTop {
    gap: 8px;
}

.invRole {
    font-weight: 1000;
    font-size: 13px;
}

.invHint {
    margin-top: 3px;
    font-size: 11px;
    line-height: 1.25;
}

.invBadge {
    font-size: 10px;
    padding: 4px 8px;
}

/* hide huge link box, show as single-line */
.invLink {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    font-size: 11px;
    color: rgba(15, 23, 42, .70);
    white-space: pre-wrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.invBtns {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.btn {
    padding: 9px 10px;
    border-radius: 12px;
    font-size: 12px;
}

.btn {
    border: none;
    padding: 10px 12px;
    border-radius: 14px;
    font-weight: 1000;
    cursor: pointer;
    font-size: 12px;
}

.btnPri {
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
}

.btnGhost {
    background: rgba(15, 23, 42, .06);
    color: rgba(15, 23, 42, .78);
}

.invBadge {
    display: inline-block;
    font-size: 11px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    font-weight: 1000;
}

.inviteTip {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid rgba(15, 23, 42, .06);
    background: rgba(15, 23, 42, .02);
    color: var(--muted);
    font-weight: 900;
    font-size: 12px;
}

/* Controls */
.controls {
    margin-top: 2px;
}

.searchRow {
    display: flex;
    gap: 10px;
}

.searchInp {
    flex: 1;
    height: 44px;
    border-radius: 16px;
    border: 1px solid rgba(15, 23, 42, .08);
    background: #fff;
    padding: 0 12px;
    outline: none;
    font-weight: 900;
}

.searchInp:focus {
    border-color: rgba(37, 99, 235, .35);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .10);
}

.searchBtn {
    height: 44px;
    padding: 0 14px;
    border-radius: 16px;
    border: none;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
    font-weight: 1000;
    cursor: pointer;
}

.chips {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    overflow: auto;
    padding-bottom: 4px;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chip {
    border: none;
    background: rgba(15, 23, 42, .05);
    color: rgba(15, 23, 42, .75);
    font-weight: 1000;
    font-size: 12px;
    padding: 9px 12px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}

.chip.active {
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
    box-shadow: 0 12px 22px rgba(0, 0, 0, .10);
}

/* Tree list */
.treeList {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mutedBox {
    border: 1px dashed rgba(15, 23, 42, .18);
    border-radius: 18px;
    padding: 16px;
    text-align: center;
    color: var(--muted);
    font-weight: 900;
    background: rgba(255, 255, 255, .8);
}

.mCard {
    border: 1px solid rgba(15, 23, 42, .06);
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
}

.mTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
}

.leftRow {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.levelDot {
    width: 30px;
    height: 30px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--chipBg);
    font-weight: 1000;
    flex: 0 0 auto;
}

.mMain {
    min-width: 0;
}

.mName {
    font-weight: 1000;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mMeta {
    margin-top: 6px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tag {
    font-size: 10px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .06);
    font-weight: 1000;
}

.tag.ok {
    background: rgba(34, 197, 94, .12);
    color: #16a34a;
}

.tag.bad {
    background: rgba(239, 68, 68, .12);
    color: #b91c1c;
}

.mBtns {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}

.mBody {
    border-top: 1px solid rgba(15, 23, 42, .06);
    padding: 12px;
    display: none;
}

.mBody.open {
    display: block;
}

.kpiRowInner {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.kpi {
    border: 1px solid rgba(15, 23, 42, .06);
    border-radius: 16px;
    padding: 10px;
    background: rgba(15, 23, 42, .02);
}

.kpiL {
    font-size: 11px;
    color: var(--muted);
    font-weight: 900;
}

.kpiV {
    margin-top: 6px;
    font-weight: 1000;
    font-size: 13px;
}

.kv {
    margin-top: 12px;
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 8px 10px;
    font-size: 12px;
}

.k {
    color: var(--muted);
    font-weight: 900;
}

.v {
    font-weight: 1000;
    word-break: break-word;
}

.actionsRow {
    margin-top: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.aBtn {
    border: none;
    padding: 10px 12px;
    border-radius: 14px;
    font-weight: 1000;
    cursor: pointer;
    background: rgba(15, 23, 42, .06);
}

.aBtn.primary {
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff;
}

/* Error */
.errBox {
    margin-top: 10px;
    color: #b91c1c;
    font-weight: 900;
}

/* Bottom nav */
.bottomNav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: #ffffffcc;
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(15, 23, 42, .06);
    padding: 8px 6px;
}

.navItem {
    flex: 1;
    text-decoration: none;
    color: rgba(15, 23, 42, .65);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 0;
    border-radius: 14px;
    font-weight: 1000;
    font-size: 11px;
}

.navItem.active {
    color: var(--brand);
    background: var(--chipBg);
}

.navIco {
    font-size: 18px;
}

.spaceBottom {
    height: 92px;
}

/* WhatsApp chooser */
.waModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: none;
    z-index: 90;
}

.waModal.show {
    display: block;
}

.waSheet {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 420px);
    background: #fff;
    border-radius: 18px;
    border: 1px solid rgba(15, 23, 42, .08);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
    overflow: hidden;
}

.waHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid rgba(15, 23, 42, .06);
}

.waTitle {
    font-weight: 1000;
}

.waClose {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    border: none;
    background: rgba(15, 23, 42, .06);
    font-weight: 1000;
    cursor: pointer;
}

.waOpt {
    width: 100%;
    border: none;
    padding: 14px 12px;
    background: #fff;
    font-weight: 1000;
    cursor: pointer;
    text-align: left;
    border-bottom: 1px solid rgba(15, 23, 42, .06);
}

.waOpt:active {
    background: rgba(15, 23, 42, .03);
}

.waNote {
    padding: 12px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
}

/* Leaderboard */
.lbWrap {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

@media(max-width:740px) {
    .lbWrap {
        grid-template-columns: 1fr;
    }
}

.lbCard {
    border: 1px solid rgba(15, 23, 42, .06);
    border-radius: 18px;
    padding: 12px;
    background: linear-gradient(135deg, rgba(255, 255, 255, .92), var(--chipBg));
}

.lbTop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.lbRank {
    width: 34px;
    height: 34px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    font-weight: 1000;
}

.lbName {
    font-weight: 1000;
    font-size: 13px;
}

.lbMeta {
    margin-top: 6px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 900;
}

.lbVal {
    margin-top: 8px;
    font-size: 14px;
    font-weight: 1000;
}