:root {
  --bg: #faf3f3;
  --surface: #ffffff;
  --surface-2: #f5eaea;
  --text: #1f1a1b;
  --muted: #74686a;
  --border: #ead9da;
  --primary: #231c1e;
  --primary-ink: #ffffff;
  --brand: #d4959a;
  --brand-ink: #231c1e;
  --accent: #c0505a;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --danger: #b3261e;
  --danger-bg: #fbe7e5;
  --shadow: 0 1px 2px rgba(40, 20, 25, .06), 0 4px 16px rgba(40, 20, 25, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161213;
    --surface: #201a1c;
    --surface-2: #2b2326;
    --text: #f0e8e9;
    --muted: #a8999c;
    --border: #3a3033;
    --primary: #e3a5aa;
    --primary-ink: #1d1517;
    --brand: #d4959a;
    --brand-ink: #1d1517;
    --accent: #ef7d86;
    --ok: #6fd3a0;
    --ok-bg: #173126;
    --warn: #f0b85a;
    --warn-bg: #352812;
    --danger: #ff8a80;
    --danger-bg: #3a1c1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }

/* ---------- 版面 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: var(--brand-ink);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand {
  font-weight: 800; font-size: 1.15rem; margin-right: auto; display: flex; align-items: center; gap: 10px;
  color: inherit; text-decoration: none; letter-spacing: .04em;
}
.brand img { width: 40px; height: 40px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0, 0, 0, .75); }
.nav { display: flex; gap: 4px; }
.nav a {
  color: inherit; text-decoration: none; padding: 6px 12px; border-radius: 999px; opacity: .8; font-size: .95rem;
}
.nav a { opacity: .75; font-weight: 600; }
.nav a[aria-current="page"] { background: var(--brand-ink); color: var(--brand); opacity: 1; }
@media (max-width: 480px) {
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .brand { font-size: 1.05rem; width: 100%; }
  .nav { width: 100%; }
  .nav a { flex: 1; text-align: center; padding: 6px 4px; font-size: .9rem; }
}

main { max-width: 760px; margin: 0 auto; padding: 20px 16px 64px; }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: .95rem; }

/* ---------- 元件 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.stack > * + * { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; min-height: 42px;
  background: var(--primary); color: var(--primary-ink); font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); padding: 6px 10px; min-height: 0; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .88rem; border-radius: 8px; }
.btn.block { width: 100%; }

label.field { display: block; font-size: .9rem; font-weight: 600; }
label.field > span.hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=tel], input[type=email], input[type=search], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row { grid-template-columns: 1fr; } }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

.alert { padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- 日期列 ---------- */
.datestrip {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin: 0 -2px;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.chip {
  flex: 0 0 auto; scroll-snap-align: start; width: 62px; padding: 8px 0 10px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  text-align: center; cursor: pointer; position: relative;
}
.chip .dow { font-size: .78rem; color: var(--muted); }
.chip .day { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.chip .mon { font-size: .72rem; color: var(--muted); }
.chip.has::after {
  content: ""; position: absolute; left: 50%; bottom: 5px; width: 5px; height: 5px; margin-left: -2.5px;
  border-radius: 50%; background: var(--accent);
}
.chip.none { opacity: .5; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip[aria-pressed="true"] .dow, .chip[aria-pressed="true"] .mon { color: inherit; opacity: .8; }
.chip[aria-pressed="true"]::after { background: var(--primary-ink); }

/* ---------- 課程卡 ---------- */
.slot { display: flex; gap: 14px; align-items: center; }
.slot .time { min-width: 64px; text-align: center; }
.slot .time b { display: block; font-size: 1.2rem; }
.slot .time small { color: var(--muted); }
.slot .info { flex: 1; min-width: 0; }
.slot .title { font-weight: 700; }
.slot .note { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.slot .meta { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.full > i { background: var(--accent); }
@media (max-width: 480px) {
  .slot { flex-wrap: wrap; }
  .slot .actions { width: 100%; }
  .slot .actions .btn { width: 100%; }
}

/* ---------- 對話框 ---------- */
dialog {
  border: none; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 14, 24, .55); }
dialog .dlg-head { padding: 18px 20px 0; }
dialog .dlg-head h3 { margin: 0; font-size: 1.15rem; }
dialog .dlg-body { padding: 14px 20px; }
dialog .dlg-foot { padding: 0 20px 20px; display: flex; gap: 8px; justify-content: flex-end; }
.summary { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .95rem; }
.code-box {
  font: 700 2rem/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .2em;
  text-align: center; padding: 14px; border: 2px dashed var(--border); border-radius: 12px; margin: 10px 0;
}

/* ---------- 後台 ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .range { font-weight: 600; margin: 0 auto 0 4px; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; border: none; padding: 10px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600;
}
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.weekdays label {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 40px;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-weight: 600; user-select: none;
}
.weekdays input { position: absolute; opacity: 0; pointer-events: none; }
.weekdays label:has(input:checked) { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.weekdays label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.day-head { font-weight: 700; margin: 22px 0 8px; color: var(--muted); font-size: .95rem; }
.day-head:first-child { margin-top: 0; }
.roster { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.roster table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.roster td { padding: 7px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.roster tr.cancelled td { color: var(--muted); text-decoration: line-through; }
.roster tr.cancelled td:last-child { text-decoration: none; }
.roster td:last-child { text-align: right; white-space: nowrap; }
.roster .num { color: var(--muted); width: 1.5em; }
.slot-admin .head { display: flex; gap: 10px; align-items: flex-start; }
.slot-admin .head .info { flex: 1; min-width: 0; }
.slot-admin .head .when { font-weight: 700; }
.slot-admin.past { opacity: .7; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: .95rem; max-width: calc(100vw - 32px);
}

/* ---------- 課程分類 ---------- */
.cat { border-left: 6px solid var(--cat, var(--border)); }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .78rem; font-weight: 700;
  background: var(--cat, var(--surface-2)); color: #231c1e;
}
.slot .subtitle { color: var(--muted); font-size: .85rem; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px; scrollbar-width: none; }
.filters button {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: .88rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.filters button i { width: 10px; height: 10px; border-radius: 50%; background: var(--cat); display: inline-block; }
.filters button[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
footer.site {
  max-width: 760px; margin: 0 auto; padding: 0 16px 40px; color: var(--muted); font-size: .88rem; text-align: center;
}

/* ---------- 課表與收費 ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week .col h3 {
  margin: 0 0 6px; font-size: .9rem; text-align: center; background: var(--surface-2); padding: 6px; border-radius: 8px;
}
.week .cls {
  background: var(--cat); color: #231c1e; border-radius: 8px; padding: 8px 6px; margin-bottom: 6px;
  text-align: center; font-size: .82rem; line-height: 1.35;
}
.week .cls b { display: block; font-size: .9rem; }
.week .cls .t { font-weight: 700; margin-top: 2px; }
.week .cls .st { display: block; white-space: nowrap; font-size: .76rem; }
.week .cls .st i { display: none; font-style: normal; }
.week .none { color: var(--muted); text-align: center; font-size: .8rem; padding: 10px 0; }
@media (max-width: 720px) {
  .week { grid-template-columns: 1fr; gap: 12px; }
  .week .col h3 { text-align: left; }
  .week .cls { display: flex; gap: 10px; text-align: left; align-items: baseline; }
  .week .cls .t { order: -1; min-width: 92px; margin: 0; }
  .week .cls b { display: inline; }
  .week .cls .st { display: inline; margin-left: 6px; white-space: normal; }
  .week .cls .st i { display: inline; }
  .week .cls .st br { display: none; }
}
.price { width: 100%; border-collapse: collapse; font-size: .95rem; }
.price th, .price td { border: 1px solid var(--border); padding: 10px; text-align: center; }
.price th { background: var(--surface-2); font-weight: 700; }
.price td b { font-size: 1.1rem; }
.callout { background: var(--surface-2); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 8px; font-size: .95rem; }
