:root {
  /* 皮肤：只改这两个值就能换一套配色，其余全部由主色推导 */
  --skin-accent: #4f7cff;
  --skin-tint: 5%;

  --accent: var(--skin-accent);
  --accent-soft: color-mix(in srgb, var(--skin-accent) 13%, #ffffff);
  --bg: color-mix(in srgb, var(--skin-accent) var(--skin-tint), #f2f4f9);
  --surface: #ffffff;
  --surface-2: color-mix(in srgb, var(--skin-accent) 6%, #eef1f7);
  --text: #1b1f2a;
  --muted: #7c8598;
  --line: color-mix(in srgb, var(--skin-accent) 11%, #e4e7f0);
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(20, 25, 45, 0.06), 0 8px 24px rgba(20, 25, 45, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 周课表表头吸顶时要让出的高度（手机上有固定的顶栏） */
  --sticky-top: 0px;
}

/* ---------------- 界面皮肤 ---------------- */
:root[data-skin="mint"] { --skin-accent: #0f9b8e; --skin-tint: 6%; }
:root[data-skin="amber"] { --skin-accent: #cf7106; --skin-tint: 9%; }
:root[data-skin="violet"] { --skin-accent: #7c5cff; --skin-tint: 6%; }
:root[data-skin="mono"] { --skin-accent: #5b6472; --skin-tint: 0%; }

/* ---------------- 深色变量：跟随系统（除非用户手动选了浅色） ---------------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: color-mix(in srgb, var(--skin-accent) 85%, #ffffff);
    --accent-soft: color-mix(in srgb, var(--skin-accent) 24%, #191c24);
    --bg: color-mix(in srgb, var(--skin-accent) calc(var(--skin-tint) * 0.6), #0c0e13);
    --surface: #191c24;
    --surface-2: color-mix(in srgb, var(--skin-accent) 11%, #20242e);
    --text: #e7eaf2;
    --muted: #8b94a8;
    --line: color-mix(in srgb, var(--skin-accent) 15%, #2a2f3b);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

/* 手动强制深色 */
:root[data-theme="dark"] {
  --accent: color-mix(in srgb, var(--skin-accent) 85%, #ffffff);
  --accent-soft: color-mix(in srgb, var(--skin-accent) 24%, #191c24);
  --bg: color-mix(in srgb, var(--skin-accent) calc(var(--skin-tint) * 0.6), #0c0e13);
  --surface: #191c24;
  --surface-2: color-mix(in srgb, var(--skin-accent) 11%, #20242e);
  --text: #e7eaf2;
  --muted: #8b94a8;
  --line: color-mix(in srgb, var(--skin-accent) 15%, #2a2f3b);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

/* 必须放在这里：.sheet / .toast 等元素自身设了 display，
   会覆盖浏览器对 hidden 属性的 display:none，导致它们"隐藏"了仍占位/可见。 */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin: 6px 0; min-height: 18px; }

/* ---------------- 登录 / 注册 ---------------- */

.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }

.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 22px;
  box-shadow: var(--shadow);
}

.auth-brand { font-size: 22px; font-weight: 700; }
.auth-sub { margin: 4px 0 0; }

.auth-tabs {
  display: flex;
  gap: 4px;
  margin: 18px 0 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 10px;
}
.auth-tab {
  flex: 1;
  padding: 7px 0;
  border-radius: 8px;
  font-size: 14px;
  color: var(--muted);
}
.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(20, 25, 45, 0.1);
}

.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 500;
}
.btn-primary {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.6; }
.btn-ghost { background: transparent; }
.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 0 4px;
}
.btn-row .btn { flex: 1; }
.btn-row .btn-primary { margin-top: 0; }

/* ---------------- 外壳 ---------------- */

.app-shell { min-height: 100dvh; }

.layout {
  display: flex;
  min-height: 100dvh;
  max-width: 1240px;
  margin: 0 auto;
}

.main-col {
  flex: 1;
  min-width: 0;
  padding: 0 16px calc(26px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}
/* 内容不足一屏时，把页脚压到底部 */
.main-col > #main { flex: 1; min-width: 0; }

/* ---------------- 侧边栏 ---------------- */

.sidebar {
  width: 196px;
  flex: 0 0 196px;
  padding: 18px 10px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  padding: 4px 10px 16px;
}
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); flex: 0 0 auto; }
/* 用户名可能很长，超长时省略而不是把侧边栏撑开 */
.brand-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }

/* 侧边栏搜索入口 */
.side-search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 4px 0 10px;
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}
.side-search:hover { color: var(--text); }
.side-search-kbd {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.side-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  text-align: left;
}
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.side-label { flex: 1; min-width: 0; }

/* 用 CSS 三角形画箭头，不依赖字体字形（▸ 在部分字体里几乎看不见） */
.side-chevron {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  margin-left: 4px;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}
.side-chevron.open { transform: rotate(90deg); }

.side-sub {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 2px 14px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
}
.side-sub .side-item { font-size: 13px; padding: 8px 10px; }

.side-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  flex: 0 0 auto;
}

.side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.mobile-bar { display: none; }
.side-backdrop { display: none; }

.icon-btn { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 13px; }
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 720px) {
  /* --sticky-top 由 app.js 按顶部栏实际高度动态设置（不同宽度高度不同） */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 70;
    width: 230px;
    flex-basis: 230px;
    background: var(--surface);
    box-shadow: 4px 0 24px rgba(10, 14, 30, 0.16);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 4px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg);
  }
  .mobile-title { font-weight: 600; font-size: 16px; }

  .side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(10, 12, 20, 0.42);
  }
}

/* ---------------- 月视图 ---------------- */

.monthbar { display: flex; align-items: center; gap: 8px; padding: 6px 4px 12px; flex-wrap: wrap; }
.month-title { font-size: 19px; }
.nav-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 18px;
  line-height: 1;
}
.monthbar .btn-ghost { margin-left: auto; }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 6px; }
.weekday { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }

.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.cell {
  display: flex;
  flex-direction: column;
  text-align: left;
  min-height: 92px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  transition: border-color 0.15s, transform 0.1s;
  overflow: hidden;
}
.cell:active { transform: scale(0.985); }
.cell.other { opacity: 0.42; }
.cell.today { border-color: var(--accent); }

.cell-num { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cell.today .cell-num { color: var(--accent); }

.chips { display: flex; flex-direction: column; gap: 2px; }
.chip {
  font-size: 11px;
  line-height: 1.35;
  padding: 1px 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  color: var(--c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.more { font-size: 11px; color: var(--muted); padding-left: 3px; }

.dot-row { display: none; gap: 3px; margin-top: auto; padding-top: 4px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--c); display: block; }

@media (max-width: 640px) {
  .main-col { padding: 0 8px calc(20px + var(--safe-bottom)); }
  .grid { gap: 4px; }
  .cell { min-height: 62px; padding: 4px; border-radius: 10px; }
  .cell .chips { display: none; }
  .cell .dot-row { display: flex; }
  .month-title { font-size: 17px; }
  .weekday { font-size: 11px; }
}

/* ---------------- 抽屉 / 编辑器 ---------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.42);
  opacity: 0;
  transition: opacity 0.18s;
  z-index: 40;
}
.backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  z-index: 50;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding-bottom: calc(12px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(10, 14, 30, 0.18);
}
.sheet.open { transform: translateY(0); }

@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: 24px;
    width: 440px;
    transform: translate(-50%, 120%);
    border-radius: 18px;
  }
  .sheet.open { transform: translate(-50%, 0); }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet-head-main { flex: 1; min-width: 0; }
.sheet-date { font-size: 16px; font-weight: 600; }
.sheet-head .icon-btn { margin-left: 0; font-size: 16px; }
.sheet-head .icon-btn:last-child { margin-left: auto; }

.sheet-body {
  overflow: auto;
  padding: 12px 18px 4px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sheet-foot { padding: 10px 18px 4px; border-top: 1px solid var(--line); }
.sheet-foot .btn-primary { margin-top: 0; }

.item {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 11px 0;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item:active { opacity: 0.7; }
.item[data-disabled] { cursor: default; }

.item-time {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.item-main { flex: 1; min-width: 0; display: block; }
.item-title { display: flex; align-items: center; gap: 6px; font-weight: 600; flex-wrap: wrap; }
.item-title::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--c);
  flex: 0 0 auto;
}
.item-loc, .item-note {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-word;
}
.badge {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
}

/* ---------------- 表单 ---------------- */

.form { display: flex; flex-direction: column; }

.form-row { display: block; padding: 9px 0; border-bottom: 1px solid var(--line); }
.form-row:last-of-type { border-bottom: 0; }
.form-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

.form-row-inline { display: flex; align-items: center; justify-content: space-between; }
.form-row-inline .form-label { margin-bottom: 0; }

.input {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 54px; }

.form-times { display: flex; align-items: center; gap: 8px; }
.form-times .input { flex: 1; }

.switch { position: relative; display: inline-flex; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.16s;
  position: relative;
  display: block;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }

.color-dots { display: flex; gap: 10px; }
.color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.45;
  border: 2px solid transparent;
  transition: opacity 0.15s, border-color 0.15s;
}
.color-dot.active { opacity: 1; border-color: var(--text); }

/* ---------------- 其他 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  z-index: 60;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(22, 26, 38, 0.92);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 有新版本时的提示条（部署后长时间开着的页面用） */
.update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 61;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 16px;
  border-radius: 999px;
  background: rgba(22, 26, 38, 0.94);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(10, 14, 30, 0.3);
}
.update-banner button {
  padding: 5px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* 下拉刷新指示条：默认藏在屏幕上方，下拉时跟着手指下来 */
.ptr {
  position: fixed;
  top: 0;
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(20, 25, 45, 0.12);
  transform: translate(-50%, -100%);
  transition: transform 0.2s ease;
  pointer-events: none;
}
.ptr.pulling { transition: none; }
.ptr.ready { color: var(--accent); }
.ptr-icon {
  display: inline-block;
  font-size: 14px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.ptr.ready .ptr-icon { transform: translateY(-1px); }
.ptr.loading .ptr-icon { animation: ptr-spin 0.9s linear infinite; }

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

.empty { text-align: center; padding: 26px 0; }
.placeholder { text-align: center; padding: 60px 20px; }

/* ---------------- 周课表 ---------------- */

.week-range { margin-left: 4px; font-size: 13px; }

.week-scroll {
  margin-top: 4px;
}

/* 只在窄屏才允许横向滚动：桌面端 1fr 有亚像素误差，
   一旦开了 overflow 就会冒出一条多余的滚动条 */
@media (max-width: 640px) {
  .week-scroll {
    /* 横向要滚动；一旦设了 overflow，这个容器就成了"最近的滚动祖先"，
       position: sticky 会相对它而不是页面，所以这里让它在竖向也滚，
       并给个高度上限 —— 这样表头在那个框里吸顶，翻看时始终可见。 */
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100dvh - 210px);
    padding-bottom: 2px;
    --sticky-top: 0px;   /* 在容器内部吸顶，不需要再让开顶部栏 */
  }
}

.week-grid {
  display: grid;
  grid-template-columns: 52px repeat(7, minmax(0, 1fr));
  grid-template-rows: 30px;   /* 表头行 */
  grid-auto-rows: 56px;       /* 之后每节一行 */
  gap: 3px;
}

.wg-head {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 2px;
}

/* 表头吸顶：往下翻时「周一到周日」始终可见；左上角同时要吸顶吸左 */
.wg-head,
.wg-corner {
  position: sticky;
  top: var(--sticky-top, 0px);
  z-index: 5;
  background: var(--bg);
}
.wg-corner { left: 0; z-index: 6; }

/* 今天：表头高亮 + 整列淡底色 */
.wg-head.is-today {
  color: var(--accent);
  font-weight: 700;
}
.wg-head.is-today::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 20px;
  height: 2px;
  margin-left: -10px;
  border-radius: 2px;
  background: var(--accent);
}
.wg-cell.is-today {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 25%, var(--line));
}

.wg-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}
.wg-time b { font-size: 12px; color: var(--text); font-weight: 600; }

.wg-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 0;
}
.wg-cell:hover { border-color: var(--accent); }

.wg-block {
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-start;
  text-align: left;
  padding: 4px 6px 4px 7px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--c) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 28%, transparent);
  border-left: 3px solid var(--c);
  overflow: hidden;
}
.wg-block:active { transform: scale(0.99); }
.wg-block-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--c);
  line-height: 1.25;
  word-break: break-all;
}
.wg-block-meta {
  font-size: 10px;
  line-height: 1.3;
  color: var(--muted);
  word-break: break-all;
  overflow: hidden;
}

.week-events { margin-top: 22px; }
.week-events-title { font-size: 14px; margin-bottom: 6px; }

.week-event {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 4px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.week-event-day { font-size: 12px; color: var(--muted); width: 44px; flex: 0 0 auto; }
.week-event-time { font-size: 12px; color: var(--muted); width: 92px; flex: 0 0 auto; }
.week-event-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.week-event-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------------- 设置 ---------------- */

.settings { display: flex; flex-direction: column; gap: 14px; padding-bottom: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card .muted { font-size: 13px; margin: 0 0 10px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .input { flex: 1; min-width: 140px; }
.row .btn { flex: 0 0 auto; }
.row .btn-primary { width: auto; margin-top: 0; }

.periods { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.period-row { display: flex; align-items: center; gap: 6px; }
.period-seq { font-size: 12px; color: var(--muted); width: 52px; flex: 0 0 auto; }
.period-row .input { flex: 1; min-width: 0; }

@media (max-width: 640px) {
  .week-grid {
    grid-template-columns: 38px repeat(7, minmax(0, 1fr));
    grid-auto-rows: 50px;
    gap: 2px;
    min-width: 560px;   /* 窄屏改为横向滚动，别把格子压扁 */
  }
  .wg-block-name { font-size: 10px; }
  /* 窄屏格子只有 ~72px 宽，老师+教室放不下就限制两行，点开可看完整信息 */
  .wg-block-meta {
    font-size: 9px;
    line-height: 12px;
    max-height: 24px;
  }
  .week-event-time { width: 72px; }

  /* 横向滚动时把「节次 / 时间」列钉在左边，否则翻页就看不见时间了。
     必须是实色背景，否则后面的格子会透过来；z-index 要高过课程块。 */
  .wg-corner,
  .wg-time {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg);
    box-shadow: 5px 0 6px -5px rgba(10, 14, 30, 0.22);
  }
}

/* ---------------- 手机端细节 ---------------- */

@media (max-width: 640px) {
  /* 输入框至少 16px，否则 iOS 聚焦时会自动放大整个页面 */
  .input,
  .field input,
  textarea,
  select {
    font-size: 16px;
  }

  .nav-btn { width: 38px; height: 38px; }
  .icon-btn { padding: 10px 12px; }
  .item { padding: 13px 0; }
  .week-event { padding: 12px 4px; }

  /* 抽屉顶部的下滑指示条 */
  .sheet::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
  }
  .sheet-head { padding-top: 20px; }
}

/* ---------------- 列表页通用 ---------------- */

.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 4px 14px;
}
.page-head h2 { font-size: 20px; }
.page-head .muted { font-size: 13px; }

.btn-inline { width: auto; margin: 0 0 0 auto; padding: 8px 14px; }

/* 工具条里的主按钮：不要 .btn-primary 的 100% 宽和上外边距 */
.btn-bar { width: auto; margin: 0; padding: 8px 14px; }

/* ---------------- 待办 / 作业 / 竞赛 ---------------- */

.task-list { display: flex; flex-direction: column; gap: 6px; }

.task {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.task:hover { border-color: var(--accent); }
.task.is-done { opacity: 0.55; }

.task-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  position: relative;
}
.task-check.on { background: var(--accent); border-color: var(--accent); }
.task-check.on::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
}

.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; word-break: break-word; }
.task.is-done .task-title { text-decoration: line-through; }
.task-meta { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }

.task-badge {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.u-overdue { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.u-urgent { background: rgba(242, 153, 74, 0.18); color: #c9761d; }
.u-soon { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.u-normal, .u-none, .u-done { background: var(--surface-2); color: var(--muted); }

.task-done-head { padding: 18px 4px 8px; }
.link-btn { color: var(--accent); font-size: 13px; padding: 4px 0; }
.task-list-done .task { opacity: 0.55; }

/* ---------------- 主页 / 可拖拽组件 ---------------- */

.widget-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 74px;
  gap: 12px;
  padding: 4px 0 8px;
}

.widget {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* iOS 风格的三种尺寸 */
.widget[data-size="sm"] { grid-column: span 1; grid-row: span 2; }
.widget[data-size="md"] { grid-column: span 2; grid-row: span 2; }
.widget[data-size="lg"] { grid-column: span 2; grid-row: span 4; }

/* 整卡可点击跳转的组件（如「待办」→ 待办页） */
.widget[data-open-view] {
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.widget[data-open-view]:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(20, 25, 45, 0.08);
}
.widget[data-open-view]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.widget[data-open-view] .widget-title::after {
  content: ' ›';
  color: var(--muted);
}

.widget[data-size="sm"] .weather-temp { font-size: 26px; }
.widget[data-size="sm"] .weather-sub,
.widget[data-size="sm"] .weather-clock { display: none; }
.widget[data-size="sm"] .widget-title { font-size: 12px; }

/* 编辑模式：宽度仍按尺寸（sm 1 列 / md·lg 2 列），但高度改为跟随内容。
   否则固定行高会把组件的配置表单（如倒计时的日期框）裁掉，导致改不了。
   注意 home-editing 类加在 .widget-grid 自身上，所以这里不能用后代选择器。 */
.widget-grid.home-editing { grid-auto-rows: auto; }
.home-editing .widget[data-size] { grid-row: auto; }
.home-editing .widget { min-height: 120px; }
.home-editing .widget-body { max-height: none; overflow: visible; }

.widget-sizes { display: none; gap: 4px; }
.home-editing .widget-sizes { display: flex; }

.size-btn {
  flex: 1;
  padding: 4px 0;
  font-size: 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.size-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  font-weight: 600;
}
.home-editing .widget {
  border-style: dashed;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
.widget.dragging { opacity: 0.3; }

.widget-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(10, 14, 30, 0.22);
}

.widget-head { display: flex; align-items: center; gap: 6px; }
.widget-title { flex: 1; font-size: 13px; color: var(--muted); }

.widget-remove,
.widget-handle { display: none; }

.home-editing .widget-remove,
.home-editing .widget-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.widget-remove {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.widget-handle {
  width: 26px;
  height: 22px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;   /* 关键：手柄上禁用滚动，否则手机上拖不动 */
}
.widget-handle:active { cursor: grabbing; }

.widget-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* 天气组件 */
.weather-main { display: flex; align-items: baseline; gap: 10px; }
.weather-temp { font-size: 34px; font-weight: 300; line-height: 1; letter-spacing: -0.02em; }
.weather-desc { font-size: 15px; font-weight: 600; }
.weather-sub { font-size: 12px; color: var(--muted); }
.widget-dot { margin: 0 4px; opacity: 0.5; }

.weather-day {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
}
.weather-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: color-mix(in srgb, #f5a623 18%, transparent);
  color: #c07c12;
}
.weather-tag.is-night {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}
.weather-range { font-weight: 600; }
.weather-precip { color: var(--muted); }
.weather-clock { font-size: 11px; margin-top: auto; }

.widget-city { display: flex; gap: 6px; }
.widget-city .input { flex: 1; min-width: 0; padding: 6px 9px; font-size: 13px; }

/* 组件内列表 */
.widget-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.widget-li { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.widget-li-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.widget-li-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.widget-li-badge { flex: 0 0 auto; font-size: 10px; padding: 1px 6px; border-radius: 999px; }

/* 添加组件面板 */
.widget-add {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 12px;
  font-size: 13px;
}
.btn-small { padding: 6px 12px; font-size: 13px; }

/* 更新日志 */
.changelog { display: flex; flex-direction: column; gap: 16px; }
.log-entry { border-left: 2px solid var(--line); padding-left: 12px; }
.log-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.log-version { font-size: 12px; font-weight: 700; color: var(--accent); }
.log-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-title { font-size: 13px; font-weight: 600; }
.log-items {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.75;
}

/* 更早的更新：默认折叠 */
.log-older { display: flex; flex-direction: column; gap: 16px; }

.log-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 0;
  border-radius: 9px;
  border: 1px dashed var(--line);
  font-size: 13px;
  color: var(--muted);
}
.log-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}
/* 用 CSS 三角形画箭头，不依赖字体字形 */
.log-toggle-arrow {
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}
.log-toggle-arrow.open { transform: rotate(90deg); }

@media (max-width: 640px) {
  .widget-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: 68px;
  }
  .widget { grid-column: 1 / -1 !important; }
  .widget[data-size="sm"],
  .widget[data-size="md"] { grid-row: span 2; }
  .widget[data-size="lg"] { grid-row: span 4; }
  .weather-temp { font-size: 30px; }
}

/* ---------------- 今日课程组件 ---------------- */

.widget-sub { font-size: 12px; color: var(--muted); }

.class-next { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.class-next-label {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.class-next.is-ongoing .class-next-label {
  background: color-mix(in srgb, #2ea043 18%, transparent);
  color: #2ea043;
}
.class-next-name {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.class-next-time {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.class-done { font-size: 15px; font-weight: 600; color: var(--muted); }
.class-rest { margin-top: 2px; padding-top: 8px; border-top: 1px solid var(--line); }
.widget-li-meta { flex: 0 0 auto; font-size: 11px; color: var(--muted); }

/* ---------------- 重点待办组件 ---------------- */

.pinned-main {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 0;
  text-align: left;
}
.pinned-badge { flex: 0 0 auto; }
.pinned-title {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}
.pinned-note {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
}

/* ---------------- 快捷记录组件 ---------------- */

.quick-add { display: flex; gap: 6px; align-items: center; }
.quick-add .input { flex: 1; min-width: 0; padding: 7px 10px; font-size: 13px; }
.quick-kind {
  flex: 0 0 auto;
  width: auto;
  padding: 7px 6px;
  font-size: 13px;
}

/* ---------------- 倒计时组件 ---------------- */

.countdown { display: flex; align-items: baseline; gap: 6px; }
.countdown-num {
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.02em;
}
.countdown-num.is-past { color: var(--muted); }
.countdown-unit { font-size: 14px; color: var(--muted); }
.countdown-edit { display: flex; flex-direction: column; gap: 6px; }
.countdown-edit .input { padding: 6px 9px; font-size: 13px; }

/* ---------------- 主题 / 皮肤切换 ---------------- */

.theme-switch { display: flex; gap: 6px; margin-top: 8px; }
.theme-btn {
  flex: 1;
  padding: 8px 0;
  border-radius: 9px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.theme-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

.skin-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.skin-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 9px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.skin-btn.active {
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}
.skin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

/* ---------------- 全局搜索 ---------------- */

.search-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(10, 14, 30, 0.42);
  backdrop-filter: blur(2px);
}

.search-panel {
  position: fixed;
  z-index: 1201;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 24px));
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(10, 14, 30, 0.32);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.search-icon { font-size: 13px; opacity: 0.7; }
.search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}
.search-esc {
  font-size: 11px;
  color: var(--muted);
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.search-results { overflow-y: auto; padding: 8px; }
.search-hint { margin: 20px 8px; text-align: center; font-size: 13px; }
.search-group { margin-bottom: 10px; }
.search-group-title {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 8px 4px;
  letter-spacing: 0.04em;
}
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  text-align: left;
}
.search-item:hover { background: var(--surface-2); }
.search-item-type {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}
.search-item-body { display: flex; flex-direction: column; min-width: 0; }
.search-item-title {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-item-meta { font-size: 12px; color: var(--muted); }

@media (max-width: 640px) {
  .search-panel { top: 6vh; max-height: 80vh; }
}

/* ---------------- 页脚（赞赏 + 备案号） ---------------- */

.site-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 28px;
  padding: 18px 0 6px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.foot-reward {
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}
.foot-reward:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.foot-icp {
  color: var(--muted);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.foot-icp:hover {
  color: var(--text);
  text-decoration: underline;
}

/* 赞赏弹窗 */
.reward-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.reward-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 18, 0.72);
  backdrop-filter: blur(3px);
}
.reward-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px;
  max-width: min(92vw, 460px);
  max-height: 88vh;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.reward-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(88vh - 90px);
  object-fit: contain;
  border-radius: 12px;
}
.reward-caption { font-size: 13px; color: var(--muted); }
.reward-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: var(--shadow);
}
.reward-close:hover { color: var(--text); }
