:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d1c1a;
  --muted: #6b675f;
  --line: #e2dfd6;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --good: #1f8a4c;
  --bad: #c2412d;
  --warn: #b7791f;
  --star: #e2a400;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614; --surface: #1f1f1c; --surface-2: #2a2a26; --text: #ecebe6; --muted: #a29e94;
    --line: #34332e; --accent: #6b9bf2; --accent-ink: #0d1424; --good: #4cc27c; --bad: #ee7a66; --warn: #e0a84a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--f-body, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif);
  background: var(--bg); color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-family: var(--f-display, inherit); }
h1 { font-size: 26px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
.topbar { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; color: var(--text); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; padding: 28px; }
.login .err { color: var(--bad); font-size: 13px; min-height: 1em; }

/* student dashboard (themes in /themes/*.css restyle these) */
.hero { margin: 4px 0 28px; }
.hero-bar { display: none; }
.hero-body { padding: 26px 26px 24px; }
.eyebrow { font-family: var(--f-label, inherit); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.hero h1 { font-size: clamp(30px, 5vw, 44px); margin: 8px 0 6px; letter-spacing: -.01em; }
.lede { margin: 0 0 16px; color: var(--muted); max-width: 52ch; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 5px 12px; border-radius: 99px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.lc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.lc-num { display: none; }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar.done > i { background: var(--good); }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { font: inherit; font-family: var(--f-label, inherit); font-weight: 600; background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--text); border-color: var(--accent); }

/* student dashboard: lessons + calendar */
.dash-body { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 24px; align-items: start; }
.cal-card { padding: 16px 16px 14px; }
.cal-card h2 { font-size: 15px; margin-bottom: 10px; }
.mcal-h { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 14px; margin-bottom: 8px; font-family: var(--f-label, inherit); }
.mnav { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: inherit; padding: 2px 8px; border-radius: 6px; }
.mnav:hover { background: var(--surface-2); }
.mcal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.mw { font-size: 11px; color: var(--muted); font-weight: 700; padding-bottom: 2px; font-family: var(--f-label, inherit); }
.md { aspect-ratio: 1; border: 0; background: none; border-radius: 50%; font: inherit; font-size: 13px; color: inherit; cursor: default; padding: 0; }
.md.out { opacity: .35; }
.md.today { box-shadow: inset 0 0 0 1.5px var(--muted); }
.md.has { background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
.md.has:hover { filter: brightness(1.08); }
.cal-list { margin-top: 12px; display: grid; gap: 4px; font-size: 13px; }
.cal-list a { display: flex; gap: 8px; color: inherit; padding: 4px 6px; border-radius: 8px; }
.cal-list a:hover { background: var(--surface-2); }
.cal-list .d { color: var(--muted); white-space: nowrap; min-width: 74px; }
.lc-date { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: -4px; }
.lesson-card.flash { animation: flash 1.6s; }
@keyframes flash { 0%, 60% { outline: 3px solid var(--accent); outline-offset: 3px; } 100% { outline: 3px solid transparent; outline-offset: 3px; } }
@media (max-width: 820px) { .dash-body { grid-template-columns: 1fr; } }

/* lesson cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.lesson-card { padding: 16px 18px; display: grid; gap: 10px; color: var(--text); transition: transform .1s, border-color .1s; }
.lesson-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lesson-card .t { font-weight: 700; font-size: 16px; font-family: var(--f-display, inherit); }
.lesson-card .meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.draft { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.published { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.badge.archived { background: var(--surface-2); color: var(--muted); }
.badge.locked { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.star { color: var(--star); }

/* lesson viewer */
.viewer { height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.viewer header { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0; }
.viewer header .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.viewer header .spacer { flex: 1; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.save { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.save.err { color: var(--bad); }
.pts { font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pts.bump { animation: bump .6s; }
@keyframes bump { 30% { transform: scale(1.35); } }
.notice { padding: 40px 16px; text-align: center; }

/* admin */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
.table-wrap { overflow-x: auto; }
.section { margin-top: 28px; }
.section > .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.students { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.student { padding: 14px 16px; display: grid; gap: 8px; cursor: pointer; }
.student.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.student .n { font-weight: 700; }
.mini { width: 70px; display: inline-block; vertical-align: middle; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--text); font-weight: 500; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .dh { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); gap: 8px; }
dialog .db { padding: 14px 18px 20px; }
dialog form.stack { display: grid; gap: 12px; padding: 18px; }
pre.val { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12.5px; max-height: 120px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ok { color: var(--good); font-weight: 700; }
.no { color: var(--bad); font-weight: 700; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; z-index: 10; max-width: calc(100vw - 32px); }

@media (max-width: 640px) {
  .viewer header { gap: 8px; padding: 8px 10px; }
  .viewer header .hide-sm { display: none; }
  h1 { font-size: 22px; }
}
