/* ---------- Bảng màu ----------
   Nền giấy ấm, xanh hoàng gia làm màu chính, vàng kim cho điểm thưởng.
   Giao diện tối tự bật theo máy; người dùng có thể ép sáng/tối qua data-theme trên <html>. */
:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #faf8f2;
  --text: #1c2333;
  --muted: #5f6678;
  --border: #e6e1d6;
  --primary: #2947a9;
  --primary-hover: #213a8c;
  --on-primary: #ffffff;
  --primary-soft: #e7ecfb;
  --gold: #e2a82b;
  --gold-text: #875800;
  --gold-soft: #fdf3d7;
  --good: #18794e;
  --good-soft: #e1f5ea;
  --bad: #c0362c;
  --bad-soft: #fdeae8;
  --hero-from: #2947a9;
  --hero-to: #1b2f78;
  --shadow: 0 1px 2px rgb(28 35 51 / 5%), 0 6px 18px rgb(28 35 51 / 6%);
  --radius: 18px;
  /* Màu nhận diện của từng trò chơi */
  --hue-fill: #2f6fd6;
  --hue-trivia: #7a4fd1;
  --hue-book: #0a726c;
  --hue-order: #a55407;
  --hue-word: #c43d7a;
  --hue-memory: #24742f;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1320;
    --surface: #181d2e;
    --surface-2: #1e2438;
    --text: #e8eaf2;
    --muted: #9ea5bb;
    --border: #2a3149;
    --primary: #8ea6ff;
    --primary-hover: #a6b9ff;
    --on-primary: #0f1320;
    --primary-soft: #222b4f;
    --gold: #f0b941;
    --gold-text: #f0b941;
    --gold-soft: #33290f;
    --good: #5ad19a;
    --good-soft: #12301f;
    --bad: #ff8f85;
    --bad-soft: #3a1917;
    --hero-from: #2a3f96;
    --hero-to: #151d45;
    --shadow: none;
    --hue-fill: #6fa4ff;
    --hue-trivia: #b08cff;
    --hue-book: #4cc9c0;
    --hue-order: #f0a04c;
    --hue-word: #f07fb0;
    --hue-memory: #6fcf7d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1320;
  --surface: #181d2e;
  --surface-2: #1e2438;
  --text: #e8eaf2;
  --muted: #9ea5bb;
  --border: #2a3149;
  --primary: #8ea6ff;
  --primary-hover: #a6b9ff;
  --on-primary: #0f1320;
  --primary-soft: #222b4f;
  --gold: #f0b941;
  --gold-text: #f0b941;
  --gold-soft: #33290f;
  --good: #5ad19a;
  --good-soft: #12301f;
  --bad: #ff8f85;
  --bad-soft: #3a1917;
  --hero-from: #2a3f96;
  --hero-to: #151d45;
  --shadow: none;
  --hue-fill: #6fa4ff;
  --hue-trivia: #b08cff;
  --hue-book: #4cc9c0;
  --hue-order: #f0a04c;
  --hue-word: #f07fb0;
  --hue-memory: #6fcf7d;
  color-scheme: dark;
}

/* ---------- Nền tảng ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { margin: 6px 0 6px; font-size: 1.65rem; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
h2 { margin: 30px 0 12px; font-size: 1.08rem; font-weight: 700; }
h3 { margin: 20px 0 8px; font-size: 0.95rem; font-weight: 700; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.22em; }

/* ---------- Khung trang ---------- */
.top { position: sticky; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { display: flex; align-items: center; gap: 16px; max-width: 1040px; margin: 0 auto; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; }
.logo { width: 30px; height: 30px; flex: none; }
.logo rect { fill: var(--primary); }
.logo path { fill: none; stroke: var(--gold); stroke-width: 2.2; stroke-linejoin: round; }
#top-xp { display: flex; gap: 6px; margin-left: auto; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}
.chip.fire { background: var(--gold-soft); color: var(--gold-text); }
main { max-width: 760px; margin: 0 auto; padding: 18px 16px 104px; }
.page { animation: page-in 0.22s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }

/* Điện thoại: thanh điều hướng bám đáy. Máy tính: nằm trên thanh đầu trang. */
#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
#nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 7px 2px 5px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
}
#nav a .ic { width: 24px; height: 24px; }
#nav a.on { color: var(--primary); }
#nav a.on .ic { stroke-width: 2.4; }
body.in-round #nav { display: none; }

@media (min-width: 860px) {
  .brand span { font-size: 1.05rem; }
  #nav {
    position: static;
    flex: 1;
    justify-content: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
  }
  #nav a { flex: none; flex-direction: row; gap: 8px; min-height: 0; padding: 8px 14px; font-size: 0.9rem; }
  #nav a .ic { width: 20px; height: 20px; }
  #nav a:hover { background: var(--surface-2); color: var(--text); }
  #nav a.on { background: var(--primary-soft); color: var(--primary); }
  body.in-round #nav { display: flex; }
  #top-xp { margin-left: 0; }
  main { padding: 28px 16px 56px; }
}
@media (max-width: 400px) {
  .brand span { display: none; }
}

/* ---------- Thành phần chung ---------- */
.card {
  display: block;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
a.card, .tile, .option, .chapter, .btn { transition: transform 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s; }
a.card:hover { border-color: var(--primary); transform: translateY(-1px); }
a.card:active, .btn:active, .option:active:enabled, .tile:active:enabled { transform: scale(0.98); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
.bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar span { display: block; height: 100%; min-width: 0; border-radius: 999px; background: var(--primary); transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 700;
  text-align: center;
}
.btn:hover:enabled, a.btn:hover { border-color: var(--primary); }
.btn.primary { border-color: var(--primary); background: var(--primary); color: var(--on-primary); box-shadow: 0 3px 0 var(--primary-hover); }
.btn.primary:hover:enabled, a.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:active { box-shadow: none; transform: translateY(2px); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); background: transparent; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: 0.85rem; border-radius: 11px; }
.btn:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.back { display: inline-flex; align-items: center; gap: 2px; margin-bottom: 2px; color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.back.link { padding: 0; border: 0; background: none; }
.back:hover { color: var(--primary); }

/* Ô biểu tượng có màu riêng theo trò chơi: đặt --hue trên phần tử */
.tile-icon {
  display: grid;
  place-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 13px;
  background: color-mix(in srgb, var(--hue, var(--primary)) 14%, var(--surface));
  color: var(--hue, var(--primary));
}
.tile-icon .ic { width: 24px; height: 24px; }
[data-game="fill"] { --hue: var(--hue-fill); }
[data-game="trivia"] { --hue: var(--hue-trivia); }
[data-game="book"] { --hue: var(--hue-book); }
[data-game="order"] { --hue: var(--hue-order); }
[data-game="word"] { --hue: var(--hue-word); }
[data-game="memory"] { --hue: var(--hue-memory); }

.row-card { display: flex; align-items: center; gap: 14px; }
.row-card > div { flex: 1; min-width: 0; }
.row-card .arrow { color: var(--muted); }
.notice { margin-bottom: 16px; border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); background: var(--primary-soft); }
.notice-text { margin-bottom: 16px; border-color: var(--gold); background: var(--gold-soft); }

/* ---------- Trang chủ ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border: 0;
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #ffffff;
}
.level-ring { position: relative; width: 84px; height: 84px; flex: none; }
.level-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.level-ring circle { fill: none; stroke-width: 7; }
.level-ring .track { stroke: rgb(255 255 255 / 18%); }
.level-ring .value { stroke: var(--gold); stroke-linecap: round; transition: stroke-dashoffset 0.7s cubic-bezier(0.2, 0.8, 0.2, 1); }
.level-ring div { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.05; }
.level-ring span { font-size: 0.62rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.8; }
.level-ring strong { font-size: 1.7rem; font-weight: 800; }
.hero-main { flex: 1; min-width: 0; }
.hero-name { font-size: 1.15rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hero-title { display: inline-block; margin-top: 2px; padding: 2px 10px; border-radius: 999px; background: rgb(255 255 255 / 16%); font-size: 0.78rem; font-weight: 600; }
.hero-xp { margin-top: 10px; font-size: 0.82rem; opacity: 0.9; }
.hero-xp b { font-weight: 700; }

.streak-card { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.streak-num { display: flex; align-items: center; gap: 8px; flex: none; color: var(--muted); }
.streak-num .ic { width: 30px; height: 30px; }
.streak-num strong { font-size: 1.5rem; font-weight: 800; line-height: 1; color: var(--text); }
.streak-num small { display: block; font-size: 0.72rem; }
.streak-card.on .streak-num .ic { color: var(--gold); fill: color-mix(in srgb, var(--gold) 35%, transparent); }
.week { display: flex; flex: 1; justify-content: space-between; gap: 4px; max-width: 320px; margin-left: auto; }
.week div { display: grid; justify-items: center; gap: 4px; font-size: 0.68rem; font-weight: 600; color: var(--muted); }
.week i { display: grid; place-content: center; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border); color: transparent; }
.week i .ic { width: 15px; height: 15px; stroke-width: 3; }
.week .done i { border-color: var(--gold); background: var(--gold); color: #3a2600; }
.week .today { color: var(--text); }
.week .today:not(.done) i { border-color: var(--gold); border-style: dashed; }

.quests { padding: 6px 16px 12px; }
.quest { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.quest + .quest { border-top: 1px solid var(--border); }
.quest-body { flex: 1; min-width: 0; font-weight: 500; }
.quest-body .bar { margin-top: 7px; }
.quest-body .bar span { background: var(--gold); }
.check {
  flex: none;
  display: grid;
  place-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: 50%;
  color: transparent;
}
.check .ic { width: 16px; height: 16px; stroke-width: 3; }
.quest.done .check { border-color: var(--good); background: var(--good); color: var(--surface); }
.quest.done .quest-body { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border); }
.quest.done .quest-body .bar span { background: var(--good); }
.reward { flex: none; padding: 3px 9px; border-radius: 999px; background: var(--gold-soft); color: var(--gold-text); font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.quest.done .reward { background: var(--good-soft); color: var(--good); }
.quests > p { margin: 8px 0 0; }

.game { display: flex; flex-direction: column; gap: 10px; }
.game strong { display: block; font-weight: 700; }
.game .muted { font-size: 0.82rem; line-height: 1.4; }
.game:hover { border-color: var(--hue, var(--primary)); }
.quota { display: block; margin-top: 6px; color: var(--hue, var(--primary)); font-size: 0.76rem; font-weight: 700; }
.quota.out { color: var(--muted); font-weight: 600; }
.practice { padding: 2px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); letter-spacing: 0; text-transform: none; }

/* ---------- Đọc ---------- */
.books { grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); }
.book { display: flex; flex-direction: column; gap: 8px; padding: 13px 14px; }
.book strong { font-weight: 600; }
.book.started { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.book.complete { border-color: var(--good); background: var(--good-soft); }
.book.complete .bar span { background: var(--good); }
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 8px; margin-top: 14px; }
.chapter {
  display: grid;
  place-content: center;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 700;
}
.chapter:hover { border-color: var(--primary); }
.chapter.done { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.chapter.next { border: 2px solid var(--primary); color: var(--primary); }

.read-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.font-size { display: flex; flex: none; gap: 6px; }
.font-size button { width: 42px; height: 42px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font-weight: 700; }
.font-size button:hover:enabled { border-color: var(--primary); }
.font-size button:disabled { opacity: 0.4; cursor: default; }
.scripture, .verse { font-family: "Noto Serif", Cambria, "Times New Roman", serif; }
.scripture { margin: 16px 0 28px; font-size: var(--read-size, 1.14rem); line-height: 1.9; }
.scripture sup { margin-right: 3px; color: var(--primary); font-family: "Be Vietnam Pro", sans-serif; font-size: 0.6em; font-weight: 700; }
.read-actions {
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgb(0 0 0 / 14%);
}
.read-actions .btn.primary { flex: 1; }
.read-actions .step { width: 46px; padding: 0; flex: none; }
.read-actions .step[aria-disabled="true"] { opacity: 0.3; pointer-events: none; }
@media (min-width: 860px) {
  .read-actions { bottom: 16px; }
}

/* ---------- Tô màu câu Kinh Thánh ---------- */
:root {
  --hl-y: rgb(250 204 21 / 42%);
  --hl-g: rgb(74 222 128 / 38%);
  --hl-b: rgb(96 165 250 / 38%);
  --hl-p: rgb(244 114 182 / 36%);
  --hl-y-solid: #eab308;
  --hl-g-solid: #22c55e;
  --hl-b-solid: #3b82f6;
  --hl-p-solid: #ec4899;
}
.read-tip { margin: 6px 0 0; }
.scripture .v { padding: 2px 1px; border-radius: 4px; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.scripture .v:hover { background: var(--surface-2); }
.scripture .v.hl-y { background: var(--hl-y); }
.scripture .v.hl-g { background: var(--hl-g); }
.scripture .v.hl-b { background: var(--hl-b); }
.scripture .v.hl-p { background: var(--hl-p); }
.scripture .v.sel { box-shadow: 0 0 0 2px var(--primary); background-color: var(--primary-soft); }
.scripture .v.sel.hl-y { background-color: var(--hl-y); }
.scripture .v.sel.hl-g { background-color: var(--hl-g); }
.scripture .v.sel.hl-b { background-color: var(--hl-b); }
.scripture .v.sel.hl-p { background-color: var(--hl-p); }
.scripture .v.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 55% { box-shadow: 0 0 0 3px var(--gold); } 100% { box-shadow: 0 0 0 3px transparent; } }
.font-size .tool { display: grid; place-content: center; width: 42px; height: 42px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--primary); }
.font-size .tool:hover { border-color: var(--primary); }
.read-actions.marking { gap: 10px; }
.mark-count { flex: none; font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.swatches { display: flex; flex: 1; justify-content: center; gap: 8px; }
.swatch { width: 40px; height: 40px; flex: none; border: 2px solid var(--surface); border-radius: 50%; box-shadow: 0 0 0 1px var(--border); }
.swatch:hover { transform: scale(1.1); }
.swatch.hl-y, .dot.hl-y { background: var(--hl-y-solid); }
.swatch.hl-g, .dot.hl-g { background: var(--hl-g-solid); }
.swatch.hl-b, .dot.hl-b { background: var(--hl-b-solid); }
.swatch.hl-p, .dot.hl-p { background: var(--hl-p-solid); }
.btn.icon-only { width: 40px; padding: 0; flex: none; }
.tile-icon.hl-tile { background: var(--hl-y); color: var(--gold-text); }
.filters { display: flex; flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
.toolbar select { min-height: 40px; padding: 6px 12px; font-size: 0.88rem; }
.filter { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 0.85rem; font-weight: 600; }
.filter[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.mark { margin-bottom: 12px; padding: 14px 16px 10px; border-left-width: 5px; }
.mark.hl-edge-y { border-left-color: var(--hl-y-solid); }
.mark.hl-edge-g { border-left-color: var(--hl-g-solid); }
.mark.hl-edge-b { border-left-color: var(--hl-b-solid); }
.mark.hl-edge-p { border-left-color: var(--hl-p-solid); }
.verse-text { margin: 0 0 8px; font-family: "Noto Serif", Cambria, "Times New Roman", serif; font-size: 1.05rem; line-height: 1.75; }
.verse-text sup { margin-right: 3px; color: var(--primary); font-family: "Be Vietnam Pro", sans-serif; font-size: 0.6em; font-weight: 700; }
.mark-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mark-ref { display: inline-flex; align-items: center; gap: 2px; color: var(--primary); font-size: 0.88rem; font-weight: 700; }
.mark-ref .ic { width: 16px; height: 16px; }
.mark-actions { display: flex; gap: 2px; }

/* ---------- Ván chơi ---------- */
.round { max-width: 640px; margin: 0 auto; }
.round-top { display: flex; align-items: center; gap: 12px; }
.round-top .bar { flex: 1; height: 12px; }
.round-top .bar span { background: var(--hue, var(--primary)); }
.round-exit { display: grid; place-content: center; width: 40px; height: 40px; margin-left: -8px; border-radius: 12px; color: var(--muted); }
.round-exit:hover { background: var(--surface); color: var(--text); }
.round-count { color: var(--muted); font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.round-title { display: flex; align-items: center; gap: 8px; margin: 16px 0 10px; font-size: 0.8rem; font-weight: 700; color: var(--hue, var(--muted)); text-transform: uppercase; letter-spacing: 0.1em; }
.combo { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; padding: 2px 9px; border-radius: 999px; background: var(--gold-soft); color: var(--gold-text); letter-spacing: 0; text-transform: none; animation: pop 0.3s; }
.ask { margin: 0 0 12px; font-size: 1.05rem; font-weight: 700; }
.ask.big { font-size: 1.3rem; line-height: 1.4; margin-bottom: 18px; }
.verse {
  margin: 0 0 18px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--gold);
  border-radius: 6px var(--radius) var(--radius) 6px;
  background: var(--surface);
  font-size: 1.1rem;
  line-height: 1.8;
}
.verse cite { display: block; margin-top: 10px; color: var(--muted); font-family: "Be Vietnam Pro", sans-serif; font-size: 0.82rem; font-style: normal; font-weight: 700; }
.blank { display: inline-block; min-width: 3.2em; border-bottom: 2px dashed var(--primary); color: transparent; text-align: center; line-height: 1.3; user-select: none; }
.piece { padding: 1px 7px; border-radius: 7px; background: var(--primary-soft); color: var(--primary); animation: pop 0.2s; }
.verse.build { min-height: 4.6em; }
.word-slot { display: inline-flex; gap: 3px; vertical-align: middle; }
.letter {
  display: inline-grid;
  place-content: center;
  width: 1.5em;
  height: 1.8em;
  border-bottom: 3px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 6px 6px 0 0;
  color: var(--primary);
  font-weight: 700;
  line-height: 1;
}

.options { display: grid; gap: 10px; counter-reset: option; }
.option, .tile {
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 16px;
  background: var(--surface);
  font-weight: 600;
  text-align: left;
}
.option { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 16px; counter-increment: option; }
.option::before {
  content: counter(option);
  display: grid;
  place-content: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 2px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}
.option:hover:enabled, .tile:hover:enabled { border-color: var(--primary); background: var(--primary-soft); }
.option:disabled { cursor: default; opacity: 0.6; }
.option.right { opacity: 1; border-color: var(--good); background: var(--good-soft); color: var(--good); animation: pop 0.3s; }
.option.right::before { border-color: var(--good); background: var(--good); color: var(--surface); content: "✓"; }
.option.wrong { opacity: 1; border-color: var(--bad); background: var(--bad-soft); color: var(--bad); animation: shake 0.35s; }
.option.wrong::before { border-color: var(--bad); background: var(--bad); color: var(--surface); content: "✕"; }
.tiles { display: flex; flex-wrap: wrap; gap: 9px; }
.tile { min-height: 48px; padding: 9px 14px; font-family: "Noto Serif", Cambria, serif; font-size: 1.02rem; }
.tile:disabled { opacity: 0.22; cursor: default; }
.tiles.letters .tile { min-width: 50px; font-size: 1.3rem; font-weight: 700; text-align: center; }
.tile-actions { display: flex; align-items: center; gap: 12px; min-height: 40px; margin-top: 14px; flex-wrap: wrap; }
.hint { font-weight: 600; color: var(--bad); }

.feedback:empty { display: none; }
.feedback {
  position: sticky;
  bottom: 12px;
  z-index: 3;
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(0 0 0 / 18%);
  animation: sheet-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.feedback.good { background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 40%, transparent); }
.feedback.bad { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.feedback > strong { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.feedback.good > strong { color: var(--good); }
.feedback.bad > strong { color: var(--bad); }
.feedback .verse { margin: 0; padding: 12px 14px; font-size: 0.98rem; max-height: 30vh; overflow-y: auto; }
.feedback.good .btn.primary { border-color: var(--good); background: var(--good); color: var(--surface); box-shadow: 0 3px 0 color-mix(in srgb, var(--good) 70%, #000); }
.feedback.bad .btn.primary { border-color: var(--bad); background: var(--bad); color: var(--surface); box-shadow: 0 3px 0 color-mix(in srgb, var(--bad) 70%, #000); }
.ref-line { margin: 0; font-weight: 700; }
.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
@keyframes pop { 0% { transform: scale(0.9); } 60% { transform: scale(1.04); } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
/* Chỉ hiện số phím tắt trên máy có bàn phím */
@media (hover: none) {
  .option::before { display: none; }
  .option.right::before, .option.wrong::before { display: grid; }
}

.summary { margin: 28px auto 0; max-width: 520px; padding: 34px 22px; text-align: center; animation: pop 0.35s; }
.big-icon {
  display: grid;
  place-content: center;
  width: 92px;
  height: 92px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold-text);
}
.big-icon .ic { width: 46px; height: 46px; }
.big-icon.good { background: var(--good-soft); color: var(--good); }
.big-icon.calm { background: var(--primary-soft); color: var(--primary); }
.score-row { display: flex; justify-content: center; gap: 10px; margin: 16px 0 4px; flex-wrap: wrap; }
.score-pill { min-width: 108px; padding: 10px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.score-pill strong { display: block; font-size: 1.35rem; font-weight: 800; }
.score-pill.xp strong { color: var(--gold-text); }
.summary-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }

/* ---------- Xếp hạng ---------- */
.tabs { display: flex; gap: 4px; margin: 12px 0 16px; padding: 4px; border-radius: 14px; background: var(--border); }
.tabs a { flex: 1; padding: 9px; border-radius: 11px; color: var(--muted); font-weight: 700; text-align: center; }
.tabs a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.board { margin: 0 0 12px; padding: 4px 14px; list-style: none; }
.board li { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.board li + li { border-top: 1px solid var(--border); }
.board li.me { margin: 0 -14px; padding: 12px 14px; background: var(--primary-soft); border-radius: 12px; border-top-color: transparent; }
.board li.me + li { border-top-color: transparent; }
.pos { flex: none; display: grid; place-content: center; width: 34px; height: 34px; border-radius: 50%; color: var(--muted); font-weight: 800; }
.board li:nth-child(1) .pos { background: #f3c552; color: #3a2600; }
.board li:nth-child(2) .pos { background: #c9cfdb; color: #1c2333; }
.board li:nth-child(3) .pos { background: #dba77c; color: #3a1c00; }
.who { flex: 1; min-width: 0; }
.who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { display: flex; align-items: center; gap: 4px; }
.who small .ic { width: 14px; height: 14px; color: var(--gold-text); }
.score { flex: none; font-weight: 800; font-variant-numeric: tabular-nums; }
.score small { color: var(--muted); font-weight: 500; }

/* ---------- Cấp bậc ---------- */
.rank-icon { display: inline-block; width: 1.5em; height: 1.5em; flex: none; vertical-align: -0.38em; }
.rank-icon svg, .rank-icon img { display: block; width: 100%; height: 100%; object-fit: contain; }
.rank-icon.md { width: 44px; height: 44px; }
.rank-icon.lg { width: 68px; height: 68px; }
.rank-icon.xl { width: 124px; height: 124px; margin: 0 auto 12px; display: block; }
.hero-rank { flex: none; filter: drop-shadow(0 4px 10px rgb(0 0 0 / 30%)); }
.chip .rank-icon { width: 1.35em; height: 1.35em; vertical-align: 0; }
.who small .rank-icon { width: 18px; height: 18px; }
.ranks { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-bottom: 10px; }
.rank {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 14px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
}
.rank strong { margin-top: 6px; font-size: 0.9rem; }
.rank small { font-size: 0.74rem; }
.rank.locked { background: transparent; }
.rank.locked .rank-icon { filter: grayscale(1); opacity: 0.4; }
.rank.locked strong { color: var(--muted); }
.rank.current { border: 2px solid var(--gold); background: var(--gold-soft); }
@media (max-width: 420px) {
  .hero { gap: 12px; padding: 16px; }
  .hero .level-ring { width: 72px; height: 72px; }
  .rank-icon.lg { width: 54px; height: 54px; }
}

/* ---------- Hồ sơ ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 16px; }
.stat strong { display: block; font-size: 1.5rem; font-weight: 800; line-height: 1.2; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(146px, 1fr)); gap: 10px; }
.badge {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
}
.badge .icon { display: grid; place-content: center; width: 40px; height: 40px; margin-bottom: 4px; border-radius: 12px; background: var(--surface-2); font-size: 1.4rem; line-height: 1; }
.badge strong { font-size: 0.92rem; }
.badge.got { border-color: var(--gold); background: var(--gold-soft); color: var(--text); }
.badge.got .icon { background: var(--surface); }
.badge small { font-size: 0.75rem; line-height: 1.35; }
.badge.has-art { align-items: center; text-align: center; }
.medal { width: 84px; height: 84px; margin-bottom: 6px; object-fit: contain; filter: grayscale(1); opacity: 0.38; }
.badge.got .medal { filter: drop-shadow(0 3px 6px rgb(0 0 0 / 22%)); opacity: 1; }
.toast-medal { width: 30px; height: 30px; margin: -6px 2px -8px -6px; vertical-align: middle; object-fit: contain; }
.account { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; border-radius: 12px; background: var(--border); }
.segmented button { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 12px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); }
.claim { margin-top: 22px; }
.claim summary { cursor: pointer; }
.claim form { margin-top: 10px; max-width: 360px; }

/* ---------- Biểu mẫu ---------- */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-weight: 600; font-size: 0.9rem; }
.form input, .toolbar input, .toolbar select {
  min-height: 46px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 400;
}
.form input:focus, .toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form p { margin: 0; }
.show-pass { display: flex !important; grid-auto-flow: column; align-items: center; gap: 8px !important; font-weight: 500 !important; color: var(--muted); }
.show-pass input { min-height: 0; width: 18px; height: 18px; accent-color: var(--primary); }
.form-error { padding: 10px 12px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.form-error:empty { display: none; }
.code {
  margin: 14px auto;
  padding: 16px 10px;
  max-width: 330px;
  border: 2px dashed var(--gold);
  border-radius: 16px;
  background: var(--gold-soft);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  user-select: all;
}

/* ---------- Trang quản trị ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1; min-width: 160px; }
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 11px 12px; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); background: var(--surface-2); }
td { border-top: 1px solid var(--border); }
tbody tr:first-child td { border-top: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.users tbody tr[data-id] { cursor: pointer; }
.users tbody tr[data-id]:hover, .users tbody tr.on { background: var(--primary-soft); }
.detail { margin-top: 16px; }
.detail h2 { margin-top: 0; }
.book-row { display: grid; gap: 6px; }

/* ---------- Thông báo nổi và màn hình lên cấp ---------- */
#toasts {
  position: fixed;
  left: 0;
  right: 0;
  top: 64px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  max-width: 440px;
  text-align: center;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
  animation: drop 0.25s;
  transition: opacity 0.4s, transform 0.4s;
}
.toast-xp { background: var(--gold); color: #2e1e00; font-weight: 800; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }

.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgb(8 11 22 / 62%); animation: fade 0.2s; }
.level-up { width: min(380px, 100%); padding: 32px 24px 24px; border-radius: 24px; background: linear-gradient(160deg, var(--hero-from), var(--hero-to)); color: #ffffff; text-align: center; animation: pop 0.4s; }
.level-up .burst { display: grid; place-content: center; width: 112px; height: 112px; margin: 0 auto 14px; border-radius: 50%; border: 6px solid var(--gold); background: rgb(255 255 255 / 12%); font-size: 3rem; font-weight: 800; line-height: 1; }
.level-up h2 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 800; }
.level-up p { margin: 0 0 20px; opacity: 0.9; }
.level-up .btn { width: 100%; border: 0; background: var(--gold); color: #2e1e00; box-shadow: 0 3px 0 #a87400; }
@keyframes fade { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
