/* =========================================================================
   WSE English Learning — stylesheet
   Light / Dark / System theme via [data-theme] on <html>
   ========================================================================= */

/* ----------------------------- TOKENS ----------------------------- */
:root {
  --bg:            #f5f6f8;
  --bg-elev:       #ffffff;
  --bg-sunken:     #eceef2;
  --sidebar-bg:    #11161f;
  --sidebar-fg:    #c7cede;
  --sidebar-fg-dim:#7c869c;
  --sidebar-active:#1d2635;

  --fg:            #1a1f2b;
  --fg-dim:        #5b6478;
  --fg-faint:      #8b93a5;
  --border:        #dfe3ea;
  --border-strong: #c6ccd8;

  --accent:        #3b6ef5;
  --accent-fg:     #ffffff;
  --accent-soft:   #e7edff;
  --accent-2:      #7a5cf0;

  --ok:            #12855a;
  --ok-soft:       #dcf5e9;
  --warn:          #a06504;
  --warn-soft:     #fdf0d5;
  --err:           #c02a2a;
  --err-soft:      #fde3e3;
  --info:          #0d6c9c;
  --info-soft:     #dff0fa;

  --radius:        12px;
  --radius-sm:     8px;
  --radius-lg:     18px;
  --shadow-sm:     0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --shadow-md:     0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.06);
  --shadow-lg:     0 24px 48px -12px rgba(16,24,40,.25);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sidebar-w: 268px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0e1218;
    --bg-elev:       #161c26;
    --bg-sunken:     #10151d;
    --sidebar-bg:    #0a0e14;
    --sidebar-fg:    #b9c2d4;
    --sidebar-fg-dim:#6d768a;
    --sidebar-active:#1b2432;

    --fg:            #e6eaf2;
    --fg-dim:        #a3acbe;
    --fg-faint:      #7b8497;
    --border:        #242c3a;
    --border-strong: #333d4f;

    --accent:        #5b86ff;
    --accent-fg:     #0b0f16;
    --accent-soft:   #1b2540;
    --accent-2:      #9a7cff;

    --ok:            #4ad4a0;
    --ok-soft:       #10291f;
    --warn:          #ecb45a;
    --warn-soft:     #2b2312;
    --err:           #ff7b7b;
    --err-soft:      #2d1717;
    --info:          #63c2ee;
    --info-soft:     #12242e;

    --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
    --shadow-md:     0 4px 14px rgba(0,0,0,.45);
    --shadow-lg:     0 24px 48px -12px rgba(0,0,0,.6);
  }
}

:root[data-theme="dark"] {
  --bg:            #0e1218;
  --bg-elev:       #161c26;
  --bg-sunken:     #10151d;
  --sidebar-bg:    #0a0e14;
  --sidebar-fg:    #b9c2d4;
  --sidebar-fg-dim:#6d768a;
  --sidebar-active:#1b2432;

  --fg:            #e6eaf2;
  --fg-dim:        #a3acbe;
  --fg-faint:      #7b8497;
  --border:        #242c3a;
  --border-strong: #333d4f;

  --accent:        #5b86ff;
  --accent-fg:     #0b0f16;
  --accent-soft:   #1b2540;
  --accent-2:      #9a7cff;

  --ok:            #4ad4a0;
  --ok-soft:       #10291f;
  --warn:          #ecb45a;
  --warn-soft:     #2b2312;
  --err:           #ff7b7b;
  --err-soft:      #2d1717;
  --info:          #63c2ee;
  --info-soft:     #12242e;

  --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
  --shadow-md:     0 4px 14px rgba(0,0,0,.45);
  --shadow-lg:     0 24px 48px -12px rgba(0,0,0,.6);
}

/* ----------------------------- RESET ----------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* QUAN TRỌNG: thuộc tính [hidden] phải luôn thắng.
   Mặc định trình duyệt chỉ đặt [hidden]{display:none}, nên bất kỳ class nào
   khai báo display:grid/flex (lớp phủ, hộp thoại…) sẽ vô hiệu hoá [hidden]
   và phần tử vẫn hiện ra, che mất giao diện. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); background-clip: content-box; }

/* ----------------------------- LAYOUT ----------------------------- */
.app {
  display: flex; overflow: hidden;
  height: 100vh;
  /* iOS Safari: thanh cong cu an/hien lam 100vh sai — dvh moi la chieu cao that */
  height: 100dvh;
}
html {
  -webkit-text-size-adjust: 100%;   /* iOS tu phong chu khi xoay ngang */
  text-size-adjust: 100%;
}
body { -webkit-tap-highlight-color: rgba(0,0,0,.08); }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.05);
}
.sidebar-head {
  padding: 16px 14px 12px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 13px;
  display: grid; place-items: center; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { color: #fff; font-size: 14px; letter-spacing: .2px; }
.brand-text span { font-size: 11.5px; color: var(--sidebar-fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close { display: none; color: var(--sidebar-fg); }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px 20px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--sidebar-fg-dim); padding: 8px 10px 6px; font-weight: 700;
}
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 2px;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--sidebar-fg); text-align: left; cursor: pointer;
  font-size: 13.5px; line-height: 1.2;
}
.nav-item .ni { width: 18px; text-align: center; font-size: 14px; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav-item .badge {
  margin-left: auto; font-style: normal; font-size: 11px;
  background: rgba(255,255,255,.08); color: var(--sidebar-fg-dim);
  padding: 1px 7px; border-radius: 20px; min-width: 22px; text-align: center;
}
.nav-item.active .badge { background: var(--accent); color: #fff; }

.sidebar-foot {
  padding: 10px 12px 14px; border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
}
.theme-switch { display: flex; gap: 2px; background: rgba(255,255,255,.06); padding: 3px; border-radius: 8px; }
.theme-switch button {
  border: 0; background: none; padding: 4px 8px; border-radius: 6px;
  cursor: pointer; font-size: 13px; opacity: .55;
}
.theme-switch button.on { background: rgba(255,255,255,.14); opacity: 1; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px; flex: 0 0 56px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.crumbs { font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.crumbs .crumb-dim { color: var(--fg-faint); font-weight: 500; }
.quick-search input {
  width: 320px; max-width: 40vw;
  padding: 7px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--bg-sunken);
  outline: none;
}
.quick-search input:focus { border-color: var(--accent); background: var(--bg-elev); }

.icon-btn {
  border: 0; background: none; cursor: pointer; padding: 7px 9px;
  border-radius: 8px; font-size: 16px; line-height: 1; color: inherit;
}
.icon-btn:hover { background: rgba(127,127,127,.14); }
#sidebarToggle { display: none; }

.content { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 22px 26px 80px; outline: none; }
.view[hidden] { display: none !important; }

/* ----------------------------- ATOMS ----------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev);
  cursor: pointer; font-size: 13.5px; font-weight: 550;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { border-color: var(--fg-faint); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn-danger:hover { background: var(--err-soft); }
.btn[disabled] { opacity: .45; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  background: var(--bg-sunken); color: var(--fg-dim); border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.ok   { background: var(--ok-soft);   color: var(--ok);   border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.err  { background: var(--err-soft);  color: var(--err);  border-color: transparent; }
.chip.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.chip.acc  { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px 18px; }

.view-head { margin-bottom: 18px; }
.view-head h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.2px; }
.view-head p { margin: 0; color: var(--fg-dim); font-size: 13.5px; }
.view-head .head-row { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.view-head .head-row .spacer { flex: 1; }

.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px; padding: 10px 12px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar input[type="search"], .toolbar input[type="text"], .toolbar select {
  padding: 6px 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--bg); outline: none; font-size: 13px;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar label { font-size: 12.5px; color: var(--fg-dim); display: inline-flex; align-items: center; gap: 5px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--fg-faint); }
.empty-state .big { font-size: 42px; margin-bottom: 10px; }

.muted { color: var(--fg-dim); }
.faint { color: var(--fg-faint); }
.tiny  { font-size: 12px; }
.mono  { font-family: var(--mono); font-size: 12.5px; }
.nowrap{ white-space: nowrap; }
.hidden{ display: none !important; }

/* ----------------------------- IMPORT ----------------------------- */
.app.is-empty .sidebar,
.app.is-empty .topbar .quick-search,
.app.is-empty .topbar #btnImportTop { display: none; }
.app.is-empty .content { padding: 0; }

.import-hero { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 30px 20px; }
.import-card {
  max-width: 720px; width: 100%;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 34px 34px 28px;
}
.import-card h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.4px; }
.import-card .lead { color: var(--fg-dim); margin: 0 0 22px; font-size: 14px; }
.import-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.import-note { margin-top: 14px; font-size: 12.5px; color: var(--fg-faint); }
.import-note .chip { margin-right: 6px; }
.import-help { margin-top: 20px; font-size: 13px; }
.import-help summary { cursor: pointer; color: var(--fg-dim); }
.tree {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-family: var(--mono); font-size: 12px; overflow-x: auto; margin-top: 10px;
  line-height: 1.55;
}
.restore-box {
  margin-top: 22px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid transparent;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.restore-box strong { display: block; font-size: 13.5px; }
.restore-box span { font-size: 12.5px; color: var(--fg-dim); }
.restore-box .restore-actions { margin-left: auto; display: flex; gap: 8px; }

/* ----------------------------- SCAN OVERLAY ----------------------------- */
.scan-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8,11,16,.62); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.scan-box {
  width: min(560px, 100%); background: var(--bg-elev);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 26px 26px 18px;
}
.scan-title { font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.scan-bar { height: 7px; background: var(--bg-sunken); border-radius: 10px; overflow: hidden; }
.scan-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .18s; }
.scan-detail { margin-top: 10px; font-size: 12.5px; color: var(--fg-dim); min-height: 18px; }
.scan-log {
  list-style: none; margin: 12px 0 0; padding: 0; max-height: 190px; overflow-y: auto;
  font-family: var(--mono); font-size: 11.5px; color: var(--fg-faint);
}
.scan-log li { padding: 2px 0; border-top: 1px dashed var(--border); }
.scan-log li.warn { color: var(--warn); }
.scan-log li.err { color: var(--err); }

/* ----------------------------- MODAL / TOAST ----------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(8,11,16,.6);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(1000px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg-elev); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15.5px; flex: 1; }
.modal-body { overflow: auto; padding: 18px; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-md); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 13px; max-width: 380px;
  animation: toastIn .18s ease-out;
}
.toast.ok   { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.err  { border-left-color: var(--err); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----------------------------- DASHBOARD ----------------------------- */
.stat-grid {
  display: grid; gap: 14px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.stat {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--fg-faint); font-weight: 700; }
.stat .v { font-size: 27px; font-weight: 750; letter-spacing: -.5px; margin: 4px 0 2px; }
.stat .s { font-size: 12px; color: var(--fg-dim); }
.stat .spark { position: absolute; right: 12px; top: 12px; font-size: 20px; opacity: .25; }

.bar { height: 7px; background: var(--bg-sunken); border-radius: 10px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 10px; transition: width .3s; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--warn); }

.ring { --p: 0; width: 108px; height: 108px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg-sunken) 0);
  position: relative; }
.ring::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--bg-elev); }
.ring b { position: relative; z-index: 1; font-size: 21px; font-weight: 750; }

.panel-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel > header {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.panel > header h3 { margin: 0; font-size: 14px; flex: 1; }
.panel > .body { padding: 14px 16px; }
.panel > .body.flush { padding: 0; }

/* level cards */
.level-list { display: grid; gap: 12px; }
.level-card {
  display: flex; align-items: center; gap: 14px; padding: 13px 15px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev);
  cursor: pointer; text-align: left; width: 100%; box-shadow: var(--shadow-sm);
}
.level-card:hover { border-color: var(--accent); }
.level-num {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 15px;
}
.lv1 { background: linear-gradient(135deg,#22b07d,#12855a); }
.lv2 { background: linear-gradient(135deg,#3b9ef5,#1c6fd0); }
.lv3 { background: linear-gradient(135deg,#7a5cf0,#5636cc); }
.lv4 { background: linear-gradient(135deg,#f0a03c,#d1761a); }
.lv5 { background: linear-gradient(135deg,#ef5f7a,#c92f4e); }
.lv6 { background: linear-gradient(135deg,#1f2937,#4b5563); }
.level-body { flex: 1; min-width: 0; }
.level-body strong { display: block; font-size: 14.5px; }
.level-body span { font-size: 12px; color: var(--fg-dim); }

/* ----------------------------- LESSON LIST ----------------------------- */
.lesson-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.lesson-card {
  text-align: left; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px; cursor: pointer; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 8px;
}
.lesson-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lesson-card .lc-top { display: flex; align-items: center; gap: 8px; }
.lesson-card .lc-id { font-weight: 800; font-size: 15px; letter-spacing: -.3px; }
.lesson-card .lc-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.lesson-card .lc-title { font-size: 12.5px; color: var(--fg-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lesson-card.done { border-color: var(--ok); }
/* Thẻ Listening: phần thân là chính file nguồn, phát ngay tại chỗ. */
.lesson-card.lc-card-media { cursor: default; }
.lesson-card.lc-card-media:hover { transform: none; }
.lc-media {
  width: 100%; min-height: 132px; border-radius: var(--radius-sm);
  background: #000; overflow: hidden; display: flex; align-items: center;
}
.lc-media video { width: 100%; max-height: 190px; display: block; background: #000; }
.lc-media audio { width: 100%; }

.unit-block { margin-bottom: 26px; }
.unit-head { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.unit-head h2 { font-size: 15px; margin: 0; }
.unit-head .line { flex: 1; height: 1px; background: var(--border); }

/* ----------------------------- LESSON DETAIL ----------------------------- */
.lesson-hero {
  display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  padding: 18px 20px; border-radius: var(--radius-lg);
  background: linear-gradient(120deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--border); margin-bottom: 18px;
}
.lesson-hero .lh-main { flex: 1; min-width: 240px; }
.lesson-hero h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.4px; }
.lesson-hero .lh-sub { color: var(--fg-dim); font-size: 13px; }
.lesson-hero .lh-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 9px 14px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--fg-dim); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--fg); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button .cnt { font-weight: 500; opacity: .65; font-size: 12px; }

.section-block { margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); overflow: hidden; }
.section-block > header {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--bg-sunken); border-bottom: 1px solid var(--border); cursor: pointer;
}
.section-block > header h3 { margin: 0; font-size: 13.5px; flex: 1; }
.section-block > header .caret { transition: transform .15s; font-size: 11px; color: var(--fg-faint); }
.section-block.collapsed > header .caret { transform: rotate(-90deg); }
.section-block.collapsed > .section-body { display: none; }
.section-body { padding: 14px 18px; }

/* ----------------------------- MARKDOWN ----------------------------- */
.md { font-size: 14.5px; line-height: 1.72; overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  line-height: 1.3; margin: 1.5em 0 .55em; font-weight: 700; letter-spacing: -.2px;
}
.md h1 { font-size: 1.55em; padding-bottom: .25em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.3em; padding-bottom: .22em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.14em; }
.md h4 { font-size: 1.02em; }
.md h5, .md h6 { font-size: .95em; color: var(--fg-dim); }
.md p { margin: 0 0 1em; }
.md ul, .md ol { margin: 0 0 1em; padding-left: 1.7em; }
.md li { margin: .25em 0; }
.md li > ul, .md li > ol { margin: .3em 0; }
.md blockquote {
  margin: 0 0 1em; padding: .5em 1em; border-left: 3px solid var(--accent);
  background: var(--bg-sunken); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--fg-dim);
}
.md blockquote > *:last-child { margin-bottom: 0; }
.md code {
  font-family: var(--mono); font-size: .88em; padding: .15em .4em;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 5px;
}
.md pre {
  margin: 0 0 1em; padding: 12px 14px; overflow-x: auto;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.md pre code { padding: 0; background: none; border: 0; font-size: 12.5px; line-height: 1.6; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.md a { text-decoration: none; border-bottom: 1px solid currentColor; }
.md .md-table-wrap { overflow-x: auto; margin: 0 0 1em; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg-sunken); font-weight: 650; }
.md tr:nth-child(even) td { background: rgba(127,127,127,.035); }
.md mark { background: #ffe479; color: #241c00; padding: 0 2px; border-radius: 3px; }
:root[data-theme="dark"] .md mark { background: #7a6210; color: #ffeaa0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .md mark { background: #7a6210; color: #ffeaa0; } }

.md-raw {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65; white-space: pre-wrap;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; overflow-x: auto; max-height: 70vh; overflow-y: auto;
}
.md-error {
  border: 1px solid var(--err); background: var(--err-soft); color: var(--err);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 10px;
}

.content-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

/* ----------------------------- VOCABULARY ----------------------------- */
.vocab-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.vocab-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px;
  position: relative;
}
.vocab-card.learned { border-color: var(--ok); }
.vocab-card .vc-emoji { font-size: 26px; line-height: 1; }
.vocab-card .vc-word { font-size: 16.5px; font-weight: 700; letter-spacing: -.2px; padding-right: 54px; }
.vocab-card .vc-ipa { font-family: var(--mono); font-size: 12.5px; color: var(--info); }
.vocab-card .vc-mean { font-size: 13.5px; }
.vocab-card .vc-ex { font-size: 12.5px; color: var(--fg-dim); font-style: italic; }
.vocab-card .vc-meta { display: flex; gap: 5px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }
.vocab-card .vc-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; }
.vocab-card .vc-tools button { border: 0; background: none; cursor: pointer; font-size: 14px; padding: 3px; border-radius: 5px; opacity: .45; }
.vocab-card .vc-tools button:hover { background: var(--bg-sunken); opacity: 1; }
.vocab-card .vc-tools button.on { opacity: 1; }
.vocab-card .vc-fields { font-size: 12.5px; display: grid; gap: 3px; }
.vocab-card .vc-fields div { display: flex; gap: 6px; }
.vocab-card .vc-fields b { color: var(--fg-faint); font-weight: 600; min-width: 76px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .3px; }
.enrich-flag { border-style: dashed !important; }

.vocab-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.vocab-table th, .vocab-table td { border-bottom: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.vocab-table th { background: var(--bg-sunken); position: sticky; top: 0; z-index: 1; font-size: 12px; }
.vocab-table tr:hover td { background: var(--bg-sunken); }

.topic-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.topic-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  background: var(--bg-elev); cursor: pointer; text-align: left; box-shadow: var(--shadow-sm);
}
.topic-card:hover { border-color: var(--accent); }
.topic-card .tc-emoji { font-size: 30px; }
.topic-card .tc-name { font-weight: 700; font-size: 14px; margin-top: 6px; }
.topic-card .tc-cnt { font-size: 12px; color: var(--fg-dim); }

/* ----------------------------- MEDIA ----------------------------- */
.media-box {
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px;
}
.media-box audio, .media-box video { width: 100%; display: block; border-radius: var(--radius-sm); }
.media-box video { max-height: 62vh; background: #000; }
.media-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12.5px; }
.media-head .fname { font-family: var(--mono); font-size: 12px; color: var(--fg-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-missing {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); color: var(--warn); font-size: 12.5px; border: 1px solid transparent;
}
.speed-ctl { display: flex; gap: 4px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.speed-ctl button { padding: 2px 8px; font-size: 11.5px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg-elev); cursor: pointer; }
.speed-ctl button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ----------------------------- EXERCISES ----------------------------- */
.ex-item {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev);
  padding: 14px 16px; margin-bottom: 12px;
}
.ex-q { font-weight: 600; margin-bottom: 10px; font-size: 14.5px; }
.ex-q .qn { color: var(--fg-faint); margin-right: 6px; }
.ex-opts { display: grid; gap: 6px; }
.ex-opt {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: 13.5px;
}
.ex-opt:hover { border-color: var(--accent); }
.ex-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.ex-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.ex-opt.wrong { border-color: var(--err); background: var(--err-soft); }
.ex-opt .k { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center; font-size: 11px; flex: 0 0 20px; }
.ex-blank {
  display: inline-block; min-width: 96px; padding: 2px 8px; margin: 0 3px;
  border: 0; border-bottom: 2px solid var(--accent); background: var(--bg-sunken);
  border-radius: 5px 5px 0 0; font-size: inherit; outline: none;
}
.ex-blank.correct { border-bottom-color: var(--ok); background: var(--ok-soft); }
.ex-blank.wrong { border-bottom-color: var(--err); background: var(--err-soft); }
.ex-foot { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.ex-answer {
  margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--ok-soft); color: var(--ok); font-size: 13px; border: 1px solid transparent;
}
.ex-answer.none { background: var(--warn-soft); color: var(--warn); }
.ex-src { font-size: 11.5px; color: var(--fg-faint); margin-top: 8px; font-family: var(--mono); }

/* -------------------------- WORD LOCATION -------------------------- */
.fc-topic-chip {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 10px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------------------- SYNONYMS ---------------------------- */
.syn-box {
  margin: 10px 0 0; padding: 10px 12px;
  background: var(--bg); border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 6px; text-align: left;
}
.syn-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.syn-label { font-size: 12px; white-space: nowrap; color: var(--fg-dim); }
.syn-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.syn-src { margin: 2px 0 0; font-size: 10.5px; }
.fc-face .syn-box {
  background: rgba(0, 0, 0, 0.30);
  max-width: 100%; margin-top: 10px; padding: 8px 10px;
}
.fc-face .syn-label, .fc-face .syn-src { color: rgba(255, 255, 255, 0.85); }
.fc-face .syn-box .chip { font-size: 11px; padding: 1px 7px; }

/* --------------------------- READING MODE --------------------------- */
.lc-reading {
  margin-top: 12px; padding: 14px 16px;
  background: var(--bg); border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.lc-reading p { margin: 0 0 12px; line-height: 1.85; font-size: 15px; }
.lc-reading p:last-child { margin-bottom: 0; }

/* ------------------------------ STORY ------------------------------ */
.st-emoji { font-size: 20px; line-height: 1; margin-right: 2px; }
.st-arc, .st-card, .st-ep { margin-bottom: 14px; }
.st-tagline { font-style: italic; color: var(--fg-dim); margin: 0 0 10px; }
.st-role {
  display: inline-block; margin: 0 0 8px; padding: 2px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600;
}
.st-beats { margin: 0; padding-left: 20px; }
.st-beats li { margin-bottom: 8px; line-height: 1.6; }
.st-sub { margin: 14px 0 8px; font-size: 13px; color: var(--fg-dim); font-weight: 600; }
.st-quotes { margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.st-quote {
  margin: 0; padding: 8px 12px; cursor: pointer;
  border-left: 3px solid var(--accent); background: var(--bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex; flex-direction: column; gap: 4px;
}
.st-quote:hover { background: var(--accent-soft); }
.st-open {
  margin: 10px 0 4px; padding: 10px 12px;
  background: var(--bg); border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.65; color: var(--fg-dim);
}

/* ----------------------------- PDF PAGES ----------------------------- */
.pdf-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.pdf-page {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 58px; padding: 8px 4px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); font-size: 11px; color: var(--fg-dim);
}
.pdf-page:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.pdf-ico { font-size: 18px; line-height: 1; }
.pdf-num { font-family: var(--mono); font-size: 10.5px; }
.pdf-grid.wide .pdf-page { width: auto; min-width: 120px; padding: 8px 12px; }
.pdf-page.book { flex-direction: row; gap: 8px; }
.pdf-page.book .pdf-num { font-family: inherit; font-size: 12px; }

/* ----------------------------- GRAMMAR ----------------------------- */
.gr-card { margin-bottom: 14px; }
.gr-card > header h3 { flex: 1; }
.gr-formula {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 12px;
}
.gr-formula-label {
  font-size: 10.5px; font-weight: 800; letter-spacing: .8px;
  color: var(--accent); flex: 0 0 auto;
}
.gr-formula code {
  font-family: var(--mono); font-size: 13.5px; font-weight: 600;
  background: none; border: 0; padding: 0; color: var(--fg);
}
.gr-rules { margin: 0 0 12px; padding-left: 1.3em; font-size: 14px; line-height: 1.75; }
.gr-rules li { margin: .3em 0; }
.gr-note {
  background: var(--warn-soft); color: var(--warn);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13.5px; margin-bottom: 10px;
}
.gr-example {
  background: var(--bg-sunken); border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px; font-size: 13.5px; margin-bottom: 8px;
}
.gr-example.gr-real { border-left-color: var(--ok); }
.gr-source { font-size: 12px; color: var(--fg-faint); margin-top: 10px; }
.gr-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.gr-row:hover { background: var(--bg-sunken); }
.gr-row-names { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }

/* ----------------------------- FLASHCARD ----------------------------- */
.fc-stage { display: grid; place-items: center; padding: 10px 0 24px; }
.fc-card { width: min(480px, 100%); min-height: 280px; perspective: 1400px; cursor: pointer; }
.fc-inner { position: relative; width: 100%; min-height: 280px; transition: transform .6s cubic-bezier(0.4, 0.0, 0.2, 1); transform-style: preserve-3d; }
.fc-card.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); padding: 20px;
  display: flex; flex-direction: column;
  /* Thẻ có kích thước cố định: KHÔNG có gì được phép tràn ra ngoài. */
  overflow: hidden;
}
/* Từ vựng có cụm 31 ký tự và từ 19 ký tự không dấu cách — phải cho xuống dòng
   giữa từ, nếu không nó chạy lọt ra ngoài mép thẻ. */
.fc-face, .fc-face * { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.fc-face.front { background: #fdfdfd; border: 1px solid #e2e8f0; align-items: center; text-align: center; color: #111; }
.fc-face.front > * { max-width: 100%; }
.fc-face.back { background: #fdfdfd; color: #111; transform: rotateY(180deg); overflow: hidden; border: 1px solid #e2e8f0; padding: 0; }

:root[data-theme="dark"] .fc-face.front { background: #1a1f2c; border-color: #334155; color: #f1f5f9; }
:root[data-theme="dark"] .fc-face.back { background: #1a1f2c; border-color: #334155; color: #f1f5f9; }

/* Hole Punch */
.fc-hole {
  position: absolute; width: 28px; height: 28px; border-radius: 50%;
  background: #e9eef5; box-shadow: inset 0 3px 6px rgba(0,0,0,0.2), 0 1px 0 rgba(255,255,255,1);
  top: 24px; z-index: 10;
}
:root[data-theme="dark"] .fc-hole { background: #0f172a; box-shadow: inset 0 3px 6px rgba(0,0,0,0.8), 0 1px 0 rgba(255,255,255,0.1); }
.fc-hole.left { left: 24px; }
.fc-hole.right { right: 24px; }

/* Top Bar */
.fc-top-bar { display: flex; justify-content: space-between; align-items: flex-start; width: 100%; padding: 0 10px; margin-bottom: 20px; }
.fc-top-spacer { width: 40px; }
.fc-topic-text { font-style: italic; font-size: 15px; color: #64748b; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; letter-spacing: 0.5px; padding-top: 4px; }
.fc-card-num-group { display: flex; gap: 4px; }
.fc-num-box {
    border: 1.5px solid #94a3b8; padding: 2px 6px; font-size: 16px; font-family: var(--mono); color: #64748b; font-weight: bold;
    border-radius: 2px; line-height: 1;
}

/* Center Front */
.fc-center {
  flex: 1; min-height: 0;                 /* cho phép co lại, không đẩy thẻ phình ra */
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  width: 100%; overflow: hidden;
}
.fc-word-row {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline;
  gap: 6px 10px; margin-bottom: 8px; max-width: 100%;
}
.fc-front-word {
  font-size: 46px; font-weight: normal; color: #0f172a;
  font-family: "Arial", sans-serif; letter-spacing: -0.5px;
  line-height: 1.15; max-width: 100%;
}
/* Từ càng dài, chữ càng nhỏ — thay vì để nó đâm ra khỏi thẻ. */
.fc-front-word.long  { font-size: 0.62em; letter-spacing: 0; }
.fc-front-word.xlong { font-size: 0.46em; letter-spacing: 0; }
:root[data-theme="dark"] .fc-front-word { color: #f8fafc; }
.fc-front-pos { font-size: 16px; font-style: italic; color: #334155; }
:root[data-theme="dark"] .fc-front-pos { color: #cbd5e1; }
.fc-front-ipa { font-size: 20px; color: #475569; font-family: "Arial", sans-serif; }
:root[data-theme="dark"] .fc-front-ipa { color: #94a3b8; }

/* Bottom Example */
/* Câu ví dụ dài nhất trong nguồn là 1.323 ký tự — bó lại tối đa 3 dòng. */
.fc-front-example {
  margin-top: auto; font-size: 16px; color: #1e293b; padding: 0 30px 10px;
  line-height: 1.4; text-align: left; width: 100%; cursor: pointer;
  transition: opacity .2s;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; max-height: 4.2em; flex: 0 0 auto;
}
.fc-front-example:hover { opacity: 0.8; text-decoration: underline; text-decoration-color: rgba(0,0,0,0.2); }
:root[data-theme="dark"] .fc-front-example { color: #e2e8f0; }

/* Back Layout */
/* Ảnh nền LÀM MỜ hẳn: nó là bối cảnh gợi nghĩa, chữ mới là thứ phải đọc được.
   inset âm + scale để viền mờ không hở ra mép thẻ. */
.fc-back-bg {
  position: absolute; inset: -12px;
  width: calc(100% + 24px); height: calc(100% + 24px);
  object-fit: cover; filter: blur(7px) saturate(1.05); z-index: 1;
}
.fc-back-overlay { position: absolute; inset: 0; background: rgba(255,255,255,0.55); z-index: 2; }
:root[data-theme="dark"] .fc-back-overlay { background: rgba(15,23,42,0.62); }

.fc-back-content {
  position: relative; z-index: 3; display: flex; width: 100%; height: 100%;
  padding: 24px; align-items: center; min-height: 0; overflow: hidden;
}
.fc-back-left { flex: 1; display: flex; justify-content: center; align-items: center; height: 100%; padding-right: 20px; }
.fc-back-illustration { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; mix-blend-mode: multiply; }
:root[data-theme="dark"] .fc-back-illustration { mix-blend-mode: normal; }

.fc-back-right { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.fc-back-meaning {
  font-size: 30px; font-weight: normal; color: #0f172a; margin-bottom: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.2; max-width: 100%;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.fc-back-meaning.long  { font-size: 0.66em; }
.fc-back-meaning.xlong { font-size: 0.5em; }
:root[data-theme="dark"] .fc-back-meaning { color: #f1f5f9; }
.fc-back-synonym { font-size: 17px; color: #475569; font-weight: normal; }
:root[data-theme="dark"] .fc-back-synonym { color: #94a3b8; }

.fc-back-fields {
  margin-top: 12px; font-size: 12.5px; line-height: 1.5; width: 100%;
  text-align: left; background: rgba(255,255,255,0.5);
  padding: 10px 14px; border-radius: 8px;
  overflow-y: auto; max-height: 132px;
}
/* Ghi chú dài: mặc định gọn một dòng, bấm "xem thêm" mới trải hết. */
.fc-note-short { display: block; }
.fc-more {
  border: 0; background: none; padding: 0 0 0 4px; cursor: pointer;
  font-size: 11.5px; font-weight: 600; color: var(--accent);
  white-space: nowrap;
}
.fc-more:hover { text-decoration: underline; }
:root[data-theme="dark"] .fc-back-fields { background: rgba(0,0,0,0.3); }
.fc-back-fields .row { display: flex; gap: 8px; margin-bottom: 5px; align-items: baseline; }
.fc-back-fields b { flex: 0 0 62px; color: #64748b; font-size: 11.5px; font-weight: 700; }

.fc-speaker-btn {
  position: absolute; bottom: 20px; right: 20px;
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: transparent; color: #64748b;
  display: grid; place-items: center; font-size: 20px;
  cursor: pointer; opacity: 0.6; transition: opacity .2s, transform .2s; z-index: 10;
}
.fc-speaker-btn:hover { opacity: 1; transform: scale(1.1); }

.fc-grade { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.fc-grade button { padding: 9px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg-elev); cursor: pointer; font-weight: 600; font-size: 13px; }
.fc-grade .g-again { border-color: var(--err); color: var(--err); }
.fc-grade .g-hard { border-color: var(--warn); color: var(--warn); }
.fc-grade .g-good { border-color: var(--accent); color: var(--accent); }
.fc-grade .g-easy { border-color: var(--ok); color: var(--ok); }
.fc-progress { text-align: center; color: var(--fg-dim); font-size: 12.5px; margin-bottom: 12px; }

/* ----------------------------- SEARCH ----------------------------- */
.search-result {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev);
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
}
.search-result:hover { border-color: var(--accent); }
.search-result .sr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; flex-wrap: wrap; }
.search-result .sr-title { font-weight: 650; font-size: 13.5px; }
.search-result .sr-snip { font-size: 12.8px; color: var(--fg-dim); line-height: 1.6; }
.search-result .sr-snip mark { background: #ffe479; color: #241c00; }
:root[data-theme="dark"] .search-result .sr-snip mark { background: #7a6210; color: #ffeaa0; }

/* ----------------------------- FILES ----------------------------- */
.file-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer;
}
.file-row:hover { background: var(--bg-sunken); }
.file-row .fi { font-size: 16px; width: 22px; text-align: center; }
.file-row .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fp { font-family: var(--mono); font-size: 11px; color: var(--fg-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34%; }
.file-row .fs { font-size: 11.5px; color: var(--fg-faint); width: 78px; text-align: right; }

.map-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap;
}
.map-row select { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-size: 12.5px; max-width: 300px; }

/* ----------------------------- AUDIT ----------------------------- */
.audit-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.audit-row .ar-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-row .ar-nums { font-family: var(--mono); font-size: 11.5px; color: var(--fg-faint); }
.audit-row.fail { background: var(--err-soft); }
.audit-summary { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); margin-bottom: 18px; }

/* ----------------------------- RESPONSIVE ----------------------------- */
@media (max-width: 1000px) {
  .sidebar {
    position: fixed; z-index: 80; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%); transition: transform .2s ease-out;
    box-shadow: var(--shadow-lg);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .sidebar-close { display: block; }
  #sidebarToggle { display: block; }
  .app:not(.is-empty) .content { padding: 16px 14px 70px; }
  .quick-search input { width: 180px; }
}
@media (max-width: 620px) {
  .crumbs { max-width: 40vw; font-size: 13px; }
  .quick-search { display: none; }
  .import-card { padding: 24px 18px; }
  .import-card h1 { font-size: 21px; }
  .stat .v { font-size: 22px; }
  .lesson-hero h1 { font-size: 20px; }
  .fc-front-word { font-size: 26px; }
  .content { padding: 14px 12px 60px; }
}

/* ------------------------- DIEN THOAI (iPhone) ------------------------- */
@media (max-width: 480px) {
  /* vung an toan quanh tai tho va thanh vuot cua iPhone */
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .content { padding-bottom: max(70px, env(safe-area-inset-bottom)); }
  .sidebar { width: min(86vw, 320px); padding-left: env(safe-area-inset-left); }

  /* o nhap phai >=16px, neu khong iOS tu phong to trang khi bam vao o */
  input, select, textarea { font-size: 16px; }

  /* nut bam du to de cham bang ngon tay */
  .btn, .nav-item, .tabs button, .fc-grade button, .fc-actions button { min-height: 40px; }

  /* the flashcard: mot cot, bo hai nut hai ben ra duoi */
  .fc-grid { gap: 16px; padding: 12px 0; }
  .fc-block { width: 100%; max-width: 420px; }
  .fc-stage > div[style] { padding: 0 !important; }
  .fc-nav-side {
    position: static; transform: none; width: 48%; justify-content: center;
    margin-top: 10px;
  }
  .fc-nav-side:hover:not([disabled]) { transform: none; }
  .fc-card, .fc-block .fc-card { min-height: 260px; }

  /* danh sach the: mot cot cho de doc */
  .lesson-grid { grid-template-columns: 1fr; }
  .lc-media video { max-height: 46vw; }

  /* bang rong thi cuon ngang trong khung cua no, khong day ca trang */
  .md table { display: block; overflow-x: auto; }
  .view-head h1 { font-size: 20px; }
}

@media print {
  .sidebar, .topbar, .content-actions, .tabs { display: none !important; }
  .content { overflow: visible; padding: 0; }
}





/* Flashcard Grid */
.fc-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 30px; padding: 20px 0; max-width: 1100px; margin: 0 auto; }
.fc-block { width: 320px; display: flex; flex-direction: column; gap: 8px; }
.fc-block .fc-card { width: 100%; min-height: 220px; margin: 0; perspective: 1200px; }
.fc-block .fc-inner { min-height: 220px; }
.fc-block .fc-grade { display: flex; justify-content: center; gap: 4px; margin-top: 4px; }
.fc-block .fc-grade button { padding: 6px 10px; font-size: 13px; flex: 1; }
.fc-block .fc-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.fc-block .fc-actions button { padding: 4px 8px; font-size: 12px; }

/* Side Nav Buttons */
.fc-nav-side { position: absolute; top: 50%; transform: translateY(-50%); padding: 12px 20px; border-radius: 30px; background: #fff; border: 1px solid #e2e8f0; box-shadow: 0 4px 15px rgba(0,0,0,0.1); font-size: 15px; font-weight: bold; color: #334155; z-index: 50; cursor: pointer; transition: all 0.2s; display: flex; align-items: center; gap: 8px; }
.fc-nav-side:hover:not([disabled]) { background: #f8fafc; color: #2563eb; box-shadow: 0 6px 20px rgba(0,0,0,0.15); transform: translateY(-50%) scale(1.05); }
.fc-nav-side[disabled] { opacity: 0.3; cursor: not-allowed; }
.fc-nav-prev { left: -10px; }
.fc-nav-next { right: -10px; }
:root[data-theme="dark"] .fc-nav-side { background: #1e293b; border-color: #334155; color: #f1f5f9; }
