/* Chun Chen — học tiếng Trung. Giao diện mobile-first, có nền sáng & tối. */

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

:root {
  /* màu thương hiệu: đỏ son + mực */
  --red: #b23a2e;
  --red-soft: #d4604f;
  --ink: #1b1b1f;

  --bg: #faf7f2;
  --bg-card: #ffffff;
  --bg-soft: #f2ece3;
  --bg-sunk: #ebe4d9;
  --fg: #22222a;
  --fg-dim: #5f5d68;
  --fg-faint: #8d8a96;
  --line: #e0d8cb;
  --line-strong: #cfc4b2;

  --ok: #2e7d52;
  --ok-bg: #e4f3ea;
  --bad: #b3322c;
  --bad-bg: #fbe9e7;
  --warn: #9a6b12;
  --warn-bg: #fbf2dd;

  /* màu thanh điệu (quy ước quen dùng: 1 đỏ, 2 cam, 3 xanh lá, 4 xanh dương, nhẹ xám) */
  --t1: #c0392b;
  --t2: #c47b16;
  --t3: #2e7d52;
  --t4: #2d6ca8;
  --t5: #8d8a96;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(30,25,20,.06), 0 6px 20px -8px rgba(30,25,20,.14);
  --shadow-lg: 0 2px 6px rgba(30,25,20,.08), 0 18px 48px -14px rgba(30,25,20,.26);

  --han: "Noto Serif SC", "Songti SC", "SimSun", "STSong", serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --nav-h: 58px;
}

:root[data-theme="dark"] {
  --bg: #15151a;
  --bg-card: #1e1e25;
  --bg-soft: #24242d;
  --bg-sunk: #2b2b35;
  --fg: #eceaf2;
  --fg-dim: #a9a6b4;
  --fg-faint: #7c7988;
  --line: #32323d;
  --line-strong: #43434f;
  --red: #e2705f;
  --red-soft: #ef8c7c;

  --ok: #6cc595;
  --ok-bg: #19301f;
  --bad: #ef8178;
  --bad-bg: #331a1a;
  --warn: #e0b45c;
  --warn-bg: #332a14;

  --t1: #f08a7c;
  --t2: #e8b45f;
  --t3: #74c79a;
  --t4: #79b2e8;
  --t5: #9b98a8;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -10px rgba(0,0,0,.6);
  --shadow-lg: 0 2px 8px rgba(0,0,0,.5), 0 20px 56px -16px rgba(0,0,0,.75);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15151a; --bg-card: #1e1e25; --bg-soft: #24242d; --bg-sunk: #2b2b35;
    --fg: #eceaf2; --fg-dim: #a9a6b4; --fg-faint: #7c7988;
    --line: #32323d; --line-strong: #43434f;
    --red: #e2705f; --red-soft: #ef8c7c;
    --ok: #6cc595; --ok-bg: #19301f; --bad: #ef8178; --bad-bg: #331a1a;
    --warn: #e0b45c; --warn-bg: #332a14;
    --t1: #f08a7c; --t2: #e8b45f; --t3: #74c79a; --t4: #79b2e8; --t5: #9b98a8;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -10px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 8px rgba(0,0,0,.5), 0 20px 56px -16px rgba(0,0,0,.75);
  }
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 var(--ui);
  color: var(--fg);
  background: var(--bg);
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
@media (min-width: 860px) { body { padding-bottom: 0; } }

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- thanh trên */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 9px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--red); color: #fff;
  font-family: var(--han); font-size: 22px; line-height: 1;
  padding-bottom: 2px;
}
.brand-mark.has-img {
  /* logo ảnh có nền trắng sẵn: giữ ô trắng bo góc để nét đen của gấu trúc
     vẫn rõ cả khi học viên bật nền tối */
  background: #fff; padding: 0; overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
}
.brand-mark.has-img img {
  width: 100%; height: 100%; object-fit: contain; display: block;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; letter-spacing: .2px; }
.brand-text small { font-size: 11.5px; color: var(--fg-faint); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-card);
  cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { border-color: var(--line-strong); }

/* ------------------------------------------------------------- điều hướng */
.mainnav { display: none; }
@media (min-width: 860px) {
  .mainnav {
    display: flex; gap: 4px; flex-wrap: wrap;
    max-width: 1060px; margin: 14px auto 0; padding: 0 20px;
  }
  .mainnav a {
    padding: 8px 13px; border-radius: 999px; color: var(--fg-dim);
    font-size: 14.5px; font-weight: 500; border: 1px solid transparent;
  }
  .mainnav a:hover { background: var(--bg-soft); text-decoration: none; }
  .mainnav a[aria-current="page"] {
    background: var(--red); color: #fff; border-color: var(--red);
  }
}
/* thanh dưới cho điện thoại */
.botnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg-card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.botnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; height: var(--nav-h); color: var(--fg-faint);
  font-size: 10.5px; font-weight: 500;
}
.botnav a:hover { text-decoration: none; }
.botnav a span.ic { font-size: 19px; line-height: 1; }
.botnav a[aria-current="page"] { color: var(--red); }
@media (min-width: 860px) { .botnav { display: none; } }

/* ------------------------------------------------------------------ bố cục */
.view { max-width: 1060px; margin: 0 auto; padding: 18px 16px 40px; }
@media (min-width: 860px) { .view { padding: 22px 20px 60px; } }
.view:focus { outline: none; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 18.5px; margin: 28px 0 12px; }
h3 { font-size: 15.5px; margin: 20px 0 8px; }
.sub { color: var(--fg-dim); margin: 0 0 20px; font-size: 14.5px; }
.loading { color: var(--fg-faint); padding: 40px 0; text-align: center; }

.card {
  background: var(--bg-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--fg-dim); }
.faint { color: var(--fg-faint); }
.small { font-size: 13px; }
.center { text-align: center; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ------------------------------------------------------------------- nút */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--bg-card);
  cursor: pointer; font-size: 14.5px; font-weight: 500;
  transition: transform .06s, background .15s;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-soft); border-color: var(--red-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--fg-dim); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.btn-bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-card); color: var(--fg-dim);
}
.chip:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"] { background: var(--red); border-color: var(--red); color: #fff; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .3px;
  background: var(--bg-sunk); color: var(--fg-dim);
}
.tag-lv { background: var(--bad-bg); color: var(--red); }

/* ----------------------------------------------------------------- ô nhập */
.input, input[type="text"], input[type="search"], select, textarea {
  width: 100%; padding: 11px 13px; font: inherit;
  color: var(--fg); background: var(--bg-card);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--red); outline-offset: 1px; border-color: var(--red);
}
.searchbar { position: relative; }
.searchbar input { padding-right: 42px; font-size: 16.5px; }
.searchbar .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; background: transparent;
  color: var(--fg-faint); cursor: pointer; border-radius: 8px;
}
.searchbar .clear:hover { background: var(--bg-soft); }

/* --------------------------------------------------------- chữ Hán & pinyin */
.han { font-family: var(--han); line-height: 1.25; }
.han-xl { font-family: var(--han); font-size: clamp(56px, 16vw, 96px); line-height: 1.1; }
.han-lg { font-family: var(--han); font-size: 34px; line-height: 1.2; }
.han-md { font-family: var(--han); font-size: 24px; line-height: 1.3; }

.py { letter-spacing: .2px; }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); }
.t4 { color: var(--t4); } .t5 { color: var(--t5); }
.hv { color: var(--fg-faint); font-size: .92em; }

/* ------------------------------------------------------------ danh sách từ */
.wordlist { display: flex; flex-direction: column; }
.wrow {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; padding: 11px 13px; background: var(--bg-card);
  border: 1px solid var(--line); cursor: pointer; text-align: left; width: 100%;
}
.wrow:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.wrow:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.wrow:only-child { border-radius: var(--radius); }
.wrow + .wrow { border-top: 0; }
.wrow:hover { background: var(--bg-soft); }
.wrow .w-han { font-family: var(--han); font-size: 22px; min-width: 2.2em; }
.wrow .w-mid { min-width: 0; }
.wrow .w-py { font-size: 13.5px; }
.wrow .w-vi {
  font-size: 14px; color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------------- khác */
.callout {
  border-left: 3px solid var(--red); background: var(--bg-soft);
  padding: 11px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px; color: var(--fg-dim);
}
.callout b { color: var(--fg); }
.note-tip {
  background: var(--warn-bg); color: var(--warn);
  border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13.5px;
}
.bar { height: 7px; border-radius: 99px; background: var(--bg-sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--red); border-radius: 99px; }

.foot {
  border-top: 1px solid var(--line); margin-top: 20px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  color: var(--fg-faint); font-size: 12.5px; text-align: center;
}
.foot p { max-width: 760px; margin: 0 auto; }

/* ------------------------------------------------------------------ modal */
.modal-back {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(20,16,12,.5); padding: 16px;
}
.modal {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: min(560px, 100%);
  max-height: 86vh; overflow: auto; padding: 20px;
}
.modal h2 { margin-top: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 70;
  background: var(--ink); color: #fff; padding: 10px 17px;
  border-radius: 999px; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease-out;
}
@media (min-width: 860px) { .toast { bottom: 24px; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

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

/* ===================================================== tài khoản & quản trị */

.avatar { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar.lg { width: 56px; height: 56px; border-radius: 50%; }

#btn-account { display: grid; place-items: center; overflow: hidden; padding: 0; }

.acct-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.acct-head b { font-size: 17px; }

.tag {
  display: inline-block; margin-top: 4px; padding: 1px 8px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: 11.5px;
}

.kv {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 16px;
  margin: 14px 0; align-items: baseline;
}
.kv dt { color: var(--fg-faint); font-size: 13.5px; }
.kv dd { margin: 0; font-weight: 600; }

.err { color: var(--red); }

.plain { list-style: none; padding: 0; margin: 8px 0; }
.plain li { padding: 5px 0; border-bottom: 1px solid var(--line); }

.note {
  width: 100%; margin: 8px 0; padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-card); color: inherit; resize: vertical;
}

.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* thẻ chuyển mục */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab {
  padding: 9px 14px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--fg-faint); font: inherit; cursor: pointer;
}
.tab[aria-current] { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }

/* bảng số liệu: trên điện thoại thì cuộn ngang trong khung riêng,
   không để cả trang bị đẩy rộng ra */
.tbl-wrap { overflow-x: auto; margin: 10px -14px; padding: 0 14px; }
.tbl { border-collapse: collapse; width: 100%; font-size: 14px; white-space: nowrap; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--fg-faint); font-weight: 600; font-size: 12.5px; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.muted { color: var(--fg-faint); }
.tbl tbody tr:hover { background: var(--bg-card); }

/* dải ngày học: ô càng đậm là hôm đó ôn càng nhiều */
.days { display: flex; flex-wrap: wrap; gap: 3px; margin: 10px 0; }
.day {
  width: 14px; height: 14px; border-radius: 3px;
  background: color-mix(in srgb, var(--red) calc(var(--v) * 85% + 15%), var(--line));
}
