/* 基础配色 */
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7684;
  --line: #e2e6ec;
  --accent: #2f6bd8;
  --accent-soft: #e8f0ff;
  --danger: #d8453f;
  --ok: #1f9d55;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.nav a {
  padding: 6px 14px; border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-size: 14px;
  border: 1px solid transparent;
}
.nav a:hover { background: var(--accent-soft); }
.nav a.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-refresh {
  padding: 6px 14px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer;
}
.nav-refresh:hover { background: var(--accent-soft); }
.nav-refresh:disabled { opacity: .5; cursor: default; }

/* 主体 */
.view { max-width: 1120px; margin: 0 auto; padding: 22px 18px 60px; }

.fold-card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; user-select: none; }
.fold-card > summary::-webkit-details-marker { display: none; }
.fold-card > summary::before { content: '\25B8'; display: inline-block; transition: transform .15s; color: var(--muted); }
.fold-card[open] > summary::before { transform: rotate(90deg); }
.fold-card:not([open]) > summary { margin-bottom: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.card-title .sub { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* 表单 */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.field-label { color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  font: inherit; cursor: pointer;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { opacity: .9; color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--line); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td .btn { padding: 3px 8px; font-size: 12px; }
.table-wrap { overflow-x: auto; }

/* 视频 */
.pager {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  margin: 12px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-card, #fff);
}
.pager .btn[disabled] { opacity: .45; cursor: default; }
.pager .btn[disabled]:hover { border-color: var(--line); color: inherit; }
.pager .pager-info { margin-left: auto; color: var(--muted); font-size: 13px; }
.pager .page-size { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: inherit; }
.up-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.up-tab {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); cursor: pointer; font-size: 13px;
}
.up-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 16px; }
.video-item { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.video-navigation { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.video-navigation a { text-decoration: none; color: var(--text); }
.video-my-menu { position: relative; margin-left: auto; }
.video-my-menu summary { user-select: none; }
.video-my-options { position: absolute; right: 0; top: calc(100% + 8px); z-index: 10; display: grid; gap: 6px; min-width: 165px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.video-heading { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.video-heading h2 { font-size: 22px; margin: 0 auto 0 0; }
.video-open { display: block; text-decoration: none; color: var(--text); }
.video-meta a { color: var(--muted); text-decoration: none; }
.video-meta a:hover { color: var(--accent); text-decoration: underline; }
.video-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 12px; margin-top: auto; }
.video-actions .btn { padding: 3px 6px; font-size: 12px; }
.viewed-badge { display: inline-block; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; }
.up-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 16px; }
.up-search, .video-search { margin-top: 14px; }
.up-search input, .video-search input { flex: 1 1 220px; max-width: 420px; width: 100%; }
.up-name { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.up-name:hover { color: var(--accent); text-decoration: underline; }
.player-actions { margin: 12px 0; }
.player-related { display: grid; gap: 14px; margin-top: 18px; }
.chatbox-page { position: relative; display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; height: calc(100vh - var(--chat-top-offset, 130px)); min-height: 340px; margin-bottom: calc(-1 * var(--chat-bottom-pad, 60px)); }
@supports (height: 100dvh) { .chatbox-page { height: calc(100dvh - var(--chat-top-offset, 130px)); } }
.chat-list { display: grid; gap: 10px; align-content: start; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scroll-padding: 8px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.chat-row { display: flex; min-width: 0; }
.chat-row.me { justify-content: flex-end; }
.chat-row.ai { justify-content: flex-start; }
.chat-bubble { max-width: 78%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 18px; line-height: 1.8; }
.chat-row.me .chat-bubble { background: var(--accent); color: #fff; }
.chat-row.ai .chat-bubble { max-width: 100%; width: 100%; border: 1px solid var(--line); }
/* 底部操作栏：选项 + 输入框 + 发送，固定在视口底部，与顶栏呼应 */
.chat-dock {
  position: sticky; bottom: 0; z-index: 15;
  display: grid; gap: 4px; margin-top: auto;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--card);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -1px 3px rgba(20, 30, 50, .08);
}
/* 用户上翻看历史时出现的「回到最新」浮标，浮在底部栏上方 */
.chat-jump { position: absolute; top: -36px; right: 12px; z-index: 1; padding: 4px 10px; font-size: 13px; box-shadow: var(--shadow); }
.chat-jump[hidden] { display: none; }
.chat-dock > .chat-option-bar { margin: 0; }
.chat-dock > .chat-composer { margin: 0; }
/* 录音：按钮 + 回放 */
.chat-voice-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chat-voice-audio { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-voice-audio audio { max-width: 100%; height: 32px; }
/* 选项条里的图标下拉：小图标 + 弹出选项 */
.chat-icon-option { position: relative; display: inline-flex; align-items: center; }
.chat-menu { position: absolute; z-index: 30; left: 0; bottom: calc(100% + 6px); min-width: 180px; max-width: 260px; max-height: 260px; overflow-y: auto; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.chat-menu[hidden] { display: none; }
.chat-menu-item { display: block; width: 100%; padding: 6px 8px; border: 0; border-radius: 6px; background: none; color: var(--text); font-size: 14px; line-height: 1.45; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.chat-menu-item:hover { background: var(--accent-soft); }
.chat-menu-item.active { color: var(--accent); font-weight: 600; }
.chat-option select.chat-select-hidden { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; }
/* 图片选择：按钮行 + 缩略图预览 */
.chat-image-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-file-input { display: none; }
.chat-images { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-image-item { position: relative; width: 72px; height: 72px; }
.chat-image-item img { width: 100%; height: 100%; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); background: var(--accent-soft); display: block; }
.chat-image-remove { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--text); font-size: 14px; line-height: 1; cursor: pointer; }
.chat-image-remove:hover { border-color: var(--danger); color: var(--danger); }
body.eink .chat-image-item img, body.eink .chat-image-remove { border-width: 2px; border-radius: 0; }
body.eink .chat-hold-btn, body.eink .chat-icon-btn, body.eink .chat-text-bar { border-width: 2px; border-radius: 0; }
/* 等待后端 / 录音中的提示：浮在对话内容上方，不占操作栏高度，也不挡交互 */
.chat-status-layer { position: absolute; top: 6px; left: 0; right: 0; z-index: 20; display: grid; gap: 6px; justify-items: center; pointer-events: none; }
.chat-status { max-width: calc(100% - 24px); padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); box-shadow: var(--shadow); color: var(--muted); font-size: 13px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status[hidden] { display: none; }
.chat-composer { display: grid; gap: 6px; }
/* 没内容就完全不占位，避免底部操作栏被空元素撑高 */
.chat-composer [hidden] { display: none; }
.chat-images[hidden] { display: none; }
/* 语音态：键盘图标 + 按住说话 */
.chat-voice-bar { display: flex; align-items: center; gap: 8px; }
.chat-hold-btn {
  flex: 1 1 auto; padding: 11px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--text); font: inherit; font-size: 16px; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chat-hold-btn.recording { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-hold-btn.cancel { background: var(--danger); border-color: var(--danger); }
/* 文字态：输入框 + 左侧语音、右侧 @ / ＋ / 发送 */
.chat-text-bar { display: grid; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.chat-text-actions { display: flex; align-items: center; gap: 8px; }
.chat-text-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.chat-icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--card);
  color: var(--text); font: inherit; font-size: 17px; line-height: 1; cursor: pointer;
}
.chat-icon-btn svg { width: 20px; height: 20px; }
.chat-icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.chat-icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-icon-btn.primary:hover { color: #fff; }
.chat-icon-btn:disabled { opacity: .5; cursor: default; }
.chat-attach-menu { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-attach-menu.hidden { display: none; }
.chat-voice-tip { min-height: 1.2em; }
.chat-voice-bar.hidden, .chat-text-bar.hidden { display: none; }
.chat-icon-btn[hidden] { display: none; }
/* 选项条里的下拉图标：比操作按钮更小 */
.chat-option-icon { width: 24px; height: 24px; }
.chat-option-icon svg { width: 14px; height: 14px; }
/* 自动朗读开关：开启时高亮 */
.chat-autoread.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-autoread.active:hover { color: #fff; }
/* 单条回答下方的「朗读」按钮 */
.chat-col { display: grid; gap: 4px; width: 100%; min-width: 0; }
.chat-actions { display: flex; align-items: center; gap: 8px; }
.chat-read-btn { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--muted); font: inherit; font-size: 13px; line-height: 1.6; cursor: pointer; }
.chat-read-btn svg { width: 15px; height: 15px; }
.chat-read-btn:hover { border-color: var(--accent); color: var(--accent); }
/* 朗读控制条：浮在对话内容上方，不占输入区高度（播放/暂停 · 波形 · 倍速 · 停止） */
.chat-tts-bar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 25; display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); box-shadow: var(--shadow); }
.chat-tts-bar[hidden] { display: none; }
.chat-tts-play { width: 34px; height: 34px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); cursor: pointer; }
.chat-tts-play svg { width: 18px; height: 18px; }
.chat-tts-play:hover { background: var(--accent); color: #fff; }
.chat-tts-wave { display: inline-flex; align-items: flex-end; gap: 3px; height: 22px; }
.chat-tts-wave i { display: block; width: 3px; height: 8px; border-radius: 2px; background: var(--accent); animation: chatTtsWave 900ms ease-in-out infinite; }
.chat-tts-wave i:nth-child(2) { animation-delay: .15s; }
.chat-tts-wave i:nth-child(3) { animation-delay: .3s; }
.chat-tts-wave i:nth-child(4) { animation-delay: .45s; }
.chat-tts-bar.paused .chat-tts-wave i { animation-play-state: paused; height: 8px; }
.chat-tts-bar.loading .chat-tts-wave i { opacity: .4; }
@keyframes chatTtsWave { 0%, 100% { height: 8px; } 50% { height: 20px; } }
.chat-tts-rate-box { position: relative; }
.chat-tts-rate { padding: 5px 14px; border: none; border-radius: 999px; background: var(--accent-soft); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.chat-tts-rate:hover { background: var(--accent); color: #fff; }
.chat-tts-menu { left: auto; right: 0; top: calc(100% + 6px); bottom: auto; min-width: 110px; }
.chat-tts-close { width: 30px; height: 30px; flex: 0 0 auto; padding: 0; border: none; background: none; color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; }
.chat-tts-close:hover { color: var(--danger); }
body.eink .chat-tts-bar { border-width: 2px; }
/* 模式切换：问答 / 作业批改 / 生成图片 */
.chat-modes { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.chat-mode { padding: 5px 14px; border: none; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chat-mode.active { background: var(--accent); color: #fff; font-weight: 600; }
.chat-mode[hidden] { display: none; }   /* 暂时屏蔽的模式（作业批改）不显示给用户 */
.chat-options-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-left: auto; }
/* 作业批改输入区 */
/* 提问里的图片缩略图 */
.chat-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chat-thumb { width: 84px; height: 84px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); cursor: zoom-in; }
/* 作业批改卡片 */
.hw-card { width: 100%; display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; }
.hw-card:hover { border-color: var(--accent); }
.hw-card-head { display: flex; align-items: center; gap: 8px; }
.hw-icon svg, .hw-arrow svg { width: 20px; height: 20px; display: block; }
.hw-card-title { font-weight: 700; font-size: 17px; }
.hw-arrow { margin-left: auto; color: var(--muted); }
.hw-card-photo { width: 100%; max-height: 200px; object-fit: cover; border-radius: var(--radius); background: var(--accent-soft); }
.hw-card-note { color: var(--muted); font-size: 13px; }
/* 批改详情弹窗 */
.hw-mask { position: fixed; inset: 0; z-index: 55; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(12, 16, 22, .55); }
.hw-modal { width: min(760px, 100%); max-height: 90vh; overflow-y: auto; display: grid; gap: 12px; padding: 16px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.hw-modal-head { display: flex; align-items: center; gap: 8px; }
.hw-modal-title { font-weight: 700; font-size: 18px; }
.hw-close { margin-left: auto; width: 30px; height: 30px; border: none; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; }
.hw-modal-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hw-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.hw-chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--accent-soft); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.hw-chip.active { background: #111; border-color: #111; color: #fff; }
.hw-body { display: grid; gap: 10px; }
.hw-photo { width: 100%; max-height: 320px; object-fit: contain; border-radius: var(--radius); background: var(--accent-soft); cursor: zoom-in; }
.hw-question { font-size: 16px; line-height: 1.7; }
/* 同一大题下的每个小题 */
.hw-sub { display: grid; gap: 6px; padding: 12px 0; border-top: 1px solid var(--line); }
.hw-sub-title { font-weight: 600; font-size: 16px; line-height: 1.7; }
.hw-sub .hw-answer { padding-top: 0; border-top: none; }
.hw-answer { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.hw-flag { font-weight: 600; }
.hw-flag.ok { color: var(--ok); }
.hw-flag.bad { color: var(--danger); }
.hw-label { color: var(--muted); font-size: 13px; }
.hw-knowledge { display: flex; gap: 6px; flex-wrap: wrap; }
.hw-tag { padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--muted); }
.hw-icon-btn { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--text); cursor: pointer; }
.hw-icon-btn svg { width: 16px; height: 16px; }
/* 公式块：由 KaTeX 渲染（/vendor/katex/） */
.hw-math { font-size: 18px; line-height: 2.1; overflow-wrap: anywhere; white-space: pre-wrap; }
.hw-math .katex { font-size: 1.05em; }
.hw-math .katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.hw-math.math-pending { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; color: var(--muted); }
.hw-math .math-error { color: var(--danger); }
/* 只显示该题所在区域 */
.hw-photo[data-cropped] { max-height: 260px; border: 1px solid var(--line); }
body.eink .hw-card, body.eink .hw-modal, body.eink .chat-modes { border-width: 2px; }
body.eink .hw-chip.active { background: #000; border-color: #000; }
.chat-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.chat-option-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }
.chat-options-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-right: auto; justify-content: flex-start; }
.chat-option { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.chat-toggles { display: flex; gap: 12px; flex-wrap: wrap; margin-left: auto; justify-content: flex-end; }
.chat-history-select { width: 8.5em; flex: 0 0 auto; padding: 4px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); font: inherit; font-size: 13px; }
.chat-flash { animation: chatFlash 1.6s ease; border-radius: var(--radius); }
@keyframes chatFlash { 0%, 60% { background: var(--accent-soft); } 100% { background: transparent; } }
.chat-text-bar textarea {
  width: 100%; padding: 6px 2px; border: none; background: none; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.6; resize: none;
}
.chat-text-bar textarea:focus { outline: none; }
.chat-composer.hidden { display: none; }
/* 助手回答的 Markdown 排版 */
.chat-md { white-space: normal; }
.chat-md > *:first-child { margin-top: 0; }
.chat-md > *:last-child { margin-bottom: 0; }
.chat-md p { margin: 0 0 10px; }
.chat-md h2, .chat-md h3, .chat-md h4, .chat-md h5, .chat-md h6 { margin: 8px 0 4px; line-height: 1.4; }
.chat-md h2 { font-size: 23px; }
.chat-md h3 { font-size: 21px; }
.chat-md h4, .chat-md h5, .chat-md h6 { font-size: 19px; }
.chat-md ul, .chat-md ol { margin: 0 0 6px; padding-left: 22px; }
.chat-md li { margin: 4px 0; line-height: 1.7; }
.chat-md li > ul, .chat-md li > ol { margin: 2px 0; }
.chat-md code { padding: 1px 5px; border-radius: 4px; background: var(--accent-soft); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; }
.chat-md pre { margin: 6px 0; padding: 8px 10px; border-radius: var(--radius); background: var(--accent-soft); overflow-x: auto; }
.chat-md pre code { padding: 0; background: none; white-space: pre; }
.chat-md blockquote { margin: 6px 0; padding: 2px 10px; border-left: 3px solid var(--line); color: var(--muted); }
.chat-md table { margin: 6px 0; border-collapse: collapse; font-size: 16px; display: block; width: max-content; max-width: 100%; overflow-x: auto; }
.chat-md th, .chat-md td { padding: 4px 8px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.chat-md hr { margin: 8px 0; border: none; border-top: 1px solid var(--line); }
.chat-md a { color: var(--accent); }
.chat-md img.chat-image { display: block; width: auto; height: auto; max-width: min(400px, 100%); max-height: 400px; margin: 6px 0; border-radius: var(--radius); background: var(--accent-soft); }
.chat-md img.chat-image { cursor: zoom-in; }   /* 点击查看原图 */
.chat-image-broken { color: var(--muted); font-size: 13px; }
/* 查看原图（灯箱） */
.lightbox { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; background: rgba(12, 16, 22, .86); cursor: zoom-out; }
.lightbox-img { max-width: 100%; max-height: 84%; object-fit: contain; border-radius: var(--radius); background: #fff; cursor: default; }
.lightbox-caption { max-width: 90%; color: #fff; font-size: 13px; text-align: center; }
.lightbox-close { position: absolute; top: 14px; right: 18px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border: 1px solid rgba(255, 255, 255, .5); border-radius: 50%; background: rgba(0, 0, 0, .35); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }
.lightbox-close:hover { background: rgba(255, 255, 255, .2); }
body.eink .lightbox { background: #fff; }
body.eink .lightbox-caption { color: #000; }
body.eink .lightbox-close { border-color: #000; background: #fff; color: #000; }
.player-layout { display: flex; gap: 14px; align-items: flex-start; }
.player-stage { flex: 1 1 auto; min-width: 0; }
.part-row { flex-wrap: wrap; margin-top: 6px; }
.part-picker { display: flex; flex-wrap: wrap; gap: 4px; max-height: 140px; overflow-y: auto; }
.part-picker .btn { padding: 2px 8px; font-size: 12px; }
/* 手机等小屏幕：收紧留白，保证聊天内容不超出屏宽 */
@media (max-width: 640px) {
  .view { padding: 10px 8px 20px; }
  .chatbox-page { gap: 8px; --chat-bottom-pad: 20px; height: calc(100vh - var(--chat-top-offset, 96px)); min-height: 240px; }
  @supports (height: 100dvh) { .chatbox-page { height: calc(100dvh - var(--chat-top-offset, 96px)); } }
  .chat-dock { padding: 5px 10px calc(5px + env(safe-area-inset-bottom, 0px)); border-radius: var(--radius) var(--radius) 0 0; }
  .chat-list { padding: 6px; gap: 8px; }
  .chat-bubble { max-width: 100%; font-size: 18px; padding: 10px 12px; }
  .chat-row.ai .chat-bubble { width: 100%; }
  .chat-option-bar { gap: 8px; margin: 6px 0 0; }
  .chat-options-left, .chat-toggles { gap: 8px; }
  .chat-history-select { width: 7.5em; font-size: 12px; }
  .chat-md h2 { font-size: 21px; }
  .chat-md h3 { font-size: 19px; }
  .chat-md h4, .chat-md h5, .chat-md h6 { font-size: 18px; }
  .chat-md pre { font-size: 15px; }
}

@media (max-width: 900px) {
  .player-layout { flex-direction: column; }
}
.up-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }
.up-chip a { color: inherit; text-decoration: none; }
.up-chip a:hover { text-decoration: underline; }
.up-chip .btn { padding: 1px 5px; font-size: 12px; }
.group-members, .up-group-control { flex-wrap: wrap; }
.group-manager { display: grid; gap: 14px; }
.group-manager .card .row { flex-wrap: wrap; }
.player-related .video-grid { margin-top: 10px; }
.video-page a:focus-visible, .video-page summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.video-content[aria-busy="true"] { opacity: .65; }
@media (max-width: 520px) {
  .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .video-title { overflow-wrap: anywhere; }
  .video-actions { padding: 6px; }
  .video-navigation { gap: 6px; }
  .video-heading h2 { font-size: 19px; }
}
.fav-btn {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 28px; height: 28px; line-height: 24px; text-align: center;
  border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, .92);
  cursor: pointer; font-size: 16px; color: #333; padding: 0;
}
.fav-btn.on { color: #f0a500; border-color: #f0a500; }
.watched-btn {
  position: absolute; bottom: 6px; right: 6px; z-index: 2;
  padding: 2px 8px; font-size: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .92); color: #333; cursor: pointer;
}
.watched-btn.on { color: #fff; background: #1a7f37; border-color: #1a7f37; }
.video-item:hover { border-color: var(--accent); }
.cover-wrap { position: relative; }
.video-cover { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #eceff3; display: block; }
.video-duration {
  position: absolute; right: 6px; bottom: 6px; z-index: 1;
  padding: 1px 5px; border-radius: 4px;
  background: rgba(0, 0, 0, .75); color: #fff;
  font-size: 12px; line-height: 1.6; pointer-events: none;
}
.video-title {
  font-size: 13px; padding: 8px 10px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 42px;
}
.video-meta { font-size: 12px; color: var(--muted); padding: 0 10px 8px; }
/* 收藏 / 历史列表条目 */
.entry {
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; margin-bottom: 10px; background: var(--card);
  flex-wrap: wrap;
}
.entry .thumb { width: 130px; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 6px; background: #eceff3; flex: none; }
.entry .body { flex: 1; min-width: 180px; }

.player-box { position: relative; }
.player-box iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; display: block; background: #000; }


a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* 黑白棋 */
.game-wrap { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .game-wrap { grid-template-columns: 1fr; } }
.board {
  display: grid; grid-template-columns: repeat(10, 1fr);
  width: 100%; aspect-ratio: 1 / 1;
  background: #fff; border: 3px solid #000;
}
.board .cell {
  position: relative; background: #fff;
  border: 1px solid #000; cursor: default;
  display: flex; align-items: center; justify-content: center;
}
.board .cell .disc {
  width: 78%; height: 78%; border-radius: 50%;
  border: 2px solid #000; background: #fff;
}
.board .cell.black .disc { background: #000; }
.board .cell.valid::after {
  content: ''; position: absolute; width: 22%; height: 22%;
  border: 2px solid #000; background: #fff;
}
.board .cell.last::before {
  content: ''; position: absolute; width: 20%; height: 20%;
  background: #000; z-index: 2;
}
.board .cell.black.last::before { background: #fff; }
.board.playable .cell.valid { cursor: pointer; }
.score { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.score-item { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; }
.chip { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #000; background: #fff; }
.chip.black { background: #000; }
.turn-badge { padding: 3px 10px; border: 2px solid #000; font-weight: 700; font-size: 14px; }
.log { font-size: 13px; max-height: 220px; overflow-y: auto; }

/* 黑板 */
.board-item {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px; background: var(--card);
}
.board-item .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.board-item .text { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; }

/* 提示 / 弹窗 */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px);
  background: #1c2430; color: #fff; padding: 10px 18px; border-radius: var(--radius);
  font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 25, 35, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
/* 关键：作者样式的 display 会覆盖浏览器对 [hidden] 的隐藏，必须显式声明 */
.modal-mask[hidden] { display: none; }
.modal {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }

.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
