/* 顏色全部定義在 theme.js（唯一來源，可在「設定 → 配色」調整）；這裡只放尺寸類的變數 */
:root {
  --radius: 14px;
  --hour: 52px;
  --top-h: 57px;
  --tab-h: 64px;
  --check-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* 關閉瀏覽器的「下拉重新整理」與邊緣回彈，避免和拖曳選時段衝突（手機上真正捲動的是 html） */
html { overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
[hidden] { display: none !important; }

/* 圖示：透明底、單色線條，顏色跟隨文字 */
.i { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.btn .i { width: 18px; height: 18px; }
.btn.icon .i { width: 22px; height: 22px; }
.fab .i { width: 28px; height: 28px; stroke-width: 2.4; }
.icon-btn { display: inline-grid; place-items: center; }
.icon-btn .i { width: 20px; height: 20px; }
.chip .i { width: 16px; height: 16px; }
.section-title .i, .detail .r .i { width: 14px; height: 14px; margin-right: 2px; }
.lcard .info .i, .ev .i { width: 13px; height: 13px; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.small { font-size: 13px; }
.muted { color: var(--muted); }

/* ── 頂部列 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bar-bg) 92%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { width: 28px; height: 28px; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: none; gap: 4px; }
.nav a { color: var(--muted); text-decoration: none; border-radius: 8px; padding: 6px 12px; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; min-width: 0; }
.who .name { overflow: hidden; text-overflow: ellipsis; }
.role-badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.role-badge.teacher { background: var(--primary-soft); color: var(--primary); }
.role-badge.parent { background: var(--ok-soft); color: var(--ok-ink); }
.role-badge.student { background: var(--warn-soft); color: var(--warn-ink); }

/* ── 底部分頁（手機） ── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: color-mix(in srgb, var(--bar-bg) 94%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tab-h); font-size: 12px; color: var(--muted); text-decoration: none; position: relative;
}
.tabbar a .ico { display: grid; place-items: center; height: 26px; transition: transform .15s; }
.tabbar a .ico .i { width: 24px; height: 24px; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tabbar a.active .ico { transform: translateY(-1px); }
.tabbar a.active .ico .i { stroke-width: 2.3; }
.tabbar a.active::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary); }

/* ── 浮動新增按鈕 ── */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); z-index: 21;
  width: 58px; height: 58px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--primary) 45%, transparent);
  transition: transform .12s;
}
.fab:active { transform: scale(.92); }

main { padding: 12px 16px; padding-bottom: calc(var(--tab-h) + 90px + env(safe-area-inset-bottom)); max-width: 1280px; margin: 0 auto; }
/* 手機登入後不顯示頂部列（功能都在底部分頁），把高度留給課表 */
@media (max-width: 767px) {
  body.authed .topbar { display: none; }
  body.authed main { padding-top: max(10px, env(safe-area-inset-top)); }
}

.desk-only { display: none !important; }
@media (min-width: 768px) {
  .nav { display: flex; }
  .tabbar, .fab { display: none !important; }
  .desk-only { display: inline-flex !important; }
  main { padding: 24px; }
}

/* ── 通用元件 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap;
  min-height: 44px; transition: transform .08s, background .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: var(--on-strong); }
.btn.small { padding: 4px 12px; min-height: 36px; font-size: 13px; }
.btn.big { min-height: 50px; font-size: 16px; font-weight: 600; }
.btn.icon { width: 44px; padding: 0; font-size: 22px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 4px 0 14px; }
.page-head h1 { font-size: 24px; margin-right: auto; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.hint-line { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0; }
.chev { color: var(--muted); width: 20px; height: 20px; margin-left: auto; }

label.field, div.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.lbl { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  font: inherit; font-size: 16px; /* iOS 不會自動放大 */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; min-height: 46px; width: 100%;
}
textarea { min-height: 76px; resize: vertical; }
/* iOS（Safari、Chrome 都是 WebKit）：日期欄位有固定的原生寬度和高度，不會縮進窄欄位，會蓋到旁邊。改成一般外觀就能跟其他欄位對齊 */
input[type=date], input[type=time], input[type=month], input[type=datetime-local] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; height: 46px; line-height: 26px; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
input::-webkit-datetime-edit { padding: 0; }
/* 格線、橫排裡的欄位可以縮到比內容窄（預設 min-width:auto 會把版面撐開） */
label.field, .field, .row2 > *, .grid-form > *, .tsel { min-width: 0; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); min-height: 46px; cursor: pointer; }
.inline { display: flex; gap: 6px; }
.grid-form { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid-form > .field:only-child, .grid-form .full { grid-column: 1 / -1; }
.section-title { grid-column: 1 / -1; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
@media (max-width: 420px) {
  .grid-form > label.field:not(.half), .grid-form > .check { grid-column: 1 / -1; }
}

/* 膠囊選擇（學生、時長、身分） */
.chips {
  display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; padding: 2px 2px 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin-bottom: 12px; }
.chip {
  flex: none; scroll-snap-align: start; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.swatch { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--surface); background: var(--c); box-shadow: 0 0 0 1px var(--border); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--c); }
.swatches { gap: 8px; }
.swatch.custom { position: relative; display: grid; place-items: center; color: #fff; overflow: hidden;
  background: conic-gradient(from 0deg, #E16B8C, #B481BB, #3E62AD, #5DAC81, #51A8DD, #8B81C3, #E16B8C); }
.swatch.custom.on { background: var(--c); }
.swatch.custom .i { width: 16px; height: 16px; filter: drop-shadow(0 0 2px rgb(0 0 0 / .5)); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }

/* ── 登入 ── */
.auth-wrap { min-height: calc(100dvh - 40px); display: grid; place-items: center; }
.auth { width: 100%; max-width: 400px; padding: 28px 22px; }
.auth h1 { font-size: 22px; display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.auth h1 img { width: 40px; }
.auth form { display: grid; gap: 14px; margin-top: 20px; }
.auth .alt { text-align: center; margin-top: 18px; font-size: 15px; }
.auth .alt a { display: inline-block; padding: 8px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ── 身分說明（可收合） ── */
.levelbar {
  margin-bottom: 10px; font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: 12px;
}
.levelbar summary { padding: 6px 12px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.levelbar summary::-webkit-details-marker { display: none; }
.levelbar summary::after {
  content: ""; margin-left: auto; width: 7px; height: 7px; flex: none; opacity: .7;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform .15s;
}
.levelbar[open] summary::after { transform: translateY(2px) rotate(-135deg); }
.levelbar summary .i { width: 16px; height: 16px; }
.levelbar > div { padding: 0 12px 10px; }

/* ── 行事曆工具列 ── */
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.date-nav { display: flex; align-items: center; gap: 6px; flex: 1 1 100%; min-width: 0; }
.date-nav .range { border: 0; background: none; color: inherit; font-family: inherit; cursor: pointer; padding: 6px 4px; border-radius: 10px; }
.date-nav .range:active { background: var(--surface-2); }
.date-nav .range { flex: 1; min-width: 0; text-align: center; font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.cal-toolbar .tools { display: flex; align-items: center; gap: 8px; flex: 1 1 100%; justify-content: space-between; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 0 11px; min-height: 38px; border-radius: 9px; font: inherit; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.cal-toolbar #today { padding: 0 14px; }
@media (max-width: 400px) { .date-nav .range { font-size: 16px; } }
@media (min-width: 768px) {
  .cal-toolbar { flex-wrap: nowrap; }
  .date-nav { flex: 0 0 auto; }
  .date-nav .range { flex: none; min-width: 230px; font-size: 19px; }
  .cal-toolbar .tools { flex: 1; justify-content: flex-end; }
}

/* 換頁動畫 */
@keyframes from-right { from { opacity: .3; transform: translateX(40px); } }
@keyframes from-left { from { opacity: .3; transform: translateX(-40px); } }
.from-right { animation: from-right .22s ease-out; }
.from-left { animation: from-left .22s ease-out; }

/* ── 日檢視：滑動換日 ── */
body.dayview main {
  height: calc(100dvh - var(--top-h)); display: flex; flex-direction: column; overflow: hidden;
  padding-bottom: 0;
}
body.dayview .cal { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* 日期滾輪（密碼鎖式）：與下方時間軸同寬、同中心 */
.strip { max-width: 688px; width: 100%; margin: 0 auto 6px; padding: 0 12px 0 40px; box-sizing: border-box; }
.wheel {
  position: relative; height: 64px; overflow: hidden; perspective: 520px; touch-action: none; user-select: none;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 22%, #000 78%, transparent);
          mask-image: linear-gradient(to right, transparent, #000 22%, #000 78%, transparent);
}
.wheel::before {                                  /* 中間的選取框 */
  content: ""; position: absolute; left: 50%; top: 2px; bottom: 2px; width: 50px; margin-left: -25px;
  border-radius: 14px; background: var(--primary); pointer-events: none;
}
.wheel button {
  position: absolute; left: 50%; top: 2px; width: 50px; height: 60px; margin-left: -25px; border-radius: 14px;
  border: 0; background: transparent; color: var(--text); font: inherit; cursor: pointer; padding: 4px 0 3px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; backface-visibility: hidden;
  -webkit-tap-highlight-color: transparent; will-change: transform, opacity;
}
.wheel .w { font-size: 12px; color: var(--muted); }
.wheel .n { font-size: 20px; font-weight: 700; line-height: 30px; font-variant-numeric: tabular-nums; }
.wheel .today .n { color: var(--primary); }
.wheel .on .w, .wheel .on .n { color: var(--primary-ink); }
.wheel .dots { display: flex; gap: 3px; height: 5px; }
.wheel .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); opacity: .6; }
.wheel .on .dots i { background: var(--primary-ink); opacity: .8; }
/* 日檢視的時間軸：左邊時間刻度、右邊留一點邊距，整體視覺置中；上方轉輪對齊長條 */
.page .dgrid { grid-template-columns: 40px minmax(0, 1fr) 12px; }
.pager {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none;
  margin: 0 -16px;
}
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow-y: auto; overscroll-behavior-y: none; }
.page-inner { padding: 4px 16px 14px; max-width: 720px; margin: 0 auto; }
/* 週、月：課表剛好填滿，不留給捲動用的大片底部空白 */
body.fit main { padding-bottom: calc(var(--tab-h) + 8px + env(safe-area-inset-bottom)); }
/* 手機的週、月、日檢視：整頁固定不捲動（iOS 的網址列伸縮會讓高度差幾十 px，造成整頁可以上下滑）。
   真的放不下時只在內容區裡捲動 */
@media (max-width: 767px) {
  body.fit, body.dayview { position: fixed; inset: 0; overflow: hidden; }
  body.fit main { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(var(--tab-h) + 6px + env(safe-area-inset-bottom)); }
  body.dayview main { height: 100%; }
}
/* 日檢視：底部分頁列不蓋住時間軸 */
@media (max-width: 767px) { body.dayview main { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); } }
@media (min-width: 768px) {
  body.fit main { padding-bottom: 16px; }
  body.dayview main { height: calc(100dvh - var(--top-h)); }
  .pager { margin: 0; }
}
.day-title { font-size: 15px; color: var(--muted); font-weight: 600; margin: 4px 2px 10px; display: flex; align-items: center; gap: 8px; }
.today-tag { font-size: 11px; background: var(--primary); color: var(--primary-ink); padding: 1px 8px; border-radius: 99px; }
.timeline { display: grid; gap: 8px; }
.loading, .none { font-size: 14px; color: var(--muted); padding: 14px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* 課程卡片 */
.lcard {
  display: flex; gap: 12px; align-items: stretch; width: 100%; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 12px 14px;
  cursor: pointer; box-shadow: var(--shadow); min-height: 64px; transition: transform .08s;
}
.lcard:active { transform: scale(.985); }
.lcard .time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; min-width: 50px; line-height: 1.25; }
.lcard .time small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.lcard .bar { width: 4px; border-radius: 4px; background: var(--c, var(--primary)); flex: none; }
.lcard .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lcard .info b { font-size: 16px; }
.lcard .info span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lcard .info .topic { color: var(--text); opacity: .8; }
.lcard .chev { align-self: center; }
.lcard.busy { cursor: default; background: var(--surface-2); box-shadow: none; }
.lcard.busy .bar { background: var(--busy); }
.lcard.busy .info b { color: var(--muted); font-weight: 600; }
.lcard.block .bar { background: repeating-linear-gradient(to bottom, var(--muted) 0 4px, transparent 4px 7px); }
.lcard.cancelled, .lcard.leave { opacity: .65; box-shadow: none; }
.lcard.cancelled .info b, .lcard.leave .info b { text-decoration: line-through; }

/* 空堂 */
.free {
  display: flex; gap: 10px; align-items: center; width: 100%; min-height: var(--h, 58px); text-align: left; font: inherit; color: var(--muted);
  background: transparent; border: 0; border-radius: 10px; padding: 0 6px 0 14px; cursor: default;
}
.free .fl { align-self: stretch; display: flex; flex-direction: column; align-items: flex-start; width: 50px; flex: none; padding: 2px 0; }
.free .ft { font-size: 13px; font-weight: 600; line-height: 1.1; color: var(--ok); font-variant-numeric: tabular-nums; }
.free .line { flex: 1; min-height: 14px; width: 0; margin: 4px 0 4px 17px; border-left: 2px solid color-mix(in srgb, var(--ok) 55%, transparent); }
.free .label { flex: 1; font-size: 14px; color: var(--ok); }
.free .plus { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; color: var(--primary); background: var(--primary-soft); padding: 6px 12px; border-radius: 99px; }
.day-col.clickable, body:has(.free .plus) .free { cursor: pointer; }
.free:has(.plus):active { background: var(--primary-soft); }

/* ── 按壓回饋：按下時顏色變深 ── */
.lcard:active { background: var(--surface-2); }
.free:active { background: var(--surface-2); }
.ev:active { filter: brightness(.82); }
.strip button:active, .week-head button:active { background: var(--surface-2); }
.chip:active, .act:active, .item.tap:active { background: var(--surface-2); }
.chip.on:active { background: color-mix(in srgb, var(--primary) 25%, var(--surface)); }

/* ── 日檢視時間軸 ── */
.dgrid { display: grid; grid-template-columns: 46px minmax(0, 1fr); }
.dgrid .day-col { border: 1px solid var(--border); border-radius: 12px; background-color: var(--surface); box-shadow: var(--shadow); }
.dgrid .day-col .now-line::before { left: -6px; }
.dgrid .day-col.today { background-color: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
.day-col { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.free-blk {
  position: absolute; left: 3px; right: 3px; pointer-events: none; border-radius: 8px;
  background: color-mix(in srgb, var(--ok) 7%, transparent); border: 1px dashed color-mix(in srgb, var(--ok) 45%, transparent);
}
.free-blk span { display: block; padding: 4px 8px; font-size: 12px; color: var(--ok); }
.ev.big { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.ev.tight { padding-top: 1px; padding-bottom: 1px; display: flex; align-items: center; }
.ev.tight .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.tight .ti { font-weight: 400; color: var(--muted); margin-left: 4px; }
.ev.big.tight .t { font-size: 13px; }
.ev.big .t { font-size: 15px; }
.ev.big .pill { margin-left: 6px; }
.ev.big.busy .t { font-size: 14px; }
.now-line { z-index: 4; }

/* ── 拖曳選取時段 ── */
.sel {
  position: absolute; left: 3px; right: 3px; z-index: 6; pointer-events: none; border-radius: 10px;
  background: color-mix(in srgb, var(--primary) 30%, transparent);
  border: 2px solid var(--primary); color: var(--primary);
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 0; text-align: center; overflow: hidden;
  transition: background .12s;
}
.sel.pressing { background: color-mix(in srgb, var(--primary) 45%, transparent); }   /* 剛按下：較深 */
.sel.active { background: color-mix(in srgb, var(--primary) 38%, transparent); box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent); }
.sel.chosen { background: color-mix(in srgb, var(--primary) 50%, transparent); }
.sel b { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.sel span { font-size: 12px; color: var(--text); opacity: .85; }
.week .sel b { font-size: 11px; }
.week .sel span { font-size: 10px; }

/* 可調整的時段框（觸控）：框內觸控不會捲動，拖曳立即生效 */
.sel.editable {
  pointer-events: auto; touch-action: none; overflow: visible; cursor: grab;
  background: color-mix(in srgb, var(--primary) 32%, var(--surface)); box-shadow: 0 6px 20px color-mix(in srgb, var(--primary) 30%, transparent);
  animation: sel-pop .14s ease-out;
}
@keyframes sel-pop { from { transform: scale(.96); opacity: .6; } }
.sel.editable.dragging { background: color-mix(in srgb, var(--primary) 45%, var(--surface)); cursor: grabbing; }
.sel.editable.dismissing { animation: none; cursor: grabbing; border-style: dashed; }   /* 左右滑動取消中 */
.sel .mid { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 8px; }
.sel .txt { display: flex; flex-direction: column; align-items: center; min-width: 0; text-align: center; line-height: 1.2; }
.sel.short .txt { flex-direction: row; gap: 6px; align-items: baseline; }
.sel .go {
  flex: none; border: 0; border-radius: 99px; background: var(--primary); color: var(--primary-ink); font: inherit; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 3px; padding: 0 12px 0 9px; height: 30px; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.sel.short .go { height: 24px; font-size: 12px; padding: 0 9px 0 7px; }
.sel .go .i { width: 15px; height: 15px; stroke-width: 2.6; }
.sel .go:active { filter: brightness(.85); }
/* 上下把手：看得到的圓點＋較大的觸控範圍 */
.sel .h { position: absolute; left: 0; right: 0; height: 32px; z-index: 2; touch-action: none; cursor: ns-resize; }
.sel .h.top { top: -16px; }
.sel .h.bottom { bottom: -16px; }
.sel .h::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.sel.drag-top .h.top::after, .sel.drag-bottom .h.bottom::after { transform: scale(1.3); background: var(--primary); }
.week .sel .go { width: 28px; height: 28px; padding: 0; justify-content: center; }
.week .sel .go span { display: none; }
.week .sel.short .go { width: 22px; height: 22px; }
@media (max-width: 767px) { .week .sel .go { display: none; } }
.week .sel .mid { padding: 0 2px; justify-content: center; }
.week .sel .txt { align-items: center; text-align: center; }
.week .sel.short .txt { flex-direction: column; gap: 0; }

.dur-read { font-size: 14px; color: var(--muted); margin-top: -4px; }

/* ── 課程表單：分區、單欄、即時結果 ── */
.fsec { display: grid; gap: 10px; padding: 14px 0; border-top: 1px solid var(--border); }
#conf + .fsec { border-top: 0; padding-top: 2px; }
.fsec-t { margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.row2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.derived { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); line-height: 1.4; }
.derived .i { color: var(--muted); }
.derived.err, .derived.err .i { color: var(--danger); }
#durChips { gap: 6px; }
#durChips .chip { padding: 0 12px; }
.seg.wide { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.seg.wide button { min-height: 42px; font-size: 15px; }
.fee-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fee-line .small { font-weight: 400; margin-left: 6px; }
.linkbtn { border: 0; background: none; color: var(--primary); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 2px; white-space: nowrap; }
details.fsec.more summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
details.fsec.more summary::-webkit-details-marker { display: none; }
details.fsec.more summary .i { color: var(--muted); }
.fsum { flex-basis: 100%; font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.fsum b { color: var(--text); }
.fsum.err { color: var(--danger); }
.btn.primary:disabled { filter: grayscale(.4); opacity: .45; }
/* ── 拖曳調整時間：暗色遮罩＋中上方大字 ── */
.hud-dim { position: fixed; inset: 0; z-index: 30; pointer-events: none; background: var(--drag-dim); opacity: 0; transition: opacity .16s ease-out; }
.hud-dim.on { opacity: 1; }
.drag-hud {                                   /* 時間卡片永遠在最上層（被拖曳的方塊在 31） */
  position: fixed; inset: 0; z-index: 40; pointer-events: none;
  display: flex; justify-content: center; align-items: flex-start;
  padding: max(13vh, calc(var(--top-h) + 20px)) 16px 0;
  opacity: 0; transition: opacity .16s ease-out;
}
.drag-hud.on { opacity: 1; }
.hud-card {
  text-align: center; color: var(--hud-text); transform: translateY(-10px) scale(.96); transition: transform .18s ease-out;
  background: var(--hud-bg); border: 1px solid rgba(255, 255, 255, .1); border-radius: 22px;
  padding: 14px 26px 18px; box-shadow: 0 18px 50px rgba(0, 0, 0, .55); max-width: calc(100vw - 32px);
}
.hud-card.conflict { border-color: #e16b8c; box-shadow: 0 0 0 2px rgba(225, 107, 140, .5), 0 18px 50px rgba(0, 0, 0, .55); }
.hud-warn { margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; font-weight: 700; color: #f3b3c3; }
.hud-warn .i { width: 18px; height: 18px; }
.lifted.conflict, .sel.conflict { outline: 3px solid var(--danger); outline-offset: 1px; }
.sel.editable.conflict { background: color-mix(in srgb, var(--danger) 26%, var(--surface)); border-color: var(--danger); }
.overlap-warn { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-soft); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.5; }
.overlap-warn .i { width: 18px; height: 18px; margin-top: 2px; flex: none; }
.fsum.warn { color: var(--warn); }
.fsum .i { width: 15px; height: 15px; }

.drag-hud.on .hud-card { transform: none; }
.hud-date { font-size: 17px; font-weight: 600; opacity: .85; letter-spacing: .5px; }
.hud-time { font-size: clamp(34px, 10.5vw, 68px); font-weight: 800; line-height: 1.08; letter-spacing: 1px; font-variant-numeric: tabular-nums; text-shadow: 0 4px 28px rgba(0, 0, 0, .45); white-space: nowrap; }
.hud-dur { display: inline-block; margin-top: 10px; padding: 5px 16px; border-radius: 99px; background: var(--primary); color: var(--primary-ink); font-size: 20px; font-weight: 700; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.hud-sub { margin-top: 10px; font-size: 14px; opacity: .75; }
.lifted { z-index: 31 !important; }            /* 被拖曳的方塊浮在遮罩上方，保持明亮 */

.repeat-end { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.repeat-end b { color: var(--text); }
.repeat-end .i { width: 13px; height: 13px; }

/* ── 拖曳移動已排好的課程 ── */
.ev.movable { cursor: grab; -webkit-touch-callout: none; }
.ev.moving { opacity: .3; }
.ev.holding { transform: scale(.96); filter: brightness(.88); transition: transform 1s ease-out, filter 1s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.ev.shake { animation: shake .36s ease-in-out; }
.ev.ghost {
  z-index: 8; pointer-events: none; cursor: grabbing; transform: scale(1.02);
  background: linear-gradient(135deg, color-mix(in srgb, var(--c0) 34%, var(--surface)) 0%, color-mix(in srgb, var(--c0) 16%, var(--surface)) 100%);
  box-shadow: 0 12px 28px rgba(0,0,0,.3);
}
.move-sum { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; margin-bottom: 10px; }
.move-sum > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.move-sum .to { background: var(--primary-soft); }
.move-sum span { font-size: 12px; color: var(--muted); }
.move-sum b { font-size: 15px; font-variant-numeric: tabular-nums; }
.move-sum .from b { text-decoration: line-through; color: var(--muted); font-weight: 600; }
.move-sum .arrow { color: var(--muted); width: 20px; height: 20px; }
.scope-note { display: flex; gap: 8px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.5; margin-bottom: 12px; }
.scope-note .i { color: var(--primary); width: 18px; height: 18px; margin-top: 2px; }
.dur-read b { color: var(--text); }

.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 2px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.pill.completed, .pill.paid { background: var(--ok-soft); color: var(--ok-ink); }
.pill.cancelled, .pill.unpaid { background: var(--danger-soft); color: var(--danger-ink); }
.pill.leave { background: var(--warn-soft); color: var(--warn-ink); }
.pill.scheduled { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) {
}

/* ── 週檢視 ── */
.week { overflow: visible; touch-action: pan-y; }
.week-head, .week-body { display: grid; grid-template-columns: 44px repeat(7, minmax(0, 1fr)); }
.week-head { border-bottom: 1px solid var(--border); position: sticky; top: var(--top-h); background: var(--surface); z-index: 5; border-radius: var(--radius) var(--radius) 0 0; }
.week-head button { border: 0; background: transparent; font: inherit; cursor: pointer; padding: 8px 2px; text-align: center; font-size: 12px; color: var(--muted); }
.week-head .d { display: block; font-size: 17px; font-weight: 700; color: var(--text); width: 32px; height: 32px; line-height: 32px; margin: 2px auto 0; border-radius: 50%; }
.week-head .today .d { color: var(--primary-ink); background: var(--primary); }
.week-body { position: relative; }
.hours div { height: var(--hour); font-size: clamp(9px, calc(var(--hour) * .4), 11px); color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.hours div:first-child { transform: translateY(-1px); }             /* 開始時間：貼在頂線下方，不被切掉 */
.hours div:last-child { height: 0; transform: translateY(-14px); }   /* 結束時間：貼在底線上方 */
/* 週檢視：行程條上的字置中 */
.ev:not(.big) { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.ev:not(.big) .t, .ev:not(.big) .s { max-width: 100%; }
.ev.tight:not(.big) { flex-direction: row; }
/* 窄欄（小手機的週檢視，一天只有 40px 左右寬）：名字改成逐字換行最多兩行，不再縮成「林…」分不出是誰；一小時的短課放不下時間就只顯示名字 */
.day-col { container-type: inline-size; }
@container (max-width: 64px) {
  .ev:not(.big) { padding-left: 2px; padding-right: 2px; }
  .ev:not(.big) .t { white-space: normal; word-break: break-all; text-overflow: clip; line-height: 1.15; max-height: 2.3em; }
  .ev.tight:not(.big) { flex-direction: column; }
  .ev.tight:not(.big) .ti { display: none; }
}
.day-col {
  position: relative; border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), var(--border) calc(var(--hour) - 1px), var(--border) var(--hour));
}
.day-col.today { background-color: color-mix(in srgb, var(--primary) 5%, transparent); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--now); z-index: 3; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--now); }
.ev {
  position: absolute; border-radius: 8px; padding: 4px 5px; overflow: hidden;
  font-size: 12px; line-height: 1.3; cursor: pointer; border: 0; text-align: left; font-family: inherit;
  /* 色框＋比底色稍深的漸層底：學生色只用在框與名字，整體較淡雅 */
  --c0: var(--c, var(--primary));
  color: var(--text);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--c0) 24%, var(--surface-2)) 0%,
    color-mix(in srgb, var(--c0) 10%, var(--surface-2)) 100%);
  border: 1.5px solid color-mix(in srgb, var(--c0) 75%, transparent);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--c0) 18%, transparent);
}
.ev .t { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: color-mix(in srgb, var(--c0) 62%, var(--text)); }
.ev .s { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.ev.busy { background: repeating-linear-gradient(135deg, var(--busy) 0 6px, color-mix(in srgb, var(--busy) 70%, transparent) 6px 12px); color: var(--muted); cursor: default; border: 0; box-shadow: none; }
.ev.busy .t { color: var(--muted); }
.ev.block { background: var(--surface-2); color: var(--muted); border: 1px dashed var(--muted); box-shadow: none; }
.ev.block .t { color: var(--muted); }
/* ── 課程方塊的顏色層次（依時間）──
   未開始：學生代表色實色、白字（最清楚）
   進行中：實色＋外框光暈（最醒目）
   已結束：同色系壓暗、文字半透明（退到背景）
   取消／請假：只留淡淡的框與刪除線（最淡） */
.ev:not(.busy):not(.block) {
  --c1: color-mix(in oklab, var(--c0) var(--ev-solid), var(--ev-mix));
  background: linear-gradient(135deg, var(--c1), color-mix(in oklab, var(--c1) 82%, #0b0d10));
  border: 0; color: #fff; box-shadow: 0 2px 6px color-mix(in srgb, var(--c0) 35%, transparent);
  text-shadow: 0 1px 1px rgb(0 0 0 / .18);
}
.ev:not(.busy):not(.block) .t { color: #fff; }
.ev:not(.busy):not(.block) .s, .ev:not(.busy):not(.block) .ti { color: rgb(255 255 255 / .85); }
.ev.live:not(.busy):not(.block) {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px color-mix(in srgb, var(--c0) 70%, transparent), 0 4px 14px color-mix(in srgb, var(--c0) 45%, transparent);
  z-index: 2;
}
.ev.past:not(.busy):not(.block) {
  background: linear-gradient(135deg, color-mix(in oklab, var(--c0) var(--ev-past), var(--ev-mix)), color-mix(in oklab, var(--c0) var(--ev-past2), var(--ev-mix)));
  box-shadow: none; text-shadow: none;
}
.ev.past:not(.busy):not(.block) .t { color: rgb(255 255 255 / .82); }
.ev.past:not(.busy):not(.block) .s, .ev.past:not(.busy):not(.block) .ti { color: rgb(255 255 255 / .6); }
.ev.cancelled:not(.block), .ev.leave:not(.block) {
  background: color-mix(in srgb, var(--c0) 8%, var(--surface)); color: var(--muted);
  border: 1.5px dashed color-mix(in srgb, var(--c0) 55%, transparent); box-shadow: none; text-shadow: none; text-decoration: line-through;
}
.ev.cancelled:not(.block) .t, .ev.leave:not(.block) .t { color: color-mix(in srgb, var(--c0) 55%, var(--muted)); }
.ev.cancelled:not(.block) .s, .ev.leave:not(.block) .s, .ev.cancelled:not(.block) .ti, .ev.leave:not(.block) .ti { color: var(--muted); }
.ev.block.live { border-style: solid; border-color: var(--text); }
.ev.block.past { opacity: .55; }
.ev.block.cancelled, .ev.block.leave { opacity: .45; text-decoration: line-through; }
/* 月檢視的小標籤：同樣的層次 */
.mchip:not(.busy):not(.block) { background: var(--c, var(--primary)); border-color: transparent; color: #fff; }
.mchip:not(.busy):not(.block) b { color: rgb(255 255 255 / .85); }
.mchip.live:not(.busy):not(.block) { box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / .9); }
.mchip.past:not(.busy):not(.block) { background: color-mix(in oklab, var(--c, var(--primary)) var(--ev-past), var(--ev-mix)); color: rgb(255 255 255 / .8); }
.mchip.past:not(.busy):not(.block) b { color: rgb(255 255 255 / .6); }
.mchip.cancelled:not(.block), .mchip.leave:not(.block) { background: transparent; color: var(--muted); border: 1px dashed color-mix(in srgb, var(--c, var(--primary)) 55%, transparent); }
.mchip.cancelled:not(.block) b, .mchip.leave:not(.block) b { color: var(--muted); }
/* 清單：左邊色條＝實色／暗色 */
.lcard.past .bar { background: color-mix(in oklab, var(--c, var(--primary)) var(--ev-past), var(--ev-mix)); }
.lcard.past .time, .lcard.past .info b { opacity: .7; }
.lcard.live { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c, var(--primary)) 60%, transparent), var(--shadow); }
.pill.live { background: var(--primary); color: var(--primary-ink); }
.pill.past { background: var(--surface-2); color: var(--muted); }
@media (max-width: 560px) { .ev { padding: 3px; font-size: 11px; } }

/* ── 月檢視 ── */
.month { overflow: hidden; touch-action: pan-y; }
.month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.month-head div { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 0; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.mcell {
  display: flex; flex-direction: column; gap: 4px; min-width: 0; height: var(--mrow, 108px); padding: 6px 6px 8px; overflow: hidden;
  border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.mcell:nth-child(7n) { border-right: 0; }
.mcell.out { color: var(--muted); background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.mcell.out .mchip, .mcell.out .mdots { opacity: .5; }
.mcell:hover, .mcell:active { background: var(--surface-2); }
.mnum { width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 50%; font-size: 14px; font-weight: 600; flex: none; }
.mcell.today .mnum { background: var(--primary); color: var(--primary-ink); }
.mcell.picked:not(.today) .mnum { box-shadow: inset 0 0 0 1.5px var(--primary); color: var(--primary); }
.mchips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mchip {
  display: block; padding: 1px 6px; border-radius: 6px; font-size: 12px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
  background: linear-gradient(135deg, color-mix(in srgb, var(--c, var(--primary)) 22%, var(--surface-2)), color-mix(in srgb, var(--c, var(--primary)) 8%, var(--surface-2)));
  border: 1px solid color-mix(in srgb, var(--c, var(--primary)) 60%, transparent);
}
.mchip b { font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.mchip.busy { --c: var(--busy); color: var(--muted); }
.mchip.block { --c: var(--muted); }
.mchip.cancelled, .mchip.leave { opacity: .55; text-decoration: line-through; }
.mmore { font-size: 11px; color: var(--muted); padding-left: 4px; }
.mdots { display: none; gap: 3px; flex-wrap: wrap; justify-content: center; }
.mdots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--primary)); }
.mdots i.busy { background: var(--muted); }
.mdots em { font-size: 10px; line-height: 6px; font-style: normal; color: var(--muted); }
@media (max-width: 767px) {
  .mcell { height: var(--mrow, 62px); padding: 5px 2px 6px; align-items: center; }
  .mchips { display: none; }
  .mdots { display: flex; }
  .mnum { font-size: 13px; }
}

/* 月檢視列太矮時（手機、橫放）：只顯示日期與圓點 */
.month-grid.compact .mcell { align-items: center; padding: 4px 2px; gap: 2px; }
.month-grid.compact .mchips { display: none; }
.month-grid.compact .mdots { display: flex; }

/* ── 清單檢視 ── */
.agenda { display: grid; gap: 16px; touch-action: pan-y; max-width: 820px; }
.agenda-day h3 { font-size: 14px; color: var(--muted); margin: 0 0 8px 4px; font-weight: 600; }
.agenda-day.today h3 { color: var(--primary); }

/* ── 列表卡片（學生、帳號、費用） ── */
.list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.item { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.item.tap { font: inherit; color: inherit; text-align: left; cursor: pointer; transition: transform .08s; }
.item.tap:active { transform: scale(.985); }
.item .row { display: flex; align-items: center; gap: 10px; }
.item .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--c); }
.item h3 { font-size: 17px; }
.item .meta { font-size: 13px; color: var(--muted); }
.item .btn { align-self: flex-start; margin-top: 8px; }
.item.inactive { opacity: .6; }
.group-title { font-size: 14px; color: var(--muted); margin: 18px 4px 8px; }

/* ── 費用 ── */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 4px 0 14px; }
.month-nav strong { font-size: 20px; min-width: 130px; text-align: center; }
#feesWrap { touch-action: pan-y; }
.stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── 設定 ── */
.settings { display: grid; gap: 14px; max-width: 720px; margin: 0 auto; }
.settings .card { padding: 18px; }
.settings h2 { font-size: 16px; margin-bottom: 12px; }
.export-list { display: grid; gap: 4px; justify-items: start; }
.export-list span { margin-bottom: 10px; }
.export-list .btn { justify-content: flex-start; text-decoration: none; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile > div { flex: 1; min-width: 0; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-size: 20px; font-weight: 700; flex: none; }

/* ── 對話框：手機為底部面板 ── */
dialog {
  border: 0; padding: 0; background: var(--modal-bg); color: var(--text);
  width: min(640px, 100vw - 24px); max-height: calc(100dvh - 24px); border-radius: 18px; box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--backdrop); }
.modal-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 10px 20px; border-bottom: 1px solid var(--border); position: relative; }
.modal-head h2 { font-size: 18px; margin-right: auto; }
.grab { display: none; }
.modal-body { padding: 16px 20px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-foot .left { margin-right: auto; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (max-width: 767px) {
  dialog { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; animation: sheet-up .24s cubic-bezier(.2, .9, .3, 1); }
  .modal-inner { max-height: 94dvh; }
  .modal-head { padding-top: 22px; touch-action: none; cursor: grab; }
  .grab { display: block; position: absolute; top: 8px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 99px; background: var(--border); }
  .modal-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; min-height: 50px; }
  .modal-foot .left { flex: 0 0 auto; margin: 0; }
  .modal-body { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* 課程詳情 */
.hero { border-radius: 16px; padding: 16px; background: color-mix(in srgb, var(--c, var(--primary)) 13%, var(--surface)); border-left: 5px solid var(--c, var(--primary)); margin-bottom: 14px; }
.hero .when { font-size: 14px; color: var(--muted); }
.hero .big { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.hero .sub { font-size: 14px; color: var(--muted); }
.hero .pill { margin-left: 4px; }
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 16px; }
.act {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer; transition: transform .08s;
}
.act:active { transform: scale(.95); }
.act .ico { display: grid; place-items: center; }
.act .ico .i { width: 24px; height: 24px; }
.act.ok .ico { color: var(--ok); }
.act.warn .ico { color: var(--warn); }
.act.danger { color: var(--danger); }
.act.primary .ico { color: var(--primary); }
.detail { display: grid; gap: 0; }
.detail .r { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.detail .r:last-child { border-bottom: 0; }
.detail .r > span:first-child { color: var(--muted); font-size: 13px; padding-top: 2px; }
.detail .r > span:last-child { white-space: pre-wrap; word-break: break-word; }
.conflicts { background: var(--warn-soft); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }


/* ── Toast ── */
.toast {
  position: fixed; left: 50%; top: calc(var(--top-h) + 10px); transform: translateX(-50%) translateY(-12px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); color: var(--on-strong); }

/* 很矮的螢幕（例如手機橫放）：收起說明列、縮小頂部，把高度留給課表 */
@media (max-height: 520px) {
  body.fit .levelbar, body.dayview .levelbar { display: none; }
  .topbar { padding-top: 6px; padding-bottom: 6px; }
  .cal-toolbar { margin-bottom: 6px; }
}

/* 24 小時制時間選擇 */
.tsel { display: flex; align-items: center; gap: 4px; }
.tsel select { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; text-align: center; }
.tsel b { color: var(--muted); }

/* ── 設定 → 配色 ── */
.theme-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.theme-pal { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; margin: 6px 0 14px; }
.theme-pal button { aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border); background: var(--c); cursor: pointer; padding: 0; }
.theme-pal button:active { transform: scale(.92); }
.theme-group { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 4px; }
.trow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; cursor: pointer; border: 1.5px solid transparent; }
.trow.on { border-color: var(--primary); background: var(--primary-soft); }
.trow .nm { flex: 1; min-width: 0; font-size: 14px; }
.trow .nm small { display: block; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.trow .sw { position: relative; width: 38px; height: 30px; border-radius: 8px; border: 1px solid var(--border); flex: none; overflow: hidden;
  background: linear-gradient(45deg, #ccc 25%, transparent 25% 75%, #ccc 75%) 0 0 / 10px 10px, linear-gradient(45deg, #ccc 25%, #fff 25% 75%, #ccc 75%) 5px 5px / 10px 10px; }
.trow .sw i { position: absolute; inset: 0; background: var(--c); }
.trow .sw input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.trow input[type=range] { width: 70px; flex: none; }
.trow .reset { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; visibility: hidden; }
.trow.changed .reset { visibility: visible; }
.theme-io textarea { width: 100%; min-height: 90px; font: 12px/1.4 ui-monospace, monospace; }

/* ── 點標題日期跳出的日期選擇 ── */
.dp-views { display: flex; width: 100%; margin-bottom: 12px; }
.dp-views button { flex: 1; }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-head b { font-size: 17px; font-variant-numeric: tabular-nums; }
.dp-wd, .dp-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dp-wd span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.dp-row { border-radius: 12px; margin: 2px 0; }
.dp-row button, .dp-months button { border: 0; background: transparent; color: var(--text); font: inherit; font-variant-numeric: tabular-nums; cursor: pointer; border-radius: 12px; }
.dp-row button { height: 42px; font-size: 16px; }
.dp-row button.out { color: var(--muted); opacity: .6; }
.dp-row button.today, .dp-months button.today { color: var(--primary); font-weight: 700; }
.dp-row button.on, .dp-months button.on { background: var(--primary); color: var(--primary-ink); font-weight: 700; }
.dp-row:not(.wk) button:active, .dp-months button:active { background: var(--surface-2); }
.dp-row.wk { cursor: pointer; }
.dp-row.wk:active { background: var(--surface-2); }
.dp-row.wk.on { background: var(--primary); }
.dp-row.wk.on button { color: var(--primary-ink); font-weight: 700; }
.dp-months { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dp-months button { height: 52px; font-size: 16px; }

/* 詳情裡的地點：點了直接開 Google 地圖 */
.maplink { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; word-break: break-word; }
/* 設定頁的帳號卡片 */
#usersCard .card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
#usersCard .card-head h2 { margin: 0; }
#usersCard .group-title { font-size: 14px; margin: 14px 0 6px; }
#usersCard .card.item { box-shadow: none; }

/* 清單：名字與「未付」等標籤垂直置中 */
.lcard .info b { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lcard .info b .pill { margin-left: 0; vertical-align: 0; line-height: 18px; flex: none; }
/* 配色組合 */
.theme-presets { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 6px; }
.theme-preset { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; }
.theme-preset .sw2 { display: flex; flex: none; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.theme-preset .sw2 i { width: 12px; height: 22px; background: var(--c); }
.theme-preset .nm { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 各頁面的響應式調整 ── */
/* 配色的調色盤：手機 8 欄；寬螢幕 16 欄，色塊不會大到誇張 */
@media (min-width: 600px) { .theme-pal { grid-template-columns: repeat(16, minmax(0, 1fr)); } }
/* 平板以上：設定頁兩欄（一般設定在左、配色在右），手機維持單欄 */
@media (min-width: 1024px) {
  .settings { max-width: 1120px; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); align-items: start; }
  .settings > #themeCard { grid-column: 2; grid-row: 1 / span 3; }
  .settings > .hint-line { grid-column: 1; }
}
/* 卡片列表裡的標題列：寬度不夠時，「每週二 19:00–20:30」等資訊換到下一行而不是擠在一起 */
.card.item .row { flex-wrap: wrap; row-gap: 2px; }
.card.item .row h3 { min-width: 0; }
.card.item .row .chev { margin-left: auto; }

.seg.wide3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
