:root{
  --bg:#f5f6fa;
  --card:#ffffff;
  --text:#111827;
  --muted:#6b7280;
  --blue:#1d4ed8;
  --purple:#5b5bd6;
  --border:#e5e7eb;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
  --radius: 18px;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}
.topbar{
  position:sticky;
  top:0;
  z-index:10;
  background:#fff;
  border-bottom:1px solid var(--border);
  padding:10px 12px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.brand{display:flex; align-items:center; gap:8px; font-size:16px;}
.topbar-actions{display:flex; gap:10px; align-items:center;}
.pill{
  border:1px solid var(--border);
  background:#f3f4f6;
  color:#111;
  padding:8px 12px;
  border-radius:999px;
  font-weight:600;
}
.pill:active{transform:scale(.98)}
.app{
  padding:14px;
  max-width:1100px;
  margin:0 auto;
}
.loading{ color:var(--muted); padding:24px 6px; }
.screen{display:block}
.section{
  background:rgba(255,255,255,.65);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:14px;
  margin:14px 0;
  box-shadow:0 6px 18px rgba(0,0,0,.04);
}
.section-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}
.section-title{display:flex; align-items:center; gap:10px; font-size:18px; font-weight:800;}
.section-sub{color:var(--muted); font-size:13px; font-weight:600;}
.grid{
  display:grid;
  grid-template-columns:repeat(3, minmax(0,1fr));
  gap:12px;
}
@media (max-width: 960px){ .grid{grid-template-columns:repeat(2, minmax(0,1fr));} }
@media (max-width: 620px){ .grid{grid-template-columns:1fr;} }
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:18px;
  padding:14px;
  box-shadow:0 10px 20px rgba(0,0,0,.06);
  display:flex;
  flex-direction:column;
  gap:10px;
  min-height:130px;
}
.card-top{display:flex; align-items:flex-start; justify-content:space-between; gap:10px;}
.card-title{font-weight:800; font-size:16px; line-height:1.2}
.card-count{color:var(--muted); font-weight:700; font-size:13px}
.card-icon{font-size:18px; opacity:.9}
.btn{
  width:100%;
  border:none;
  color:#fff;
  font-weight:800;
  padding:12px 14px;
  border-radius:14px;
  cursor:pointer; /* NEW: pointer cursor */
}
.btn.blue{background:var(--blue)}
.btn.purple{background:var(--purple)}
.btn:active{transform:scale(.99)}
.quiz-wrap{
  background:#fff;
  border:1px solid var(--border);
  border-radius:22px;
  box-shadow:var(--shadow);
  padding:16px;
  max-width:880px;
  margin:10px auto;
}
.quiz-head{display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px;}
.quiz-title{font-weight:900}
.quiz-progress{color:var(--muted); font-weight:800}
.quiz-body{
  padding:14px;
  border:1px dashed var(--border);
  border-radius:18px;
  text-align:center;
}
.big-emoji{font-size:40px; margin-bottom:8px}
.qtext{font-size:26px; font-weight:900; line-height:1.35; margin:6px 0 2px;}
.hint{
  margin-top:12px;
  border-top:1px dashed var(--border);
  padding-top:12px;
  color:#16a34a;
  font-weight:800;
  font-style:italic;
  font-size:18px;
}
.controls{display:flex; gap:14px; justify-content:center; margin:16px 0 10px; flex-wrap:wrap;}
.circle{
  width:64px;height:64px;border-radius:999px;border:none;
  font-size:28px;font-weight:900;color:#fff;
  box-shadow:0 10px 18px rgba(0,0,0,.12);
}
.circle:active{transform:scale(.95)}
.circle.orange{background:#ff9f0a}
.circle.blue{background:#007aff}
.circle.green{background:#32d74b}

/* Next button styles (USED by other modules) */
.nextbar{display:flex; justify-content:center; margin-top:10px;}
.next{
  width:min(720px, 100%);
  border:none;
  background:var(--purple);
  color:#fff;
  padding:16px 18px;
  border-radius:16px;
  font-weight:900;
  font-size:18px;
}
.next:active{transform:scale(.99)}

.options{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:12px;
  margin-top:14px;
}
@media (max-width: 620px){ .options{grid-template-columns:1fr;} }
.opt{
  border:1px solid var(--border);
  background:#f9fafb;
  padding:14px 14px;
  border-radius:14px;
  text-align:left;
  font-weight:800;
  font-size:16px;
}
.opt:active{transform:scale(.99)}
.opt.correct{outline:3px solid rgba(34,197,94,.35); background:rgba(34,197,94,.12)}
.opt.wrong{outline:3px solid rgba(239,68,68,.25); background:rgba(239,68,68,.10)}
.explain{
  margin-top:12px;
  color:#111;
  font-size:15px;
  line-height:1.45;
  background:#fff7ed;
  border:1px solid #fed7aa;
  border-radius:14px;
  padding:12px 12px;
}
.muted{color:var(--muted)}
.finish{text-align:center; padding:22px 10px;}
.finish h2{margin:0 0 6px}

/* ===== Mobile & iOS polish (append at end) ===== */

/* iOS safe area + tránh lỗi 100vh */
body{
  min-height: 100svh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Chữ câu hỏi co giãn theo màn hình (PC/iPad/iPhone) */
.qtext{
  font-size: clamp(20px, 4.2vw, 28px);
  line-height: 1.35;
}

/* Tối ưu topbar cho màn nhỏ */
@media (max-width: 520px){
  .topbar{
    padding: 8px 10px;
  }
  .brand{
    font-size: 14px;
  }
  .pill{
    padding: 7px 10px;
    font-size: 14px;
  }
  .app{
    padding: 10px;
  }
}

/* Nút tròn và Next dễ bấm hơn trên iPhone */
@media (max-width: 520px){
  .circle{
    width: 58px;
    height: 58px;
    font-size: 26px;
  }
  .next{
    font-size: 17px;
    padding: 14px 16px;
  }
}

/* Grammar options: 1 cột trên iPhone để không chật */
@media (max-width: 620px){
  .options{
    grid-template-columns: 1fr;
  }
  .opt{
    font-size: 16px;
    padding: 14px 14px;
  }
}

/* Giảm cảm giác bị “cuộn xuống dưới” khi bấm Start */
.screen[hidden]{ display:none !important; }

/* ===== App-like screens for iPhone/iPad: each screen full viewport ===== */
@media (max-width: 820px){
  html, body{ height: 100%; overflow: hidden; }
  .screen{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--topbar-h);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .screen[hidden]{ display:none !important; }
}

/* ===== Pronunciation additions ===== */
.btn.green{background:#16a34a;}
/* ===== Vocabulary additions ===== */
.btn.teal{
  background: #14b8a6;      /* teal-500 */
  color: #ffffff;
}
.btn.teal:hover{
  background: #0d9488;      /* teal-600 */
}

.opt-line{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.opt-text{flex:1; min-width:0;}
.opt-say{
  flex:0 0 auto;
  border:1px solid var(--border);
  background:#fff;
  border-radius:12px;
  padding:8px 10px;
  font-weight:900;
}
.opt-say:active{transform:scale(.98)}
.finish-box{
  margin-top:12px;
  padding:12px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#f9fafb;
}
.finish-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:center;
  margin-top:10px;
}
.finish-actions .btn{
  min-width:160px;
}

/* Pronunciation: show EN bold, VI in parentheses smaller */
.en-strong{
  font-weight: 800;
}
.vi-paren{
  font-size: 0.9em;  /* nhỏ hơn 1 cỡ */
  opacity: 0.85;
  margin-left: 6px;
}

/* ===== V2 UI polish (append) ===== */
:root{
  --brand1:#2563eb;
  --brand2:#7c3aed;
  --glass: rgba(255,255,255,.72);
}

/* Topbar: glass + gradient */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
  background: linear-gradient(120deg, rgba(37,99,235,.16), rgba(124,58,237,.14));
  border-bottom: 1px solid rgba(229,231,235,.9);
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
}

.brand-mark{
  width:38px;
  height:38px;
  display:grid;
  place-items:center;
  border-radius:14px;
  background: linear-gradient(135deg, rgba(37,99,235,.95), rgba(124,58,237,.95));
  color:#fff;
  box-shadow: 0 10px 22px rgba(0,0,0,.12);
  font-size:18px;
}

.brand-text{display:flex; flex-direction:column; line-height:1.05}
.brand-title{
  font-weight:900;
  letter-spacing:.2px;
}
.brand-sub{
  font-size:12px;
  color: var(--muted);
  margin-top:3px;
}

/* Buttons */
.pill{
  border: 1px solid rgba(229,231,235,.95);
  background: var(--glass);
  box-shadow: 0 6px 18px rgba(0,0,0,.06);
}
.pill:hover{filter:brightness(1.02)}
.pill.danger{
  border-color: rgba(239,68,68,.35);
}

/* Hero card */
.hero{
  margin: 6px 0 14px;
  border-radius: 22px;
  border: 1px solid rgba(229,231,235,.95);
  background: linear-gradient(135deg, rgba(37,99,235,.10), rgba(124,58,237,.10));
  box-shadow: var(--shadow);
}
.hero-inner{
  padding: 16px 16px 14px;
}
.hero-title{
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .2px;
}
.hero-sub{
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}
.hero-chips{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top: 12px;
}
.chip{
  cursor: pointer;
  user-select: none;
  display:flex;
  align-items:center;
  gap:8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(229,231,235,.95);
  font-weight:700;
  font-size:13px;
}
.chip-num{
  font-weight:900;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(17,24,39,.06);
}
.hero-note{
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

/* Slightly nicer cards */
.card{
  border: 1px solid rgba(229,231,235,.95);
}
.card-icon{
  filter: saturate(1.1);
}

/* ===== FIX: iPhone/iPad header che nội dung (topbar overlap) ===== */
:root{
  --topbar-h: 72px; /* JS sẽ tự đo và cập nhật */
}

/* Safe-area cho topbar trên iPhone/iPad (tai thỏ) */
.topbar{
  padding-top: calc(10px + env(safe-area-inset-top));
}

/* Hero chips behave like navigation buttons */
.chip:active{transform:scale(.98)}

.topic-img{
  width: 100%;
  max-width: 520px;
  height: auto;              /* ✅ để ảnh tự giữ tỷ lệ */
  max-height: 60vh;          /* ✅ không quá cao trên mobile */
  object-fit: contain;       /* ✅ KHÔNG CẮT ẢNH */
  border-radius: 14px;
  margin: 10px auto 8px;
  display: block;
  background: #fff;          /* nền trắng nếu ảnh không phủ kín */
  box-shadow: 0 6px 18px rgba(0,0,0,.10);
}

.kwhint{
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,.05);
  font-weight: 600;
}

/* ===== Bedtime: bottom dock (always visible, safe on iPhone) ===== */
.bt-dock{
  position: sticky;
  bottom: 0;
  z-index: 50;
  background: var(--bg);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

/* Thu nhỏ icon như Reading */
.bt-controls{
  gap: 12px;
  margin-top: 0;
  margin-bottom: 10px;
}
.bt-controls .circle{
  width: 54px;
  height: 54px;
  font-size: 22px;
}
@media (max-width: 520px){
  .bt-controls .circle{
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}
@media (max-width: 820px){
  .bt-dock{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
  }
}

/* Bedtime: chừa chỗ cho dock (đã bỏ NextBig nên giảm lại) */
#screenBedtime{
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

/* =========================================================
   Grammar Topic: Start + Learn (50 / 50)
   Scoped – không ảnh hưởng module khác
   ========================================================= */

.card-actions{
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.card-actions .half{
  flex: 1 1 0;
  min-width: 0;
}

/* Learn button style */
/* Learn button (better look) */
.btn.ghost{
  background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(245,245,255,.9));
  border: 2px solid rgba(93, 95, 239, .35);
  color: #2b2b7a;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(0,0,0,.06);
}
.btn.ghost:active{
  transform: scale(.99);
}


/* Mobile tuning */
@media (max-width: 520px){
  .card-actions{
    gap: 8px;
  }
}
