:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --card: #1c212a;
  --card-2: #232935;
  --line: #2c333f;
  --text: #e8ecf2;
  --text-2: #9aa5b6;
  --text-3: #6b7686;
  --brand: #4f8cff;
  --brand-soft: rgba(79, 140, 255, 0.14);
  --ok: #35c98a;
  --warn: #f0a132;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { 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-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

/* ---------- 通用 ---------- */
.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }
.btn {
  appearance: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 600;
  border-radius: 11px; padding: 13px 18px;
  background: var(--brand); color: #fff;
  transition: transform .12s ease, opacity .12s ease;
  min-height: 46px;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--card-2); color: var(--text-2); }
.btn.danger { background: rgba(224, 82, 82, .16); color: #ff8f8f; }
.btn.block { width: 100%; }
.input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS 聚焦不缩放 */
  outline: none;
  transition: border-color .15s ease;
}
.input:focus { border-color: var(--brand); }
label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; font-size: 13px; color: var(--text-2);
  margin-bottom: 7px; font-weight: 500;
}
.hidden { display: none !important; }
.err {
  color: #ff9a9a; font-size: 13.5px; margin-top: 10px;
  min-height: 18px; line-height: 1.4;
}
.muted { color: var(--text-2); font-size: 13px; }

/* ---------- 登录页 ---------- */
.gate {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-b));
}
.gate-card {
  width: 100%; max-width: 400px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 30px 24px;
}
.gate-logo {
  width: 52px; height: 52px; border-radius: 15px;
  background: linear-gradient(140deg, var(--brand), #7b5cff);
  display: flex; align-items: center; justify-content: center;
  font-size: 25px; margin-bottom: 18px;
}
.gate h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -.2px; }
.gate p.sub { color: var(--text-2); font-size: 14px; margin: 0 0 24px; line-height: 1.5; }

.code-input {
  letter-spacing: 9px; font-size: 22px; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15, 17, 21, .88);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  display: flex; align-items: center; gap: 12px;
  height: 56px;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.brand small { display: block; font-size: 11.5px; color: var(--text-3); font-weight: 500; letter-spacing: 0; }
.spacer { flex: 1; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  border: 1px solid rgba(79, 140, 255, .3);
}
.linkbtn {
  background: none; border: 0; color: var(--text-3);
  font: inherit; font-size: 13px; cursor: pointer; padding: 8px;
  min-height: 40px;
}

/* ---------- 分段切换 ---------- */
.seg {
  display: flex; gap: 4px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin: 18px 0 6px;
}
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent;
  color: var(--text-2); font: inherit; font-weight: 600; font-size: 14.5px;
  padding: 10px 8px; border-radius: 9px; cursor: pointer; min-height: 42px;
  transition: background .15s ease, color .15s ease;
}
.seg button.on { background: var(--card-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* ---------- 进度条 ---------- */
.progress-wrap { padding: 14px 0 6px; }
.progress-bar {
  height: 5px; background: var(--card-2); border-radius: 3px; overflow: hidden;
}
.progress-fill { height: 100%; background: var(--brand); border-radius: 3px; transition: width .25s ease; }
.progress-txt {
  display: flex; justify-content: space-between;
  font-size: 12.5px; color: var(--text-3); margin-top: 8px;
}

/* ---------- 列表 ---------- */
.list { padding: 12px 0 calc(30px + var(--safe-b)); }
.unit-head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 20px 0 8px; position: sticky; top: 56px;
  background: linear-gradient(var(--bg) 72%, transparent);
  z-index: 5;
}
.unit-head b { font-size: 15px; letter-spacing: -.1px; }
.unit-head span { font-size: 12.5px; color: var(--text-3); }

.item {
  display: flex; align-items: center; gap: 13px;
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px;
  margin-bottom: 8px; cursor: pointer;
  color: var(--text); font: inherit;
  transition: border-color .15s ease, background .15s ease;
  min-height: 62px;
}
.item:active { background: var(--card-2); }
.item.playing { border-color: var(--brand); background: var(--brand-soft); }
.item.done { border-color: rgba(53, 201, 138, .32); }

.item-idx {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 11px; background: var(--card-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700; color: var(--text-2);
  font-family: ui-monospace, Menlo, monospace;
}
.item.playing .item-idx { background: var(--brand); color: #fff; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 14.5px; font-weight: 600; letter-spacing: -.1px; }
.item-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.item-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.badge-done {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(53, 201, 138, .16); color: var(--ok);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.play-ico { color: var(--text-3); font-size: 15px; }

/* ---------- 播放器 ---------- */
.player {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 12, 15, .97);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: 0 } to { transform: none; opacity: 1 } }
.player-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.player-bar .t { font-size: 14.5px; font-weight: 600; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  appearance: none; border: 0; background: var(--card-2); color: var(--text);
  width: 38px; height: 38px; border-radius: 11px; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  flex: 0 0 38px;
}
.player-body { flex: 1; display: flex; flex-direction: column; min-height: 0; justify-content: center; }
.player video {
  width: 100%; background: #000; display: block;
  max-height: 56vh; object-fit: contain;
}
.audio-stage {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 24px;
}
.disc {
  width: 132px; height: 132px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--brand), #7b5cff, var(--brand));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 12px 40px rgba(79, 140, 255, .28);
}
.disc::after { content: "♪"; font-size: 46px; color: #fff; }
.player-foot {
  padding: 16px 16px calc(16px + var(--safe-b));
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
/* 视频模式无底部信息，隐藏以免留白 */
.player-foot:empty { display: none; }
.player-foot audio { width: 100%; height: 40px; }
.pf-meta { flex: 1; font-size: 12.5px; color: var(--text-3); line-height: 1.5; }

/* ---------- 老师面板 ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 16px 0 4px;
}
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 12px;
}
.stat b { display: block; font-size: 22px; letter-spacing: -.5px; line-height: 1.2; }
.stat span { display: block; font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

.section-title {
  font-size: 13px; color: var(--text-3); font-weight: 600;
  margin: 26px 0 10px; letter-spacing: .3px;
}

.stu {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
}
.stu-head {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  cursor: pointer; width: 100%; background: none; border: 0;
  color: var(--text); font: inherit; text-align: left;
}
.stu-avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%;
  background: linear-gradient(140deg, #4f8cff, #7b5cff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.stu-info { flex: 1; min-width: 0; }
.stu-name { font-size: 15px; font-weight: 600; }
.stu-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.stu-cnt { display: flex; gap: 6px; flex: 0 0 auto; }
.chip {
  font-size: 11px; padding: 4px 8px; border-radius: 7px;
  background: var(--card-2); color: var(--text-2); font-weight: 600;
  white-space: nowrap;
}
.chip.a { background: rgba(79,140,255,.14); color: #7fb0ff; }
.chip.v { background: rgba(123,92,255,.16); color: #a68fff; }

.stu-body { border-top: 1px solid var(--line); padding: 6px 14px 14px; }
.plays { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.plays li {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 0; border-bottom: 1px solid rgba(44, 51, 63, .5);
  font-size: 13.5px;
}
.plays li:last-child { border-bottom: 0; }
.p-ico { font-size: 13px; flex: 0 0 auto; }
.p-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-time { font-size: 11.5px; color: var(--text-3); flex: 0 0 auto; }
.p-times {
  font-size: 10.5px; background: var(--card-2); color: var(--text-2);
  padding: 2px 6px; border-radius: 5px; flex: 0 0 auto;
}

.empty {
  text-align: center; padding: 46px 20px; color: var(--text-3);
}
.empty .ico { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty p { margin: 0; font-size: 14px; line-height: 1.6; }

.toolbar { display: flex; gap: 8px; padding: 4px 0 8px; flex-wrap: wrap; }
.toolbar .btn { padding: 10px 14px; font-size: 13.5px; min-height: 40px; }

.sheet {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6); display: flex; align-items: flex-end; justify-content: center;
}
.sheet-in {
  width: 100%; max-width: 520px;
  background: var(--card); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + var(--safe-b));
  animation: slideUp .22s ease;
  max-height: 88dvh; overflow-y: auto;
}
.sheet h3 { margin: 0 0 6px; font-size: 17px; }
.sheet .desc { color: var(--text-2); font-size: 13px; margin: 0 0 20px; line-height: 1.5; }
.sheet-actions { display: flex; gap: 9px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }

.code-display {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 30px; letter-spacing: 10px; text-align: center;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 12px 18px 22px;
  margin-bottom: 18px; color: var(--brand);
}

.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 12px 18px; font-size: 13.5px; z-index: 300;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  animation: slideUp .2s ease; max-width: 88vw; text-align: center;
}
.toast.ok { border-color: rgba(53,201,138,.4); color: #7ee0b4; }
.toast.bad { border-color: rgba(224,82,82,.4); color: #ff9a9a; }

@media (max-width: 400px) {
  .stats { gap: 7px; }
  .stat b { font-size: 19px; }
  .item-title { font-size: 14px; }
}
@media (min-width: 720px) {
  .wrap { max-width: 860px; }
  .player video { max-height: 62vh; }
}
