/* Tus - 北京工业大学试卷共享平台 */
/* 基础样式 - Tailwind 覆盖 */

/* 基础 reset — Tailwind v4 的 @layer base 已处理 margin/padding，此处只保留 box-sizing */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
}

/* ===== 暗色模式变量 ===== */
html.dark {
    --bg-body: #141210;
    --bg-gradient: #1f1b18;
    --bg-card: #2d2824;
    --bg-card-hover: #35302a;
    --bg-nav: rgba(20, 18, 16, 0.94);
    --border-light: #3d3630;
    --text-primary: #ece6de;
    --text-secondary: #a69a8e;
    --text-muted: #8a7e72;
    --accent: #f59e0b;
    --accent-hover: #d97706;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --card-border: rgba(255, 255, 255, 0.04);
}

/* 暗色背景渐变 */
html.dark body {
    background: linear-gradient(135deg, var(--bg-body), var(--bg-gradient));
}

/* 暗色纸张纹理 — 反色 */
html.dark body::after {
    opacity: 0.025;
    mix-blend-mode: screen;
}

/* 暗色模式切换按钮 — 印章风格 */
.dark-toggle {
    width: 28px;
    height: 28px;
    border: 1.5px solid #b91c1c;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    font-family: 'Noto Serif SC', 'SimSun', serif;
    color: #b91c1c;
    padding: 0;
    transition: all 0.2s ease;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
@media (hover: hover) {
    .dark-toggle:hover {
        background: rgba(185, 28, 28, 0.06);
        transform: translateY(-1px);
    }
}
html.dark .dark-toggle {
    border-color: #dc2626;
    color: #dc2626;
}
@media (hover: hover) {
    html.dark .dark-toggle:hover {
        background: rgba(220, 38, 38, 0.1);
    }
}

/* ===== 回到顶部按钮 ===== */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 800;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #44403c;
    color: #f5f0ea;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}
.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.back-to-top:hover {
    background: #5a5048;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
}
.back-to-top:active {
    background: #33302c;
    transform: translateY(0);
}

@media (max-width: 640px) {
    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
}

/* 试卷卡片 */
.paper-card {
    transition: all 0.25s ease;
    cursor: pointer;
    touch-action: manipulation;
}
.paper-card:active {
    background-color: #ede5dc;
}
@media (hover: hover) {
    .paper-card:hover {
        background-color: #f5f0ea;
        border-color: #d6cec4;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    }
}

/* 暗色模式卡片交互 */
html.dark .paper-card:active {
    background-color: #3d3630;
}
@media (hover: hover) {
    html.dark .paper-card:hover {
        background-color: var(--bg-card-hover);
        border-color: rgba(255, 255, 255, 0.08);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }
}
html.dark .subject-card:hover {
    background-color: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.08) !important;
}

/* 暗色选择框箭头 — 自定义替换浏览器默认箭头 */
html.dark select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a69a8e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    padding-right: 36px;
}

/* 暗色 Hero 标签 */
html.dark .hero-label {
    background: rgba(255, 255, 255, 0.06);
    color: #a69a8e;
}
html.dark .hero-label::before,
html.dark .hero-label::after {
    background: #eab308;
}

/* Hero 标签 */
.hero-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 3px 14px;
    background: rgba(68, 64, 60, 0.06);
    border-radius: 999px;
    font-size: 12px;
    color: #78716c;
    letter-spacing: 1px;
    margin-bottom: 16px;
}
.hero-label::before,
.hero-label::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ca8a04;
    display: inline-block;
}

/* 纸张纹理背景 */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.035;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* 主标题 — 更精致的排版 */
.site-title {
    font-size: 2.25rem;
    font-weight: 700;
    color: #44403c;
    letter-spacing: 4px;
    line-height: 1.3;
}
html.dark .site-title {
    color: #ece6de;
}
@media (max-width: 640px) {
    .site-title { font-size: 1.75rem; letter-spacing: 2px; }
}

/* 导航品牌字标 */
nav .text-2xl.font-bold {
    letter-spacing: 3px;
    position: relative;
}
nav .text-2xl.font-bold::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    width: 1px;
    height: 18px;
    background: #d6cec4;
    transform: translateY(-50%);
}

/* 科目卡片入场动画 */
.subject-card {
    position: relative;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.5s ease, transform 0.5s ease, box-shadow 0.25s ease;
}
.subject-card.card-visible {
    opacity: 1;
    transform: translateY(0);
}
.subject-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
}

/* 科目年级标记 — 右上角绝对定位 */
.subj-grade {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 8px !important;
    border-bottom-left-radius: 8px !important;
    border-bottom-right-radius: 0 !important;
}

/* 科目标题溢出裁切 + 跑马灯 */
.subject-card h2 {
    overflow: hidden;
    white-space: nowrap;
    -webkit-mask-image: linear-gradient(to right, black 92%, transparent 100%);
    mask-image: linear-gradient(to right, black 92%, transparent 100%);
}
.subject-card h2 .marquee-inner {
    display: inline-block;
    white-space: nowrap;
}

/* 试卷标题自适应淡出截断（百分比相对卡片宽度自动适配） */
.paper-card h2 {
    overflow: hidden;
    white-space: nowrap;
    -webkit-mask-image: linear-gradient(to right, black 92%, transparent 100%);
    mask-image: linear-gradient(to right, black 92%, transparent 100%);
}

/* 跑马灯内层 — 由 Web Animations API 驱动 translateX，GPU 加速 60fps */
.paper-card h2 .marquee-inner {
    display: inline-block;
    white-space: nowrap;
}

/* 表单验证错误高亮 */
.submit-error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15) !important;
}
html.dark .submit-error {
    border-color: #f87171 !important;
    box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.15) !important;
}

/* 拖拽上传区高亮 */
.drop-zone-active {
    border-color: #d97706 !important;
    background-color: #fffbeb !important;
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 加载骨架屏 */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 响应式字体 */
@media (max-width: 640px) {
    .text-3xl { font-size: 1.5rem; }
    .text-2xl { font-size: 1.25rem; }
}

/* 页脚置底 */
body {
    display: flex;
    flex-direction: column;
}
main {
    flex: 1;
}

/* ===== 试卷详情弹窗 ===== */
.paper-detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(30, 26, 22, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: overlay-fade-in 0.3s ease;
}

@keyframes overlay-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.paper-detail-card {
    background: #fcfaf7;
    max-width: 460px;
    width: 100%;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    animation: card-in 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
}

@keyframes card-in {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.detail-header {
    text-align: center;
    padding: 20px 24px 14px;
    font-size: 17px;
    font-weight: 600;
    color: #3d3430;
    letter-spacing: 4px;
    border-bottom: 1px solid #ece6de;
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
}

.detail-body {
    padding: 18px 24px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 7px 0;
    font-size: 14px;
    line-height: 1.6;
    border-bottom: 1px dashed #f0eae2;
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
}
.detail-row:last-of-type {
    border-bottom: none;
}

.detail-label {
    color: #9e9488;
    white-space: nowrap;
    margin-right: 12px;
    flex-shrink: 0;
}

.detail-value {
    color: #4a4038;
    text-align: right;
    word-break: break-all;
}

.detail-footer {
    display: flex;
    gap: 8px;
    padding: 14px 24px 20px;
}
.detail-footer-triple {
    flex-wrap: wrap;
}

.detail-preview-btn,
.detail-download-btn,
.detail-close-btn {
    text-align: center;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
    text-decoration: none;
    border: none;
    flex: 1 1 80px;
    min-width: 0;
}

.detail-preview-btn {
    background: #f0ece6;
    color: #3d3430;
    border: 1px solid #d0c8be;
}
.detail-preview-btn:hover {
    background: #e4dcd2;
}

.detail-download-btn {
    background: #ca8a04;
    color: #292524;
}
.detail-download-btn:hover {
    background: #a16207;
    color: #1c1917;
}

.detail-close-btn {
    background: #ece6de;
    color: #5a5048;
}
.detail-close-btn:hover {
    background: #e0d8ce;
}

@media (max-width: 480px) {
    .paper-detail-card { max-width: 100%; }
    .detail-body { padding: 14px 18px; }
    .detail-footer { padding: 12px 18px 18px; }
    .detail-header { padding: 16px 18px 12px; font-size: 15px; }
}

/* ===== 弹窗内嵌预览 ===== */
.preview-container {
    display: flex;
    flex-direction: column;
    height: 420px;
    max-height: 50vh;
    border-bottom: 1px solid #ece6de;
    overflow-y: auto;
}

.preview-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 48px 20px;
    color: #9e9488;
    font-size: 14px;
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
}

.preview-loading .spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid #e4dcd2;
    border-top-color: #ca8a04;
    border-radius: 50%;
    animation: preview-spin 0.8s linear infinite;
}

@keyframes preview-spin {
    to { transform: rotate(360deg); }
}

.preview-iframe,
.word-container,
.pdf-container {
    width: 100%;
    flex: 1;
    border: none;
    background: #525252;
    min-height: 0;
}
.word-container {
    background: #525252;
    min-height: 0;
    overflow-y: auto;
    height: 100%;
    padding: 0 8px;
}
.word-container .docx-preview {
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-radius: 2px;
    overflow-x: hidden;
    word-wrap: break-word;
    padding: 18px 20px !important;
    margin: 0 !important;
    width: auto !important;   /* JS 会设置精确宽度 */
}
.word-container .docx-preview > * {
    max-width: 100% !important;
    box-sizing: border-box;
}
.word-container .docx-preview table {
    max-width: 100% !important;
    word-break: break-word;
}
.word-container .docx-preview img {
    max-width: 100% !important;
    height: auto !important;
}

.pdf-container {
    background: #525252;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    overflow-y: auto;
}
.pdf-container .pdf-page {
    max-width: 100%;
    height: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-radius: 2px;
}
html.dark .pdf-container {
    background: #333;
}

/* 预览模式：卡片放大，全屏适配 */
.paper-detail-card.preview-mode {
    max-width: 800px;
    height: 88vh;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}

.paper-detail-card.preview-mode .detail-header {
    flex-shrink: 0;
}

.paper-detail-card.preview-mode .preview-container {
    flex: 1;
    min-height: 0;
    height: auto;
    max-height: none;
}

.paper-detail-card.preview-mode .detail-footer {
    flex-shrink: 0;
}

/* 返回详情按钮（同预览按钮样式） */
.detail-back-btn {
    text-align: center;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Noto Serif SC', 'SimSun', 'STSong', serif;
    text-decoration: none;
    border: 1px solid #d0c8be;
    flex: 1 1 80px;
    min-width: 0;
    background: #f0ece6;
    color: #3d3430;
}
.detail-back-btn:hover {
    background: #e4dcd2;
}

@media (max-width: 480px) {
    .paper-detail-card.preview-mode {
        max-width: 100%;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
    .paper-detail-card.preview-mode .preview-container,
    .paper-detail-card.preview-mode .preview-container .pdf-container,
    .paper-detail-card.preview-mode .preview-container .word-container {
        max-height: none;
        height: auto;
        flex: 1;
        min-height: 0;
    }
    .preview-container {
        max-height: 40vh;
    }
    .paper-detail-overlay {
        padding: 0;
    }
    .paper-detail-card.preview-mode .detail-header {
        padding: 14px 16px 10px;
        font-size: 14px;
    }
    .paper-detail-card.preview-mode .detail-footer {
        padding: 10px 12px 14px;
    }
}

html.dark .preview-container {
    border-bottom-color: #3d3630;
}
html.dark .preview-loading {
    color: #8a7e72;
}
html.dark .preview-loading .spinner {
    border-color: #3d3630;
    border-top-color: #eab308;
}
html.dark .preview-iframe {
    background: #333;
}
html.dark .word-container {
    background: #333;
}
html.dark .word-container .docx-preview {
    background: #fff;
    color: #1c1917;
}
html.dark .word-container .docx-preview {
    background: #fff;
    color: #1c1917;  /* 深色文字保持可读 */
}
html.dark .detail-back-btn {
    background: #3d3630;
    color: #d6cec4;
    border-color: #4a4038;
}
html.dark .detail-back-btn:hover {
    background: #4a4038;
}

/* ===== 暗色模式弹窗 ===== */
html.dark .paper-detail-overlay {
    background: rgba(10, 8, 6, 0.6);
}
html.dark .paper-detail-card {
    background: #2d2824;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
html.dark .detail-header {
    color: #ece6de;
    border-bottom-color: #3d3630;
}
html.dark .detail-row {
    border-bottom-color: rgba(255, 255, 255, 0.05);
}
html.dark .detail-label {
    color: #8a7e72;
}
html.dark .detail-value {
    color: #d6cec4;
}
html.dark .detail-preview-btn {
    background: #3d3630;
    color: #d6cec4;
    border-color: #4a4038;
}
html.dark .detail-preview-btn:hover {
    background: #4a4038;
}
html.dark .detail-download-btn {
    background: #eab308;
    color: #292524;
}
html.dark .detail-download-btn:hover {
    background: #facc15;
    color: #1c1917;
}
html.dark .detail-close-btn {
    background: #3d3630;
    color: #a69a8e;
}
html.dark .detail-close-btn:hover {
    background: #4a4038;
    color: #ece6de;
}