/* ════════════════════════════════════════════════════
   MathKids AI — Stylesheet
   Sections:
     1. CSS Variables & Reset
     2. Auth Screen
     3. Payment Modal
     4. User Dropdown
     5. Header
     6. Layout & Sidebars
     7. Main / Chat
     8. Practice Mode
     9. Right Sidebar Cards
    10. Animations & Utilities
   ════════════════════════════════════════════════════ */

/* ── 1. CSS VARIABLES & RESET ── */
:root {
  --pri: #FF6B35;
  --pri-l: #FF8C5A;
  --pri-d: #E55A24;
  --sec: #4ECDC4;
  --sec-d: #3AB5AD;
  --acc: #FFE66D;
  --acc-d: #F5D800;
  --pur: #7C5CBF;
  --pur-l: #9B7DD4;
  --grn: #6BCB77;
  --grn-d: #4CAF57;
  --blu: #4D96FF;
  --bg: #FFF9F0;
  --bg2: #FFFFFF;
  --tx: #2C1810;
  --tx2: #5A4A42;
  --tx3: #8A7A72;
  --br: #F0E8E0;
  --r: 16px;
  --rl: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Nunito', sans-serif;
  font-size: 18px;
  background: var(--bg);
  color: var(--tx);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── 2. AUTH SCREEN ── */
#authScreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #FFF0E8 0%, #FFF9F0 40%, #E8F5FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.auth-card {
  background: var(--bg2);
  border-radius: var(--rl);
  padding: 36px 40px;
  width: 400px;
  box-shadow: 0 16px 56px rgba(255, 107, 53, .15);
  text-align: center;
  position: relative;
}

.auth-logo {
  font-family: 'Baloo 2', cursive;
  font-size: 30px;
  font-weight: 800;
  color: var(--pri);
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 13px;
  color: var(--tx3);
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  background: var(--bg);
  border: 2px solid var(--br);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 22px;
  gap: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border-radius: 9px;
  border: none;
  background: transparent;
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: var(--tx3);
  cursor: pointer;
  transition: all .2s;
}

.auth-tab.active {
  background: var(--pri);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 107, 53, .3);
}

.login-input {
  width: 100%;
  padding: 11px 16px;
  border: 2px solid var(--br);
  border-radius: 12px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  color: var(--tx);
  background: var(--bg);
  outline: none;
  margin-bottom: 10px;
  transition: border-color .2s;
}

.login-input:focus {
  border-color: var(--pri);
}

.input-hint {
  font-size: 11px;
  color: var(--tx3);
  text-align: left;
  margin-top: -6px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.login-grade-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  justify-content: center;
}

.lg-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid var(--br);
  background: var(--bg);
  font-family: 'Baloo 2', cursive;
  font-size: 16px;
  font-weight: 700;
  color: var(--tx2);
  cursor: pointer;
  transition: all .2s;
}

.lg-btn.active {
  background: var(--pri);
  border-color: var(--pri);
  color: #fff;
  box-shadow: 0 3px 10px rgba(255, 107, 53, .35);
}

.login-btn {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  color: #fff;
  border: none;
  border-radius: 12px;
  font-family: 'Baloo 2', cursive;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  box-shadow: 0 4px 14px rgba(255, 107, 53, .35);
}

.login-btn:hover {
  transform: translateY(-1px);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--tx3);
  font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--br);
}

.auth-error {
  background: #FFF0F0;
  border: 2px solid #FFB3B3;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 12px;
  color: #CC3333;
  font-weight: 700;
  margin-bottom: 12px;
  display: none;
}

.auth-form { display: none; }
.auth-form.visible { display: block; }

/* ── 3. PAYMENT MODAL ── */
#payModal {
  position: fixed;
  inset: 0;
  background: rgba(44, 24, 16, .55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  backdrop-filter: blur(4px);
}
#payModal.open { display: flex; }

.pay-card {
  background: var(--bg2);
  border-radius: var(--rl);
  width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0,0,0,.2);
  position: relative;
}

.pay-close {
  position: absolute;
  top: 14px; right: 16px;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--br);
  background: var(--bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--tx3);
  transition: all .2s; z-index: 2;
}
.pay-close:hover { background:#FFE5E5; border-color:#FFB3B3; color:#CC3333; }

.pay-steps {
  display: flex;
  border-bottom: 2px solid var(--br);
  background: var(--bg);
  border-radius: var(--rl) var(--rl) 0 0;
  overflow: hidden;
}
.pay-step {
  flex: 1;
  padding: 13px 8px;
  text-align: center;
  font-family: 'Baloo 2', cursive;
  font-size: 11px;
  font-weight: 700;
  color: var(--tx3);
  transition: all .2s;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.pay-step.active { background: var(--bg2); color: var(--pri); }
.pay-step.done   { color: var(--grn-d); }
.pay-step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
}
.pay-step.done .pay-step-num { background: var(--grn); border-color: var(--grn); color: #fff; }

.pay-body { padding: 24px 28px 28px; }

.plan-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.plan-card {
  border: 3px solid var(--br);
  border-radius: 16px;
  padding: 18px 14px;
  cursor: pointer;
  transition: all .25s;
  position: relative;
}
.plan-card:hover { border-color: var(--pri); transform: translateY(-2px); }
.plan-card.selected { border-color: var(--pri); background: #FFF5F2; }
.plan-badge {
  position: absolute; top: -11px; left: 50%;
  transform: translateX(-50%);
  background: var(--pri); color: #fff;
  font-family: 'Baloo 2', cursive; font-size: 10px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px; white-space: nowrap;
}
.plan-icon { font-size: 26px; margin-bottom: 6px; }
.plan-name { font-family: 'Baloo 2', cursive; font-size: 15px; font-weight: 800; color: var(--tx); }
.plan-price { font-family: 'Baloo 2', cursive; font-size: 22px; font-weight: 800; color: var(--pri); margin: 5px 0 2px; }
.plan-price span { font-size: 12px; font-weight: 600; color: var(--tx3); }
.plan-feats { margin-top: 9px; display: flex; flex-direction: column; gap: 4px; }
.plan-feat { font-size: 11px; color: var(--tx2); display: flex; align-items: center; gap: 5px; }
.plan-feat::before { content: '✓'; color: var(--grn-d); font-weight: 800; }
.plan-feat.no::before { content: '✗'; color: #CCC; }
.plan-feat.no { color: var(--tx3); }

.qr-panel {
  display: flex; gap: 20px; align-items: flex-start;
  background: var(--bg); border: 2px solid var(--br);
  border-radius: 16px; padding: 18px; margin-bottom: 16px;
}
.qr-img-wrap {
  flex-shrink: 0;
  width: 150px; height: 150px;
  background: #fff;
  border: 3px solid var(--br); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.qr-img-wrap img { width: 100%; height: 100%; object-fit: contain; }
.qr-img-wrap .qr-loading {
  font-size: 11px; color: var(--tx3); text-align: center; padding: 8px;
}
.qr-info { flex: 1; }
.qr-bank-name {
  font-family: 'Baloo 2', cursive; font-size: 14px; font-weight: 800;
  color: var(--tx); margin-bottom: 10px;
}
.qr-row {
  display: flex; flex-direction: column; margin-bottom: 8px;
}
.qr-label { font-size: 10px; font-weight: 700; color: var(--tx3); text-transform: uppercase; letter-spacing: .5px; }
.qr-value { font-size: 13px; font-weight: 800; color: var(--tx); }
.qr-value.mono { font-family: monospace; font-size: 15px; }
.qr-copy {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px;
  background: var(--bg2); border: 1.5px solid var(--br);
  font-size: 10px; font-weight: 700; color: var(--tx2);
  cursor: pointer; transition: all .15s; margin-left: 6px;
}
.qr-copy:hover { border-color: var(--pri); color: var(--pri); }

.qr-amount-box {
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  border-radius: 12px; padding: 12px 16px;
  color: #fff; text-align: center; margin-bottom: 14px;
}
.qr-amount-lbl { font-size: 11px; opacity: .85; margin-bottom: 2px; }
.qr-amount-val {
  font-family: 'Baloo 2', cursive; font-size: 28px; font-weight: 800;
}

.qr-countdown {
  display: flex; align-items: center; justify-content: space-between;
  background: #FFF7E0; border: 2px solid #FFD700;
  border-radius: 10px; padding: 9px 14px; margin-bottom: 14px;
  font-size: 12px; font-weight: 700; color: #8B6914;
}
.qr-timer { font-family: 'Baloo 2', cursive; font-size: 18px; font-weight: 800; }

.qr-status {
  display: flex; align-items: center; gap: 8px;
  background: #EFF6FF; border: 2px solid #BAD8FE;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px;
  font-size: 12px; color: var(--blu); font-weight: 700;
}
.qr-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--blu);
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
.qr-status.paid { background:#E8F8E8; border-color:var(--grn); color:var(--grn-d); }
.qr-status.paid .dot { background:var(--grn); animation:none; }
.qr-status.success { background:#E8F8E8; border-color:var(--grn); color:var(--grn-d); }
.qr-status.success .dot { background:var(--grn); animation:none; }
.qr-status.error { background:#FFF0F0; border-color:#FF4D4D; color:#CC0000; }
.qr-status.error .dot { background:#FF4D4D; animation:none; }

.pay-btn {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  color: #fff; border: none; border-radius: 12px;
  font-family: 'Baloo 2', cursive; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: all .2s;
  box-shadow: 0 4px 14px rgba(255,107,53,.35);
}
.pay-btn:hover { transform: translateY(-1px); }
.pay-btn:disabled { opacity:.6; cursor:not-allowed; transform:none; }
.pay-btn.secondary {
  background: var(--bg); color: var(--tx2);
  border: 2px solid var(--br); box-shadow: none; margin-top: 8px;
}
.pay-btn.secondary:hover { border-color: var(--pri); color: var(--pri); }

.current-plan-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: #E8F8E8; border: 2px solid var(--grn);
  border-radius: 20px; padding: 4px 12px;
  font-family: 'Baloo 2', cursive; font-size: 12px; font-weight: 700; color: var(--grn-d);
}

.pay-instructions {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 16px;
}
.pay-inst-row {
  display: flex; align-items: flex-start; gap: 10px;
}
.pay-inst-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--pri); color: #fff;
  font-family: 'Baloo 2', cursive; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.pay-inst-txt { font-size: 12px; color: var(--tx2); line-height: 1.5; }

/* ── 4. USER DROPDOWN ── */
.user-dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg2);
  border: 2px solid var(--br);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .12);
  min-width: 200px;
  z-index: 500;
  overflow: hidden;
  display: none;
}

.dropdown-menu.open { display: block; }

.dd-header {
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  color: #fff;
}

.dd-name {
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 800;
}

.dd-email {
  font-size: 11px;
  opacity: .85;
  margin-top: 1px;
}

.dd-plan {
  font-size: 10px;
  background: rgba(255,255,255,.25);
  border-radius: 20px;
  padding: 2px 8px;
  display: inline-block;
  margin-top: 5px;
  font-weight: 700;
}

.dd-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tx2);
  cursor: pointer;
  transition: background .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.dd-item:hover { background: var(--bg); color: var(--tx); }
.dd-item.danger:hover { background: #FFF0F0; color: #CC3333; }
.dd-sep { height: 1px; background: var(--br); margin: 4px 0; }

/* ── 5. HEADER ── */
.pro-badge {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #5C3A00;
  font-family: 'Baloo 2', cursive;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 4px;
}

header {
  background: var(--bg2);
  border-bottom: 2px solid var(--br);
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Baloo 2', cursive;
  font-size: 20px;
  font-weight: 800;
  color: var(--pri);
}

.logo-box {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.hdr-mid {
  display: flex;
  gap: 5px;
}

.gb {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 2px solid var(--br);
  background: var(--bg);
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: var(--tx2);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gb.active {
  background: var(--pri);
  border-color: var(--pri);
  color: #fff;
}

.gb:hover:not(.active) {
  border-color: var(--pri);
  color: var(--pri);
}

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

.stars-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #FFF7E6;
  border: 2px solid #FFD700;
  border-radius: 20px;
  padding: 4px 12px;
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 700;
  color: #B8860B;
}

.streak-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #FFE5D9;
  border: 2px solid var(--pri);
  border-radius: 20px;
  padding: 4px 10px;
  font-family: 'Baloo 2', cursive;
  font-size: 13px;
  font-weight: 700;
  color: var(--pri-d);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 2px solid var(--br);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--tx2);
  cursor: pointer;
}

/* ── 6. LAYOUT & SIDEBARS ── */
.layout {
  display: grid;
  grid-template-columns: 262px 1fr 280px;
  height: calc(100vh - 60px);
}

/* Left sidebar */
.sl {
  background: var(--bg2);
  border-right: 2px solid var(--br);
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sl-title {
  font-family: 'Baloo 2', cursive;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--tx3);
  padding: 6px 8px 2px;
}

.ti {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 11px;
  cursor: pointer;
  transition: all .2s;
  border: 2px solid transparent;
}

.ti:hover {
  background: var(--bg);
  border-color: var(--br);
}

.ti.active {
  background: #FFF0EB;
  border-color: var(--pri);
}

.ti-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.ti-info {
  flex: 1;
  min-width: 0;
}

.ti-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--tx);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ti-bar {
  height: 3px;
  background: var(--br);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.ti-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--pri), var(--pri-l));
  transition: width .5s;
}

/* ── 7. MAIN / CHAT ── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ch {
  background: var(--bg2);
  border-bottom: 2px solid var(--br);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ch-title {
  font-family: 'Baloo 2', cursive;
  font-size: 18px;
  font-weight: 700;
}

.ch-sub {
  font-size: 11px;
  color: var(--tx3);
  margin-top: 1px;
}

.tabs {
  display: flex;
  gap: 5px;
}

.tab {
  padding: 5px 13px;
  border-radius: 20px;
  border: 2px solid var(--br);
  background: var(--bg);
  font-size: 11px;
  font-weight: 700;
  color: var(--tx2);
  cursor: pointer;
  transition: all .2s;
}

.tab.active {
  background: var(--sec);
  border-color: var(--sec);
  color: #fff;
}

/* Chat messages */
.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: 8px;
  max-width: 84%;
  animation: fu .3s ease;
}

@keyframes fu {
  from { opacity: 0; transform: translateY(8px) }
  to   { opacity: 1; transform: translateY(0)    }
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.av {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  border: 2px solid var(--br);
  background: var(--bg);
}

.av.ai {
  background: linear-gradient(135deg, var(--sec), var(--sec-d));
  border-color: var(--sec);
  font-size: 13px;
}

.bub {
  background: var(--bg2);
  border: 2px solid var(--br);
  border-radius: 14px;
  padding: 9px 13px;
  font-size: 17px;
  line-height: 1.65;
  color: var(--tx);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .04);
}

.msg.user .bub {
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  border-color: var(--pri);
  color: #fff;
  border-radius: 14px 3px 14px 14px;
}

.msg.ai .bub {
  border-radius: 3px 14px 14px 14px;
}

/* AI response formatting */
.math-box {
  background: #EFF6FF;
  border: 2px solid #BAD8FE;
  border-radius: 9px;
  padding: 10px;
  margin: 7px 0;
  text-align: center;
  font-family: 'Baloo 2', cursive;
  font-size: 24px;
  font-weight: 700;
  color: var(--blu);
}

.step-box {
  background: #F3FBF0;
  border: 2px solid #B8E6A0;
  border-radius: 7px;
  padding: 10px 14px;
  margin: 4px 0;
  font-size: 18px !important;
  color: var(--grn-d);
}

.sn {
  display: inline-flex;
  width: 24px;
  height: 24px;
  background: var(--grn);
  color: #fff;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 14px !important;
}

.praise {
  background: linear-gradient(135deg, #FFFAE0, #FFF3C0);
  border: 2px solid var(--acc-d);
  border-radius: 9px;
  padding: 7px 13px;
  font-family: 'Baloo 2', cursive;
  font-size: 18px !important;
  font-weight: 700;
  color: #8B6914;
  text-align: center;
  margin: 5px 0;
}

.tip {
  background: #FFF7E0;
  border: 2px solid #FFD700;
  border-radius: 7px;
  padding: 6px 10px;
  margin: 4px 0;
  font-size: 16px !important;
  color: #8B6914;
}

/* Chat input */
.inp-area {
  padding: 10px 18px;
  background: var(--bg2);
  border-top: 2px solid var(--br);
  flex-shrink: 0;
}

.qps {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}

.qp {
  padding: 3px 9px;
  background: var(--bg);
  border: 2px solid var(--br);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--tx2);
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.qp:hover {
  border-color: var(--pri);
  color: var(--pri);
  background: #FFF0EB;
}

.irow {
  display: flex;
  gap: 7px;
  align-items: flex-end;
}

.ci {
  flex: 1;
  padding: 9px 13px;
  border: 2px solid var(--br);
  border-radius: 12px;
  font-family: 'Nunito', sans-serif;
  font-size: 17px;
  background: var(--bg);
  color: var(--tx);
  outline: none;
  transition: border-color .2s;
  resize: none;
  min-height: 38px;
  max-height: 90px;
}

.ci:focus {
  border-color: var(--pri);
}

.sb {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: all .2s;
  flex-shrink: 0;
}

.sb:hover { transform: scale(1.08); }
.sb:disabled { opacity: .5; cursor: not-allowed; }

/* ── 8. PRACTICE MODE ── */
.ph {
  background: linear-gradient(135deg, var(--sec), var(--sec-d));
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.p-bar {
  width: 120px;
  height: 6px;
  background: rgba(255, 255, 255, .3);
  border-radius: 3px;
  overflow: hidden;
}

.p-fill {
  height: 100%;
  background: #fff;
  border-radius: 3px;
  transition: width .4s;
}

.ea {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 32px;
  gap: 16px;
  overflow-y: auto;
}

.eq {
  font-family: 'Baloo 2', cursive;
  font-size: 52px;
  font-weight: 800;
  color: var(--tx);
  text-align: center;
  white-space: pre-line;
}

.ectx {
  font-size: 13px;
  color: var(--tx2);
  text-align: center;
  max-width: 460px;
  line-height: 1.6;
  background: var(--bg2);
  border: 2px solid var(--br);
  border-radius: 12px;
  padding: 11px 18px;
}

.ag {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  width: 100%;
  max-width: 380px;
}

.ac {
  padding: 16px;
  background: var(--bg2);
  border: 3px solid var(--br);
  border-radius: 16px;
  cursor: pointer;
  font-family: 'Baloo 2', cursive;
  font-size: 32px;
  font-weight: 800;
  color: var(--tx);
  text-align: center;
  transition: all .2s;
  box-shadow: 0 4px 0 var(--br);
}

.ac:hover {
  border-color: var(--pri);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(255, 107, 53, .2);
}

.ac.correct {
  border-color: var(--grn);
  background: #E8F8E8;
  color: var(--grn-d);
  box-shadow: 0 4px 0 var(--grn-d);
}

.ac.wrong {
  border-color: #FF6B6B;
  background: #FFF0F0;
  color: #CC3333;
  box-shadow: 0 4px 0 #CC3333;
  animation: shake .4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0)  }
  25%       { transform: translateX(-8px) }
  75%       { transform: translateX(8px)  }
}

.hintrow {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.hbtn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border: 2px solid;
  border-radius: 20px;
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
}

.hbtn.yellow {
  background: #FFF7E0;
  border-color: var(--acc-d);
  color: #8B6914;
}

.hbtn.purple {
  background: #F0EDFF;
  border-color: #A5B4FC;
  color: var(--pur);
}

.hbtn:hover { transform: translateY(-1px); }

/* ── 9. RIGHT SIDEBAR CARDS ── */
.sr {
  background: var(--bg2);
  border-left: 2px solid var(--br);
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sc {
  background: linear-gradient(135deg, var(--pri), var(--pri-l));
  border-radius: var(--rl);
  padding: 16px;
  color: #fff;
  text-align: center;
}

.sav {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .25);
  margin: 0 auto 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  border: 3px solid rgba(255, 255, 255, .5);
}

.sname {
  font-family: 'Baloo 2', cursive;
  font-size: 14px;
  font-weight: 700;
}

.sgrade {
  font-size: 11px;
  opacity: .85;
  margin-top: 1px;
}

.srow {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, .25);
}

.sitem { text-align: center; }

.snum {
  font-family: 'Baloo 2', cursive;
  font-size: 18px;
  font-weight: 800;
}

.slbl {
  font-size: 10px;
  opacity: .8;
}

.card {
  background: var(--bg);
  border: 2px solid var(--br);
  border-radius: var(--r);
  padding: 12px;
}

.ctitle {
  font-family: 'Baloo 2', cursive;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--tx3);
  margin-bottom: 9px;
}

.prow {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 7px;
}

.pinfo {
  display: flex;
  justify-content: space-between;
}

.pn {
  font-size: 11px;
  font-weight: 700;
  color: var(--tx);
}

.pp {
  font-size: 10px;
  color: var(--tx3);
  font-weight: 700;
}

.pbar {
  height: 4px;
  background: var(--br);
  border-radius: 2px;
  overflow: hidden;
}

.pfill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--pri), var(--pri-l));
  transition: width .5s;
}

.bg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.bdg {
  aspect-ratio: 1;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  transition: transform .2s;
  border: 2px solid transparent;
  background: var(--bg);
}

.bdg:hover { transform: scale(1.08); }
.bdg.earned { border-color: var(--acc-d); }
.bdg.locked { opacity: .35; filter: grayscale(80%); }

.blbl {
  font-size: 7px;
  font-weight: 700;
  color: var(--tx2);
  text-align: center;
}

.daily {
  background: linear-gradient(135deg, #EEF2FF, #E0E7FF);
  border: 2px solid #A5B4FC;
  border-radius: var(--r);
  padding: 13px;
}

.dt {
  font-family: 'Baloo 2', cursive;
  font-size: 11px;
  font-weight: 700;
  color: var(--pur);
  margin-bottom: 7px;
}

.dp {
  font-family: 'Baloo 2', cursive;
  font-size: 22px;
  font-weight: 800;
  color: var(--pur);
  text-align: center;
  margin: 8px 0;
}

.dbttn {
  width: 100%;
  padding: 8px;
  background: var(--pur);
  color: #fff;
  border: none;
  border-radius: 9px;
  font-family: 'Baloo 2', cursive;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
}

.dbttn:hover { background: var(--pur-l); }

/* Pro banner & Free limit */
.pro-banner {
  background: linear-gradient(135deg, #7C5CBF, #9B7DD4);
  border-radius: var(--r);
  padding: 13px 14px;
  color: #fff;
  display: none;
}
.pro-banner.visible { display: block; }
.pro-banner-title { font-family:'Baloo 2',cursive; font-size:13px; font-weight:800; margin-bottom:3px; }
.pro-banner-sub { font-size:11px; opacity:.85; margin-bottom:10px; }
.pro-features { display:flex; flex-direction:column; gap:4px; margin-bottom:10px; }
.pro-feat { font-size:11px; display:flex; align-items:center; gap:5px; }
.pro-feat::before { content:'✓'; font-weight:800; }

.free-limit-bar {
  background: #FFF3E0; border: 2px solid #FFB74D;
  border-radius: var(--r); padding: 10px 12px; display: none;
}
.free-limit-bar.visible { display: block; }
.flb-title { font-family:'Baloo 2',cursive; font-size:11px; font-weight:700; color:#E65100; margin-bottom:5px; }
.flb-track { background:rgba(0,0,0,.1); border-radius:99px; height:7px; overflow:hidden; margin-bottom:4px; }
.flb-fill { height:100%; border-radius:99px; background:linear-gradient(90deg,#4CAF50,#FF9800,#F44336); transition:width .4s; }
.flb-text { font-size:10px; color:#BF360C; font-weight:700; }

/* AI Gate (free limit reached) */
.ai-gate {
  background:linear-gradient(135deg,#FFF5E0,#FFF0D0); border:2px solid #FFB74D;
  border-radius:14px; padding:18px 20px; text-align:center; margin:12px 0;
}
.ai-gate-icon { font-size:36px; margin-bottom:6px; }
.ai-gate-title { font-family:'Baloo 2',cursive; font-size:16px; font-weight:800; color:var(--tx); margin-bottom:4px; }
.ai-gate-sub { font-size:12px; color:var(--tx2); margin-bottom:12px; line-height:1.5; }
.ai-gate-btn { padding:9px 22px; background:linear-gradient(135deg,#FFD700,#FFA500); border:none; border-radius:20px; font-family:'Baloo 2',cursive; font-size:13px; font-weight:800; color:#5C3A00; cursor:pointer; transition:all .2s; box-shadow:0 3px 10px rgba(255,165,0,.4); }
.ai-gate-btn:hover { transform:translateY(-1px); }

/* History panel */
.hist-panel {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
}

.hist-item {
  background: var(--bg);
  border: 2px solid var(--br);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: all .2s;
}

.hist-item:hover {
  border-color: var(--pri);
  background: #FFF0EB;
}

.hist-topic {
  font-size: 12px;
  font-weight: 700;
  color: var(--tx);
}

.hist-meta {
  font-size: 10px;
  color: var(--tx3);
  margin-top: 2px;
}

/* ── 10. ANIMATIONS & UTILITIES ── */

/* Typing indicator */
.typ {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 13px;
  background: var(--bg2);
  border: 2px solid var(--br);
  border-radius: 3px 13px 13px 13px;
  width: fit-content;
}

.td {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tx3);
  animation: tp 1.2s infinite ease-in-out;
}

.td:nth-child(2) { animation-delay: .2s; }
.td:nth-child(3) { animation-delay: .4s; }

@keyframes tp {
  0%, 80%, 100% { opacity: .3; transform: scale(.8)  }
  40%           { opacity: 1;  transform: scale(1.1) }
}

/* Confetti */
.cf-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.cf {
  position: absolute;
  top: -10px;
  border-radius: 2px;
  animation: cff linear forwards;
}

@keyframes cff {
  0%   { opacity: 1; transform: translateY(0)    rotate(0deg)   }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg) }
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--tx);
  color: #fff;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  z-index: 9998;
  animation: tin .3s ease;
  pointer-events: none;
}

@keyframes tin {
  from { opacity: 0; transform: translateX(-50%) translateY(10px) }
  to   { opacity: 1; transform: translateX(-50%) translateY(0)    }
}

/* Pro animations */
.pro-glow { animation: proGlow 2.5s ease-in-out infinite alternate; }
@keyframes proGlow { from{box-shadow:0 0 0 0 rgba(255,215,0,0)} to{box-shadow:0 0 12px 3px rgba(255,165,0,.45)} }

@keyframes proActivate { 0%{transform:scale(.8);opacity:0} 60%{transform:scale(1.05);opacity:1} 100%{transform:scale(1)} }
.pro-success-anim { animation: proActivate .5s ease forwards; }
.sc.pro-mode { background: linear-gradient(135deg, #7C5CBF, #4ECDC4); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--br); border-radius: 2px; }

/* Utility */
.hidden { display: none !important; }
/* ════════════════════════════════════════════════════
   11. RESPONSIVE — Mobile First
   ════════════════════════════════════════════════════ */

.mob-nav { display:none; position:fixed; bottom:0; left:0; right:0; height:58px; background:var(--bg2); border-top:2px solid var(--br); z-index:300; box-shadow:0 -3px 12px rgba(0,0,0,.08); }
.mob-nav-inner { display:flex; height:100%; }
.mbn { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; border:none; background:transparent; cursor:pointer; font-family:'Baloo 2',cursive; font-size:9px; font-weight:700; color:var(--tx3); -webkit-tap-highlight-color:transparent; }
a.mbn { text-decoration:none; }
.mbn .mi { font-size:22px; line-height:1; transition:transform .2s; }
.mbn.active { color:var(--pri); }
.mbn.active .mi { transform:scale(1.2); }

.mob-overlay { display:none; position:fixed; inset:0; background:rgba(44,24,16,.5); z-index:400; backdrop-filter:blur(3px); }
.mob-overlay.open { display:block; }

.mob-drawer { position:fixed; top:0; height:100vh; width:min(82vw,300px); background:var(--bg2); z-index:500; overflow-y:auto; transition:transform .28s cubic-bezier(.4,0,.2,1); display:flex; flex-direction:column; gap:4px; padding:56px 10px 70px; }
.mob-drawer-left  { left:0; border-right:2px solid var(--br); transform:translateX(-100%); }
.mob-drawer-right { right:0; border-left:2px solid var(--br); transform:translateX(100%); gap:12px; padding:56px 12px 70px; }
.mob-drawer.open  { transform:translateX(0); }

.mob-drawer-close { position:absolute; top:12px; right:12px; width:32px; height:32px; border-radius:50%; border:2px solid var(--br); background:var(--bg); cursor:pointer; font-size:14px; color:var(--tx3); display:flex; align-items:center; justify-content:center; }

.mob-grade-row { display:flex; gap:6px; padding:8px 8px 12px; flex-wrap:wrap; }
.mob-grade-row .gb { min-width:44px; min-height:44px; }

/* ── ≤ 1100px tablet landscape ── */
@media (max-width:1100px) {
  .layout { grid-template-columns:220px 1fr 240px; }
}

/* ── ≤ 860px tablet portrait ── */
@media (max-width:860px) {
  .sl, .sr { display:none; }
  .layout { grid-template-columns:1fr; height:calc(100vh - 60px - 58px); }
  .mob-nav { display:flex; }

  /* Payment modal — bottom sheet on tablet */
  #payModal { align-items:flex-end; }
  .pay-card { width:100%; max-width:100%; border-radius:20px 20px 0 0; max-height:92dvh; }
  .pay-steps { border-radius:20px 20px 0 0; }
  .pay-body { padding:16px 20px 24px; }
  .plan-cards { grid-template-columns:1fr; }
  .qr-panel { flex-direction:column; align-items:center; }
  #planProYearly { flex-direction:column !important; align-items:flex-start !important; }

  .eq { font-size:38px; }
  .ac { font-size:26px; padding:12px; }
}

/* ── ≤ 600px mobile ── */
@media (max-width:600px) {
  header { padding:0 10px; height:54px; }
  .logo  { font-size:15px; gap:6px; }
  .logo-box { width:28px; height:28px; font-size:14px; }
  .hdr-mid { display:none; }
  .stars-pill { display:none; }
  .streak-pill { padding:3px 8px; font-size:11px; }
  #upgradeBtn { padding:4px 9px; font-size:10px; }
  .user-pill { padding:3px 9px; font-size:11px; }
  .layout { height:calc(100vh - 54px - 58px); }

  /* Auth screen — full page on mobile */
  #authScreen { align-items:flex-start; padding-top:0; }
  .auth-card { width:100%; min-height:100dvh; border-radius:0; padding:40px 20px 30px; box-shadow:none; }
  .auth-logo { font-size:26px; }
  .login-grade-row { flex-wrap:wrap; justify-content:center; }

  /* Payment modal — bottom sheet */
  #payModal { align-items:flex-end; }
  .pay-card { width:100%; max-width:100%; border-radius:20px 20px 0 0; max-height:92dvh; }
  .pay-steps { border-radius:20px 20px 0 0; }
  .pay-body { padding:14px 14px 20px; }
  .plan-price { font-size:18px; }
  .qr-img-wrap { width:130px; height:130px; }
  .qr-amount-val { font-size:22px; }
  .qr-panel { gap:12px; padding:12px; }
  .qr-countdown { flex-direction:column; align-items:flex-start; gap:4px; }
  .pay-instructions { gap:6px; }

  .ch { padding:8px 12px; flex-wrap:wrap; gap:6px; }
  .ch-title { font-size:14px; }
  .ch-sub { font-size:10px; }
  .tabs { width:100%; justify-content:flex-end; }
  .tab { padding:4px 10px; font-size:10px; }

  .msgs { padding:10px; gap:8px; }
  .msg  { max-width:92%; }
  .bub  { font-size:14px; padding:8px 11px; }
  .av   { width:26px; height:26px; font-size:12px; }

  .inp-area { padding:7px 10px; }
  .ci  { font-size:15px; padding:8px 11px; min-height:36px; }
  .sb  { width:36px; height:36px; font-size:14px; }
  .qp  { font-size:10px; padding:2px 7px; }

  .ph  { padding:9px 12px; }
  .eq  { font-size:28px; }
  .ea  { padding:14px 12px; gap:10px; }
  .ac  { font-size:20px; padding:10px; border-radius:12px; }
  .ag  { max-width:100%; gap:7px; }
  .ectx { font-size:12px; padding:8px 12px; }
  #pracMode > div:last-child { padding:7px 10px; gap:5px; flex-wrap:wrap; }
  .hbtn { padding:5px 10px; font-size:10px; }

  .math-box { font-size:18px; }
  .step-box  { font-size:14px !important; }
  .praise    { font-size:14px !important; }
  .tip       { font-size:13px !important; }

  .toast { bottom:68px; font-size:12px; padding:8px 16px; }
  .dropdown-menu { min-width:175px; }
}

/* ── ≤ 400px small phone (Galaxy S8, iPhone SE…) ── */
@media (max-width:400px) {
  header { padding:0 8px; height:50px; }
  .logo  { font-size:13px; gap:5px; }
  .logo-box { width:26px; height:26px; font-size:13px; }
  .streak-pill { padding:2px 6px; font-size:10px; gap:3px; }
  #upgradeBtn { padding:3px 7px; font-size:9px; }
  .user-pill { padding:3px 7px; font-size:10px; gap:4px; }
  .layout { height:calc(100vh - 50px - 58px); }

  /* Auth */
  .auth-card { padding:32px 14px 24px; }
  .auth-logo { font-size:22px; }
  .login-input { font-size:13px; padding:9px 12px; }
  .login-btn { font-size:13px; padding:11px; }

  /* Payment */
  .pay-body { padding:12px 12px 18px; }
  .plan-cards { gap:8px; }
  .plan-card { padding:14px 10px; }
  .plan-price { font-size:16px; }
  .qr-img-wrap { width:110px; height:110px; }
  .qr-amount-val { font-size:19px; }
  .qr-value.mono { font-size:12px; }
  .pay-steps { overflow-x:auto; }
  .pay-step { padding:10px 4px; font-size:10px; }

  /* Practice */
  .eq { font-size:24px; }
  .ac { font-size:17px; padding:8px; }
  .ea { padding:10px 8px; gap:8px; }

  /* Chat */
  .bub { font-size:13px; }
  .mbn .mi { font-size:20px; }
  .mbn { font-size:8px; }

  #hdName { display:none; }
}

/* ── ≤ 350px extra small (Galaxy Z Fold outer, older devices) ── */
@media (max-width:350px) {
  header { height:46px; padding:0 6px; }
  .logo-box { width:22px; height:22px; font-size:11px; }
  .logo { font-size:11px; gap:4px; }
  #upgradeBtn { display:none; }

  /* Auth */
  .auth-card { padding:24px 10px 20px; }
  .auth-logo { font-size:18px; }
  .lg-btn { width:40px; height:40px; font-size:14px; }
  .login-grade-row { gap:5px; }

  /* Payment */
  .pay-card { border-radius:16px 16px 0 0; }
  .plan-price { font-size:14px; }
  .pay-step-num { width:18px; height:18px; font-size:9px; }
  .qr-img-wrap { width:95px; height:95px; }

  /* Layout */
  .layout { height:calc(100vh - 46px - 58px); }
  .eq { font-size:20px; }
  .ac { font-size:15px; padding:6px; }
  .ag { gap:5px; }
  .mob-drawer { width:88vw; }
}

/* ════════════════════════════════════════════════════
   FRACTION DISPLAY — Phân số kiểu tử/mẫu trên/dưới
   ════════════════════════════════════════════════════ */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 3px;
  line-height: 1;
}
.frac-num,
.frac-den {
  display: block;
  text-align: center;
  padding: 1px 5px;
  font-weight: 700;
  line-height: 1.2;
}
.frac-num {
  border-bottom: 2px solid currentColor;
}

/* Kích thước trong từng context */
.eq .frac-num,
.eq .frac-den   { font-size: 0.72em; }   /* câu hỏi luyện tập */

.ac .frac-num,
.ac .frac-den   { font-size: 0.75em; }   /* ô đáp án */

.bub .frac-num,
.bub .frac-den  { font-size: 0.8em; }    /* chat bubble */

.math-box .frac-num,
.math-box .frac-den { font-size: 0.85em; } /* math block */

.ectx .frac-num,
.ectx .frac-den { font-size: 0.8em; }    /* context câu hỏi */

/* Mobile — tăng size lên cho trẻ dễ đọc */
@media (max-width: 600px) {
  .eq .frac-num,
  .eq .frac-den   { font-size: 0.78em; }
  .ac .frac-num,
  .ac .frac-den   { font-size: 0.82em; }
}

/* ── Badge tooltip & unlock ── */
.bdg{position:relative}
.bdg-hint{display:none;position:absolute;bottom:calc(100% + 8px);left:50%;transform:translateX(-50%);background:rgba(0,0,0,.82);color:#fff;font-size:11px;line-height:1.4;padding:5px 9px;border-radius:8px;white-space:nowrap;pointer-events:none;z-index:99;font-family:'Nunito',sans-serif}
.bdg-hint::after{content:'';position:absolute;top:100%;left:50%;transform:translateX(-50%);border:5px solid transparent;border-top-color:rgba(0,0,0,.82)}
.bdg.locked{cursor:help}
.bdg.locked:hover .bdg-hint,.bdg.locked:focus .bdg-hint{display:block}
@keyframes badgeUnlock{0%{transform:scale(1)}40%{transform:scale(1.35) rotate(-5deg)}70%{transform:scale(1.2) rotate(3deg)}100%{transform:scale(1)}}
.bdg.just-unlocked{animation:badgeUnlock .6s ease}
/* ── Fraction display ── */
.frac{display:inline-flex;flex-direction:column;align-items:center;vertical-align:middle;margin:0 3px;line-height:1}
.frac-num,.frac-den{display:block;text-align:center;padding:1px 5px;font-weight:700;line-height:1.2}
.frac-num{border-bottom:2px solid currentColor}
.eq .frac-num,.eq .frac-den{font-size:.72em}
.ac .frac-num,.ac .frac-den{font-size:.75em}
.bub .frac-num,.bub .frac-den{font-size:.8em}
@media(max-width:600px){.eq .frac-num,.eq .frac-den{font-size:.78em}.ac .frac-num,.ac .frac-den{font-size:.82em}}