/* ============================================================================
 * 富文本（题目内容 / 选项）渲染与编辑样式
 * ----------------------------------------------------------------------------
 * 全部走主题 CSS 变量（--text-* / --border-color / --bg-muted / --accent-color），
 * 因此管理员、选手、观察员三套主题色自动适配，无需按角色重复定义。
 * 由 static/js/rich_text.js 生成的 class 命名统一以 rt- 前缀，避免与既有页面样式碰撞。
 * ========================================================================== */

/* ---------------------------------------------------------------- 只读渲染 */
.rt-content {
    line-height: 1.75;
    word-break: break-word;
    overflow-wrap: anywhere;   /* 长公式/长链接不撑破容器 */
}

.rt-content > *:first-child { margin-top: 0; }
.rt-content > *:last-child { margin-bottom: 0; }

.rt-p {
    margin: 0 0 0.75em;
}

/* 图片：自适应宽度，避免大截图撑破题目卡片 */
.rt-img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0.6em auto;
    border-radius: 8px;
    border: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-card, #fff);
    cursor: zoom-in;
}

/* 行内代码 / 代码块 */
.rt-code {
    font-family: 'Cascadia Code', Consolas, Monaco, 'Courier New', monospace;
    font-size: 0.9em;
    padding: 0.15em 0.42em;
    border-radius: 4px;
    background: var(--bg-muted, #f1f5f9);
    border: 1px solid var(--border-color, #e2e8f0);
    color: var(--accent-color-dark, #0284c7);
}

.rt-pre {
    margin: 0.75em 0;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--bg-muted, #f8fafc);
    border: 1px solid var(--border-color, #e2e8f0);
    overflow-x: auto;
}

.rt-pre code {
    font-family: 'Cascadia Code', Consolas, Monaco, 'Courier New', monospace;
    font-size: 0.88em;
    line-height: 1.6;
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary, #2d3748);
    white-space: pre;
}

/* 公式 */
.rt-tex {
    display: inline-block;
    max-width: 100%;
    vertical-align: middle;
}

.rt-tex-block {
    display: block;
    margin: 0.75em 0;
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
}

.rt-content mjx-container {
    max-width: 100%;
}

.rt-content mjx-container[display="true"] {
    margin: 0.4em 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
}

/* 无障碍 MathML 副本必须隐藏。
   MathJax 自己也会注入这条规则，但注入依赖「首次排版文档」这一步；
   本项目为业务关闭了全页扫描（见 rich_text.js 的 startup.typeset=false），
   一旦注入失败，读屏用的 MathML 会与 SVG 一起显示、看起来像公式被渲染了两遍。
   这里放一条不依赖 MathJax 的兜底规则，保证任何情况下都只显示一份。 */
mjx-assistive-mml {
    position: absolute !important;
    top: 0;
    left: 0;
    display: block !important;
    width: auto !important;
    height: auto !important;
    padding: 1px 0 0 0;
    border: 0;
    margin: 0;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

/* 列表 */
.rt-ul,
.rt-ol {
    margin: 0.5em 0 0.75em;
    padding-left: 1.6em;
}

.rt-ul li,
.rt-ol li {
    margin: 0.22em 0;
}

/* 引用 */
.rt-quote {
    margin: 0.75em 0;
    padding: 8px 14px;
    border-left: 4px solid var(--accent-color, #0ea5e9);
    border-radius: 0 6px 6px 0;
    background: var(--bg-muted, #f8fafc);
    color: var(--text-secondary, #475569);
}

/* 小标题（用 div 而非 h4，避免与页面既有 h1~h6 样式冲突） */
.rt-h {
    margin: 1em 0 0.5em;
    font-weight: 700;
    color: var(--text-primary, #2d3748);
    line-height: 1.4;
}

.rt-h4 { font-size: 1.15em; }
.rt-h5 { font-size: 1.05em; }
.rt-h6 { font-size: 1em; color: var(--text-secondary, #475569); }

.rt-hr {
    margin: 1.1em 0;
    border: none;
    border-top: 1px dashed var(--border-color, #e2e8f0);
}

.rt-link {
    color: var(--accent-color, #0ea5e9);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-color, #0ea5e9);
}

.rt-link:hover {
    color: var(--accent-color-dark, #0284c7);
}

/* ---------------------------------------------------------------- 编辑器 */
.rt-editor-wrap {
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    background: var(--bg-card, #fff);
    overflow: hidden;
}

.rt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--bg-muted, #f8fafc);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.rt-btn {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    font-size: 13px;
    line-height: 1;
    color: var(--text-secondary, #475569);
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.rt-btn:hover {
    color: var(--accent-color-dark, #0284c7);
    border-color: var(--accent-color, #0ea5e9);
    background: var(--accent-ring, #eff6ff);
}

.rt-btn:active {
    transform: translateY(1px);
}

.rt-btn-math {
    color: var(--accent-color-dark, #0284c7);
    font-weight: 600;
}

.rt-sep {
    width: 1px;
    height: 20px;
    margin: 0 3px;
    background: var(--border-color, #e2e8f0);
}

.rt-hint {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    padding-right: 2px;
}

/* 编辑区本体：覆盖各页面自带的 textarea 样式，统一字号与行高 */
.rt-editor-wrap textarea.rt-textarea,
textarea.rt-textarea {
    display: block;
    width: 100%;
    min-height: 150px;
    padding: 12px 14px;
    margin: 0;
    border: none;
    border-radius: 0;
    outline: none;
    resize: vertical;
    font-family: 'Cascadia Code', Consolas, Monaco, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary, #2d3748);
    background: var(--bg-card, #fff);
    box-sizing: border-box;
}

textarea.rt-textarea:focus {
    box-shadow: inset 0 0 0 2px var(--accent-ring, #e0f2fe);
}

/* 预览面板 */
.rt-preview {
    margin-top: 10px;
    padding: 12px 14px;
    min-height: 60px;
    border: 1px dashed var(--border-color, #e2e8f0);
    border-radius: 8px;
    background: var(--bg-muted, #f8fafc);
}

.rt-preview-empty::before {
    content: '预览区：输入内容后会实时显示渲染效果（公式、图片等）';
    color: var(--text-muted, #64748b);
    font-size: 13px;
}

.rt-preview-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #475569);
}

/* 上传中的轻量提示 */
.rt-uploading {
    opacity: 0.6;
    pointer-events: none;
}

/* 图片点击放大 */
.rt-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(15, 23, 42, 0.82);
    cursor: zoom-out;
}

.rt-lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
