:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --accent: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --shadow: 0 6px 20px rgba(31, 41, 55, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 22px;
  background: linear-gradient(120deg, #4f46e5, #7c3aed);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.brand .logo { font-size: 26px; }
.nav { display: flex; flex-wrap: wrap; gap: 8px; }
.nav-btn {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s, transform 0.1s;
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.3); }
.nav-btn.active { background: #fff; color: var(--primary); font-weight: 700; }
.nav-btn.teacher { background: var(--warn); color: #fff; font-weight: 700; }
.nav-btn.teacher:hover { filter: brightness(1.05); }

.container { max-width: 1080px; margin: 0 auto; padding: 24px 18px 60px; }

.view { display: none; animation: fade 0.25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 22px; margin-bottom: 16px; }
.section-title.inline { margin-bottom: 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* 卡片通用 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* 天气卡片 */
.weather-card { text-align: center; max-width: 460px; margin: 10px auto; }
.clock { font-size: 56px; font-weight: 800; letter-spacing: 2px; color: var(--primary); font-variant-numeric: tabular-nums; }
.date { font-size: 18px; color: var(--muted); margin-bottom: 18px; }
.weather { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 10px 0; }
.weather-emoji { font-size: 72px; line-height: 1; }
.weather-info { text-align: left; }
.weather-temp { font-size: 32px; font-weight: 700; }
.weather-desc { font-size: 16px; color: var(--ink); }
.weather-meta { font-size: 13px; color: var(--muted); }
.weather-city { margin-top: 16px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--muted); font-size: 14px; }

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid var(--line); padding: 10px 12px; text-align: center; font-size: 14px; }
th { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.schedule-table td input { width: 100%; border: none; text-align: center; font-size: 14px; background: transparent; padding: 6px; }
.schedule-table td input:disabled { color: var(--ink); }
.schedule-table td input:not(:disabled) { background: #fffbe6; border-radius: 6px; }

/* 商品网格 */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.product {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: transform 0.15s;
}
.product:hover { transform: translateY(-4px); }
.product .emoji { font-size: 56px; }
.product .name { font-size: 17px; font-weight: 700; margin: 8px 0 4px; }
.product .desc { color: var(--muted); font-size: 13px; min-height: 36px; }
.product .price { color: var(--accent); font-weight: 800; font-size: 18px; margin: 6px 0; }
.product .stock { font-size: 12px; color: var(--muted); }
.product .buy { margin-top: 10px; width: 100%; }

/* 学分榜 */
.credits-table td:nth-child(3) { font-weight: 700; color: var(--primary); }
.bar { height: 10px; background: var(--primary-soft); border-radius: 999px; overflow: hidden; min-width: 120px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, #4f46e5, #10b981); }
.rank-badge { display: inline-block; min-width: 26px; padding: 2px 0; border-radius: 8px; font-weight: 700; }
.rank-1 { background: #fde68a; color: #92400e; }
.rank-2 { background: #e5e7eb; color: #374151; }
.rank-3 { background: #fcd9b6; color: #9a3412; }

/* 按钮 */
button { font-family: inherit; }
.mini-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
}
.mini-btn:hover { background: #f3f4f6; }
.mini-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.mini-btn.primary:hover { filter: brightness(1.05); }
.mini-btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.mini-btn.danger:hover { background: #fef2f2; }
.buy { background: var(--accent); color: #fff; border: none; padding: 9px 0; border-radius: 10px; cursor: pointer; font-weight: 700; }
.buy:hover { filter: brightness(1.05); }
.buy:disabled { background: #cbd5e1; cursor: not-allowed; }

/* 后台 */
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab-btn { border: none; background: var(--primary-soft); color: var(--primary); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.tab-btn.active { background: var(--primary); color: #fff; }
.admin-panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.admin-panel table { margin-top: 12px; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

/* 表单 */
input[type="text"], input[type="number"], input[type="password"], select {
  font-family: inherit;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  width: 100%;
}
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.inline-edit { display: flex; gap: 6px; align-items: center; justify-content: center; }
.inline-edit input { width: 80px; text-align: center; }
.delta-up { color: #ef4444; font-weight: 600; }
.delta-down { color: #22c55e; font-weight: 600; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: min(92vw, 380px); box-shadow: var(--shadow); }
.modal h3 { margin-bottom: 14px; }
.modal label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.redeem-info { font-size: 14px; color: var(--ink); background: var(--primary-soft); padding: 10px; border-radius: 10px; margin: 12px 0; }
.redeem-info.success { background: rgba(34, 197, 94, 0.12); color: #15803d; }
.redeem-info.warn { background: rgba(251, 191, 36, 0.15); color: #92400e; }
.redeem-info.error { background: rgba(239, 68, 68, 0.12); color: #b91c1c; }

/* Toast */
.toast {
  position: fixed;
  bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff;
  padding: 12px 20px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 600px) {
  .clock { font-size: 42px; }
  .nav-btn { font-size: 13px; padding: 8px 11px; }
}

/* 班级媒体 */
.media-card { max-width: 760px; margin: 18px auto 0; }
.media-title { font-size: 18px; margin-bottom: 12px; }
.media-player { margin-bottom: 14px; }
.media-player video { width: 100%; border-radius: 12px; max-height: 440px; background: #000; display: block; }
.audio-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px; background: var(--primary-soft); border-radius: 12px; }
.audio-wrap .audio-icon { font-size: 54px; }
.audio-wrap .audio-name { font-weight: 700; }
.audio-wrap audio { width: 100%; max-width: 440px; }
.media-placeholder { color: var(--muted); font-size: 14px; padding: 14px; text-align: center; }
.iframe-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.iframe-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.media-list { display: flex; flex-wrap: wrap; gap: 8px; }
.media-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; }
.media-item:hover { background: #f3f4f6; }
.media-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.media-item .media-badge { font-size: 16px; }

/* 归档记录折叠区 */
.archive-section {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(243, 244, 246, 0.6);
}
.archive-section summary {
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.archive-section[open] summary { margin-bottom: 10px; }

/* 毛玻璃背景：开启全局背景后，内容卡片使用半透明 + 模糊 */
body.bg-enabled .card,
body.bg-enabled .product,
body.bg-enabled .table-wrap,
body.bg-enabled .admin-panel,
body.bg-enabled .archive-section {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.45);
}
