/* Học Vui – giao diện chung: màu, chữ, khung, nút, các màn hình chính. */
:root {
  --bg: #fff6e5;
  --paper: #ffffff;
  --ink: #2a2750;
  --muted: #6b6890;
  --primary: #5b5bd6;
  --accent: #ff7a59;
  --good: #1f9d4c;
  --good-bg: #e3f7e9;
  --bad: #d93a3f;
  --bad-bg: #fdeaea;
  --gold: #ffb020;
  --line: 3px solid var(--ink);
  --radius: 20px;
  --shadow: 0 5px 0 var(--ink);
  --font: "Nunito", "Baloo 2", ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg) radial-gradient(circle at 12% 8%, #ffe9b8 0 120px, transparent 121px), radial-gradient(circle at 92% 30%, #d9ecff 0 90px, transparent 91px);
  background-attachment: fixed;
  color: var(--ink); font: 600 18px/1.45 var(--font);
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }
a { color: var(--primary); }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 2px dashed #d9d4ee; margin: 1.2em 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 4px solid #8fb4ff; outline-offset: 2px; }
.muted { color: var(--muted); font-weight: 600; }
.center { text-align: center; }
.loading { text-align: center; padding: 3rem 0; color: var(--muted); }

/* Thanh trên cùng */
#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 14px calc(8px); background: #fff; border-bottom: var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 900; font-size: 1.2rem; }
.brand-icon { font-size: 1.6rem; }
.bar-right { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; min-height: 36px;
  background: #fff3cf; border: 2px solid var(--ink); border-radius: 999px; font-weight: 800; font-size: .95rem; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.chip-me { background: #e6e6ff; }

#app { max-width: 780px; margin: 0 auto; padding: 16px 14px 56px; outline: none; }
.panel { background: var(--paper); border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 22px; }

/* Nút */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 10px 22px;
  background: var(--primary); color: #fff; border: var(--line); border-radius: 16px; box-shadow: 0 4px 0 var(--ink);
  font-weight: 900; text-decoration: none; cursor: pointer; transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-big { min-height: 62px; font-size: 1.25rem; padding: 12px 30px; background: var(--accent); }
.btn-alt { background: #3ecf8e; color: var(--ink); }
.btn-ghost { background: #fff; color: var(--ink); }
.btn-danger { background: var(--bad); }
.btn-small { min-height: 40px; padding: 4px 14px; font-size: .9rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 16px; }
.back { display: inline-block; margin: 0 0 12px; font-weight: 900; text-decoration: none; }

/* Form */
.input { width: 100%; min-height: 52px; padding: 8px 14px; background: #fff; border: var(--line); border-radius: 14px; font-weight: 700; }
.field { display: block; text-align: left; margin: 0 0 16px; }
.field-label { display: block; font-weight: 900; margin-bottom: 6px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 8px; }
.check input { width: 24px; height: 24px; accent-color: var(--primary); }
.form-msg { color: var(--bad); font-weight: 800; min-height: 1.4em; margin-top: 8px; }
.avatars { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.avatar { width: 58px; height: 58px; font-size: 2rem; background: #fff; border: var(--line); border-radius: 50%; cursor: pointer; }
.avatar.sel { background: #ffe08a; box-shadow: 0 0 0 4px var(--primary); }

/* Tiêu đề trang, khối lưới */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.page-head h1 { margin: 0; flex: 1; }
.page-icon { font-size: 2.2rem; }
.section-title { margin: 22px 0 10px; }
.grid { display: grid; gap: 14px; }
.grid-subjects { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-topics, .grid-games { grid-template-columns: 1fr; }
.grid-badges { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (min-width: 640px) { .grid-topics { grid-template-columns: 1fr 1fr; } }

/* Trang chủ */
.hello { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.hello h1 { margin: 0; }
.hello-avatar { width: 68px; height: 68px; display: grid; place-items: center; font-size: 2.4rem; background: #ffe08a; border: var(--line); border-radius: 50%; }
.hero {
  display: flex; align-items: center; gap: 14px; padding: 16px; text-decoration: none; color: var(--ink);
  background: linear-gradient(135deg, #ffd45e, #ffab5e); border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-icon { font-size: 2.6rem; }
.hero-text { flex: 1; min-width: 0; }
.hero-why { font-size: .9rem; font-weight: 800; opacity: .8; }
.hero-title { font-size: 1.2rem; font-weight: 900; line-height: 1.25; }
.hero-go { width: 52px; height: 52px; display: grid; place-items: center; background: #fff; border: var(--line); border-radius: 50%; font-size: 1.3rem; }
.card-subject {
  display: block; padding: 16px; text-align: center; text-decoration: none; color: var(--ink);
  background: #fff; border: var(--line); border-radius: var(--radius); box-shadow: 0 5px 0 var(--accent, var(--ink));
}
.card-subject:active, .card-topic:active, .card-game:active, .tile-link:active { transform: translateY(3px); }
.subject-icon { font-size: 2.6rem; }
.subject-name { font-size: 1.25rem; font-weight: 900; margin-bottom: 8px; }
.subject-sub { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.meter, .progress, .timebar { height: 12px; background: #ece9f8; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
.meter-fill, .progress-fill { height: 100%; width: 0; background: var(--accent, var(--primary)); transition: width .3s; }
.progress-fill { background: #3ecf8e; }
.tile-link {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 76px; padding: 12px; text-decoration: none;
  font-weight: 900; color: var(--ink); background: #d9f3ff; border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.tile-badges { background: #ffe3f0; }
.tile-emoji { font-size: 2rem; }

/* Chủ đề, trò chơi trong danh sách */
.card-topic, .card-game {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; color: var(--ink);
  background: #fff; border: var(--line); border-radius: 18px; box-shadow: 0 4px 0 var(--accent, var(--ink));
}
.topic-icon, .game-icon { width: 54px; height: 54px; flex: none; display: grid; place-items: center; font-size: 1.9rem; background: #f3f0ff; border: 2px solid var(--ink); border-radius: 14px; }
.topic-body, .game-body { min-width: 0; }
.topic-name { font-weight: 900; line-height: 1.25; }
.topic-stars { color: #e69500; letter-spacing: 2px; }
.topic-meta { color: var(--muted); font-size: .85rem; letter-spacing: 0; }
.tag { display: inline-block; margin-left: 8px; padding: 1px 8px; font-size: .72rem; background: #e6e6ff; border-radius: 999px; vertical-align: middle; }
.tag-warn { background: #ffe0a8; }

/* Huy hiệu, thống kê */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 8px 0 16px; }
.stat { text-align: center; padding: 10px 6px; background: #fff3cf; border: 2px solid var(--ink); border-radius: 16px; }
.stat-num { font-size: 1.4rem; font-weight: 900; }
.badge { text-align: center; padding: 14px 10px; background: #f0eef8; border: 2px dashed #b7b2d6; border-radius: 18px; filter: grayscale(1); opacity: .75; }
.badge.got { background: #fff3cf; border: var(--line); filter: none; opacity: 1; box-shadow: 0 4px 0 var(--gold); }
.badge-icon { font-size: 2.4rem; }
.badge-name { font-weight: 900; }
.badge .muted { font-size: .85rem; }

/* Phụ huynh */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid #e3dff3; }
.table .num { text-align: center; white-space: nowrap; }
.table .weak { color: var(--bad); font-weight: 900; }
.fold { margin: 10px 0; }
.fold summary { cursor: pointer; font-weight: 900; font-size: 1.05rem; padding: 6px 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #e3dff3; }

/* Thông báo nổi */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 60;
  max-width: 90vw; padding: 10px 20px; background: var(--ink); color: #fff; border-radius: 999px; font-weight: 800; transition: .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Tài khoản ---- */
.form { display: grid; gap: 4px; }
.form-msg.ok { color: var(--good, #1f8f4e); }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }
.chip-sync { background: #eef7ee; }
.panel code { background: #f0edfb; padding: 1px 6px; border-radius: 6px; }
