/* grid.css —— 二维课表网格（单周 7 天 × 7 节）的布局与视觉。
   配色只走 data-state / data-locked / data-cnt 选择器，:root 变量由 css/app.css 提供。
   移动端 < 720px 压列宽、缩行高、隐藏时间与课程名。 */

#grid2d { min-width: 0; }

.g2d {
  --g2d-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;
  --g2d-gap: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  font-family: "Inter", "HarmonyOS Sans SC", "Microsoft YaHei UI", system-ui, sans-serif;
}

/* ---------- 顶部：只读标签 ---------- */
.g2d-bar { display: flex; align-items: center; gap: 8px; }
.g2d-bar[hidden] { display: none; }
.g2d-bar:empty { display: none; }

.g2d-ro {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border: 1px solid var(--violet, #7a5cff);
  border-radius: 999px;
  background: rgba(122, 92, 255, 0.1);
  color: var(--ink-1, #8fa6c0);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.g2d-ro[hidden] { display: none; }

/* ---------- 滚动容器 ---------- */
.g2d-scroll {
  overflow-x: auto;
  overflow-y: visible;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* ---------- 网格本体 ---------- */
.g2d-grid {
  position: relative;
  display: grid;
  grid-template-columns: 96px repeat(7, minmax(96px, 1fr));
  grid-template-rows: auto repeat(7, minmax(58px, 1fr));
  gap: var(--g2d-gap);
  min-width: 0;
  opacity: 1;
  transition: opacity 120ms ease;
}
.g2d-grid.is-week-out { opacity: 0; }

/* ---------- 表头 ---------- */
.g2d-corner {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 2px 6px 6px;
  border-bottom: 1px solid var(--line, rgba(120, 220, 255, 0.18));
}
.g2d-corner-label {
  color: var(--ink-2, #5a7089);
  font-size: 11px;
  letter-spacing: 0.12em;
}
.g2d-corner-week {
  color: var(--ink-1, #8fa6c0);
  font-family: var(--g2d-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
}

/* 表头单元：一个「周X」= 一个 grid item（7 列轨道不增不减），
   内部改成竖排两行：第 1 行星期、第 2 行自然日（.g2d-day-date）。
   竖排用 column flex 而不是「再加一行 grid」——因为加行要同时补一个 corner 占位，
   容易把 8 列轨道数写错；竖排对列宽的影响恒为 0。 */
.g2d-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;      /* 原来 align-items:flex-end 的等效写法：两行一起贴底 */
  gap: 1px;
  min-width: 0;                   /* 防止内容把轨道撑开（轨道最小宽度已固定 96px） */
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--line, rgba(120, 220, 255, 0.18));
  color: var(--ink-1, #8fa6c0);
  font-size: 12.5px;
  letter-spacing: 0.06em;
}
.g2d-day-name { line-height: 1.25; white-space: nowrap; }

/* 第二行小字日期：字号比星期小一号，等宽数字让 11/30 和 12/01 的斜杠对齐 */
.g2d-day-date {
  max-width: 100%;
  color: var(--ink-2, #5a7089);
  font-family: var(--g2d-mono);
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;        /* 极端窄列时截自己，绝不撑列 */
}
/* 没有日期数据（如 tool 只给一周）时整行不占位，表头回落到原样 */
.g2d-day-date:empty { display: none; }
.g2d-day-date[hidden] { display: none; }

/* ---------- 行头（节次） ---------- */
.g2d-rh {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px 6px;
  min-width: 0;
}
.g2d-rh-label {
  color: var(--ink-0, #e8f4ff);
  font-size: 12.5px;
  letter-spacing: 0.01em;
}
.g2d-rh-time {
  color: var(--ink-2, #5a7089);
  font-family: var(--g2d-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.g2d-rh-short { display: none; }

/* ---------- 格子 ---------- */
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 8px 9px;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line, rgba(120, 220, 255, 0.18));
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.03);
  background-repeat: no-repeat;
  color: var(--ink-1, #8fa6c0);
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease,
    color 180ms ease;
}

.cell-badge {
  position: absolute;
  right: 7px;
  bottom: 5px;
  color: var(--ink-2, #5a7089);
  font-family: var(--g2d-mono);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  transition: color 180ms ease;
}
.cell-badge:empty { display: none; }

.cell-course {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 4px;
  color: var(--lock, #ff8a3d);
  font-size: 10.5px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-course:empty { display: none; }

/* 三态：0 有空（绿）/ 1 没空（红）/ 2 未填写（白纸，等用户第一次点） */
.cell[data-state="0"] {
  border-color: rgba(43, 255, 168, 0.3);
  color: var(--ok, #2bffa8);
  box-shadow: inset 0 0 12px rgba(43, 255, 168, 0.26);
}
.cell[data-state="1"] {
  border-color: rgba(255, 77, 109, 0.32);
  background-color: rgba(255, 77, 109, 0.09);
  color: var(--no, #ff4d6d);
}
/* 未填写 = 一张白纸：浅白底 + 比默认更亮的描边，让人一眼看出「这里可以点」；
   不加任何纹理（原来的灰斜纹会读成「灰掉的禁用态」）。 */
.cell[data-state="2"] {
  border-color: rgba(255, 255, 255, 0.46);
  background-color: rgba(233, 240, 250, 0.42);
  color: rgba(14, 22, 33, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 0 18px rgba(255, 255, 255, 0.05);
}

/* 悬停：轻微上浮 + 描边提亮 */
.cell:hover { transform: translateY(-1px); }
.cell[data-state="0"]:hover { border-color: rgba(43, 255, 168, 0.58); }
.cell[data-state="1"]:hover { border-color: rgba(255, 77, 109, 0.58); }
.cell[data-state="2"]:hover {
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);   /* 极淡白色内发光 */
}

/* ---------- 关键角色封禁：粉色（第四态） ----------
   优先级：锁定格（橙斜纹） > 自己标没空（红） > 被关键角色封禁（粉） > 有空（绿）/未填写（白）。
   靠 :not() 链 + 更高的选择器特异性实现这条链，不靠强制提升权重：
     · [data-locked="1"] —— 锁定格虽然渲染层已把 data-veto 恒置 '0'，这里再排一次，双保险；
     · [data-state="1"]  —— 红格也要排除：红格可能是「我自己也没空 + 被封」，红必须压住粉。
   特异性：(0,4,0) > 三态 (0,2,0) 与三态悬停 (0,3,0)，所以后面的三态规则不会把粉色吃掉。 */
.cell[data-veto="1"]:not([data-locked="1"]):not([data-state="1"]) {
  border-color: rgba(255, 140, 200, 0.88);
  background-color: rgba(255, 90, 170, 0.30);
  color: rgba(255, 228, 242, 0.98);
  box-shadow: inset 0 0 16px rgba(255, 105, 180, 0.32), 0 0 0 1px rgba(255, 105, 180, 0.18);
}

/* 还没填（本来是一张白纸）就已经被封：同底色但更淡 + 虚线描边，
   跟「已经填了、但被关键角色否掉」的实线实底粉区分开，一眼能看出「我还没表态」。 */
.cell[data-veto="1"][data-state="2"]:not([data-locked="1"]) {
  background-color: rgba(255, 105, 180, 0.10);
  border-color: rgba(255, 128, 191, 0.42);
  border-style: dashed;
}

/* 粉色格悬停：描边提到 0.8，表示「能点，但点了也救不回来」 */
.cell[data-veto="1"]:not([data-locked="1"]):not([data-state="1"]):hover {
  border-color: rgba(255, 128, 191, 0.8);
  box-shadow: inset 0 0 14px rgba(255, 105, 180, 0.26);
}

/* 粉色格的角标（n/总人数，5 人时即 n/5）数字不变、只换粉色系；
   放在 data-cnt 分级色与 data-state="2" 角标之后，特异性也更高，压得住。 */
.cell[data-veto="1"]:not([data-locked="1"]):not([data-state="1"]) .cell-badge {
  color: rgba(255, 205, 228, 0.85);
}

/* 锁定格：橙底 + 45° 斜纹 + --lock 细描边，不用纯红填充。
   锁定格的状态字符恒为 '2'（渲染层强制），所以必须放在三态与 hover 之后、
   用 .g2d 前缀抬高特异性，否则白纸的底色/描边会把橙色吃掉。 */
.g2d .cell[data-locked="1"] {
  cursor: not-allowed;
  background-color: rgba(255, 138, 61, 0.08);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 138, 61, 0.22) 0 1px,
    transparent 1px 7px
  );
  border-color: var(--lock, #ff8a3d);
  box-shadow: none;
  color: var(--lock, #ff8a3d);
}
.g2d .cell[data-locked="1"]:hover {
  transform: none;
  border-color: var(--lock, #ff8a3d);
  box-shadow: none;
}

/* 角标配色：全员有空 / ≥60% / ≥30% / 其余 */
.cell[data-cnt="all"] .cell-badge { color: var(--ok, #2bffa8); }
.cell[data-cnt="high"] .cell-badge { color: var(--cyan, #35e0ff); }
.cell[data-cnt="mid"] .cell-badge { color: var(--ink-1, #8fa6c0); }
.cell[data-cnt="low"] .cell-badge { color: var(--ink-2, #5a7089); }

/* 未填写格的角标跟着白纸走（放在 data-cnt 之后才压得住分级色），
   否则默认的 --ink-2 太暗，整格会被读成「禁用」。 */
.cell[data-state="2"] .cell-badge { color: rgba(232, 244, 255, 0.62); }

/* 只读：保留 pointer-events，只换光标（点击由脚本给提示） */
.g2d[data-readonly="1"] .cell { cursor: default; }
.g2d[data-readonly="1"] .cell[data-locked="1"] { cursor: not-allowed; }

/* 键盘焦点 */
.cell:focus { outline: none; }
.cell:focus-visible {
  outline: 2px solid var(--cyan, #35e0ff);
  outline-offset: 2px;
}

/* 锁定格抖动 320ms */
@keyframes g2d-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
.cell.is-shake { animation: g2d-shake 320ms ease-in-out; }

/* 长按：缩放 + 进度环 */
.cell.is-pressing {
  transform: scale(0.97);
  border-color: var(--cyan, #35e0ff);
}
.cell.is-pressing::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--cyan, #35e0ff);
  border-radius: 6px;
  pointer-events: none;
  animation: g2d-press 500ms linear forwards;
}
@keyframes g2d-press {
  from { transform: scale(0.55); opacity: 0.15; }
  to { transform: scale(1); opacity: 0.95; }
}

/* ---------- 浮动提示 ---------- */
.g2d-toast {
  position: absolute;
  z-index: 6;
  max-width: min(260px, calc(100% - 16px));
  padding: 6px 10px;
  border: 1px solid var(--cyan, #35e0ff);
  border-radius: 8px;
  background: var(--glass, rgba(10, 18, 30, 0.72));
  backdrop-filter: blur(8px);
  color: var(--ink-0, #e8f4ff);
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: break-word;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.g2d-toast.is-on { opacity: 1; transform: translateY(0); }
/* 锁定格完整课程卡：宽一点、允许折行，把课程名 · 教师 · 周次 · 地点全读出来 */
.g2d-toast[data-kind="lock"] {
  max-width: 260px;
  white-space: normal;
  line-height: 1.45;
  border-color: var(--lock, #ff8a3d);
}
.g2d-toast[data-kind="info"] { border-color: var(--cyan, #35e0ff); }
/* 粉色格封禁提醒：粉描边 + 允许折行（句子比普通提示长） */
.g2d-toast[data-kind="veto"] {
  max-width: 240px;
  white-space: normal;
  line-height: 1.45;
  border-color: rgba(255, 128, 191, 0.85);
}

/* ---------- 手机：右边缘渐隐（还有内容） + 一次性滑动提示 ---------- */
.g2d-scroll.is-overflowing.has-more-right {
  -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
  mask-image: linear-gradient(to right, #000 88%, transparent 100%);
}

.g2d-swipe {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 7;
  padding: 4px 10px;
  border: 1px solid var(--line, rgba(120, 220, 255, 0.18));
  border-radius: 999px;
  background: var(--glass, rgba(10, 18, 30, 0.72));
  backdrop-filter: blur(6px);
  color: var(--ink-1, #8fa6c0);
  font-size: 11px;
  line-height: 1.3;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 1;
  transition: opacity 600ms ease;
}
.g2d-swipe.is-off { opacity: 0; }
@media (min-width: 641px) {
  .g2d-swipe { display: none; }
}

/* ---------- 手机（< 720px） ---------- */
@media (max-width: 719.98px) {
  .g2d { gap: 6px; }
  .g2d-grid {
    grid-template-columns: 44px repeat(7, minmax(44px, 1fr));
    grid-template-rows: auto repeat(7, 44px);
    gap: 4px;
    min-width: 352px;
  }
  .g2d-corner {
    position: sticky;
    left: 0;
    z-index: 4;
    padding: 0 2px;
    background: var(--bg-1, #0a1524);
  }
  .g2d-corner-label { display: none; }
  .g2d-corner-week { font-size: 10px; letter-spacing: 0; }
  .g2d-day { font-size: 11px; padding: 0 1px 4px; letter-spacing: 0; }
  /* 手机断点（< 720px）：表头日期行隐藏，高度还给 44px 的行；7 列仍各占 44px 起 */
  .g2d-day-date { display: none; }

  .g2d-rh {
    position: sticky;
    left: 0;
    z-index: 3;
    align-items: center;
    padding: 0 2px;
    border-right: 1px solid var(--line, rgba(120, 220, 255, 0.18));
    background: var(--bg-1, #0a1524);
    font-family: var(--g2d-mono);
    font-size: 11px;
    color: var(--ink-1, #8fa6c0);
  }
  .g2d-rh-label,
  .g2d-rh-time { display: none; }
  .g2d-rh-short { display: block; }

  .cell { padding: 3px 4px; border-radius: 6px; }
  .cell-course { display: none; }
  .cell-badge { right: 4px; bottom: 3px; font-size: 9.5px; }
  .g2d-toast { font-size: 11.5px; padding: 5px 8px; }
}

/* 尊重系统减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  .g2d-grid,
  .cell,
  .g2d-toast,
  .g2d-swipe,
  .cell-badge { transition-duration: 1ms; }
  .cell:hover { transform: none; }
  .cell.is-shake { animation-duration: 1ms; }
  .cell.is-pressing::after { animation-duration: 1ms; }
}
