:root {
  --bg: #fff7fa;
  --bg2: #f3efff;
  --card: rgba(255, 255, 255, 0.86);
  --text: #221b26;
  --muted: #7b7082;
  --faint: #b0a6b6;
  --line: rgba(120, 90, 130, 0.14);
  --accent: #e2557f;
  --accent-soft: rgba(226, 85, 127, 0.12);
  --bubble: rgba(255, 255, 255, 0.94);
  --bubble-line: rgba(226, 85, 127, 0.25);
  --user-bubble: #e2557f;
  --warn: #d9822b;
  --danger: #d6424f;
  --heart-opacity: 0.13;
  --zh-size: 20px;
  --radius: 16px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1622;
    --bg2: #171a2a;
    --card: rgba(40, 32, 46, 0.86);
    --text: #f3edf6;
    --muted: #a99db0;
    --faint: #6f6477;
    --line: rgba(255, 255, 255, 0.1);
    --accent: #ff7aa2;
    --accent-soft: rgba(255, 122, 162, 0.16);
    --bubble: rgba(45, 36, 52, 0.94);
    --bubble-line: rgba(255, 122, 162, 0.3);
    --user-bubble: #c9446d;
    --heart-opacity: 0.18;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

/* 比心背景 */
#bg {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, var(--bg), var(--bg2));
}
#bg::after {
  content: ""; position: absolute; inset: 0;
  background: url("../img/heart.webp") center 58% / min(92vw, 640px) auto no-repeat;
  opacity: var(--heart-opacity);
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sat) + 8px) 12px 8px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 12px; background: transparent;
  color: var(--text); font-size: 24px; line-height: 1; cursor: pointer;
}
.icon-btn:active { background: var(--accent-soft); }

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px calc(var(--sab) + 24px); }
#viewLive { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
small { display: block; font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
a { color: var(--accent); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 auto 14px; max-width: 720px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
details.card summary { font-weight: 600; cursor: pointer; }

.hero { display: flex; align-items: center; gap: 14px; max-width: 720px; margin: 4px auto 16px; }
.hero-icon { width: 64px; height: 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); }
.hero-title { font-size: 24px; font-weight: 800; }
.hero-sub { color: var(--muted); margin-top: 2px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=text], input:not([type]), input[type=password], input[type=search] {
  width: 100%; font-size: 16px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bubble); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 15px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.chip { border: none; background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 999px; font-size: 14px; cursor: pointer; }

.big-btn {
  width: 100%; border: none; border-radius: 14px; padding: 15px; font-size: 18px; font-weight: 700;
  color: #fff; background: linear-gradient(135deg, #f06b93, #b77cf0); cursor: pointer;
  box-shadow: 0 6px 18px rgba(226, 85, 127, 0.3);
}
.big-btn:disabled { opacity: 0.5; }
.btn { border: 1px solid var(--line); background: var(--bubble); color: var(--text); border-radius: 10px; padding: 9px 14px; font-size: 15px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.result { font-size: 14px; white-space: pre-wrap; margin: 6px 0; }
.result.ok { color: var(--text); }
.result.err { color: var(--danger); }

.banner {
  max-width: 720px; margin: 0 auto 12px; padding: 12px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  font-size: 14.5px; line-height: 1.5;
}
.banner button { margin-top: 8px; }

.section-head { display: flex; align-items: center; gap: 10px; max-width: 720px; margin: 22px auto 10px; }
.section-head h2 { margin: 0; white-space: nowrap; }
.section-head input { flex: 1; padding: 8px 12px; font-size: 15px; }
.course-group { max-width: 720px; margin: 0 auto 12px; }
.course-name { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 4px 6px; }
.hist-item {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; font-size: 15px;
}
.hist-item .meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; max-width: 720px; margin: 0 auto; }

/* 上课页 */
.live-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex: none; }
.live-course { font-size: 17px; font-weight: 700; }
.live-status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.on { background: #e5484d; animation: pulse 1.2s infinite; }
.dot.hear { background: #30a46c; }
@keyframes pulse { 50% { opacity: 0.35; } }
.notice {
  margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  background: color-mix(in srgb, var(--warn) 16%, var(--card)); flex: none;
}
.live-body { flex: 1; min-height: 0; display: flex; }
.transcript-wrap { flex: 1; min-width: 0; position: relative; }
.transcript { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px 24px; }
.follow-btn {
  position: absolute; right: 14px; bottom: 14px; border: none; border-radius: 999px; padding: 9px 14px;
  background: var(--accent); color: #fff; font-size: 14px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.live-actions {
  display: flex; gap: 8px; padding: 10px 12px calc(var(--sab) + 10px); flex: none;
  border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.act {
  flex: 1; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 14px;
  padding: 13px 6px; font-size: 15.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.act:active { transform: scale(0.98); }
.act.stop { background: #e5484d; color: #fff; border-color: transparent; flex: 0.7; }
.act.warn { background: var(--warn); color: #fff; border-color: transparent; }
.act.danger { color: var(--danger); flex: 0.5; }
.act:disabled { opacity: 0.45; }

/* 一句字幕：英文小字 + 头像 + 中文气泡 */
.seg { margin-bottom: 16px; cursor: pointer; }
.seg-meta, .seg-en { margin-left: calc(var(--avatar) + 10px); }
.seg-meta { font-size: 12px; color: var(--faint); display: flex; gap: 6px; align-items: center; font-variant-numeric: tabular-nums; }
.seg-en { font-size: calc(var(--zh-size) * 0.78); color: var(--muted); line-height: 1.4; margin-top: 2px; }
.hide-en .seg-en { display: none; }
.seg-row { display: flex; gap: 10px; align-items: flex-start; margin-top: 5px; }
.avatar { width: var(--avatar); height: var(--avatar); border-radius: 50%; flex: none; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15); }
.bubble {
  background: var(--bubble); border: 1px solid var(--bubble-line); border-radius: 16px;
  padding: 8px 12px; font-size: var(--zh-size); font-weight: 600; line-height: 1.45; max-width: 100%; word-break: break-word;
}
.bubble.pending { color: var(--faint); font-weight: 400; font-size: calc(var(--zh-size) * 0.8); }
.bubble.failed { color: var(--danger); font-weight: 400; font-size: calc(var(--zh-size) * 0.8); }
.live-line { margin-left: calc(var(--avatar) + 10px); color: var(--faint); font-style: italic; font-size: calc(var(--zh-size) * 0.78); min-height: 1.4em; }
.hello { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; }
.hello .bubble { font-weight: 400; color: var(--muted); font-size: 16px; }

/* 问 AI 助教 */
.side-panel { display: none; }
@media (min-width: 900px) {
  .side-panel { display: flex; width: 380px; border-left: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 60%, transparent); }
  #btnAsk { display: none; }
}
.assistant { display: flex; flex-direction: column; width: 100%; min-height: 0; flex: 1; }
.assistant-title { font-weight: 700; padding: 12px 14px 8px; }
.chat { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 12px 12px; }
.msg { display: flex; gap: 8px; margin-bottom: 12px; align-items: flex-start; }
.msg.me { justify-content: flex-end; }
.msg .text { border-radius: 14px; padding: 8px 12px; font-size: 15.5px; line-height: 1.55; max-width: 85%; word-break: break-word; }
.msg.me .text { background: var(--user-bubble); color: #fff; }
.msg.bot .text { background: var(--bubble); border: 1px solid var(--bubble-line); }
.msg .time { font-size: 11px; color: var(--faint); text-align: right; margin-top: 2px; }
.msg .avatar { --avatar: 32px; }
.thinking { color: var(--muted); }
.thinking::after { content: "…"; animation: pulse 1s infinite; }
.examples { margin-top: 10px; }
.hw-item { margin-bottom: 8px; }
.examples button {
  display: block; width: 100%; text-align: left; border: none; background: var(--accent-soft); color: var(--text);
  border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; font-size: 14.5px; cursor: pointer;
}
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 0; flex: none; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex: none; }
.ask-row { display: flex; gap: 8px; padding: 8px 12px 12px; align-items: flex-end; flex: none; }
.ask-row textarea {
  flex: 1; resize: none; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bubble); color: var(--text); max-height: 120px; outline: none;
}
.ask-row button { border: none; width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 20px; flex: none; }
.ask-row button:disabled { opacity: 0.4; }
.panel-error { color: var(--danger); font-size: 13.5px; padding: 0 14px 6px; }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.3); display: flex; align-items: flex-end; }
.sheet-card {
  width: 100%; height: 86%; background: var(--bg); border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  padding-bottom: var(--sab); box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2); animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0.5; } }
.sheet-grip { display: flex; justify-content: flex-end; padding: 6px 8px 0; flex: none; }
.sheet-panel { flex: 1; min-height: 0; display: flex; }

.menu { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.3); display: flex; align-items: flex-end; justify-content: center; }
.menu-card { width: min(100%, 520px); background: var(--bg); border-radius: 18px 18px 0 0; padding: 12px 12px calc(var(--sab) + 12px); animation: up 0.18s ease-out; }
.menu-preview { font-size: 14px; color: var(--muted); padding: 4px 6px 10px; max-height: 5.5em; overflow: hidden; }
.menu-card button { display: block; width: 100%; border: none; background: var(--card); color: var(--text); padding: 14px; border-radius: 12px; margin-bottom: 6px; font-size: 16px; }
.menu-card .cancel { color: var(--muted); }

/* 一节课的记录 */
.session-head { max-width: 900px; margin: 0 auto 10px; }
.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; max-width: 900px; margin: 0 auto 14px; }
.tab { flex: 1; border: none; background: transparent; color: var(--muted); padding: 8px 4px; border-radius: 9px; font-size: 14.5px; font-weight: 600; }
.tab.on { background: var(--accent); color: #fff; }
#sessBody { max-width: 900px; margin: 0 auto; }
#sessBody .assistant { height: 62vh; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.sum-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; line-height: 1.6; }
.sum-card h3 { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
.sum-card.hw { border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 10%, var(--card)); }
.sum-card.hw h3 { color: var(--warn); }
.sum-card.exam h3 { color: var(--danger); }
.sum-card ol, .sum-card ul { margin: 0; padding-left: 1.3em; }
.sum-card li { margin-bottom: 4px; }
.due { color: var(--warn); font-weight: 600; font-size: 14px; }
.quote { color: var(--muted); font-size: 13px; }
.gloss { display: grid; grid-template-columns: auto auto 1fr; gap: 6px 12px; font-size: 14.5px; }
.gloss b { white-space: nowrap; }
.gloss span:nth-child(3n) { color: var(--muted); }
@media (max-width: 520px) {
  .gloss { grid-template-columns: 1fr; gap: 2px; }
  .gloss span:nth-child(3n) { margin-bottom: 8px; }
}
.session-actions { display: flex; gap: 8px; max-width: 900px; margin: 16px auto 0; }
.foot { font-size: 12px; color: var(--faint); margin: 8px 2px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 90px); transform: translateX(-50%); z-index: 40;
  background: rgba(30, 24, 34, 0.9); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw;
}
