/* Quest Teacher v2 — shared design system (index.html + chapter-edit.html) */

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: var(--font);
  --display: var(--font);

  --sky-bg: var(--frame);
  --shell: rgba(255, 255, 255, .5);
  --shell-line: rgba(255, 255, 255, .75);
  --shell-shadow: 0 40px 90px -40px rgba(38, 56, 92, .45), 0 2px 8px rgba(38, 56, 92, .06);

  --frame: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eff2f6;
  --line: #e4e8ee;
  --line-2: #eef1f5;

  --ink: #0f1218;
  --text: #1c2230;
  --text-2: #586071;
  --muted: #8f97a6;
  --faint: #b8bfcb;

  --blue: #2f80ed;
  --sky: #66b6e8;
  --sky-soft: #eaf4fc;
  --focus: rgba(47, 128, 237, .16);

  --t1: #3b82f6; --t1-soft: #eaf2ff;
  --t2: #e59a1c; --t2-soft: #fdf3e2;
  --t3: #8b6cf5; --t3-soft: #f1edfe;
  --t4: #1fa97a; --t4-soft: #e5f6ef;
  --t5: #e8527a; --t5-soft: #fdebf0;

  --green: #16a06b; --green-soft: #e3f6ee;
  --red: #e5484d; --red-soft: #fdecec;
  --amber: #d98a0b; --amber-soft: #fdf2df;

  --r-xl: 22px;
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 1px rgba(16, 24, 40, .03);
  --shadow-2: 0 10px 28px -12px rgba(16, 24, 40, .18), 0 2px 6px -2px rgba(16, 24, 40, .06);
  --shadow-pop: 0 28px 70px -20px rgba(16, 24, 40, .32), 0 4px 12px -4px rgba(16, 24, 40, .08);

  --ai: var(--surface);

  --on-ink: #ffffff;
  --ink-hover: #272d38;
  --line-strong: #d3dae4;
  --focus-line: #8fbaf3;
  --row-hover: #fafbfc;
  --row-sel: #f3f7fc;
  --row-new: #f1faf6;
  --glass: rgba(255, 255, 255, .62);
  --glass-line: rgba(255, 255, 255, .9);
  --skel-a: #eef1f5;
  --skel-b: #f7f9fb;
  --shine: rgba(255, 255, 255, .65);
  --toast-bg: #0f1218;
  --card-back: .9;

  --t1-ink: #2764c9; --t2-ink: #a86a06; --t3-ink: #6546d4; --t4-ink: #13805b; --t5-ink: #c23a61;
  --sky-ink: #2a6fbe; --red-ink: #c93d42; --green-line: #9fdcc2;

  color-scheme: light dark;
}

/* ---------- dark: follows the system setting ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --frame: #0b0d11;
    --surface: #15181e;
    --surface-2: #1b1f26;
    --surface-3: #232830;
    --line: #2a303a;
    --line-2: #21262e;
    --line-strong: #3a414d;

    --ink: #f2f4f7;
    --on-ink: #0f1218;
    --ink-hover: #d6dbe3;
    --text: #e4e8ee;
    --text-2: #a3abb8;
    --muted: #7d8696;
    --faint: #555d6a;

    --blue: #5b9cf2;
    --sky-soft: rgba(102, 182, 232, .14);
    --focus: rgba(91, 156, 242, .26);
    --focus-line: #4a7fc4;

    --t1-soft: rgba(59, 130, 246, .16);
    --t2-soft: rgba(229, 154, 28, .16);
    --t3-soft: rgba(139, 108, 245, .18);
    --t4-soft: rgba(31, 169, 122, .16);
    --t5-soft: rgba(232, 82, 122, .16);
    --t1-ink: #8db5ff; --t2-ink: #f0bb5f; --t3-ink: #b9a5ff; --t4-ink: #5fd3a6; --t5-ink: #f58aa7;
    --sky-ink: #8cc7f0; --red-ink: #ff8f93;

    --green-soft: rgba(22, 160, 107, .16); --green-line: rgba(22, 160, 107, .5);
    --red-soft: rgba(229, 72, 77, .16);
    --amber-soft: rgba(217, 138, 11, .16);

    --row-hover: #1a1e25;
    --row-sel: #1b2433;
    --row-new: #15241e;
    --glass: rgba(255, 255, 255, .06);
    --glass-line: rgba(255, 255, 255, .07);
    --skel-a: #1f242c;
    --skel-b: #2a3039;
    --shine: rgba(255, 255, 255, .1);
    --toast-bg: #2a303b;
    --card-back: .4;

    --sky-bg: var(--frame);
    --shell: rgba(18, 21, 27, .62);
    --shell-line: rgba(255, 255, 255, .06);
    --shell-shadow: 0 40px 90px -30px rgba(0, 0, 0, .8);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-2: 0 10px 28px -12px rgba(0, 0, 0, .6), 0 2px 6px -2px rgba(0, 0, 0, .3);
    --shadow-pop: 0 28px 70px -20px rgba(0, 0, 0, .75), 0 4px 12px -4px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body.qt {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--frame);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body.qt.locked { visibility: hidden; }
body.qt.auth-required #appShell { display: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
img { display: block; }
[hidden] { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.ic { width: 18px; height: 18px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.ic-sm { width: 15px; height: 15px; }
.ic-lg { width: 22px; height: 22px; }
.ic-xs { width: 13px; height: 13px; }

/* ---------- scrollbars ---------- */
.qt ::-webkit-scrollbar { width: 10px; height: 10px; }
.qt ::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; border: 3px solid transparent; background-clip: padding-box; }
.qt ::-webkit-scrollbar-thumb:hover { background-color: var(--line-strong); }
.qt ::-webkit-scrollbar-track { background: transparent; }

/* ====================== SHELL ======================
   floating app window on a soft sky, frosted sidebar + white work panel */
#appShell {
  position: fixed; inset: 0; z-index: 1;
  display: grid; grid-template-columns: 240px minmax(0, 1fr);
  padding: 8px 8px 8px 0;
}

.display { font-family: var(--font); font-weight: 600; letter-spacing: -.022em; color: var(--ink); }

/* ---------- sidebar ---------- */
#sidebar { display: flex; flex-direction: column; min-height: 0; padding: 12px 10px 4px 6px; }

.sb-brand {
  display: flex; align-items: center; gap: 10px; width: fit-content;
  padding: 4px 8px 4px 6px; margin-bottom: 18px;
  border-radius: 8px; text-decoration: none; color: var(--ink);
}
.sb-mark { width: 28px; height: 28px; flex: 0 0 auto; }
.sb-word { font-size: 18px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }

/* class switcher (like a team switcher) */
.sb-switch { position: relative; margin-bottom: 18px; }
.sb-switch-btn {
  width: 100%; display: flex; align-items: center; gap: 11px; text-align: left;
  padding: 8px 12px 8px 8px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
  transition: border-color .14s ease, box-shadow .14s ease;
}
.sb-switch-btn:hover, .sb-switch.open .sb-switch-btn { border-color: var(--line-strong); }
.sb-switch-btn > .ic { color: var(--muted); width: 16px; height: 16px; }
.sb-switch-btn .avatar.lg { width: 38px; height: 38px; border-radius: 8px; font-size: 13px; }
.sb-switch-btn .avatar:empty { background: var(--surface-3); }
.sb-switch-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.sb-switch-text small { font-size: 11.5px; color: var(--muted); }
.sb-switch-text strong { font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.sb-switch-menu {
  left: 0; right: 0; top: calc(100% + 6px); min-width: 0;
  max-height: min(62vh, 520px); overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.sb-switch-menu .search { width: 100%; height: 36px; margin-bottom: 4px; }
.sb-switch-menu .search input { width: 100%; }
.sb-switch-menu .sb-nav { gap: 2px; }

.sb-label, .sb-sub {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 6px; color: var(--muted); font-size: 11.5px; font-weight: 500;
}
.sb-sub:first-child { padding-top: 2px; }
.sb-label .mono { font-family: var(--mono); font-size: 11px; }

.sb-main { display: flex; flex-direction: column; gap: 3px; }
.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.sb-section { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 14px; }
.sb-section .sb-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 2px; margin: -2px; }
.sb-fill { flex: 1; }

.sb-item { position: relative; }
.sb-link {
  width: 100%; height: 42px; display: flex; align-items: center; gap: 12px;
  padding: 0 12px; border-radius: 8px; border: 1px solid transparent;
  color: var(--text-2); font-size: 14px; font-weight: 500; text-align: left; text-decoration: none;
  transition: background .14s ease, color .14s ease, border-color .14s ease, box-shadow .14s ease;
}
.sb-link > .ic { color: var(--muted); transition: color .14s ease; }
.sb-link:hover { background: var(--glass); color: var(--ink); }
.sb-link:hover > .ic { color: var(--ink); }
.sb-link.active { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-1); }
.sb-link.active > .ic { color: var(--ink); }
.sb-link:disabled { opacity: .55; cursor: default; }
.sb-link .sb-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-link .sb-count {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-2); font-weight: 500;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 5px; background: var(--surface-3);
  display: inline-flex; align-items: center; justify-content: center;
}
.sb-link .sb-count:empty { display: none; }
.sb-switch-menu .sb-link { height: 40px; padding: 0 10px 0 7px; gap: 10px; color: var(--text); }
.sb-switch-menu .sb-link.active { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.sb-switch-menu .sb-link .sb-count { background: none; }
.sb-item .pinBtn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; color: var(--muted); opacity: 0; transition: opacity .12s ease, background .12s ease, color .12s ease;
}
.sb-item .pinBtn .ic { width: 14px; height: 14px; }
.sb-item:hover .pinBtn, .sb-item .pinBtn.pinned { opacity: 1; }
.sb-item:hover .sb-count, .sb-item:has(.pinBtn.pinned) .sb-count { opacity: 0; }
.sb-item .pinBtn:hover { background: var(--surface-3); color: var(--ink); }
.sb-item .pinBtn.pinned { color: var(--ink); }

.avatar {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; letter-spacing: -.01em; line-height: 1;
  background: var(--sky-soft); color: var(--sky-ink);
}
.avatar.round { border-radius: 50%; }
.avatar.lg { width: 34px; height: 34px; font-size: 12.5px; border-radius: 8px; }
.tint-1 { background: var(--t1-soft); color: var(--t1-ink); }
.tint-2 { background: var(--t2-soft); color: var(--t2-ink); }
.tint-3 { background: var(--t3-soft); color: var(--t3-ink); }
.tint-4 { background: var(--t4-soft); color: var(--t4-ink); }
.tint-5 { background: var(--t5-soft); color: var(--t5-ink); }

.sb-account { position: relative; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--glass-line); }
.sb-account-btn {
  width: 100%; display: flex; align-items: center; gap: 11px; text-align: left;
  padding: 8px 10px 8px 8px; border-radius: 10px; transition: background .14s ease;
}
.sb-account-btn:hover, .sb-account-btn[aria-expanded="true"] { background: var(--glass); }
.sb-account-btn > .ic { color: var(--muted); }
.sb-account .avatar { width: 34px; height: 34px; font-size: 12px; background: var(--ink); color: var(--on-ink); }
.sb-account-text { flex: 1; min-width: 0; line-height: 1.25; display: flex; flex-direction: column; }
.sb-account-text strong { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-account-text span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-account .dropdown { left: 0; right: 0; min-width: 0; }

/* ---------- main panel ---------- */
#main {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
#topbar {
  flex: 0 0 auto; height: 58px; display: flex; align-items: center; gap: 12px;
  padding: 0 22px 0 26px; border-bottom: 1px solid var(--line-2);
}
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs a { color: var(--muted); text-decoration: none; border-radius: 6px; transition: color .12s ease; }
.crumbs a:hover { color: var(--ink); }
.crumbs strong { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.crumbs .crumb-sep { color: var(--faint); }
.crumbs span:empty, .crumbs span:empty + .crumb-sep { display: none; }
.tb-date { font-size: 12px; color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.top-search { height: 36px; background: var(--surface-2); }
.top-search input { width: 190px; }
body.results-open .top-search { display: none; }
.main-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 30px 34px 44px; }

.iconbtn.menuToggle, .menuToggle { display: none; }
.scrim { display: none; }

.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface);
  font-family: var(--mono); font-size: 11px; color: var(--muted); line-height: 1;
}
.search:focus-within .kbd, .search.has-value .kbd { display: none; }

/* ====================== CONTROLS ====================== */
.btn {
  height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; border-radius: 6px; white-space: nowrap;
  font-size: 13.5px; font-weight: 500; line-height: 1;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease, opacity .15s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .ic { width: 17px; height: 17px; }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover:not(:disabled) { background: var(--ink-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #d13a3f; }
.btn-soft-danger { color: var(--red); }
.btn-soft-danger:hover:not(:disabled) { background: var(--red-soft); }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-glass { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-glass:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }
.btn-sm { height: 34px; padding: 0 14px; font-size: 13px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 14px; }

.btn-ai { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-ai .ic { color: var(--blue); }
.btn-ai:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }
.btn-ai .ic { width: 16px; height: 16px; }

.iconbtn {
  width: 36px; height: 36px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; color: var(--text-2);
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.iconbtn:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.iconbtn:disabled { opacity: .35; cursor: default; }
.iconbtn.bordered { border: 1px solid var(--line); background: var(--surface); }
.iconbtn.bordered:hover:not(:disabled) { background: var(--surface-2); }
.iconbtn.active { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.iconbtn.danger:hover:not(:disabled) { background: var(--red-soft); color: var(--red); }
.iconbtn.sm { width: 30px; height: 30px; border-radius: 6px; }
.iconbtn.sm .ic { width: 16px; height: 16px; }

.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  font-size: 14px; color: var(--text); outline: none;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
.input, .select { height: 42px; padding: 0 13px; }
.textarea { padding: 11px 13px; line-height: 1.5; resize: vertical; min-height: 84px; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .textarea:focus, .select:focus { border-color: var(--focus-line); box-shadow: 0 0 0 4px var(--focus); }
input[type="date"].input { font-family: var(--mono); font-size: 13.5px; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, .field-label { font-size: 12.5px; font-weight: 500; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { min-height: 0; font-size: 12.5px; color: var(--red); }
.form-error:empty { display: none; }

.search {
  height: 38px; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 8px 0 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid transparent;
  color: var(--muted); transition: background .14s ease, border-color .14s ease, box-shadow .14s ease;
}
.search:hover { background: var(--surface-3); }
.search:focus-within { background: var(--surface); border-color: var(--focus-line); box-shadow: 0 0 0 4px var(--focus); }
.search input { width: 150px; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 13.5px; color: var(--text); }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.search .search-count { display: none; font-family: var(--mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.search .search-clear { display: none; width: 22px; height: 22px; border-radius: 5px; align-items: center; justify-content: center; color: var(--muted); }
.search .search-clear:hover { background: var(--surface-3); color: var(--ink); }
.search.has-value .search-clear { display: inline-flex; }
.search.has-value .search-count { display: inline; }

.seg {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--surface-3); border-radius: 6px;
}
.seg > button {
  height: 32px; padding: 0 14px; border-radius: 6px; display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}
.seg > button:hover { color: var(--ink); }
.seg > button.active, .seg > button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1), 0 0 0 1px rgba(16,24,40,.04); }
.seg > button .ic { width: 16px; height: 16px; }
.seg.sm > button { height: 28px; padding: 0 11px; font-size: 12.5px; }

.tabs { display: flex; align-items: stretch; gap: 22px; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 7px; height: 44px;
  font-size: 13.5px; font-weight: 500; color: var(--muted); transition: color .14s ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ink); }
.tab .mono { font-size: 11.5px; color: var(--muted); padding: 1px 6px; border-radius: 6px; background: var(--surface-3); }
.tab.active .mono { color: var(--text); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border-radius: 6px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.chip::before { display: none; }
.chip.nodot::before { display: none; }
.chip.live { background: var(--green-soft); color: var(--green); }
.chip.soon { background: var(--sky-soft); color: var(--sky-ink); }
.chip.ended { background: var(--surface-3); color: var(--muted); }
.chip.locked { background: var(--surface-3); color: var(--muted); }

.tdot { display: none; }
.t1 .tdot, .tdot.t1 { background: var(--t1); }
.t2 .tdot, .tdot.t2 { background: var(--t2); }
.t3 .tdot, .tdot.t3 { background: var(--t3); }
.t4 .tdot, .tdot.t4 { background: var(--t4); }
.t5 .tdot, .tdot.t5 { background: var(--t5); }
.ttag { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 4px; background: var(--surface-3); font-size: 11px; font-weight: 500; color: var(--text-2); white-space: nowrap; }

.check {
  width: 18px; height: 18px; flex: 0 0 auto; appearance: none; -webkit-appearance: none; cursor: pointer;
  border: 1.5px solid var(--line-strong); border-radius: 6px; background: var(--surface); display: inline-grid; place-content: center;
  transition: background .12s ease, border-color .12s ease;
}
.check::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--on-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.check:checked { background: var(--ink); border-color: var(--ink); }
.check:checked::after { opacity: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; color: var(--muted); font-size: 13.5px; padding: 32px 20px;
}
.empty strong { color: var(--muted); font-weight: 500; font-size: 13.5px; }

.skel {
  display: block; height: 12px; border-radius: 6px;
  background: linear-gradient(100deg, var(--skel-a) 30%, var(--skel-b) 50%, var(--skel-a) 70%);
  background-size: 300% 100%; animation: qtShimmer 1.3s linear infinite;
}
@keyframes qtShimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; animation: qtSpin .7s linear infinite;
}
.spinner.dark { border-color: rgba(15,18,24,.15); border-top-color: var(--ink); }
@keyframes qtSpin { to { transform: rotate(360deg); } }

/* ---------- chapter icon (same look as the Quest app: picture on a tilted blue card) ---------- */
.qicon {
  --qs: 44px;
  position: relative; width: var(--qs); height: var(--qs); flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
}
.qicon::before { display: none; }
.qicon-legacy-card::before {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 194 197'%3E%3Crect y='39.6152' width='156.271' height='156.271' rx='22.981' transform='rotate(-14.6849 0 39.6152)' fill='%23A3CBE5'/%3E%3Crect x='22.0615' y='40.8069' width='156.271' height='156.271' rx='22.981' transform='rotate(-5.87205 22.0615 40.8069)' fill='%23A3CBE5'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  opacity: var(--card-back);
}
.qicon-fg {
  position: relative; width: 100%; height: 100%;
  border-radius: 6px; overflow: hidden; background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, .08);
  display: flex; align-items: center; justify-content: center;
}
.qicon-fg img { width: 100%; height: 100%; object-fit: cover; }
.qicon-fg.is-empty { font-weight: 600; font-size: calc(var(--qs) * .36); letter-spacing: -.02em; box-shadow: none; }
.qicon-fg.is-empty.tint-1 { background: linear-gradient(var(--t1-soft), var(--t1-soft)) var(--surface); color: var(--t1-ink); }
.qicon-fg.is-empty.tint-2 { background: linear-gradient(var(--t2-soft), var(--t2-soft)) var(--surface); color: var(--t2-ink); }
.qicon-fg.is-empty.tint-3 { background: linear-gradient(var(--t3-soft), var(--t3-soft)) var(--surface); color: var(--t3-ink); }
.qicon-fg.is-empty.tint-4 { background: linear-gradient(var(--t4-soft), var(--t4-soft)) var(--surface); color: var(--t4-ink); }
.qicon-fg.is-empty.tint-5 { background: linear-gradient(var(--t5-soft), var(--t5-soft)) var(--surface); color: var(--t5-ink); }
.qicon.plain::before { display: none; }
.qicon.plain .qicon-fg { width: 100%; height: 100%; margin: 0; }
button.qicon { cursor: pointer; border-radius: 8px; }
button.qicon:focus-visible { outline: 2px solid var(--focus-line); outline-offset: 3px; }
.qicon .qicon-edit {
  position: absolute; right: -4px; bottom: -4px; width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); opacity: 0; transform: scale(.9);
  transition: opacity .15s ease, transform .15s ease;
}
.qicon .qicon-edit .ic { width: 15px; height: 15px; }
button.qicon:hover .qicon-edit, button.qicon:focus-visible .qicon-edit { opacity: 1; transform: none; }

/* ====================== MODALS ====================== */
.modal-back {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(15, 20, 30, .28); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: qtFade .16s ease;
}
.modal {
  width: min(460px, 100%); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; background: var(--surface); border-radius: 12px;
  box-shadow: var(--shadow-pop); overflow: hidden; animation: qtRise .2s cubic-bezier(.2, .9, .3, 1);
}
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 0 24px; }
.modal-head .modal-titles { flex: 1; min-width: 0; }
.modal-title { font-size: 17px; font-weight: 600; letter-spacing: -.01em; color: var(--ink); line-height: 1.35; }
.modal-sub { font-size: 13px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-body { padding: 18px 24px 4px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 24px 22px; }
@keyframes qtFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes qtRise { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }

/* confirm */
.qt-confirm .modal { width: min(400px, 100%); }
.qt-confirm .modal-body { padding-top: 8px; color: var(--text-2); font-size: 13.5px; line-height: 1.55; }

/* toasts */
#qt-toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 400;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.qt-toast {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 10px; max-width: min(520px, calc(100vw - 32px));
  padding: 10px 16px 10px 12px; border-radius: 8px; background: var(--toast-bg); color: #fff;
  font-size: 13.5px; line-height: 1.4; box-shadow: var(--shadow-2); animation: qtRise .2s ease;
}
.qt-toast .ic { width: 17px; height: 17px; }
.qt-toast.ok .ic { color: #5ad5a0; }
.qt-toast.error .ic { color: #ff8d8f; }
.qt-toast.out { opacity: 0; transform: translateY(6px); transition: opacity .2s ease, transform .2s ease; }

/* dropdown menu */
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px;
  padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-pop); animation: qtRise .14s ease;
}
.dropdown.up { top: auto; bottom: calc(100% + 6px); }
.dropdown.floating { position: fixed; right: auto; top: 0; left: 0; z-index: 180; }
.dropdown > button, .dropdown .dd-item {
  width: 100%; height: 40px; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--text); text-align: left;
}
.dropdown > button .ic { color: var(--text-2); }
.dropdown > button:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.dropdown > button:disabled { opacity: .4; cursor: default; }
.dropdown > button.danger, .dropdown > button.danger .ic { color: var(--red); }
.dropdown > button.danger:hover { background: var(--red-soft); }
.dropdown hr { border: 0; height: 1px; background: var(--line-2); margin: 6px 6px; }

/* ====================== LOGIN ====================== */
body.qt #loginScreen { background: var(--sky-bg); }
body.qt #loginScreen .loginCard {
  max-width: 360px; padding: 34px 30px 30px; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-2);
}
body.qt #loginScreen .loginLogo { width: 150px; margin-bottom: 4px; }
body.qt #loginScreen .loginService {
  font-family: var(--mono); font-weight: 500; letter-spacing: .08em; color: var(--muted); margin: 0 0 14px;
}
body.qt #loginScreen .loginCard picture { display: contents; }
body.qt #loginScreen input { height: 46px; border-radius: 8px; border-color: var(--line); font-family: var(--font); background: var(--surface); color: var(--text); }
body.qt #loginScreen input::placeholder { color: var(--muted); }
body.qt #loginScreen input:focus { border-color: var(--focus-line); box-shadow: 0 0 0 4px var(--focus); }
body.qt #loginScreen .authSubmit { height: 46px; margin-top: 6px; background: var(--ink); color: var(--on-ink); font-weight: 600; }
body.qt #loginScreen .status { font-size: 12.5px; color: var(--red); min-height: 0; text-align: center; }
body.qt #loginScreen .status:empty { display: none; }
body.qt #loginScreen .status.ok { color: var(--green); }

/* ====================== RESPONSIVE SHELL ====================== */
@media (max-width: 1100px) {
  #appShell { inset: 8px; }
  .tb-date { display: none; }
  .main-scroll { padding: 24px 22px 40px; }
}
@media (max-width: 900px) {
  #appShell { grid-template-columns: minmax(0, 1fr); inset: 0; border-radius: 0; padding: 0; border: 0; background: transparent; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  #sidebar {
    position: fixed; top: 8px; left: 8px; bottom: 8px; z-index: 90; width: 280px; padding: 14px 10px 6px 10px;
    border-radius: 12px; background: var(--shell); -webkit-backdrop-filter: blur(28px) saturate(1.4); backdrop-filter: blur(28px) saturate(1.4);
    border: 1px solid var(--shell-line); visibility: hidden;
    transform: translateX(calc(-100% - 16px)); transition: transform .22s ease, visibility 0s linear .22s;
  }
  #appShell.navOpen #sidebar { transform: none; visibility: visible; box-shadow: var(--shadow-pop); transition: transform .22s ease, visibility 0s; }
  #appShell.navOpen .scrim { display: block; position: fixed; inset: 0; z-index: 80; background: rgba(15,20,30,.25); }
  #main { margin: 8px; }
  #topbar { padding: 0 14px 0 10px; }
  .iconbtn.menuToggle, .menuToggle { display: inline-flex; }
}
@media (max-width: 560px) {
  #main { margin: 0; border-radius: 0; border: 0; }
  .tb-date { display: none; }
  .top-search input { width: 64px; }
  .top-search .kbd { display: none; }
  .main-scroll { padding: 20px 16px 36px; }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { border-radius: 12px 12px 0 0; max-height: 92vh; }
  .field-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* keyboard focus */
.qt button:focus-visible, .qt a:focus-visible, .qt [tabindex]:focus-visible { outline: 2px solid var(--focus-line); outline-offset: 2px; }
.qt .search input:focus-visible, .qt .input:focus-visible, .qt .textarea:focus-visible { outline: none; }

/* ====================== v3: flat, dense system ======================
   one font (Inter), 6px controls / 10px surfaces, no gradients, no glass. */
body.qt { font-size: 13.5px; letter-spacing: -.006em; font-feature-settings: "cv11" 1, "ss01" 1; }
body.qt #loginScreen { font-family: var(--font); }
body.qt #loginScreen .loginCard { border-radius: 12px; box-shadow: none; }
body.qt #loginScreen input { height: 40px; border-radius: 6px; }
body.qt #loginScreen .authSubmit { height: 40px; border-radius: 6px; }
body.qt #loginScreen .loginService { font-family: var(--font); letter-spacing: .06em; }

#sidebar { padding: 14px 10px 8px 10px; }
.sb-brand { margin-bottom: 14px; padding: 2px 6px; gap: 8px; }
.sb-mark { width: 22px; height: 22px; }
.sb-word { font-size: 15px; font-weight: 600; }

.sb-switch { margin-bottom: 14px; }
.sb-switch-btn { padding: 6px 8px 6px 6px; border-radius: 8px; box-shadow: none; gap: 9px; }
.sb-switch-btn .avatar.lg { width: 28px; height: 28px; border-radius: 6px; font-size: 11px; }
.sb-switch-text small { font-size: 11px; }
.sb-switch-text strong { font-size: 13.5px; }
.sb-switch-menu { padding: 4px; }

.sb-main { gap: 1px; }
.sb-link { height: 32px; gap: 10px; padding: 0 10px; border-radius: 6px; font-size: 13.5px; color: var(--text-2); }
.sb-link > .ic { width: 16px; height: 16px; }
.sb-link:hover { background: rgba(15, 18, 24, .045); }
.sb-link.active { background: var(--surface); border-color: var(--line); box-shadow: none; }
.sb-link .sb-count { background: none; min-width: 0; padding: 0; height: auto; font-size: 12px; color: var(--muted); font-weight: 400; }
.sb-label, .sb-sub { padding: 14px 10px 4px; font-size: 11.5px; }
.sb-section { margin-top: 6px; }
.nav-chapter { height: 34px !important; }
.nav-chapter .qicon { --qs: 20px !important; }

.sb-account { border-top-color: var(--line); padding-top: 8px; }
.sb-account-btn { padding: 6px; border-radius: 8px; gap: 9px; }
.sb-account-btn:hover, .sb-account-btn[aria-expanded="true"] { background: rgba(15, 18, 24, .045); }
.sb-account .avatar { width: 28px; height: 28px; font-size: 11px; }
.sb-account-text strong { font-size: 13px; }
.sb-account-text span { font-size: 11.5px; }

#main { border-radius: 10px; box-shadow: none; }
#topbar { height: 48px; padding: 0 12px 0 20px; }
.crumbs { font-size: 13px; }
.top-search { height: 30px; }
.top-search input { width: 180px; font-size: 13px; }
.tb-date { display: none; }
.main-scroll { padding: 28px 32px 40px; }

.btn { height: 32px; padding: 0 12px; border-radius: 6px; font-size: 13px; gap: 6px; }
.btn .ic { width: 15px; height: 15px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-lg { height: 36px; }
.btn-icon { width: 32px; padding: 0; }
.btn:active:not(:disabled) { transform: none; }
.iconbtn { width: 30px; height: 30px; border-radius: 6px; }
.iconbtn .ic { width: 16px; height: 16px; }
.iconbtn.sm { width: 26px; height: 26px; border-radius: 5px; }
.iconbtn.sm .ic { width: 15px; height: 15px; }

.input, .select { height: 34px; border-radius: 6px; font-size: 13.5px; padding: 0 10px; }
.textarea { border-radius: 6px; font-size: 13.5px; }
.input:focus, .textarea:focus, .select:focus { box-shadow: 0 0 0 3px var(--focus); }
.field { gap: 6px; }
.field > span, .field-label { font-size: 12.5px; }

.search { height: 30px; border-radius: 6px; padding: 0 6px 0 9px; gap: 6px; border-color: var(--line-2); }
.search:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.kbd { height: 18px; min-width: 18px; border-radius: 4px; font-size: 10.5px; }

.seg { border-radius: 7px; padding: 2px; gap: 0; }
.seg > button { height: 26px; padding: 0 10px; border-radius: 5px; font-size: 12.5px; }
.seg > button.active, .seg > button.on { box-shadow: 0 1px 1px rgba(16, 24, 40, .06), 0 0 0 1px rgba(16, 24, 40, .06); }
.seg.sm > button { height: 24px; padding: 0 8px; font-size: 12px; }

.chip { height: 20px; padding: 0 7px; border-radius: 4px; font-size: 11.5px; gap: 5px; }
.chip { font-weight: 500; }

.avatar { border-radius: 5px; }

.dropdown { border-radius: 8px; padding: 4px; box-shadow: 0 8px 24px -8px rgba(16, 24, 40, .18), 0 1px 2px rgba(16, 24, 40, .06); min-width: 190px; }
.dropdown > button, .dropdown .dd-item { height: 30px; border-radius: 5px; font-size: 13px; gap: 9px; padding: 0 8px; }
.dropdown > button .ic { width: 15px; height: 15px; }
.dropdown hr { margin: 4px 2px; }

.modal { border-radius: 10px; box-shadow: 0 24px 60px -20px rgba(16, 24, 40, .35); }
.modal-head { padding: 16px 16px 0 20px; }
.modal-title { font-size: 15px; }
.modal-body { padding: 14px 20px 4px; gap: 12px; }
.modal-foot { padding: 16px 20px 18px; }
.modal-back { background: rgba(15, 20, 30, .32); -webkit-backdrop-filter: none; backdrop-filter: none; }

.qt-toast { border-radius: 8px; font-size: 13px; padding: 8px 14px 8px 10px; }

@media (prefers-color-scheme: dark) {
  .sb-link:hover, .sb-account-btn:hover, .sb-account-btn[aria-expanded="true"] { background: rgba(255, 255, 255, .05); }
  .dropdown { box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .6); }
}
@media (max-width: 900px) {
  #appShell { padding: 0; }
  #sidebar { top: 0; left: 0; bottom: 0; border-radius: 0; background: var(--frame); -webkit-backdrop-filter: none; backdrop-filter: none; border: 0; border-right: 1px solid var(--line); }
  #main { margin: 0; border-radius: 0; border: 0; }
}

/* ====================== v3: calm sidebar (flat panel, text block, accent bar) ====================== */
:root { --side: #efefee; --accent: #2f80ed; }
@media (prefers-color-scheme: dark) { :root { --side: #111317; --accent: #5b9cf2; } }

body.qt { background: var(--side); }
#appShell { grid-template-columns: 252px minmax(0, 1fr); padding: 0; }
#sidebar { padding: 0; background: var(--side); border-right: 1px solid var(--line); }

.sb-brand { margin: 0; padding: 26px 24px 0; }
.sb-mark { width: 26px; height: 26px; }
.sb-word { display: none; }

.sb-switch { position: relative; margin: 44px 0 0; border-bottom: 1px solid var(--line); }
.sb-switch-btn {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  padding: 0 18px 22px 24px; border: 0; border-radius: 0; background: none; box-shadow: none; text-align: left;
}
.sb-switch-btn:hover, .sb-switch.open .sb-switch-btn { border: 0; }
.sb-switch-btn > .ic { width: 15px; height: 15px; margin-top: 3px; color: var(--faint); transition: color .12s ease; }
.sb-switch-btn:hover > .ic, .sb-switch.open .sb-switch-btn > .ic { color: var(--ink); }
.sb-switch-text { gap: 1px; }
.sb-switch-text strong { font-size: 16px; font-weight: 500; letter-spacing: -.015em; line-height: 1.3; }
.sb-switch-text small { font-size: 16px; font-weight: 400; color: var(--muted); letter-spacing: -.015em; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-switch-menu { left: 16px; right: 16px; top: calc(100% - 12px); }
.dd-label { padding: 6px 8px 4px; font-size: 11.5px; color: var(--muted); }
.dropdown .dd-action { width: 100%; height: 30px; display: flex; align-items: center; gap: 9px; padding: 0 8px; border-radius: 5px; font-size: 13px; font-weight: 500; color: var(--text); text-align: left; }
.dropdown .dd-action .ic { width: 15px; height: 15px; color: var(--text-2); }
.dropdown .dd-action:hover { background: var(--surface-3); }

.sb-main { gap: 0; padding: 10px 0; }
.sb-main .sb-link {
  position: relative; height: 50px; gap: 16px; padding: 0 24px; border: 0; border-radius: 0;
  font-size: 15px; font-weight: 500; color: var(--text-2); background: none;
}
.sb-main .sb-link > .ic { width: 19px; height: 19px; color: var(--text-2); }
.sb-main .sb-link:hover { background: none; color: var(--ink); }
.sb-main .sb-link:hover > .ic { color: var(--ink); }
.sb-main .sb-link.active { background: none; border: 0; color: var(--ink); }
.sb-main .sb-link.active > .ic { color: var(--ink); }
.sb-main .sb-link.active::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 2px; background: var(--accent); }
.sb-main .sb-count { display: none; }

.sb-section { margin-top: 0; padding: 12px 12px 12px; border-top: 1px solid var(--line); }
.sb-section .sb-label { padding: 6px 12px 6px; }
.sb-section .sb-link { height: 32px; padding: 0 12px; font-size: 13.5px; color: var(--text-2); border: 0; background: none; border-radius: 5px; }
.sb-section .sb-link:hover { color: var(--ink); background: rgba(15, 18, 24, .04); }
.sb-section .sb-link.active { color: var(--ink); background: none; font-weight: 500; }
.sb-section .nav-chapter .qicon { display: none; }
.sb-section .sb-link { position: relative; }
.sb-section .nav-chapter.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 2px; background: var(--accent); }

#main { border: 0; border-radius: 0; background: var(--surface); }
#topbar { height: 56px; padding: 0 20px 0 28px; }
.main-scroll { padding: 32px 40px 48px; }

@media (prefers-color-scheme: dark) {
  .sb-section .sb-link:hover { background: rgba(255, 255, 255, .04); }
}
@media (max-width: 900px) {
  #sidebar { width: 272px; }
  #topbar { padding: 0 14px 0 10px; }
  .main-scroll { padding: 22px 18px 36px; }
}

/* ====================== v3: fresh — white, cool tints, Quest blue ====================== */
:root {
  --side: #ffffff;
  --frame: #ffffff;
  --surface-2: #f5f8fd;
  --surface-3: #ecf1f9;
  --line: #e5eaf2;
  --line-2: #eef2f8;
  --line-strong: #d3dcea;
  --row-hover: #f7faff;
  --row-sel: #eef5ff;
  --muted: #8a93a6;
  --accent: #2f7cf6;
  --accent-hover: #1f6ae0;
  --accent-soft: #eaf2ff;
  --accent-ink: #1d63d8;
  --on-accent: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --side: #111317; --frame: #111317;
    --surface-2: #1a1e25; --surface-3: #212631;
    --line: #262c36; --line-2: #1f242d; --line-strong: #36404e;
    --row-hover: #181c23; --row-sel: #1a2433; --muted: #7d8696;
    --accent: #4f8ff7; --accent-hover: #6aa1f8; --accent-soft: rgba(79, 143, 247, .14); --accent-ink: #8db5ff; --on-accent: #ffffff;
  }
}

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary, .btn-ai { border-color: var(--line); }

.sb-mark { width: 28px; height: 28px; }
.sb-main .sb-link.active { color: var(--accent-ink); }
.sb-main .sb-link.active > .ic { color: var(--accent); }
.sb-section .nav-chapter.active { color: var(--accent-ink); }
.sb-switch-menu .sb-link.active { background: var(--accent-soft); color: var(--accent-ink); }

.seg { background: var(--surface-3); }
.seg > button.active, .seg > button.on { color: var(--accent-ink); }
.search { background: var(--surface-2); }
.chip.soon { background: var(--accent-soft); color: var(--accent-ink); }
.ttag { background: var(--surface-2); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.kbd { background: var(--surface); }
:root { --focus-line: #8db8fb; --focus: rgba(47, 124, 246, .16); }
.sb-section .nav-chapter.active::before { display: none; }
.sb-section .nav-chapter.active { box-shadow: inset 2px 0 0 var(--accent); border-radius: 0 5px 5px 0; background: var(--accent-soft); }
.sb-section .nav-chapter.active .sb-text { color: var(--accent-ink) !important; }

/* ====================== v3: warm & soft (RevenueX direction) ======================
   cream sidebar, white floating work panel, serif only for headings, one warm gradient (the "now" card). */
:root {
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --side: #f3f0ea;
  --frame: #f3f0ea;
  --surface-2: #f8f6f2;
  --surface-3: #f1eee8;
  --line: #ebe7e0;
  --line-2: #f1eee9;
  --line-strong: #dcd6cc;
  --row-hover: #faf8f5;
  --row-sel: #f6f2ea;
  --ink: #1b1916;
  --text: #2a2723;
  --text-2: #5f5a52;
  --muted: #958f85;
  --faint: #c2bcb2;
  --accent: #1b1916;
  --accent-hover: #34302b;
  --accent-soft: #f1ede5;
  --accent-ink: #1b1916;
  --on-accent: #ffffff;
  --focus-line: #cbbfa8;
  --focus: rgba(160, 130, 70, .14);
}
@media (prefers-color-scheme: dark) {
  :root {
    --side: #141311; --frame: #141311;
    --surface: #1c1b18; --surface-2: #22201d; --surface-3: #292724;
    --line: #2d2a26; --line-2: #25231f; --line-strong: #3c3833;
    --row-hover: #211f1c; --row-sel: #262420;
    --ink: #f3f0ea; --text: #e6e2da; --text-2: #aca69b; --muted: #857f75; --faint: #5a554d;
    --accent: #f3f0ea; --accent-hover: #ddd8ce; --accent-soft: #2a2824; --accent-ink: #f3f0ea; --on-accent: #1b1916;
    --focus-line: #6b604d; --focus: rgba(200, 170, 110, .16);
  }
}

body.qt { background: var(--side); }
#appShell { grid-template-columns: 256px minmax(0, 1fr); padding: 10px 10px 10px 0; }
#sidebar { background: none; border-right: 0; padding: 22px 14px 12px 16px; }

.sb-brand { padding: 0 8px; margin: 0 0 26px; gap: 9px; }
.sb-mark { width: 26px; height: 26px; }
.sb-word { display: inline; font-size: 17px; font-weight: 600; letter-spacing: -.02em; color: var(--ink); }

.sb-label { padding: 0 10px 8px; font-size: 12px; font-weight: 500; color: var(--muted); display: block; }
.sb-main { padding: 0; gap: 2px; margin-bottom: 22px; }
.sb-main .sb-link, .sb-section .sb-link {
  height: 38px; gap: 11px; padding: 0 10px; border-radius: 11px; border: 0;
  font-size: 14px; font-weight: 500; color: var(--text-2); background: none; box-shadow: none;
}
.sb-main .sb-link > .ic { width: 18px; height: 18px; color: var(--text-2); }
.sb-main .sb-link:hover, .sb-section .sb-link:hover { background: rgba(60, 50, 30, .05); color: var(--ink); }
.sb-main .sb-link.active, .sb-section .sb-link.active {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 0 0 1px rgba(60, 45, 20, .04);
}
.sb-main .sb-link.active > .ic { color: var(--ink); }
.sb-main .sb-link.active::before { display: none; }
.sb-main .sb-count { display: inline; font-size: 12px; color: var(--muted); }

.sb-section { border-top: 0; padding: 0; margin: 0 0 18px; min-height: 0; }
.sb-section .sb-nav { gap: 2px; }
.sb-classes .sb-link .avatar { width: 28px; height: 28px; border-radius: 8px; font-size: 11px; }
.sb-classes .sb-link { height: 42px; }
.sb-classes .sb-link .sb-count { font-size: 12px; color: var(--muted); background: none; padding: 0; min-width: 0; height: auto; }
.sb-classes-sm .sb-link { height: 36px; }
.sb-classes-sm .sb-link .avatar { width: 24px; height: 24px; font-size: 10px; border-radius: 7px; }
.sb-section .nav-chapter { height: 34px !important; font-size: 13.5px; }
.sb-section .nav-chapter.active { box-shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 0 0 1px rgba(60, 45, 20, .04); background: var(--surface); border-radius: 11px; }
.sb-section .nav-chapter.active .sb-text { color: var(--ink) !important; }
.sb-section .nav-chapter .qicon { display: inline-flex; --qs: 22px !important; }
.sb-section .nav-chapter .qicon-fg { border-radius: 6px; }
.nav-now { color: var(--green); }
.sb-sub { padding: 8px 10px 4px; font-size: 11.5px; }

.sb-fill { flex: 1; }
.sb-account { margin-top: auto; padding-top: 10px; border-top: 0; }
.sb-account-btn {
  padding: 8px 10px 8px 8px; border-radius: 14px; gap: 10px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 0 0 1px rgba(60, 45, 20, .04);
}
.sb-account-btn:hover, .sb-account-btn[aria-expanded="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 0 0 1px rgba(60, 45, 20, .08); }
.sb-account .avatar { width: 34px; height: 34px; font-size: 12px; background: var(--ink); color: var(--on-accent); }
.sb-account-text strong { font-size: 13.5px; }
.sb-account-text span { font-size: 12px; color: var(--muted); }

#main {
  border-radius: 20px; border: 0; background: var(--surface);
  box-shadow: 0 1px 2px rgba(60, 45, 20, .05), 0 12px 32px -18px rgba(60, 45, 20, .18);
}
#topbar { height: 64px; padding: 0 22px 0 28px; border-bottom: 0; }
.top-search {
  height: 40px; flex: 0 1 440px; padding: 0 8px 0 14px; gap: 10px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(60, 45, 20, .04);
}
.top-search input { width: 100%; font-size: 13.5px; }
.top-search .kbd { height: 22px; min-width: 22px; border-radius: 6px; background: var(--surface-3); border: 0; font-size: 11px; }
#chaptersView ~ *, .main-scroll { }
.main-scroll { padding: 18px 36px 48px; }

.display { font-family: var(--serif); font-weight: 400; letter-spacing: -.015em; }

.btn { height: 36px; padding: 0 14px; border-radius: 10px; font-size: 13.5px; }
.btn-sm { height: 30px; border-radius: 8px; }
.btn-icon { width: 36px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary, .btn-ai, .btn-glass { background: var(--surface); border: 1px solid var(--line); box-shadow: 0 1px 2px rgba(60, 45, 20, .04); }
.btn-ai .ic { color: #c9892b; }
.iconbtn { border-radius: 9px; }
.seg { background: var(--surface-3); border-radius: 10px; padding: 3px; }
.seg > button { height: 28px; border-radius: 8px; padding: 0 12px; font-size: 13px; }
.seg > button.active, .seg > button.on { color: var(--ink); background: var(--surface); box-shadow: 0 1px 2px rgba(60, 45, 20, .08); }
.chip { height: 22px; border-radius: 7px; padding: 0 8px; font-size: 12px; }
.chip.soon { background: #eef3fb; color: #3d6db3; }
.chip.ended { background: var(--surface-3); color: var(--muted); }
.ttag { background: var(--surface-3); box-shadow: none; border-radius: 6px; height: 20px; padding: 0 7px; }
.input, .select { height: 38px; border-radius: 10px; }
.textarea { border-radius: 10px; }
.search { border-radius: 10px; }
.dropdown { border-radius: 14px; padding: 6px; box-shadow: 0 12px 32px -12px rgba(60, 45, 20, .25), 0 0 0 1px rgba(60, 45, 20, .06); border: 0; }
.dropdown > button, .dropdown .dd-item { height: 34px; border-radius: 9px; }
.modal { border-radius: 18px; }
.qt-toast { border-radius: 12px; }
.qicon-fg { border-radius: 9px; }
@media (prefers-color-scheme: dark) {
  .chip.soon { background: rgba(90, 140, 220, .16); color: #9cc0f5; }
  .sb-main .sb-link:hover, .sb-section .sb-link:hover { background: rgba(255, 255, 255, .04); }
  #main { box-shadow: none; }
}
@media (max-width: 900px) {
  #appShell { padding: 0; }
  #sidebar { background: var(--side); }
  #main { border-radius: 0; box-shadow: none; }
  .top-search { flex: 1; }
}
.sb-section { flex: 0 0 auto; }
.sb-section:not(.sb-classes) .sb-nav { max-height: 42vh; }
.sb-classes .sb-nav { max-height: 36vh; overflow-y: auto; }

/* ====================== v3: v1 blue theme ======================
   same palette as the original panel: cool blue-grey background, #4b9dff accent. */
:root {
  --blue: #4b9dff;
  --blue-ink: #2f7fe6;
  --blue-soft: #eaf3ff;
  --side: #f1f4f8;
  --frame: #f1f4f8;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-3: #eef2f7;
  --line: #e9edf3;
  --line-2: #f0f3f7;
  --line-strong: #d8deea;
  --row-hover: #f8fafd;
  --row-sel: #eef5ff;
  --ink: #111827;
  --text: #1f2430;
  --text-2: #5b6273;
  --muted: #8b92a4;
  --faint: #bcc3d0;
  --accent: #4b9dff;
  --accent-hover: #3a8ef5;
  --accent-soft: #eaf3ff;
  --accent-ink: #2f7fe6;
  --on-accent: #ffffff;
  --focus-line: #9cc8ff;
  --focus: rgba(75, 157, 255, .18);
  --sky-soft: #eaf3ff;
  --sky-ink: #2f7fe6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --blue: #5aa6ff; --blue-ink: #8ec2ff; --blue-soft: rgba(75, 157, 255, .14);
    --side: #0e1116; --frame: #0e1116;
    --surface: #161a21; --surface-2: #1b2029; --surface-3: #222833;
    --line: #262d38; --line-2: #1f252f; --line-strong: #364050;
    --row-hover: #1a1f28; --row-sel: #1a2638;
    --ink: #f1f4f8; --text: #e3e8f0; --text-2: #a4acbb; --muted: #7e8797; --faint: #515a69;
    --accent: #4b9dff; --accent-hover: #64abff; --accent-soft: rgba(75, 157, 255, .15); --accent-ink: #8ec2ff; --on-accent: #ffffff;
    --focus-line: #3d6fb0; --focus: rgba(75, 157, 255, .22);
    --sky-soft: rgba(75, 157, 255, .15); --sky-ink: #8ec2ff;
  }
}
.sb-main .sb-link.active > .ic { color: var(--accent); }
.sb-main .sb-link:hover, .sb-section .sb-link:hover { background: rgba(75, 110, 160, .06); }
.sb-main .sb-link.active, .sb-section .sb-link.active, .sb-section .nav-chapter.active, .sb-account-btn {
  box-shadow: 0 1px 2px rgba(20, 40, 80, .06), 0 0 0 1px rgba(20, 40, 80, .05);
}
#main { box-shadow: 0 1px 2px rgba(20, 40, 80, .05), 0 12px 32px -18px rgba(20, 40, 80, .16); }
.top-search, .btn-secondary, .btn-ai, .btn-glass { box-shadow: 0 1px 2px rgba(20, 40, 80, .04); }
.seg > button.active, .seg > button.on { color: var(--accent-ink); box-shadow: 0 1px 2px rgba(20, 40, 80, .08); }
.btn-ai .ic { color: var(--accent); }
.dropdown { box-shadow: 0 12px 32px -12px rgba(20, 40, 80, .22), 0 0 0 1px rgba(20, 40, 80, .06); }
.sb-account .avatar { background: var(--accent); color: #fff; }
.chip.soon { background: var(--accent-soft); color: var(--accent-ink); }
@media (prefers-color-scheme: dark) {
  .sb-main .sb-link:hover, .sb-section .sb-link:hover { background: rgba(255, 255, 255, .04); }
  #main { box-shadow: none; }
}


/* ====================== v3: plain sans, dark buttons, fewer extras ====================== */
:root { --serif: var(--font); --display: var(--font); }
.display { font-family: var(--font); font-weight: 600; letter-spacing: -.022em; }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 86%, var(--surface)); }
.sb-account .avatar { background: var(--ink); color: var(--surface); }
.sb-main .sb-count, .sb-classes .sb-link .sb-count { display: none; }
.top-search .kbd { display: none; }
.dates-btn .ic { display: none; }


/* ====================== v3: no top bar (no search, no path) ====================== */
@media (min-width: 901px) { #topbar { display: none; } }
@media (max-width: 900px) { #topbar { height: 52px; } }
.main-scroll { padding-top: 34px; }

/* ====================== v3: a bit bigger (~10%) ====================== */
body.qt { font-size: 14.5px; }
#appShell { grid-template-columns: 272px minmax(0, 1fr); }
.sb-brand { margin-bottom: 28px; }
.sb-mark { width: 28px; height: 28px; }
.sb-word { font-size: 18px; }
.sb-label { font-size: 12.5px; padding-bottom: 9px; }
.sb-main .sb-link, .sb-section .sb-link { height: 42px; font-size: 15px; gap: 12px; }
.sb-main .sb-link > .ic { width: 19px; height: 19px; }
.sb-classes .sb-link { height: 46px; }
.sb-classes .sb-link .avatar { width: 30px; height: 30px; font-size: 11.5px; }
.sb-account .avatar { width: 38px; height: 38px; font-size: 13px; }
.sb-account-text strong { font-size: 14.5px; }
.sb-account-text span { font-size: 12.5px; }
.btn { height: 40px; padding: 0 16px; font-size: 14.5px; }
.btn .ic { width: 16px; height: 16px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13.5px; }
.btn-icon { width: 40px; }
.iconbtn { width: 34px; height: 34px; }
.iconbtn .ic { width: 17px; height: 17px; }
.iconbtn.sm { width: 30px; height: 30px; }
.iconbtn.sm .ic { width: 16px; height: 16px; }
.input, .select { height: 42px; font-size: 14.5px; }
.textarea { font-size: 14.5px; }
.seg > button { height: 32px; padding: 0 14px; font-size: 14px; }
.chip { height: 24px; padding: 0 9px; font-size: 12.5px; }
.dropdown > button, .dropdown .dd-item { height: 38px; font-size: 14px; }
.dropdown > button .ic { width: 16px; height: 16px; }
.modal-title { font-size: 17px; }
.qt-toast { font-size: 14px; }
.main-scroll { padding: 38px 40px 48px; }


/* ====================== v4: closer to the original Quest panel ======================
   Poppins (as in the original panel and the mobile app), Quest wordmark in the sidebar,
   default chapter pictures instead of letters (ui.js chapterIcon). */
:root { --font: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif; }
.sb-logo { display: block; height: 30px; width: auto; }
/* phones: the desktop column rules above (252/256/272px) must not leave a sidebar column behind the off-canvas menu */
@media (max-width: 900px) { #appShell { grid-template-columns: minmax(0, 1fr); padding: 0; } }
