/* Bé Học Tiếng Việt — giao diện dùng chung cho trang gốc và mọi trang bài (template: scripts/bhtv/template.html) */
:root {
  --amber: #FBBF24; --amber-d: #F59E0B; --amber-l: #FEF3C7;
  --sky: #0EA5E9; --green: #10B981; --rose: #F43F5E;
  --ink: #1E293B; --bg: #FFFDF7;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink);
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, select { font-family: inherit; cursor: pointer; }
button { border: 0; }

/* ---- Header ---- */
header {
  background: var(--amber); position: sticky; top: 0; z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
  padding-top: env(safe-area-inset-top);
}
.bar {
  max-width: 1100px; margin: 0 auto; padding: 6px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { color: inherit; text-decoration: none; margin: 0; font-size: 1.35rem; font-weight: 900; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { flex: 0 0 auto; }
.settings { max-width: 1100px; margin: 0 auto; padding: 0 16px 10px; display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; }
.settings .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* Thông tin cho ba mẹ + bản quyền: nằm trong ⚙️ để màn hình của bé chỉ có nội dung bài */
.parents { background: rgba(255,255,255,.8); border-radius: 14px; padding: 4px 12px; font-size: .9rem; font-weight: 700; line-height: 1.5; color: #451A03; user-select: text; -webkit-user-select: text; }
.parents summary { min-height: 40px; display: flex; align-items: center; font-weight: 900; cursor: pointer; }
.parents p { margin: 4px 0; }
.parents ol { margin: 4px 0 8px; padding-left: 20px; }
.note { margin: 0; font-size: .8rem; font-weight: 700; line-height: 1.45; color: #78350F; user-select: text; -webkit-user-select: text; }
.note a { color: inherit; }
.hbtn.icon { width: 44px; padding: 0; font-size: 1.2rem; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#voiceSelect {
  min-height: 44px; flex: 1 1 200px; max-width: 320px; min-width: 0; padding: 0 10px; border-radius: 14px;
  border: 2px solid rgba(180,83,9,.25); background: #fff; font-weight: 800; font-size: .85rem; color: var(--ink);
}
.seg { display: flex; background: #FCD34D; padding: 4px; border-radius: 16px; }
.seg button {
  min-height: 40px; padding: 0 14px; border-radius: 12px; background: transparent;
  font-weight: 900; font-size: .9rem; color: #451A03;
}
.seg button.on { background: #fff; color: #92400E; box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ---- Main ---- */
main { max-width: 1100px; margin: 0 auto; padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 48px; padding: 0 18px; border-radius: 18px;
  font-weight: 900; font-size: 1rem; background: #fff; color: #475569;
  border: 2px solid #E2E8F0; transition: transform .1s;
}
a.chip { display: inline-flex; align-items: center; text-decoration: none; }
/* Chấm màu cấp độ trên chip bài: xanh lá (1) → xanh dương (2) → cam (3) → tím (4) */
.chip.poem::before { content: ''; flex: 0 0 auto; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--lv, #CBD5E1); }
.lv-1 { --lv: #10B981; } .lv-2 { --lv: #0EA5E9; } .lv-3 { --lv: #F97316; } .lv-4 { --lv: #8B5CF6; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--lv); vertical-align: middle; }
.chip:active { transform: scale(.95); }

.chip.cat.on { background: var(--sky); color: #fff; border-color: #0284C7; }
.chip.poem.on { background: var(--amber); color: #0F172A; border-color: var(--amber-d); }

/* ---- Card ---- */
.card { background: #fff; border: 3px solid #FDE68A; border-radius: 28px; padding: 16px 18px 22px; box-shadow: 0 6px 18px rgba(245,158,11,.12); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 2px solid var(--amber-l); }
#poemTitle { margin: 0; font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 900; line-height: 1.15; }
#poemAuthor { margin: 2px 0 0; font-size: .9rem; font-weight: 800; color: #64748B; }
.play {
  min-height: 52px; padding: 0 22px; border-radius: 18px; color: #fff; font-weight: 900; font-size: 1.05rem;
  background: var(--green); box-shadow: 0 3px 0 #059669; transition: transform .1s;
}
.play:active { transform: translateY(2px) scale(.97); box-shadow: 0 1px 0 #059669; }
.play.stop { background: var(--rose); box-shadow: 0 3px 0 #BE123C; }
[hidden] { display: none !important; }

/* Ảnh ở trên, giống trang sách giáo khoa */
#imageWrapper { display: flex; justify-content: center; margin: 14px 0 6px; }
#poemImage {
  width: auto; max-width: 100%; max-height: 42vh; object-fit: contain;
  border-radius: 20px; border: 3px solid var(--amber-l); background: #fff;
}

/* ---- Dòng thơ: cỡ chữ cố định, câu dài tự xuống dòng ---- */
/* Khối thơ nằm giữa trang, các dòng bên trong canh trái (như SGK) */
#lines {
  --fs: clamp(26px, 4.6vw, 44px); margin-top: 12px;
  display: grid; grid-template-columns: minmax(0, max-content);
  justify-content: center; row-gap: 4px;
}
.row { display: flex; align-items: center; gap: 12px; padding: 4px 8px; border-radius: 20px; max-width: 100%; transition: background-color .15s; }
.row.gap-after { margin-bottom: calc(var(--fs) * .7); }
.row.line-active { background: #FEF9C3; }
.spk {
  flex: 0 0 auto; width: 52px; height: 52px; border-radius: 16px; font-size: 1.4rem;
  background: #E0F2FE; transition: transform .1s;
}
.spk:active { transform: scale(.9); background: #BAE6FD; }
.words { display: flex; flex-wrap: wrap; min-width: 0; font-size: var(--fs); font-weight: 800; line-height: 1.25; }
.w { display: inline-block; padding: .05em .22em; border-radius: .4em; cursor: pointer; transition: transform .15s, background-color .15s; }
.w:active { background: var(--amber-l); }
.w.word-active { background: var(--amber) !important; color: #0F172A; transform: scale(1.1); box-shadow: 0 4px 12px rgba(245,158,11,.4); }

/* ---- Cài đặt app & hướng dẫn giọng Việt ---- */
.hbtn {
  min-height: 44px; padding: 0 14px; border-radius: 14px; background: #fff; color: #92400E;
  font-weight: 900; font-size: .85rem; border: 2px solid rgba(180,83,9,.25);
}
.hbtn.warn { background: #FEE2E2; color: #B91C1C; border-color: #FCA5A5; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet {
  background: #fff; border-radius: 24px; max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 20px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); user-select: text; -webkit-user-select: text;
}
.sheet h3 { margin: 0 0 8px; font-size: 1.3rem; font-weight: 900; }
.sheet p, .sheet li { font-size: .95rem; line-height: 1.5; font-weight: 700; color: #334155; }
.sheet ol { padding-left: 22px; margin: 6px 0 12px; }
.sheet details { background: #FFFBEB; border-radius: 14px; padding: 8px 12px; margin: 8px 0; }
.sheet summary { font-weight: 900; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.sheet details[open] summary { color: #B45309; }
.sheet .close { width: 100%; min-height: 48px; margin-top: 10px; border-radius: 16px; background: var(--amber); font-weight: 900; font-size: 1rem; color: #451A03; }
.sheet .test { min-height: 44px; padding: 0 16px; border-radius: 14px; background: var(--green); color: #fff; font-weight: 900; }
#ttsBanner { background: #FEF2F2; border: 2px solid #FCA5A5; border-radius: 18px; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; font-weight: 800; color: #991B1B; }
#ttsBanner button { min-height: 44px; padding: 0 16px; border-radius: 14px; background: #DC2626; color: #fff; font-weight: 900; }

@media (max-width: 480px) {
  .brand { font-size: 1.05rem; }
  .seg button { padding: 0 10px; }
  .seg .lbl { display: none; }
  .spk { width: 44px; height: 44px; }
  .row { gap: 8px; padding: 3px 4px; }
  .card { padding: 12px 12px 18px; border-radius: 22px; }
}
/* Máy tính bảng ngang: ảnh bên trái nhỏ hơn để vừa màn hình */
@media (orientation: landscape) and (max-height: 700px) {
  #poemImage { max-height: 30vh; }
}
