:root {
  --bg: #fafafa;
  --card: #ffffff;
  --line: #eeeeee;
  --text: #1f1f1f;
  --sub: #8c8c8c;

  --a: #4a7fd6;
  --a-bg: #eaf1fc;
  --a-text: #2c5aa8;

  --b: #e0668e;
  --b-bg: #fcebf1;
  --b-text: #b33f67;

  --row-h: 46px;
  --head-h: 36px;
  --time-w: 30px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.45, 0.5, 1);
}

/* 真实弹簧曲线（支持 linear() 的浏览器） */
@supports (animation-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(
      0, 0.006, 0.025 2.1%, 0.096 4.8%, 0.231 8.5%, 0.419 13.2%, 0.618 18.2%,
      0.785 23.3%, 0.912 28.5%, 0.994 33.9%, 1.033 39.5%, 1.04 43.1%, 1.035 46.9%,
      1.015 54.9%, 1.002 63.2%, 0.998 72%, 1
    );
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 12px 36px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============ 入场动效 ============ */
.rise {
  animation: rise 0.65s var(--ease-out) backwards;
  animation-delay: var(--d, 0s);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.988); filter: blur(3px); }
}

.rv {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding-bottom: 2px;
}
.rv > span {
  display: inline-block;
  animation: rvUp 0.65s var(--ease-out) backwards;
  animation-delay: var(--d, 0s);
}
@keyframes rvUp {
  from { transform: translateY(108%) rotate(3deg); }
}

/* ============ 顶部 ============ */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}
.title-wrap { display: flex; align-items: center; gap: 12px; }

/* 两颗绕行的小圆点：你和 Ta */
.logo {
  position: relative;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  animation: orbit 9s linear infinite, rise 0.9s var(--ease-out) backwards;
}
.orb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 50%;
  mix-blend-mode: multiply;
  transition: transform 0.9s var(--spring);
}
.orb.a { background: var(--a); transform: translateX(-8px); }
.orb.b { background: var(--b); transform: translateX(8px); }
.logo.together .orb.a { transform: translateX(-3px) scale(1.08); }
.logo.together .orb.b { transform: translateX(3px) scale(1.08); }
.logo.together { animation: orbit 9s linear infinite, beat 1.6s ease-in-out infinite; }
.logo.hug .orb.a { transform: translateX(-1.5px) scale(1.22); }
.logo.hug .orb.b { transform: translateX(1.5px) scale(1.22); }
.logo::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  border: 1.5px solid var(--b);
  opacity: 0;
  pointer-events: none;
}
.logo.hug::after { animation: logoRing 0.75s var(--ease-out); }
@keyframes logoRing {
  0% { transform: scale(0.6); opacity: 0.65; }
  100% { transform: scale(1.65); opacity: 0; }
}

@keyframes orbit { to { rotate: 360deg; } }
@keyframes beat {
  0%, 100% { scale: 1; }
  15% { scale: 1.14; }
  30% { scale: 0.98; }
  45% { scale: 1.08; }
}

.week { font-size: 24px; font-weight: 750; letter-spacing: 0.5px; line-height: 1.15; }
.week .num { font-weight: 800; }
.date { font-size: 13px; color: var(--sub); margin-top: 2px; }

.pill-btn {
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 13px;
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.4s var(--spring), box-shadow 0.3s;
}
.pill-btn:active { transform: scale(0.92); }

.text-btn {
  border: none;
  background: none;
  font-size: 14px;
  color: var(--sub);
  padding: 4px 2px;
  cursor: pointer;
}

.link-btn {
  border: none;
  background: none;
  font-size: 12px;
  color: var(--a);
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn.center { align-self: center; color: var(--sub); }

/* ============ 此刻 ============ */
.now {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px 14px;
}

.now-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.now-row:nth-child(2) { border-bottom: none; }
.now-row.swap { animation: swap 0.6s var(--ease-out); }
@keyframes swap {
  from { opacity: 0; transform: translateY(8px); filter: blur(3px); }
}

.dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.a { background: var(--a); }
.dot.b { background: var(--b); }
.dot.live::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: ripple 1.8s var(--ease-out) infinite;
}
@keyframes ripple {
  from { transform: scale(1); opacity: 0.6; }
  to { transform: scale(3.4); opacity: 0; }
}

.now-main { flex: 1; min-width: 0; }
.now-name { font-size: 12px; color: var(--sub); }
.now-course {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.now-course.idle { font-weight: 400; color: var(--sub); }

.now-side {
  flex-shrink: 0;
  text-align: right;
  font-size: 12px;
  color: var(--sub);
}
.now-side b { color: var(--text); font-size: 16px; font-weight: 650; }

.bar {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  margin-top: 7px;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width 1.2s var(--ease-out) 0.35s;
  position: relative;
}
.bar.a i { background: var(--a); }
.bar.b i { background: var(--b); }
.bar i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  background-size: 40px 100%;
  background-repeat: no-repeat;
  animation: barShine 2.4s ease-in-out infinite;
}
@keyframes barShine {
  from { background-position: -40px 0; }
  to { background-position: calc(100% + 40px) 0; }
}

.now-together {
  border-top: 1px solid var(--line);
  padding: 10px 0 11px;
  font-size: 12px;
  color: var(--sub);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.now-together:empty { display: none; }
.now-together.swap { animation: swap 0.55s var(--ease-out); }
.now-together .hint {
  font-size: 11px;
  color: #b5b5b5;
  flex-shrink: 0;
  transition: color 0.25s;
}
.now-together.active .hint { color: var(--b-text); }
.now-together .hl {
  font-weight: 650;
  background: linear-gradient(90deg, var(--b-text), var(--a-text) 50%, var(--b-text));
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============ 周课表 ============ */
.week-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 6px 6px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 10px;
  gap: 8px;
}

.week-nav { display: flex; align-items: center; gap: 4px; }
.nav-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg);
  border-radius: 9px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.4s var(--spring), background 0.2s;
}
.nav-btn:active { transform: scale(0.86); background: #f0f0f0; }
.grid-week {
  display: inline-block;
  font-size: 14px;
  font-weight: 650;
  min-width: 54px;
  text-align: center;
}
.grid-week.next { animation: slideInR 0.45s var(--ease-out); }
.grid-week.prev { animation: slideInL 0.45s var(--ease-out); }
@keyframes slideInR { from { opacity: 0; transform: translateX(10px); } }
@keyframes slideInL { from { opacity: 0; transform: translateX(-10px); } }

/* 分段控件 + 滑动指示块 */
.seg {
  position: relative;
  display: flex;
  background: var(--bg);
  border-radius: 9px;
  padding: 2px;
}
.seg-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 0;
  background: #fff;
  border-radius: 7px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.09);
}
.seg-thumb.ready { transition: transform 0.55s var(--spring), width 0.55s var(--spring); }
.seg-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: none;
  font-size: 12px;
  color: var(--sub);
  padding: 4px 11px;
  border-radius: 7px;
  cursor: pointer;
  max-width: 72px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.25s;
}
.seg-btn.active { color: var(--text); font-weight: 600; }

.edit-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 6px 8px;
  padding: 6px 10px;
  font-size: 12px;
  background: #fff8e6;
  color: #8a6512;
  border-radius: 8px;
  animation: swap 0.5s var(--ease-out);
}

/* 网格 */
.grid {
  position: relative;
  display: grid;
  grid-template-columns: var(--time-w) repeat(5, minmax(0, 1fr)) repeat(2, minmax(0, 0.6fr));
  grid-template-rows: var(--head-h) repeat(12, var(--row-h));
}

.g-head {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 11px;
  line-height: 1.2;
  color: var(--sub);
}
.g-head small { font-size: 9px; opacity: 0.8; }
.g-head b {
  font-weight: inherit;
  font-size: 9px;
  padding: 0 5px;
  border-radius: 999px;
}
.g-head.today { color: var(--text); font-weight: 700; }
.g-head.today b {
  background: var(--text);
  color: #fff;
  animation: pop 0.7s var(--spring) 0.55s backwards;
}
@keyframes pop { from { transform: scale(0.2); opacity: 0; } }

.g-head.in,
.g-time.in {
  animation: headIn 0.6s var(--ease-out) backwards;
  animation-delay: var(--d, 0s);
}
@keyframes headIn {
  from { opacity: 0; transform: translate(var(--dx, 0), 6px); }
}

.g-time {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--sub);
  line-height: 1.1;
}
.g-time small { font-size: 7.5px; opacity: 0.75; }

.g-cell { border-top: 1px solid #f3f3f3; transition: background 0.35s var(--ease-out); }
.g-cell.today { background: #fbfbfb; }
.g-cell.free-glow {
  background: linear-gradient(135deg, rgba(74, 127, 214, 0.1), rgba(224, 102, 142, 0.12));
  box-shadow: inset 0 0 0 1px rgba(224, 102, 142, 0.2);
}
.grid.editing .g-cell { cursor: pointer; }
.grid.editing .g-cell:hover { background: #fff8e6; }

/* 课程块 */
.blk {
  position: relative;
  z-index: 2;
  margin: 1px;
  border-radius: 7px;
  padding: 3px 3px 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.45s var(--spring), box-shadow 0.3s;
}
.blk.a { background: var(--a-bg); color: var(--a-text); }
.blk.b { background: var(--b-bg); color: var(--b-text); }
.blk.half-l { width: calc(50% - 1px); justify-self: start; }
.blk.half-r { width: calc(50% - 1px); justify-self: end; }
.blk:active { transform: scale(0.93); }
@media (hover: hover) {
  .blk:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.07); }
}

.blk.in {
  animation: blkIn 0.8s var(--spring) backwards;
  animation-delay: var(--d, 0s);
}
@keyframes blkIn {
  from { opacity: 0; transform: translate(var(--dx, 0), 16px) scale(0.82); }
}

/* 正在上的课：描边 + 一道流光 */
.blk.live { box-shadow: inset 0 0 0 1.5px currentColor; }
.blk.live::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.85) 50%, transparent 65%);
  background-size: 260% 100%;
  animation: sweep 2.8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes sweep {
  from { background-position: 130% 0; }
  to { background-position: -130% 0; }
}

.blk-name {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.blk-p {
  position: absolute;
  left: 3px;
  right: 2px;
  bottom: 2px;
  font-size: 8px;
  opacity: 0.72;
  white-space: nowrap;
}
.blk.half-l .blk-p,
.blk.half-r .blk-p {
  left: 1px;
  right: 1px;
  font-size: 7px;
  letter-spacing: -0.4px;
  text-align: center;
}

/* 当前时间线：全局细参考线 + 今日列高亮段 */
.now-line {
  position: absolute;
  left: var(--time-w);
  right: 0;
  height: 0;
  border-top: 1px dashed rgba(31, 31, 31, 0.16);
  z-index: 1;
  pointer-events: none;
  transform-origin: left center;
}
.now-line.in { animation: draw 0.85s var(--ease-out) 0.45s backwards; }
@keyframes draw { from { transform: scaleX(0); } }

.now-today-bar {
  position: absolute;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--a), var(--b));
  z-index: 4;
  pointer-events: none;
  transform-origin: left center;
}
.now-today-bar.in { animation: draw 0.65s var(--ease-out) 0.55s backwards; }
.now-today-bar::before,
.now-today-bar::after {
  content: "";
  position: absolute;
  left: -3px;
  top: -2.5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--b);
}
.now-today-bar::after { animation: ripple 2s var(--ease-out) infinite; }

/* ============ 弹层 ============ */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.22);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease both;
}
.mask.bottom { align-items: flex-end; padding: 0; }
.mask.out { animation: fadeOut 0.22s ease both; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }

.sheet {
  width: 100%;
  max-width: 520px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 18px 16px 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 88vh;
  overflow-y: auto;
}
.mask.bottom .sheet { animation: sheetUp 0.65s var(--spring) both; }
.mask.bottom.out .sheet { animation: sheetDown 0.22s ease-in both; }
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes sheetDown { to { transform: translateY(100%); } }

.sheet.small {
  max-width: 330px;
  border-radius: 18px;
  padding: 18px;
  animation: popIn 0.55s var(--spring) both;
}
.mask.out .sheet.small { animation: popOut 0.2s ease-in both; }
@keyframes popIn { from { opacity: 0; transform: scale(0.9) translateY(10px); } }
@keyframes popOut { to { opacity: 0; transform: scale(0.95); } }

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 17px;
  font-weight: 650;
}

/* 课程详情卡：颜色与课程块一致，方便形变过渡 */
.pop-sheet {
  width: 100%;
  max-width: 300px;
  border-radius: 20px;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: popIn 0.55s var(--spring) both;
}
.mask.out .pop-sheet { animation: popOut 0.2s ease-in both; }
.pop-sheet.a { background: var(--a-bg); color: var(--a-text); }
.pop-sheet.b { background: var(--b-bg); color: var(--b-text); }
.pop-who { font-size: 12px; font-weight: 600; opacity: 0.75; }
.pop-name { font-size: 21px; font-weight: 750; line-height: 1.3; color: inherit; }
.sheet .pop-name { color: var(--text); font-size: 18px; }
.pop-meta { font-size: 13px; opacity: 0.8; }

.pop-sheet > * { animation: rise 0.6s var(--ease-out) backwards; }
.pop-sheet > :nth-child(1) { animation-delay: 0.12s; }
.pop-sheet > :nth-child(2) { animation-delay: 0.18s; }
.pop-sheet > :nth-child(3) { animation-delay: 0.24s; }

/* 支持 View Transitions 时，交给共享元素形变 */
.has-vt #pop,
.has-vt .pop-sheet { animation: none; }
#pop { view-transition-name: pop-mask; }

::view-transition-group(*) {
  animation-duration: 0.6s;
  animation-timing-function: var(--spring);
}
::view-transition-old(*),
::view-transition-new(*) {
  animation-duration: 0.3s;
  height: 100%;
  width: 100%;
  object-fit: none;
  object-position: left top;
}
::view-transition-image-pair(*) { overflow: hidden; border-radius: 8px; }
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-image-pair(root),
::view-transition-image-pair(pop-mask) { border-radius: 0; }

/* 表单 */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--sub); }
.field input, .field select, .share-fallback {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus { border-color: #cfcfcf; box-shadow: 0 0 0 3px #f2f2f2; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.4s var(--spring), filter 0.2s;
}
.btn:active { transform: scale(0.95); }
.btn-a { background: var(--a-bg); color: var(--a-text); }
.btn-b { background: var(--b-bg); color: var(--b-text); }
.btn-dark { background: var(--text); color: #fff; }
.btn-ghost { background: var(--bg); color: #c0392b; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  background: rgba(31, 31, 31, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 80;
  white-space: nowrap;
  transform: translateX(-50%);
}
.toast.show { animation: toastIn 0.55s var(--spring) both; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px) scale(0.9); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
