/* =========================================================
   Học tiếng Nhật — hệ thống giao diện
   Tông màu: giấy washi, mực tàu, đỏ son (朱), chàm (藍)
   ========================================================= */

:root {
  --bg: #f6f1e8;
  --surface: #fffcf6;
  --surface-2: #f0e9dd;
  --surface-3: #e8dfd0;
  --text: #221c18;
  --muted: #6d635a;
  --border: #e2d8c9;
  --accent: #c23b2a;
  --accent-hover: #a83223;
  --accent-soft: #f7ddd6;
  --on-accent: #ffffff;
  --indigo: #2d4a7a;
  --indigo-soft: #e1e8f3;
  --success: #2c7a4b;
  --success-soft: #dcefe3;
  --danger: #b42318;
  --danger-soft: #f9dcd8;
  --warn: #a8640f;
  --warn-soft: #f6e6c8;
  --gold: #b8860b;
  --gold-soft: #f7ecc9;
  --ink: #221c18;
  --guide: rgba(34, 28, 24, 0.13);
  --lv-n5: #2c7a4b;
  --lv-n4: #2d6a9f;
  --lv-n3: #7a4bb0;
  --lv-n2: #c0711a;
  --lv-n1: #c23b2a;
  --heat-0: #ebe3d6;
  --heat-1: #f3c9bd;
  --heat-2: #e8907c;
  --heat-3: #d4604b;
  --heat-4: #a83223;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 6px 20px rgba(60, 40, 20, 0.07);
  --shadow-lg: 0 10px 40px rgba(60, 40, 20, 0.14);
  --radius: 14px;
  --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-jp: 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', 'Meiryo', sans-serif;
  --font-kana: 'Klee One', 'Noto Sans JP', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --header-h: 60px;
  --sidebar-w: 264px;
  --bottom-nav-h: 0px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f; --surface: #1e1a16; --surface-2: #29241e; --surface-3: #332d25; --text: #f2ece3; --muted: #a99f93; --border: #3a332b;
    --accent: #ec6a55; --accent-hover: #f2826f; --accent-soft: #3d231d; --on-accent: #1a0f0c; --indigo: #a3b8e2; --indigo-soft: #232c3d;
    --success: #6cc794; --success-soft: #1c3025; --danger: #f08a7c; --danger-soft: #3b201c; --warn: #e2b062; --warn-soft: #362a17;
    --gold: #e6c15a; --gold-soft: #3a3118; --ink: #f2ece3; --guide: rgba(242, 236, 227, 0.14);
    --lv-n5: #6cc794; --lv-n4: #7fb2e5; --lv-n3: #b993e8; --lv-n2: #f0a656; --lv-n1: #ec6a55;
    --heat-0: #2a251f; --heat-1: #4a2a22; --heat-2: #7a3a2c; --heat-3: #b04c38; --heat-4: #ec6a55;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15120f; --surface: #1e1a16; --surface-2: #29241e; --surface-3: #332d25; --text: #f2ece3; --muted: #a99f93; --border: #3a332b;
  --accent: #ec6a55; --accent-hover: #f2826f; --accent-soft: #3d231d; --on-accent: #1a0f0c; --indigo: #a3b8e2; --indigo-soft: #232c3d;
  --success: #6cc794; --success-soft: #1c3025; --danger: #f08a7c; --danger-soft: #3b201c; --warn: #e2b062; --warn-soft: #362a17;
  --gold: #e6c15a; --gold-soft: #3a3118; --ink: #f2ece3; --guide: rgba(242, 236, 227, 0.14);
  --lv-n5: #6cc794; --lv-n4: #7fb2e5; --lv-n3: #b993e8; --lv-n2: #f0a656; --lv-n1: #ec6a55;
  --heat-0: #2a251f; --heat-1: #4a2a22; --heat-2: #7a3a2c; --heat-3: #b04c38; --heat-4: #ec6a55;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25); --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ===== Nền tảng ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui); font-size: 16px; line-height: 1.6;
  padding-bottom: var(--bottom-nav-h);
}
[lang="ja"] { font-family: var(--font-jp); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5rem; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: clamp(1.55rem, 4vw, 2.15rem); }
h2 { font-size: 1.28rem; }
h3 { font-size: 1.06rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
small { font-size: 0.82em; }
ruby rt { font-size: 0.5em; color: var(--muted); font-weight: 400; letter-spacing: 0; }
.hide-furigana rt { display: none; }
.hide-romaji .romaji { display: none !important; }
.muted { color: var(--muted); }
.lead { font-size: 1.05rem; color: var(--muted); max-width: 68ch; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--accent); color: var(--on-accent); padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }

/* ===== Bố cục ứng dụng ===== */
.app { min-height: 100vh; }
.main-col { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
#view:focus { outline: none; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { margin-right: auto; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-family: var(--font-kana); font-weight: 600; font-size: 1.2rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 1rem; white-space: nowrap; }
.brand-text small { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(var(--sidebar-w), 86vw);
  display: flex; flex-direction: column; gap: 14px; padding: 16px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-102%); transition: transform 0.22s ease;
}
.sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
.drawer-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(20, 15, 10, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.drawer-backdrop.show { opacity: 1; pointer-events: auto; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 500; font-size: 0.95rem;
}
.side-nav a svg { width: 20px; height: 20px; flex: none; }
.side-nav a .nav-glyph { width: 20px; text-align: center; font-family: var(--font-kana); font-weight: 600; font-size: 1.05rem; line-height: 1; }
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav-label { margin: 12px 12px 4px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.count-pill { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 0.72rem; font-weight: 700; line-height: 20px; text-align: center; }
.count-pill:empty { display: none; }
.side-xp { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--surface-2); font-size: 0.85rem; }
.side-xp .xp-line { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }

.level-switch { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.level-switch button {
  border: 0; background: transparent; border-radius: 8px; padding: 6px 0; cursor: pointer;
  font-weight: 700; font-size: 0.85rem; color: var(--muted);
}
.level-switch button[aria-pressed="true"] { background: var(--surface); color: var(--lv-color, var(--accent)); box-shadow: var(--shadow); }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 58px; text-decoration: none; color: var(--muted); font-size: 0.66rem; font-weight: 600; }
.bottom-nav svg { width: 22px; height: 22px; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav .count-pill { position: absolute; top: 5px; left: calc(50% + 6px); margin: 0; line-height: 17px; min-width: 18px; padding: 0 5px; font-size: 0.65rem; }
body { --bottom-nav-h: calc(58px + env(safe-area-inset-bottom)); }

@media (min-width: 1024px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); transform: none; z-index: 10; box-shadow: none; }
  .drawer-backdrop, .bottom-nav, .topbar .menu-btn, .topbar .brand { display: none; }
  .topbar .topbar-actions { margin-left: auto; }
  body { --bottom-nav-h: 0px; }
  .container { padding: 28px 32px 56px; }
}

.app-footer { max-width: 1120px; width: 100%; margin: 0 auto; padding: 12px 16px 28px; font-size: 0.83rem; color: var(--muted); text-align: center; }
.app-footer p { margin: 0 0 4px; }

/* ===== Nút & điều khiển ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.95rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 0.86rem; border-radius: 10px; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 1.04rem; }
.btn-block { width: 100%; }
.btn-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.btn-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-weight: 500; }
.back-link { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; font-weight: 500; font-size: 0.9rem; margin-bottom: 10px; }
.back-link svg { width: 16px; height: 16px; }

.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 12px; flex-wrap: wrap; }
.seg > a, .seg > button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 0.9rem; text-decoration: none; }
.seg > .on, .seg > [aria-pressed="true"], .seg > [aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.9rem; color: var(--muted); user-select: none; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; font-weight: 500; font-size: 0.92rem; text-decoration: none; color: var(--text);
}
.chip[aria-pressed="true"], .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .chip-jp { font-family: var(--font-kana); font-size: 1.12rem; font-weight: 600; }

.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs button, .tabs a { border: 0; background: none; padding: 11px 15px; cursor: pointer; white-space: nowrap; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.tabs [aria-selected="true"], .tabs .on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs svg { width: 17px; height: 17px; }

.input, .select, textarea.input {
  width: 100%; min-height: 46px; padding: 0 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font-size: 1rem;
}
textarea.input { padding: 12px 14px; min-height: 90px; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.correct { border-color: var(--success); background: var(--success-soft); }
.input.wrong { border-color: var(--danger); background: var(--danger-soft); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.tight { padding: 14px 16px; }
.card.flat { box-shadow: none; }
.card-link { display: block; text-decoration: none; color: inherit; transition: border-color 0.15s, transform 0.15s; }
.card-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.3s; }
.progress.thin { height: 5px; }
.progress.success > span { background: var(--success); }
.progress.gold > span { background: var(--gold); }

.ring { position: relative; width: var(--ring-size, 120px); height: var(--ring-size, 120px); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .ring-bg { stroke: var(--surface-2); }
.ring .ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.5s; }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring .ring-label b { display: block; font-size: 1.4rem; }
.ring .ring-label small { color: var(--muted); }

.level-chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; color: #fff; background: var(--lv-color, var(--accent)); vertical-align: middle; }
:root[data-theme="dark"] .level-chip, .level-chip { color: var(--surface); }
.lv-n5 { --lv-color: var(--lv-n5); } .lv-n4 { --lv-color: var(--lv-n4); } .lv-n3 { --lv-color: var(--lv-n3); } .lv-n2 { --lv-color: var(--lv-n2); } .lv-n1 { --lv-color: var(--lv-n1); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 0.76rem; font-weight: 600; }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.success { background: var(--success-soft); color: var(--success); }
.tag.indigo { background: var(--indigo-soft); color: var(--indigo); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.hv { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--indigo-soft); color: var(--indigo); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em; vertical-align: middle; }

/* ===== Tiêu đề trang & lưới ===== */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-head .lead { margin-bottom: 0; }
.page-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.section-title { margin: 34px 0 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-title small { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.stack { display: grid; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid-2, .grid-3, .grid-4, .grid-auto { display: grid; gap: 14px; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 16px 18px; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.stat-value small { font-size: 0.88rem; color: var(--muted); font-weight: 500; }
.stat-label { font-size: 0.84rem; color: var(--muted); }

.empty-state { text-align: center; padding: 48px 16px; }
.empty-state b { display: block; font-family: var(--font-kana); font-size: 3.6rem; color: var(--accent); line-height: 1.2; }
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 60px 16px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.callout { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--indigo-soft); color: var(--text); }
.callout.warn { background: var(--warn-soft); }
.callout.success { background: var(--success-soft); }
.callout svg { width: 20px; height: 20px; flex: none; color: var(--indigo); margin-top: 2px; }
.callout p:last-child { margin: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: var(--surface-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table td [lang="ja"] { font-size: 1.08rem; }

.toast {
  position: fixed; left: 50%; top: calc(var(--header-h) + 12px); z-index: 90;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px;
  font-size: 0.92rem; font-weight: 500; width: max-content; max-width: min(480px, calc(100vw - 32px)); text-align: center; box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.gold { background: var(--gold); color: #1a1408; }

/* ===== Hộp thoại ===== */
dialog.modal {
  border: 1px solid var(--border); border-radius: 18px; padding: 20px; background: var(--surface); color: var(--text);
  width: min(440px, calc(100% - 32px)); max-height: calc(100vh - 32px); box-shadow: var(--shadow-lg);
}
dialog.modal.wide { width: min(720px, calc(100% - 32px)); }
dialog.modal::backdrop { background: rgba(20, 15, 10, 0.55); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.modal-head h2 { margin: 0; }

/* ===== Nét viết & bảng luyện viết ===== */
.stroke-box { width: 100%; max-width: 280px; aspect-ratio: 1; margin: 0 auto; border: 2px solid var(--border); border-radius: 16px; background: var(--surface); }
.stroke-svg { width: 100%; height: 100%; }
.stroke-svg .grid { stroke: var(--border); stroke-width: 0.6; stroke-dasharray: 2 2; fill: none; }
.stroke-svg .ghost path { fill: none; stroke: var(--guide); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.stroke-svg .ink path { fill: none; stroke: var(--ink); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.stroke-svg .ink path.current { stroke: var(--accent); }
.stroke-svg .nums text { font: 600 7px var(--font-ui); fill: var(--accent); opacity: 0; transition: opacity 0.15s; }
.stroke-svg .nums text.on { opacity: 1; }
.stroke-controls { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.trace-box { position: relative; width: 100%; aspect-ratio: 1; margin: 12px 0; border: 2px solid var(--accent); border-radius: 14px; overflow: hidden; background: var(--surface); }
.trace-guide { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.trace-guide.hidden { visibility: hidden; }
.trace-guide .stroke-svg .ink path { stroke: var(--accent); }
.trace-guide .stroke-svg .ghost path { stroke-width: 4.5; }
.trace-guide .font-guide { font-family: var(--font-kana); font-size: min(62vw, 260px); line-height: 1; color: var(--guide); user-select: none; }
.trace-guide .font-guide.multi { font-size: min(34vw, 150px); }
.trace-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; z-index: 1; }
.trace-actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.trace-actions .middle { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pad-hint { margin: 0; font-size: 0.86rem; }

/* ===== Trang chủ ===== */
.hero {
  position: relative; overflow: hidden; display: grid; gap: 24px; align-items: center;
  padding: 28px 22px; margin-bottom: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow);
}
.hero::before { content: ''; position: absolute; right: -90px; top: -90px; width: 300px; height: 300px; border-radius: 50%; background: var(--accent-soft); }
.hero > * { position: relative; }
.eyebrow { font-size: 0.84rem; font-weight: 700; color: var(--accent); letter-spacing: 0.02em; margin-bottom: 8px; }
.hero h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
@media (min-width: 820px) { .hero { grid-template-columns: 1.5fr 1fr; padding: 40px 38px; } }
.hero-side { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.big-number { font-size: clamp(2rem, 6vw, 2.8rem); font-weight: 800; line-height: 1; color: var(--accent); }
.feature-card { display: flex; gap: 14px; align-items: flex-start; }
.feature-icon {
  width: 52px; height: 52px; flex: none; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-family: var(--font-kana); font-size: 1.5rem; font-weight: 600;
}
.feature-icon svg { width: 24px; height: 24px; }
.feature-card h3 { margin: 2px 0 2px; }
.feature-card p { margin: 0 0 8px; font-size: 0.9rem; color: var(--muted); }
.feature-meta { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--heat-0); }
.heatmap i.h1 { background: var(--heat-1); } .heatmap i.h2 { background: var(--heat-2); } .heatmap i.h3 { background: var(--heat-3); } .heatmap i.h4 { background: var(--heat-4); }
.heat-legend { display: flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.heat-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.badge-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.badge-item { text-align: center; padding: 16px 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); }
.badge-item .badge-icon {
  width: 60px; height: 60px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-kana); font-size: 1.7rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 2px dashed var(--border);
}
.badge-item.earned .badge-icon { background: var(--gold-soft); color: var(--gold); border: 2px solid var(--gold); }
.badge-item h3 { font-size: 0.92rem; margin: 0 0 2px; }
.badge-item p { font-size: 0.78rem; color: var(--muted); margin: 0; }
.badge-item:not(.earned) h3 { color: var(--muted); }

/* ===== Bảng chữ cái kana ===== */
.chart-layout { display: grid; gap: 24px; }
@media (min-width: 1180px) { .chart-layout { grid-template-columns: minmax(0, 1fr) 280px; align-items: start; } }
.kana-section + .kana-section { margin-top: 34px; }
.kana-section .section-head { margin-bottom: 12px; }
.kana-section .section-head p { margin: 0; color: var(--muted); font-size: 0.94rem; }
.kana-grid { display: grid; gap: 8px; }
.kana-grid.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: 620px; }
.kana-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 380px; }
.kana-cell {
  position: relative; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; padding: 0;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.kana-cell:hover { border-color: var(--accent); }
.kana-cell:active { transform: scale(0.96); }
.kana-cell .k { font-family: var(--font-kana); font-size: clamp(1.5rem, 6.5vw, 2.3rem); line-height: 1.1; font-weight: 600; }
.kana-grid.cols-3 .kana-cell .k { font-size: clamp(1.35rem, 6vw, 2rem); }
.kana-cell .r { font-size: 0.76rem; color: var(--muted); font-weight: 500; }
.kana-cell.empty { background: transparent; border: 1px dashed var(--border); cursor: default; opacity: 0.5; }
.kana-cell.active { border-color: var(--accent); background: var(--accent-soft); }
.kana-cell::after { content: ''; position: absolute; top: 7px; right: 7px; width: 7px; height: 7px; border-radius: 50%; }
.kana-cell.lvl-1::after { background: var(--danger); } .kana-cell.lvl-2::after { background: var(--warn); } .kana-cell.lvl-3::after { background: var(--success); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.8rem; color: var(--muted); margin: 0 0 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--border); }
.legend .l1 { background: var(--danger); } .legend .l2 { background: var(--warn); } .legend .l3 { background: var(--success); }
.row-tips { margin-top: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.row-tips summary { cursor: pointer; padding: 12px 16px; font-weight: 600; font-size: 0.94rem; }
.row-tips ul { margin: 0; padding: 0 16px 14px 36px; font-size: 0.92rem; }
.row-tips li { margin-bottom: 6px; }
.row-tips li b { font-family: var(--font-kana); font-weight: 600; }
.kana-detail { position: sticky; top: calc(var(--header-h) + 16px); text-align: center; }
.kana-detail .detail-glyph { font-family: var(--font-kana); font-size: 5.5rem; line-height: 1.1; font-weight: 600; }
.kana-detail .detail-romaji { font-size: 1.35rem; font-weight: 700; color: var(--accent); }
.kana-detail .detail-stats { font-size: 0.85rem; color: var(--muted); margin: 6px 0 12px; }
.kana-detail .detail-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.kana-detail .stroke-box { max-width: 200px; margin-bottom: 8px; }
.kana-detail .placeholder { color: var(--muted); font-size: 0.94rem; padding: 24px 0; }
.kana-detail .placeholder b { display: block; font-family: var(--font-kana); font-size: 3.4rem; color: var(--border); }
@media (max-width: 1179px) {
  .kana-detail { position: sticky; top: auto; bottom: calc(var(--bottom-nav-h) + 12px); z-index: 5; display: none; text-align: left; padding: 12px 14px; }
  .kana-detail.has-selection { display: block; }
  .kana-detail .detail-inner { display: flex; align-items: center; gap: 14px; }
  .kana-detail .detail-glyph { font-size: 2.8rem; min-width: 60px; text-align: center; }
  .kana-detail .detail-info { flex: 1; min-width: 0; }
  .kana-detail .detail-romaji { font-size: 1.1rem; }
  .kana-detail .detail-stats { margin: 0 0 6px; }
  .kana-detail .detail-actions { justify-content: flex-start; flex-wrap: nowrap; }
  .kana-detail .detail-actions .btn-text { display: none; }
  .kana-detail .stroke-box { display: none; }
}
.rules { display: grid; gap: 14px; }
@media (min-width: 760px) { .rules { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rule h3 { margin-bottom: 6px; }
.rule p { color: var(--muted); font-size: 0.93rem; }
.example-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ex-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 5px 5px 5px 12px; background: var(--bg); font-size: 0.88rem; }
.ex-chip [lang="ja"] { font-size: 1.08rem; font-weight: 500; }
.ex-chip .icon-btn { width: 30px; height: 30px; }
.confusables { display: grid; gap: 12px; }
@media (min-width: 760px) { .confusables { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.confusable { display: flex; gap: 14px; align-items: flex-start; }
.confusable .pair { display: flex; gap: 4px; flex: none; }
.confusable .pair button { width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); font-family: var(--font-kana); font-size: 1.55rem; font-weight: 600; cursor: pointer; }
.confusable .pair button:hover { border-color: var(--accent); }
.confusable p { margin: 0; font-size: 0.9rem; color: var(--muted); }

/* ===== Trắc nghiệm & luyện tập (dùng chung) ===== */
.setup { display: grid; gap: 22px; }
.setup fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.setup legend { font-weight: 700; margin-bottom: 10px; padding: 0; }
.mini-actions { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 0.9rem; }
.mode-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.mode-card { text-align: left; padding: 14px 16px; border-radius: 12px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); }
.mode-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.mode-card strong { display: block; font-size: 0.97rem; }
.mode-card span { font-size: 0.84rem; color: var(--muted); }
.mode-card .mode-ex { font-family: var(--font-kana); font-weight: 600; color: var(--accent); margin-right: 4px; }
.start-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

.quiz { max-width: 640px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 0.9rem; color: var(--muted); }
.quiz-top .score { color: var(--success); font-weight: 700; }
.quiz-prompt { display: grid; place-items: center; min-height: 210px; margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); text-align: center; padding: 18px; }
.big-kana { font-family: var(--font-kana); font-size: clamp(4.3rem, 21vw, 7.5rem); font-weight: 600; line-height: 1.1; }
.big-jp { font-size: clamp(2rem, 8vw, 3rem); font-weight: 500; line-height: 1.7; }
.big-vi { font-size: clamp(1.35rem, 5vw, 1.9rem); font-weight: 700; line-height: 1.35; }
.big-romaji { font-size: clamp(2.8rem, 13vw, 4.6rem); font-weight: 700; letter-spacing: 0.02em; }
.prompt-hint { font-size: 0.87rem; color: var(--muted); margin-top: 4px; }
.listen-btn { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; color: var(--accent); font-weight: 600; }
.listen-btn svg { width: 74px; height: 74px; padding: 19px; border-radius: 50%; background: var(--accent-soft); }
.options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.options.one-col { grid-template-columns: 1fr; }
.option {
  position: relative; min-height: 62px; padding: 10px 14px 10px 28px; display: flex; align-items: center; justify-content: center; text-align: center;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); font-size: 1.2rem; font-weight: 600; cursor: pointer; line-height: 1.4;
  transition: border-color 0.15s, background 0.15s;
}
.option.jp { font-family: var(--font-kana); font-size: 1.7rem; }
.option.word { font-family: var(--font-jp); font-size: 1.25rem; font-weight: 500; line-height: 1.8; }
.option.text { font-size: 0.98rem; line-height: 1.4; }
.option.left { justify-content: flex-start; text-align: left; }
.option:hover:not([disabled]) { border-color: var(--accent); }
.option kbd { position: absolute; left: 10px; top: 8px; font-family: var(--font-ui); font-size: 0.68rem; color: var(--muted); font-weight: 500; }
.option.selected { border-color: var(--indigo); background: var(--indigo-soft); }
.option.correct { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.option.wrong { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.option[disabled] { cursor: default; }
.type-answer { display: flex; gap: 10px; }
.type-answer .input { font-size: 1.2rem; min-height: 52px; }
.ime-preview { font-family: var(--font-jp); font-size: 1.3rem; min-height: 1.8em; margin-top: 8px; color: var(--accent); text-align: center; }
.feedback { min-height: 60px; margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.feedback .msg { font-weight: 600; }
.msg.ok { color: var(--success); }
.msg.bad { color: var(--danger); }
.feedback .msg [lang="ja"] { font-size: 1.2rem; }
.kbd-hint { font-size: 0.8rem; color: var(--muted); text-align: center; margin-top: 8px; }
@media (hover: none) { .kbd-hint, .option kbd { display: none; } .option { padding-left: 14px; } }
.result { text-align: center; max-width: 640px; margin: 0 auto; }
.result-score { font-size: 3.1rem; font-weight: 800; line-height: 1.1; color: var(--accent); }
.result-score small { display: block; font-size: 1rem; color: var(--muted); font-weight: 500; margin-top: 4px; }
.result h3 { margin-top: 20px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
.xp-gain { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); font-weight: 700; font-size: 0.9rem; }
.mistakes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0 4px; }
.mistake { display: inline-flex; align-items: center; gap: 8px; padding: 5px 5px 5px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.mistake b { font-family: var(--font-kana); font-size: 1.35rem; font-weight: 600; }
.mistake .icon-btn { width: 30px; height: 30px; }
.weak-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.weak-list span { min-width: 44px; height: 44px; padding: 0 8px; display: inline-grid; place-items: center; background: var(--danger-soft); color: var(--danger); border-radius: 10px; font-family: var(--font-kana); font-size: 1.35rem; font-weight: 600; }

/* ===== Thẻ ghi nhớ ===== */
.flashcard { display: block; width: 100%; max-width: 500px; height: 310px; margin: 0 auto; perspective: 1200px; cursor: pointer; border: 0; background: none; padding: 0; }
.fc-inner { position: relative; width: 100%; height: 100%; transition: transform 0.45s; transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 20px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.fc-back { transform: rotateY(180deg); overflow-y: auto; }
.fc-hint { font-size: 0.78rem; color: var(--muted); position: absolute; bottom: 12px; }
.fc-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.fc-count { text-align: center; color: var(--muted); font-size: 0.88rem; margin-bottom: 10px; }
.grade-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 520px; margin: 18px auto 0; }
.grade-row .btn { flex-direction: column; gap: 0; min-height: 56px; line-height: 1.2; padding: 6px; }
.grade-row .btn small { font-weight: 500; opacity: 0.8; font-size: 0.72rem; }

/* ===== Danh sách từ ===== */
.word-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.word-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 14px; align-items: start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.word-row.known { border-left: 4px solid var(--success); }
.word-row.learning { border-left: 4px solid var(--warn); }
.w-jp { font-size: 1.42rem; font-weight: 500; line-height: 1.5; }
.w-jp a { color: inherit; text-decoration: none; }
.w-jp a:hover { color: var(--accent); }
.w-romaji { font-size: 0.84rem; color: var(--muted); }
.w-vi { font-weight: 600; margin-top: 2px; }
.w-note { font-size: 0.87rem; color: var(--muted); margin: 6px 0 0; }
.w-ex { margin-top: 8px; padding: 8px 12px; background: var(--bg); border-radius: 10px; font-size: 0.9rem; }
.w-ex [lang="ja"] { font-size: 1.02rem; line-height: 1.9; }
.w-ex .romaji { color: var(--muted); font-size: 0.8rem; }
.w-ex-jp { display: flex; align-items: center; gap: 8px; }
.w-ex-jp .icon-btn { width: 30px; height: 30px; }
.pos-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-left: 6px; vertical-align: middle; }
@media (max-width: 560px) { .word-row { grid-template-columns: auto minmax(0, 1fr); } .word-row > :last-child:not(:nth-child(2)) { grid-column: 2; justify-self: start; } }

/* ===== Kanji ===== */
.kanji-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.kanji-tile {
  position: relative; aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--text);
  transition: border-color 0.15s, transform 0.1s;
}
.kanji-tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.kanji-tile .kt-char { font-family: var(--font-kana); font-size: 2rem; font-weight: 600; line-height: 1.1; }
.kanji-tile .kt-hv { font-size: 0.62rem; font-weight: 700; color: var(--indigo); letter-spacing: 0.02em; max-width: 92%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanji-tile.learning { border-color: var(--warn); }
.kanji-tile.known { border-color: var(--success); background: var(--success-soft); }
.kanji-hero { display: grid; gap: 22px; }
@media (min-width: 820px) { .kanji-hero { grid-template-columns: 300px minmax(0, 1fr); align-items: start; } }
.kanji-big { font-family: var(--font-kana); font-size: 7rem; line-height: 1; font-weight: 600; }
.reading-row { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin: 4px 0; }
.reading-row .label { min-width: 74px; font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.reading-row [lang="ja"] { font-size: 1.12rem; }
.parts { display: flex; gap: 6px; flex-wrap: wrap; }
.parts span { padding: 2px 10px; border-radius: 8px; background: var(--surface-2); font-family: var(--font-kana); font-size: 1.1rem; }

/* ===== Ngữ pháp ===== */
.pattern { margin: 16px 0 20px; padding: 16px 20px; background: var(--accent-soft); border-radius: 14px; border-left: 5px solid var(--accent); font-family: var(--font-jp); font-size: clamp(1.2rem, 4.2vw, 1.55rem); font-weight: 700; }
.pattern small { display: block; font-family: var(--font-ui); font-size: 0.78rem; font-weight: 700; color: var(--accent); margin-bottom: 4px; letter-spacing: 0.03em; }
.lesson { max-width: 820px; margin: 0 auto; }
.lesson-body p { font-size: 1.01rem; line-height: 1.75; }
.lesson-body b { color: var(--accent); }
.examples { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.example { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; align-items: start; padding: 14px 16px; }
.example .jp { font-size: 1.25rem; line-height: 1.9; }
.example .romaji { font-size: 0.84rem; color: var(--muted); }
.example .vi { font-weight: 500; }
.notes { margin: 0; padding: 16px 20px 16px 40px; background: var(--warn-soft); border-radius: 14px; }
.notes li { margin-bottom: 6px; line-height: 1.7; }
.notes li:last-child { margin-bottom: 0; }
.q-card .q-text { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; line-height: 1.9; }
.q-card .q-options { display: flex; flex-wrap: wrap; gap: 8px; }
.q-card .q-options .option { min-height: 46px; font-size: 1.05rem; flex: 1 1 130px; padding-left: 14px; }
.q-card .q-explain { margin: 12px 0 0; font-size: 0.92rem; padding: 10px 14px; border-radius: 10px; background: var(--bg); }
.q-card .q-explain.ok { color: var(--success); }
.q-card .q-explain.bad { color: var(--danger); }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--border); }
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.lesson-link { display: flex; gap: 14px; align-items: flex-start; text-decoration: none; color: inherit; height: 100%; transition: border-color 0.15s, transform 0.15s; }
.lesson-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.lesson-num { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.88rem; background: var(--surface-2); color: var(--muted); }
.lesson-link.done .lesson-num { background: var(--success-soft); color: var(--success); }
.lesson-link h3 { font-size: 1.05rem; margin: 0 0 2px; font-family: var(--font-jp); font-weight: 600; }
.lesson-link p { margin: 0; font-size: 0.88rem; color: var(--muted); }

/* ===== Hội thoại ===== */
.chat { display: grid; gap: 12px; }
.bubble-row { display: flex; gap: 10px; align-items: flex-end; }
.bubble-row.right { flex-direction: row-reverse; }
.avatar { width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 0.9rem; background: var(--indigo-soft); color: var(--indigo); }
.bubble-row.right .avatar { background: var(--accent-soft); color: var(--accent); }
.bubble { max-width: min(560px, 82%); padding: 10px 14px; border-radius: 16px 16px 16px 4px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); cursor: pointer; }
.bubble-row.right .bubble { border-radius: 16px 16px 4px 16px; background: var(--accent-soft); border-color: transparent; }
.bubble.playing { outline: 3px solid var(--gold); }
.bubble .jp { font-size: 1.15rem; line-height: 1.9; }
.bubble .romaji { font-size: 0.8rem; color: var(--muted); }
.bubble .vi { font-size: 0.9rem; color: var(--muted); margin-top: 2px; }
.hide-vi .bubble .vi { display: none; }
.speaker-name { font-size: 0.74rem; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.player-bar { position: sticky; bottom: calc(var(--bottom-nav-h) + 10px); z-index: 5; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 10px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); margin-top: 16px; }

/* ===== Thi thử ===== */
.exam-head { position: sticky; top: var(--header-h); z-index: 6; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin: -8px 0 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.timer.low { color: var(--danger); }
.timer svg { width: 18px; height: 18px; }
.part-head { margin: 26px 0 10px; }
.part-head h2 { font-family: var(--font-jp); font-size: 1.1rem; margin-bottom: 4px; }
.part-head .instr { font-family: var(--font-jp); }
.passage { padding: 18px 20px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-family: var(--font-jp); font-size: 1.05rem; line-height: 2; white-space: pre-line; margin-bottom: 12px; }
.u { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.exam-q { padding: 16px 18px; margin-bottom: 10px; }
.exam-q .q-text { font-family: var(--font-jp); font-size: 1.08rem; line-height: 2; margin-bottom: 10px; }
.exam-q .q-num { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 8px; background: var(--surface-2); font-weight: 700; font-size: 0.85rem; margin-right: 8px; font-family: var(--font-ui); }
.exam-q .options { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.exam-q .option { font-family: var(--font-jp); font-size: 1.02rem; font-weight: 500; min-height: 48px; justify-content: flex-start; text-align: left; }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; }
.qnav a, .qnav button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 0.8rem; font-weight: 600; text-decoration: none; color: var(--text); cursor: pointer; }
.qnav .answered { background: var(--indigo-soft); border-color: var(--indigo); color: var(--indigo); }
.qnav .right { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.qnav .wrongq { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.score-bars { display: grid; gap: 12px; }
.score-bar-row { display: grid; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr) 70px; gap: 12px; align-items: center; font-size: 0.92rem; }

/* ===== Tìm kiếm ===== */
.search-box { position: relative; }
.search-box svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); }
.search-box .input { padding-left: 46px; min-height: 54px; font-size: 1.08rem; border-radius: 16px; }
.result-group h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 22px 0 8px; }
.result-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 10px 14px; border-radius: 12px; text-decoration: none; color: inherit; border: 1px solid transparent; }
.result-item:hover { background: var(--surface); border-color: var(--border); }
.result-item .ri-jp { font-size: 1.25rem; font-weight: 500; min-width: 3em; }
.result-item .ri-sub { font-size: 0.82rem; color: var(--muted); }
mark { background: var(--gold-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ===== Chủ đề từ vựng ===== */
.topic-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.topic-card { display: flex; gap: 14px; align-items: center; }
.topic-icon { width: 50px; height: 50px; flex: none; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-family: var(--font-kana); font-size: 1.55rem; font-weight: 600; }
.topic-card h3 { font-size: 1rem; margin: 0 0 4px; }
.topic-card .meta { font-size: 0.78rem; color: var(--muted); margin-top: 4px; display: block; }

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