:root {
  color-scheme: light dark;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1f6feb;
  --primary-hover: #1a5fd0;
  --danger: #d93025;
  --ok: #1a7f37;
  --shadow: 0 8px 28px rgba(0, 0, 0, .08);

  /* Android 应用的配色 */
  --android-orange: #ff8800;
  --android-red: #f44336;
  --android-cyan: #00bcd4;
  --dim-text: #757575;

  /* 天数数字至少是考试名称字号的 3 倍 */
  --exam-name-size: 15px;
  --exam-days-size: 48px;
  --home-name-size: 16px;
  --home-days-size: 52px;
}

@media (max-width: 520px) {
  :root {
    --exam-name-size: 13px;
    --exam-days-size: 40px;
    --home-name-size: 14px;
    --home-days-size: 44px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --card: #1c2027;
    --text: #e6e8eb;
    --muted: #9ca3af;
    --line: #2d323b;
    --primary: #58a6ff;
    --primary-hover: #79b8ff;
    --danger: #f85149;
    --ok: #3fb950;
    --shadow: 0 8px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

.topbar, main, .tabs {
  max-width: 860px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding-top: calc(28px + env(safe-area-inset-top));
  padding-bottom: 16px;
  flex-wrap: wrap;
}

.topbar-tools { display: flex; align-items: end; gap: 16px; flex-wrap: wrap; }

h1 { margin: 0; font-size: 26px; letter-spacing: .5px; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* 顶部极轻量账号入口 */
.account-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  min-height: 32px;
}
.account-chip a { color: var(--primary); text-decoration: none; }
.account-chip a:hover { text-decoration: underline; }
.account-chip .dot { opacity: .5; }
.account-email {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.chip-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.chip-btn:hover { color: var(--text); border-color: var(--primary); }

.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 15px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--line);
  color: var(--text);
  font-size: 11px;
  text-align: center;
}

main { padding-top: 18px; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.filters, .section-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.filters select, .filters input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
}
.section-head { justify-content: space-between; }
.section-head h2 { margin: 0; font-size: 18px; }
.page-title { margin: 16px 0 10px; font-size: 20px; color: var(--text); }

button.primary, button.secondary, .filters button,
a.inline-link {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
}
button.primary, a.primary { background: var(--primary); color: #fff; }
button.primary:hover, a.primary:hover { background: var(--primary-hover); }
button.secondary, a.secondary { background: var(--card); color: var(--text); border-color: var(--line); }
button.secondary:hover, a.secondary:hover { border-color: var(--primary); }
button:disabled { cursor: default; opacity: .6; }

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

/* ---- 列表分组标题 ---- */
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 20px 0 6px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--line);
  font-size: 14px;
  font-weight: 600;
}
.group-title:first-child { margin-top: 4px; }
.group-upcoming { color: var(--primary); }
.group-finished { color: var(--muted); }
.group-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  text-align: center;
}
.year-title {
  margin: 14px 0 4px;
  padding-left: 10px;
  border-left: 3px solid var(--android-orange);
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* ---- 所有考试：卡片头部 + 日期/时段/时间/科目表格 ---- */
.exam-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
  margin-bottom: 14px;
  overflow: hidden;
}
.exam-card-head {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(255, 136, 0, .10), transparent 45%);
}
.exam-card-title { min-width: 0; }
.exam-card-title h3 {
  margin: 0;
  font-size: var(--exam-name-size);
  line-height: 1.35;
  word-break: break-word;
}
.exam-card-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.exam-card-days { text-align: center; min-width: 84px; }
.exam-card-days strong {
  display: block;
  font-size: var(--exam-days-size);
  font-weight: 700;
  line-height: 1;
}
.exam-card-days span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.days-soon { color: var(--android-red); }
.days-done { color: var(--dim-text); }

.schedule-wrap { overflow-x: auto; }
.schedule-mobile { display: none; }
.schedule-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 13px;
}
.schedule-table th {
  padding: 7px 12px;
  background: rgba(255, 136, 0, .08);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.schedule-table td {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.exam-name-cell {
  width: 190px;
  font-size: var(--exam-name-size);
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
  border-right: 1px solid var(--line);
}
.schedule-date {
  width: 88px;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  background: rgba(0, 0, 0, .015);
}
.schedule-weekday {
  width: 52px;
  color: var(--muted);
  white-space: nowrap;
  background: rgba(0, 0, 0, .015);
}
.schedule-period { width: 88px; }
.schedule-time-cell { width: 140px; }
.time-list {
  display: block;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
  white-space: nowrap;
}
.schedule-subject { line-height: 1.9; }
.period-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.period-morning { background: rgba(255, 136, 0, .16); color: #b35c00; }
.period-afternoon { background: rgba(31, 111, 235, .14); color: var(--primary); }
.period-evening { background: rgba(142, 68, 173, .14); color: #8e44ad; }
.period-allday { background: var(--line); color: var(--muted); }
.subject-empty { color: var(--muted); }
.schedule-empty { padding: 18px 16px; color: var(--muted); font-size: 13px; text-align: center; }

.local-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--line);
  color: var(--muted);
  font-size: 10px;
  vertical-align: middle;
}

/* Android SwitchCompat 风格开关 */
.switch { position: relative; display: inline-block; width: 34px; height: 18px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #b8bcc4;
  border-radius: 18px;
  transition: background .18s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform .18s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(31, 111, 235, .25); }

/* ---- 首页：Android 的「距离 … 考试还有 N 天」 ---- */
.home-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 68px 110px 36px;
  align-items: center;
  min-height: 78px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  text-align: center;
}
.home-to, .home-label { color: var(--dim-text); font-size: 13px; }
.home-name { font-size: var(--home-name-size); color: var(--text); word-break: break-all; }
.home-detail {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.3;
}
.home-days { color: var(--android-red); font-size: var(--home-days-size); font-weight: 700; line-height: 1; }
.home-days.done { color: var(--dim-text); }
.home-unit { color: var(--android-cyan); font-size: var(--home-days-size); line-height: 1; }

.fab {
  position: fixed;
  right: max(24px, calc((100vw - 860px) / 2 + 24px));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .24);
}
.fab:hover { background: var(--primary-hover); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  white-space: nowrap;
}
.tag-admin { background: rgba(217, 48, 37, .12); color: var(--danger); margin-left: 6px; }

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.empty p { margin: 0; }

/* ---- 独立登录/注册页 ---- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-shell, .admin-shell { width: min(440px, 100%); }
.admin-shell { width: min(860px, 100%); align-self: flex-start; }
.admin-select {
  width: 100%;
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  margin-bottom: 18px;
}
.session-row-head, .session-row {
  display: grid;
  grid-template-columns: 140px 80px 100px 100px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}
.session-row-head {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}
.session-row { margin-bottom: 8px; }
.session-row input, .session-row select {
  width: 100%;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.session-remove { font-size: 18px; line-height: 1; padding: 4px; }
.admin-actions { display: flex; gap: 10px; margin: 16px 0 10px; }
@media (max-width: 760px) {
  .session-row-head { display: none; }
  .session-row { grid-template-columns: 1fr 1fr 34px; }
  .session-row input[data-field="subject"] { grid-column: 1 / 3; }
  .session-row input[data-field="date"] { grid-column: 1 / 2; }
}
.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--primary); }
.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card-head { margin-bottom: 22px; }
.auth-card-head h1 { font-size: 24px; margin: 0 0 6px; }
.auth-card-head p { margin: 0; color: var(--muted); font-size: 14px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 600; }
.field > span em { font-style: normal; font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }
.field-error { color: var(--danger); font-size: 12px; }
.form-error {
  color: var(--danger);
  font-size: 13px;
  padding: 9px 11px;
  background: rgba(217,48,37,.08);
  border-radius: 8px;
  margin: 0 0 16px;
}
button.block { width: 100%; padding: 11px; font-size: 15px; font-weight: 600; }

.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.oauth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.oauth-btn {
  display: block;
  text-align: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.oauth-btn:hover { border-color: var(--primary); color: var(--primary); }
.auth-switch { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast[hidden] { display: none; }
.toast-success { background: var(--ok); }
.toast-error { background: var(--danger); }

@media (max-width: 520px) {
  .topbar { padding-top: 18px; }
  h1 { font-size: 22px; }
  .filters { flex-wrap: wrap; }
  .filters select { flex-basis: 100%; }
  .topbar-tools { width: 100%; justify-content: space-between; }
  .account-email { max-width: 120px; }
  .exam-card-head { grid-template-columns: 30px minmax(0, 1fr) 72px; gap: 8px; padding: 12px; }
  .exam-card-days { min-width: 68px; }
  .home-row { grid-template-columns: 30px minmax(0, 1fr) 52px 92px 32px; min-height: 68px; }
  .oauth-grid { grid-template-columns: 1fr 1fr; }
  .auth-card { padding: 22px 18px; }
}

/* ---- 手机 / PWA：自适应布局，表格改为无横向滚动的信息卡 ---- */
@media (max-width: 680px) {
  .auth-page {
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    padding-top: 8px;
    padding-bottom: 8px;
    background: var(--bg);
  }
  .tab { padding: 10px 12px; font-size: 14px; }

  .filters { gap: 8px; }
  .filters select, .filters input[type="search"], .filters button { min-height: 44px; }
  .filters select, .filters input[type="search"],
  .field input, .admin-select, .session-row input, .session-row select { font-size: 16px; }

  .exam-card-head { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .schedule-desktop { display: none; }
  .schedule-mobile { display: block; }
  .mobile-session { padding: 12px 14px; border-top: 1px solid var(--line); }
  .mobile-session:first-child { border-top: 0; }
  .mobile-session-name {
    margin-bottom: 8px;
    font-size: var(--exam-name-size);
    font-weight: 600;
    line-height: 1.4;
  }
  .mobile-session-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .mobile-session-grid > div, .mobile-time-subject > div { min-width: 0; }
  .mobile-session-grid > div > span:first-child,
  .mobile-time-subject > div > span:first-child {
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.4;
  }
  .mobile-session-grid strong, .mobile-time-subject strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.7;
  }
  .mobile-time-subject {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
  }
  .mobile-times strong { font-variant-numeric: tabular-nums; }
  .mobile-session-grid .period-badge { margin-top: 1px; }
  .mobile-subjects > div { font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }

  .home-row {
    grid-template-columns: 28px minmax(0, 1fr) 44px 76px 28px;
    gap: 5px;
    margin-bottom: 10px;
    padding: 10px 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
  }
  .home-to, .home-label, .home-unit { font-size: 11px; }

  .switch { width: 40px; height: 24px; }
  .slider::before { width: 20px; height: 20px; }
  .switch input:checked + .slider::before { transform: translateX(16px); }
  .fab {
    right: max(16px, calc((100vw - 860px) / 2 + 16px));
    width: 48px;
    height: 48px;
    font-size: 26px;
  }
}

@media (max-width: 380px) {
  .mobile-session-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
