/* ==========================================================================
   课表随心配 · 网页版样式

   三条硬约束（都是 iOS Safari 的坑，别改）：
   1. 高度用 `dvh` 不用 `vh` —— Safari 地址栏收放会让 `100vh` 算错。
   2. 四周留 `env(safe-area-inset-*)` —— 添加到主屏幕后内容会顶到刘海。
   3. 输入框字号 ≥16px —— 否则 iOS 会自动放大整页。

   适配策略：移动优先，向上加两个断点
   - 手机  < 720px   铺满
   - 平板  720–1099  限宽 900、格子加大
   - 桌面 ≥1100      限宽 1100、格子再加大、可鼠标悬停
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #eef0f4;
  --text: #1b1d21;
  --text-dim: #6b7280;
  --border: rgba(0, 0, 0, 0.08);
  --accent: #3d5afe;
  --accent-2: #7c4dff;
  --danger: #d93025;
  --radius: 12px;
  --row-min: 36px;
  /* 节次栏宽度。手机压到最窄，把宽度全让给 7 天 */
  --period-col: 34px;
  /* 内容最大宽度：手机上铺满，大屏上居中 */
  --max-width: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-alt: #272b33;
    --text: #e8eaed;
    --text-dim: #9aa0a6;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #7b93ff;
    --accent-2: #a78bfa;
  }
}

/* 课程配色：与 Android 版一致的 12 色 */
:root {
  --c0: #3d5afe; --c1: #00897b; --c2: #e65100; --c3: #8e24aa;
  --c4: #c62828; --c5: #0277bd; --c6: #2e7d32; --c7: #6d4c41;
  --c8: #ad1457; --c9: #455a64; --c10: #f9a825; --c11: #5e35b1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
}

/* ------------------------------------------------------------------ 顶栏 */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  min-height: var(--head-height);
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex: none;
}

.topbar__title { font-size: 17px; font-weight: 600; }

.topbar__actions { display: flex; gap: 4px; flex: none; }

.iconbtn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
}

/* 编辑模式打开时把顶栏按钮标出来，否则用户不知道自己在编辑态 */
.iconbtn.is-on {
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

/* -------------------------------------------------------- 视图切换（分段） */

.segmented {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex: none;
}

.segmented__item {
  flex: 1;
  border: none;
  background: var(--surface-alt);
  color: var(--text-dim);
  font-size: 15px;
  padding: 9px 0;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
}

.segmented__item.is-active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ------------------------------------------------------------------ 内容 */

.content {
  flex: 1;
  min-height: 0;           /* 关键：不加这行，flex 子项不会收缩，内部滚动失效 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ============================================================== 主界面大卡片

   安卓版有一样的做法：核心入口必须放在主界面顶部，不能埋进设置页
   （老板原话「没有看到」）。这里常驻一张卡，把两件最重要的事摆在最显眼处。 */

.hero {
  margin: 14px 16px 2px;
  border-radius: 16px;
  padding: 18px 18px 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  flex: none;
}

.hero__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hero__title { font-size: 18px; font-weight: 600; line-height: 1.35; }

.hero__sub {
  font-size: 13px;
  opacity: 0.92;
  margin-top: 5px;
  line-height: 1.55;
}

.hero__close {
  border: none;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}

.hero__actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.hero__btn {
  flex: 1;
  min-height: 62px;
  background: rgba(255, 255, 255, 0.20);
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 13px;
  padding: 11px 10px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.hero__btn:active { background: rgba(255, 255, 255, 0.32); }

.hero__btn small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.88;
}

.hero__note {
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.6;
  opacity: 0.92;
}

/* ------------------------------------------------------------------ 周视图 */

/* ⚠️ 表头行与网格行必须放在同一个横向滚动容器里，
   各挂一个会出现「两个滚动轴互相观察」导致的齿轮式卡顿。 */
.week__scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  padding: 10px 0 16px;
}

.week__grid {
  display: grid;
  /* ⚠️ 7 列**强制均分**（minmax(0, 1fr)），不设最小列宽。
     设了下限的话，7×下限 + 节次栏会超出手机宽度，
     右边几天（周五~周日）就被挤出屏幕了 —— 而安卓版的硬要求是「一整周一屏放下」。 */
  grid-template-columns: var(--period-col) repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  margin: 0 8px;
  border-radius: 10px;
  overflow: hidden;
}

.week__corner,
.week__head {
  background: var(--surface);
  padding: 6px 2px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.35;
}

.week__head.is-today {
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.week__period {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
}

.week__slot {
  background: var(--surface);
  position: relative;
  min-height: var(--row-min);
  cursor: pointer;
}

.week__slot.is-today { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }

.course {
  position: absolute;
  inset: 1px;
  border-radius: 6px;
  padding: 3px 4px;
  color: #fff;
  font-size: 11px;
  line-height: 1.25;
  overflow: hidden;             /* 放不下时靠字号逐档缩小，不截断文字 */
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  word-break: break-word;
}

.course__name { font-weight: 600; }
.course__meta { opacity: 0.9; font-size: 10px; }
.course.is-cancelled { opacity: 0.35; text-decoration: line-through; }
.course.is-moved { outline: 2px dashed rgba(255, 255, 255, 0.75); outline-offset: -3px; }
.course.is-makeup { outline: 2px solid #fff; outline-offset: -3px; }

.course--s0 { background: var(--c0); }
.course--s1 { background: var(--c1); }
.course--s2 { background: var(--c2); }
.course--s3 { background: var(--c3); }
.course--s4 { background: var(--c4); }
.course--s5 { background: var(--c5); }
.course--s6 { background: var(--c6); }
.course--s7 { background: var(--c7); }
.course--s8 { background: var(--c8); }
.course--s9 { background: var(--c9); }
.course--s10 { background: var(--c10); }
.course--s11 { background: var(--c11); }

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

.month { padding: 12px 12px 24px; }

.month__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 12px;
}

.month__title { font-size: 17px; font-weight: 600; }

.month__nav {
  border: none;
  background: var(--surface-alt);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 17px;
  cursor: pointer;
  font-family: inherit;
}

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

.month__weekdays div {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding-bottom: 4px;
}

.month__cell {
  background: var(--surface);
  border-radius: 8px;
  min-height: 62px;
  padding: 5px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  overflow: hidden;
}

.month__cell.is-outside { opacity: 0.42; }
.month__cell.is-today { box-shadow: inset 0 0 0 1.5px var(--accent); }

.month__daynum { font-size: 15px; font-weight: 600; line-height: 1.15; }

.month__cell.is-today .month__daynum {
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  width: 23px; height: 23px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

.month__info { font-size: 10px; color: var(--text-dim); line-height: 1.35; }

.month__dots { display: flex; gap: 3px; flex-wrap: wrap; }
.month__dot { width: 6px; height: 6px; border-radius: 50%; }

/* ------------------------------------------------------------------ 日视图 */

.day { padding: 12px 16px 24px; }

.day__card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.day__date { font-size: 20px; font-weight: 600; }
.day__sub { font-size: 13px; color: var(--text-dim); margin-top: 5px; }

.day__item {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 9px;
  align-items: flex-start;
  cursor: pointer;
}

.day__bar { width: 4px; border-radius: 2px; align-self: stretch; flex: none; }
.day__body { flex: 1; min-width: 0; }
.day__name { font-size: 15px; font-weight: 500; }
.day__meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }

/* ------------------------------------------------------------------ 天气面板 */

.wx-now {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4a6cf7 0%, #7c4dff 100%);
  color: #fff;
}

.wx-now__icon { font-size: 46px; line-height: 1; }
.wx-now__temp { font-size: 30px; font-weight: 600; line-height: 1.1; }
.wx-now__desc { font-size: 13px; opacity: 0.92; margin-top: 3px; }
.wx-now__date { font-size: 12px; opacity: 0.85; margin-top: 6px; }

.wx-tabs {
  display: flex;
  gap: 6px;
  margin: 14px 0 8px;
  flex-wrap: wrap;
}

.wx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px;
}

.wx-row:last-child { border-bottom: none; }
.wx-row__day { width: 74px; flex: none; color: var(--text-dim); font-size: 13px; }
.wx-row__icon { width: 28px; text-align: center; font-size: 18px; flex: none; }
.wx-row__text { flex: 1; font-size: 13px; }
.wx-row__temp { font-variant-numeric: tabular-nums; font-size: 13px; }

/* ------------------------------------------------------------------ 通用 */

.empty { padding: 52px 24px; text-align: center; color: var(--text-dim); }
.empty__title { font-size: 16px; color: var(--text); margin-bottom: 8px; }
.empty__hint { font-size: 13px; line-height: 1.7; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 15px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  min-height: 46px;
}

.btn--ghost { background: var(--surface-alt); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { display: block; width: 100%; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card__title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px;
}

.row:last-child { border-bottom: none; }

.hint { font-size: 12px; color: var(--text-dim); line-height: 1.65; }
.hint--danger { color: var(--danger); }

/* ---------------------------------------------------------- 可选标签（chips） */

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 20px;
  padding: 9px 15px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  min-height: 40px;
}

.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

.chip--static { cursor: default; }
.chip--add { color: var(--accent); border-style: dashed; }

/* ------------------------------------------------------------------ 弹层 */

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 620px;
  max-height: 84dvh;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet__title { font-size: 17px; font-weight: 600; margin-bottom: 14px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.sheet__actions .btn { flex: 1; min-width: 110px; }

input[type="date"],
input[type="time"],
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  font-size: 16px;            /* ⚠️ 小于 16px 时 iOS 会放大整个页面 */
  font-family: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }

/* ------------------------------------------------------------------ 安装引导 */

.install { padding: 28px 20px; text-align: center; }
.install__title { font-size: 19px; font-weight: 600; margin-bottom: 10px; }

.install__steps {
  text-align: left;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 18px 0;
  font-size: 14px;
  line-height: 1.95;
}

.install__steps b { color: var(--accent); }

.install__warn {
  text-align: left;
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  border-radius: var(--radius);
  padding: 13px 15px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
}

/* ------------------------------------------------------------------ 提示条 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(30, 32, 38, 0.95);
  color: #fff;
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 22px;
  max-width: 82vw;
  text-align: center;
  z-index: 90;
  line-height: 1.55;
}

/* ------------------------------------------------------------ 颜色选择器 */

.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { display: block; cursor: pointer; }
.swatch input { display: none; }

.swatch span {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

.swatch input:checked + span {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

/* 天气图标（SVG，与安卓版同一份几何） */
.wx-svg {
  display: inline-block;
  vertical-align: -3px;   /* 与旁边的日期文字视觉对齐 */
}

/* ------------------------------------------------------------------ 底部栏 */

.bottombar {
  display: flex;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  flex: none;
}

.bottombar__item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  padding: 9px 4px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 58px;
}

.bottombar__item:active { background: var(--surface-alt); }

.bottombar__icon { font-size: 19px; line-height: 1; }

/* ==========================================================================
   断点：平板 / 桌面

   手机上铺满是对的，但大屏上如果不限宽，周视图的 7 列会被拉得很宽、
   每格空得能跑马，反而更难扫视。所以两个断点各限一次宽度、加大格子。
   ========================================================================== */

@media (min-width: 720px) {
  :root {
    --max-width: 900px;
    --period-col: 50px;
    --row-min: 46px;
  }

  .hero { margin: 18px 20px 4px; padding: 22px; }
  .hero__title { font-size: 20px; }
  .hero__btn { min-height: 70px; font-size: 17px; }

  .week__grid { margin: 0 16px; }
  .week__head { font-size: 13px; }
  .course__name { font-size: 12px; }

  .month { padding: 16px 16px 28px; }
  .month__cell { min-height: 84px; padding: 7px 8px; }
  .month__daynum { font-size: 16px; }
  .month__info { font-size: 11px; }

  .day { padding: 16px 20px 28px; }

  .sheet-mask { align-items: center; }
  .sheet {
    border-radius: 18px;
    max-height: 80dvh;
    padding-bottom: 18px;
    margin-bottom: env(safe-area-inset-bottom);
  }
}

@media (min-width: 1100px) {
  :root {
    --max-width: 1180px;
    --period-col: 58px;
    --row-min: 52px;
  }

  .hero { margin: 22px 24px 6px; }
  .hero__title { font-size: 22px; }
  .hero__sub { font-size: 14px; }
  .hero__btn { min-height: 76px; font-size: 18px; }
  .hero__btn small { font-size: 12px; }

  .week__grid { margin: 0 20px; }

  .month { padding: 20px 20px 32px; }
  .month__cell { min-height: 104px; }
  .month__cell:hover { box-shadow: inset 0 0 0 1px var(--border); }

  .course { font-size: 12px; }

  /* 桌面上鼠标悬停要给反馈：触屏没有 hover，只有指针设备才有意义 */
  .day__item:hover { background: var(--surface-alt); }
  .month__cell:hover { background: var(--surface-alt); }

  .bottombar__item:hover { color: var(--accent); }
}

/* 横屏手机：矮，顶部大卡片要收紧，否则课表没地方了 */
@media (max-height: 560px) and (orientation: landscape) {
  .hero { padding: 12px 16px; margin: 8px 12px 0; }
  .hero__title { font-size: 15px; }
  .hero__sub { display: none; }
  .hero__btn { min-height: 48px; font-size: 14px; }
  .hero__note { display: none; }
  :root { --row-min: 30px; }
}

/* 打印（老师同学偶尔会打一张课表） */
@media print {
  .topbar, .segmented, .bottombar, .hero, .toast { display: none !important; }
  .content { overflow: visible; }
  .app { height: auto; }
}
