:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #eaf0ec;
  --text: #15201b;
  --muted: #5b6a63;
  --border: #dbe3de;
  --accent: #1f6f5c;
  --accent-contrast: #ffffff;
  --accent-soft: #e0efe8;
  --ok: #26734a;
  --ok-soft: #dcefe2;
  --warn: #9a5b10;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 6px 20px rgb(0 0 0 / 6%);
  --tabbar-h: 60px;
  --mini-h: 64px;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1311;
    --surface: #151d1a;
    --surface-2: #1d2824;
    --text: #e5ede9;
    --muted: #9aaba3;
    --border: #2a3632;
    --accent: #58c4a4;
    --accent-contrast: #062219;
    --accent-soft: #173a30;
    --ok: #6fd093;
    --ok-soft: #173826;
    --warn: #f0b35a;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.overlay-open { overflow: hidden; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1 { font-size: 23px; margin: 2px 0 10px; line-height: 1.25; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 8px 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--ok); font-weight: 600; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.center { justify-content: center; text-align: center; }
.grow { flex: 1; min-width: 0; }
.loading { color: var(--muted); padding: 32px 0; text-align: center; }

.ico { width: 20px; height: 20px; flex: none; }

/* ---------- khung ---------- */

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

body.has-mini #app { padding-bottom: calc(var(--tabbar-h) + var(--mini-h) + env(safe-area-inset-bottom) + 28px); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 0 10px;
  /* nền đặc: backdrop-filter sẽ làm thanh tab (position: fixed bên trong) bám theo header thay vì đáy màn hình */
  background: var(--bg);
}

.brand { font-weight: 750; font-size: 17px; color: var(--text); text-decoration: none; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.tabs a.on { color: var(--accent); }
.tabs .ico { width: 22px; height: 22px; }

.sync-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.sync-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sync-badge[data-status="ok"] .dot { background: var(--ok); }
.sync-badge[data-status="syncing"] .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-badge[data-status="error"] .dot { background: var(--warn); }
.sync-badge[data-status="auth"] .dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: 0.3; } }

/* điện thoại: bỏ thanh trên cùng (tên app + chấm đồng bộ), chỉ giữ nền dưới thanh trạng thái.
   Đồng bộ lỗi thì hiện chấm trên tab Cài đặt; chi tiết xem trong Cài đặt. */
@media (max-width: 819px) {
  .topbar { padding: env(safe-area-inset-top) 0 0; }
  .brand, .sync-badge { display: none; }
  .tabs a { position: relative; }
  body:is([data-sync="error"], [data-sync="auth"]) .tabs a[data-tab="settings"]::after {
    content: "";
    position: absolute;
    top: 9px;
    left: calc(50% + 8px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warn);
  }
}

@media (min-width: 820px) {
  #app { max-width: 980px; padding-bottom: 32px; }
  body.has-mini #app { padding-bottom: calc(var(--mini-h) + 40px); }
  .tabs {
    position: static;
    display: flex;
    gap: 4px;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
  }
  .tabs a { flex-direction: row; gap: 6px; padding: 7px 12px; border-radius: 10px; font-size: 14px; }
  .tabs a.on { background: var(--accent-soft); }
  .tabs .ico { width: 18px; height: 18px; }
}

/* ---------- bố cục trang: 1 cột trên điện thoại, 2 cột khi đủ rộng ---------- */

.view { container: view / inline-size; }

/* điện thoại: 2 cột "tan" ra để thẻ xếp theo order (Phút hôm nay → Bài đang học → 14 ngày qua) */
.layout { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.layout > div { display: contents; }
.layout .card { margin: 0; }
.layout .today { order: 1; }
.layout .study { order: 2; }
.layout .history { order: 3; }
.layout .pager { order: 5; }

@container view (min-width: 860px) {
  .layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 20px; align-items: start; margin: 16px 0; }
  .layout > div { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
  .chart-bars { height: 110px; }
  .pager { margin: 0 4px; }
}

.settings { display: grid; gap: 12px; margin: 12px 0; }
.settings .card { margin: 0; }
@container view (min-width: 700px) {
  .settings { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 20px; align-items: start; margin: 16px 0; }
}

/* ---------- thẻ & thành phần ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}

.card.flush { padding: 0; overflow: hidden; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

.link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 14px; }

.title { font-weight: 650; }

.bar { height: 8px; margin: 8px 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s; }

.today { padding: 12px 16px 10px; }
.today .bar { margin: 8px 0 2px; }
.goal-text { font-size: 15px; }
.goal-text strong { font-size: 26px; line-height: 1.1; }

.chart { margin-top: 12px; }
.chart-bars { position: relative; display: flex; align-items: flex-end; gap: 4px; height: 76px; }
.chart-bars::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--goal);
  border-top: 1px dashed var(--muted);
  opacity: 0.6;
  pointer-events: none;
}
.chart .col { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.chart .col > span {
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 2px 2px;
  background: color-mix(in srgb, var(--accent) 40%, var(--surface-2));
}
.chart .col > span.hit { background: var(--accent); }
.chart-labels { display: flex; gap: 4px; margin-top: 4px; }
.chart-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }

.hint { margin: 12px 0 4px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14.5px; }
.hint summary { cursor: pointer; list-style: none; }
.hint summary::-webkit-details-marker { display: none; }
.hint .more { display: inline-flex; align-items: center; gap: 1px; color: var(--accent); font-weight: 650; white-space: nowrap; }
.hint .more .ico { width: 16px; height: 16px; transition: transform 0.2s; }
.hint[open] .more .ico { transform: rotate(180deg); }
.hint ol { margin: 8px 0 2px; padding-left: 20px; }
.hint li { margin: 5px 0; }

.lesson-name { margin: 2px 0 0; font-size: 20px; line-height: 1.25; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
  vertical-align: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: transparent; }
.btn.icon { min-width: 40px; padding: 8px; }
.btn.wide { width: 100%; }

.btn-play {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
}
.btn-play .ico { width: 20px; height: 20px; }
.btn-play.xl { width: 76px; height: 76px; }
.btn-play.xl .ico { width: 32px; height: 32px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

/* ---------- danh sách file trong bài ---------- */

.files { list-style: none; margin: 10px 0 0; padding: 0; }
.file { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.file .title { overflow-wrap: anywhere; }
.file.is-current .title { color: var(--accent); }
/* PDF: cả dòng là nút mở */
.file-open { display: flex; flex: 1; align-items: center; gap: 12px; min-width: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.kind { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }

.checklist { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.card > .checklist:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.checklist > p { margin: 0 0 4px; }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; font-size: 15px; cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); }
.checklist .btn { margin-top: 8px; }

/* ---------- danh sách bài ---------- */

.segmented { display: flex; gap: 4px; margin: 12px 0; padding: 4px; border-radius: 12px; background: var(--surface-2); }
.segmented :is(a, button) { flex: 1; padding: 8px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: inherit; font-weight: 650; text-align: center; text-decoration: none; cursor: pointer; }
.segmented .on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.lessons { list-style: none; margin: 0; padding: 0; }
.lessons li + li { border-top: 1px solid var(--border); }
.lesson-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text); text-decoration: none; }
.lesson-row:hover { background: var(--surface-2); }
.lesson-row .title { display: block; }
.lesson-row .muted { display: block; }
.badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.lesson-row.done .badge { background: var(--ok-soft); color: var(--ok); }
.lesson-row.current .badge { background: var(--accent); color: var(--accent-contrast); }
.offline-mark { color: var(--accent); }

@container view (min-width: 700px) {
  .segmented { max-width: 520px; }
  .card.flush:has(> .lessons) { padding: 0; border: 0; background: none; box-shadow: none; overflow: visible; }
  .lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  .lessons li + li { border-top: 0; }
  .lessons li { display: flex; }
  .lesson-row { flex: 1; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
  .lesson-row.current { border-color: var(--accent); }
}

.back { display: inline-flex; align-items: center; gap: 2px; margin-top: 6px; color: var(--accent); font-weight: 650; text-decoration: none; }
.pager { display: flex; justify-content: space-between; margin: 4px 4px 16px; }
.pager a { color: var(--accent); font-weight: 650; text-decoration: none; }

/* ---------- cài đặt ---------- */

.field { display: grid; gap: 2px; margin-top: 10px; }
.field > span { color: var(--muted); font-size: 14px; }
.field .segmented { margin: 4px 0 0; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; font-size: 15px; }
.setting-row .btn { flex: none; }
.advanced { margin-top: 8px; }
.advanced summary, .pw summary, .add-user summary { cursor: pointer; color: var(--accent); font-weight: 650; font-size: 14.5px; }
.advanced summary { color: var(--muted); }

/* ---------- tài khoản & người dùng ---------- */

.warn { color: var(--warn); }
.avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 750; }
.me { display: flex; align-items: center; gap: 12px; }
.me + .pw { margin-top: 12px; }
.form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.form .btn { align-self: flex-start; }
.link-btn { padding: 4px 0; border: 0; background: none; color: var(--accent); font: inherit; font-weight: 650; cursor: pointer; }

.users { grid-column: 1 / -1; }
.user-list { list-style: none; margin: 8px 0 0; padding: 0; }
.user-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.user-row.is-disabled .avatar { background: var(--surface-2); color: var(--muted); }
.user-row .grow { flex: 1 1 180px; }
.user-actions { display: flex; gap: 6px; margin-left: auto; }
.add-user { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.add-user summary { display: inline-flex; align-items: center; gap: 6px; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form-row .input { flex: 1 1 200px; width: auto; }
.form-row .btn { flex: none; }
.invite-box { margin: 10px 0; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: 12px; background: var(--accent-soft); }
.invite-box p { margin: 0 0 8px; font-size: 14.5px; }
.invite-link { display: flex; flex-wrap: wrap; gap: 8px; }
.invite-link .input { flex: 1 1 240px; width: auto; font-size: 13.5px; }

/* ---------- mini-player ---------- */

.mini {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 744px;
  height: var(--mini-h);
  margin: 0 auto;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgb(0 0 0 / 14%);
}
.mini-progress { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--surface-2); }
.mini-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
.mini-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.mini-info > span { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mini-time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-ctrl { order: -1; display: flex; align-items: center; gap: 4px; }
.mini-end { display: flex; align-items: center; gap: 10px; }
.mini .desk { display: none; }
.mini-ctrl .btn.icon { position: relative; border: 0; border-radius: 50%; background: transparent; }

@media (max-width: 380px) { .mini-time { display: none; } }
@media (min-width: 820px) { .mini { bottom: 16px; max-width: 948px; } }

/* ---------- lớp phủ: trình phát, PDF ---------- */

.overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--bg); }
.overlay-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.overlay-head .btn.icon { border: 0; background: transparent; }
.overlay-title { flex: 1; min-width: 0; overflow: hidden; color: var(--text); font-weight: 650; text-decoration: none; white-space: nowrap; text-overflow: ellipsis; }

.panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  overflow: auto;
}
.panel-title { font-size: 25px; font-weight: 750; text-align: center; }
#panel-hint { text-align: center; }
#seek { width: 100%; margin: 18px 0 0; accent-color: var(--accent); }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 14px; }
.controls .btn.icon { position: relative; width: 54px; height: 54px; border: 0; border-radius: 50%; background: transparent; }
.controls .btn.icon .ico { width: 28px; height: 28px; }
.jump-n { position: absolute; inset: 0; display: grid; place-items: center; padding-top: 1px; font-size: 10px; font-weight: 800; }
.video-wrap video { display: block; width: 100%; max-height: 42vh; border-radius: 12px; background: #000; }

.zoom { display: flex; align-items: center; gap: 2px; }
.zoom span { min-width: 42px; text-align: center; color: var(--muted); }
/* căn giữa bằng margin auto (không dùng align-items: center) để khi phóng to vẫn cuộn ngang được tới mép trái */
.pdf-pages { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 8px; overflow: auto; background: var(--surface-2); }
.pdf-page { position: relative; flex: none; margin-inline: auto; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 20%); }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-msg { padding: 24px; color: var(--muted); text-align: center; }

/* lớp chữ của pdf.js (rút gọn từ pdf_viewer.css) để bôi đen/tra từ */
.textLayer {
  position: absolute;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  text-align: initial;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 0;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer :is(span, br) { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; }
.textLayer > :not(.markedContent),
.textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgb(0 90 255 / 25%); color: transparent; }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { position: absolute; inset: 100% 0 0; z-index: 0; display: block; cursor: default; user-select: none; }
.textLayer.selecting .endOfContent { top: 0; }

/* ---------- đăng nhập, thông báo ---------- */

.login { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { display: flex; flex-direction: column; gap: 10px; width: min(360px, 100%); text-align: center; }
.login-card img { align-self: center; border-radius: 14px; }
.login-card h1 { margin: 4px 0 0; }
.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input[readonly] { background: var(--surface-2); }
#invite-user { text-align: center; font-weight: 650; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--mini-h) + env(safe-area-inset-bottom) + 24px);
  z-index: 200;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

/* ---------- máy tính: sidebar trái, thanh phát dưới đáy, trình phát là ngăn bên phải ---------- */

@media (min-width: 1024px) {
  :root { --mini-h: 76px; --side-w: 236px; --drawer-w: 420px; }

  #app {
    display: grid;
    grid-template-columns: var(--side-w) minmax(0, 1fr);
    max-width: none;
    padding: 0;
  }
  body.has-mini #app { padding-bottom: var(--mini-h); }

  .topbar {
    align-self: start;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    height: 100vh;
    height: 100dvh;
    padding: 24px 14px 18px;
    border-right: 1px solid var(--border);
    background: var(--surface);
  }
  body.has-mini .topbar { height: calc(100dvh - var(--mini-h)); }
  .brand { padding: 0 10px 18px; font-size: 18px; }
  .tabs { flex-direction: column; gap: 2px; }
  .tabs a { justify-content: flex-start; padding: 10px 12px; font-size: 15px; }
  .sync-badge { align-self: flex-start; margin: auto 0 0; }
  .sync-badge .label { display: inline; }

  .view { width: 100%; max-width: 1320px; margin: 0 auto; padding: 20px 40px 40px; }
  h1 { font-size: 28px; }

  /* thanh phát toàn chiều ngang */
  .mini {
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 16px;
    max-width: none;
    padding: 0 24px;
    border-width: 1px 0 0;
    border-radius: 0;
    box-shadow: 0 -4px 20px rgb(0 0 0 / 6%);
  }
  .mini .desk { display: inline-flex; }
  .mini-ctrl { order: 0; gap: 6px; }
  .mini-ctrl .btn.icon .ico { width: 22px; height: 22px; }
  .mini-end { justify-self: end; }
  .mini-time { display: inline; }
  .mini-info .title { font-size: 15px; }

  /* lớp phủ không che thanh phát */
  body.has-mini .overlay { bottom: var(--mini-h); }
  .toast { bottom: calc(var(--mini-h) + 20px); }

  /* trình phát: ngăn bên phải, vẫn xem/cuộn được trang phía sau */
  .panel { left: auto; width: var(--drawer-w); border-left: 1px solid var(--border); box-shadow: -8px 0 30px rgb(0 0 0 / 8%); }
  .panel .overlay-head .btn.icon .ico { transform: rotate(-90deg); }
  .panel-body { justify-content: flex-start; padding-top: 32px; }
  body:has(#panel:not([hidden])) #app { padding-right: var(--drawer-w); }
  body.overlay-open:not(:has(#pdf:not([hidden]))) { overflow: auto; }

  /* đọc transcript/story cạnh trình phát */
  body:has(#panel:not([hidden])) .pdf { right: var(--drawer-w); }
}

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