:root {
    --red-900: #7f1d1d;
    --red-700: #b91c1c;
    --red-600: #dc2626;
    --red-500: #ef4444;
    --red-100: #fee2e2;
    --red-50: #fef2f2;
    --ink-900: #1c1917;
    --ink-700: #44403c;
    --ink-500: #78716c;
    --ink-300: #d6d3d1;
    --ink-200: #e7e5e4;
    --ink-100: #f5f5f4;
    --bg: #faf9f7;
    --white: #fff;
    --green-700: #15803d;
    --green-600: #16a34a;
    --green-50: #f0fdf4;
    --amber-600: #d97706;
    --amber-50: #fffbeb;
    --blue-600: #2563eb;
    --blue-50: #eff6ff;
    --radius-lg: 16px;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(28, 25, 23, .06);
    --shadow: 0 4px 16px rgba(28, 25, 23, .08);
    --shadow-lg: 0 12px 40px rgba(28, 25, 23, .12);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.65;
    color: var(--ink-900);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 20px;
}

.page { flex: 1; padding-top: 28px; padding-bottom: 56px; }

/* ---------- 头部 ---------- */
.site-header {
    background: var(--white);
    border-bottom: 1px solid var(--ink-200);
    position: sticky;
    top: 0;
    z-index: 30;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 62px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--red-700);
    font-weight: 700;
    font-size: 17px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(145deg, var(--red-500), var(--red-700));
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.site-nav { display: flex; gap: 4px; }

.site-nav a {
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--ink-700);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.site-nav a:hover { background: var(--ink-100); color: var(--ink-900); }
.site-nav a.is-active { background: var(--red-50); color: var(--red-700); }

/* ---------- 管理员 ---------- */
.admin-login-card { max-width: 460px; margin: 40px auto 0; text-align: center; padding: 40px 32px; }
.admin-login-card .notice-icon { margin: 0 auto 12px; }
.admin-login-card .card-title { justify-content: center; }
.admin-hint { color: var(--ink-500); font-size: 13px; margin: 0 0 18px; }
.admin-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.admin-back { margin: 20px 0 0; font-size: 13px; }
.inline-form { margin: 0; }

.btn-sm { padding: 7px 14px; font-size: 13px; }

.site-footer {
    border-top: 1px solid var(--ink-200);
    background: var(--white);
    padding: 20px 0;
    color: var(--ink-500);
    font-size: 13px;
    text-align: center;
}

.site-footer p { margin: 0; }
.site-footer strong { color: var(--ink-700); }

/* ---------- 通用组件 ---------- */
.card {
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 26px;
    margin-bottom: 20px;
}

.card-title {
    margin: 0 0 18px;
    font-size: 18px;
    font-weight: 700;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
    line-height: 1.4;
}

.btn:active { transform: translateY(1px); }
.btn-lg { padding: 13px 26px; font-size: 15px; }
.btn-primary { background: var(--red-600); color: #fff; box-shadow: 0 2px 10px rgba(220, 38, 38, .22); }
.btn-primary:hover { background: var(--red-700); }
.btn-ghost { background: var(--white); border-color: var(--ink-300); color: var(--ink-700); }
.btn-ghost:hover { background: var(--ink-100); border-color: var(--ink-500); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    margin-bottom: 18px;
    font-size: 14px;
}

.alert-error { background: var(--red-50); border-color: #fecaca; color: var(--red-900); }
.alert-info { background: var(--blue-50); border-color: #bfdbfe; color: #1e40af; }
.alert-info a { color: #1d4ed8; font-weight: 700; }

.hint { margin: 8px 0 0; font-size: 13px; color: var(--ink-500); }

.field { margin-bottom: 24px; }
.field-label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.req { color: var(--red-600); margin-left: 3px; }

.input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--ink-300);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 15px;
    background: var(--white);
    color: var(--ink-900);
    transition: border-color .15s, box-shadow .15s;
}

.input:focus {
    outline: none;
    border-color: var(--red-500);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, .13);
}

.select { max-width: 240px; }

.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }

/* ---------- 首页 ---------- */
.hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #7f1d1d 0%, #b91c1c 55%, #dc2626 100%);
    color: #fff;
    padding: 40px 36px;
    margin-bottom: 22px;
    box-shadow: var(--shadow-lg);
}

.hero::after {
    content: "";
    position: absolute;
    right: -70px;
    top: -70px;
    width: 260px;
    height: 260px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .08);
}

.hero-copy { position: relative; z-index: 1; max-width: 640px; }

.eyebrow {
    display: inline-block;
    font-size: 12px;
    letter-spacing: .12em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, .16);
    padding: 5px 12px;
    border-radius: 999px;
    margin-bottom: 14px;
    font-weight: 600;
}

.hero h1 { margin: 0 0 12px; font-size: 32px; line-height: 1.25; letter-spacing: -.01em; }
.hero p { margin: 0 0 18px; color: rgba(255, 255, 255, .9); font-size: 15px; }
.hero-rules { margin: 0; padding-left: 20px; color: rgba(255, 255, 255, .88); font-size: 14px; }
.hero-rules li { margin-bottom: 5px; }

.start-card { padding: 28px; }

.paper-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.paper-card { position: relative; cursor: pointer; }

.paper-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.paper-inner {
    display: block;
    position: relative;
    border: 2px solid var(--ink-200);
    border-radius: var(--radius-lg);
    padding: 18px 18px 20px;
    transition: border-color .15s, background .15s, box-shadow .15s;
    background: var(--white);
    height: 100%;
}

.paper-card:hover .paper-inner { border-color: var(--red-300, #fca5a5); background: var(--red-50); }

.paper-card input:checked + .paper-inner {
    border-color: var(--red-600);
    background: var(--red-50);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, .1);
}

.paper-card input:focus-visible + .paper-inner { outline: 2px solid var(--red-500); outline-offset: 2px; }

.paper-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    color: var(--red-700);
    background: var(--red-100);
    border-radius: 999px;
    padding: 3px 10px;
    margin-bottom: 10px;
}

.paper-name { display: block; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.paper-meta { display: block; font-size: 13px; color: var(--ink-500); }

.paper-check {
    position: absolute;
    right: 14px;
    top: 14px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--red-600);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 13px;
    opacity: 0;
    transform: scale(.7);
    transition: opacity .15s, transform .15s;
}

.paper-card input:checked + .paper-inner .paper-check { opacity: 1; transform: scale(1); }

.howto-list { margin: 0; padding-left: 22px; color: var(--ink-700); font-size: 14px; }
.howto-list li { margin-bottom: 8px; }

/* ---------- 提示卡 ---------- */
.notice-card, .install-card {
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 44px 32px;
    text-align: center;
    max-width: 560px;
    margin: 40px auto;
}

.notice-card h1, .install-card h1 { font-size: 22px; margin: 12px 0 10px; }
.notice-card p, .install-card p { color: var(--ink-700); margin-bottom: 22px; }

.notice-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 0 auto;
    background: var(--red-100);
    color: var(--red-700);
    font-weight: 800;
    font-size: 22px;
}

.notice-icon.ok { background: var(--green-50); color: var(--green-700); }

.install-line {
    text-align: left;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    margin: 0 0 8px;
    font-size: 14px;
    background: var(--ink-100);
}

.install-line.ok { background: var(--green-50); color: var(--green-700); }
.install-line.err { background: var(--red-50); color: var(--red-900); }
.install-card { text-align: left; }
.install-card h1 { text-align: center; }
.install-done { text-align: center; margin-top: 18px; }

/* ---------- 答题页 ---------- */
.page:has(.exam-topbar) { padding-top: 0; max-width: 1240px; padding-left: 20px; padding-right: 20px; }

.exam-topbar {
    position: sticky;
    top: 62px;
    z-index: 25;
    background: var(--white);
    border-bottom: 1px solid var(--ink-200);
    margin: 0 -20px 22px;
    padding: 12px 20px;
    box-shadow: var(--shadow-sm);
}

.exam-topbar-inner {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    max-width: 1200px;
    margin: 0 auto;
}

.exam-meta { font-size: 14px; color: var(--ink-700); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.exam-name { font-weight: 700; color: var(--ink-900); }
.sep { color: var(--ink-300); }

.exam-timer {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--ink-100);
    font-variant-numeric: tabular-nums;
}

.timer-label { font-size: 12px; color: var(--ink-500); }
.exam-timer strong { font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.exam-timer.is-warn { background: var(--amber-50); }
.exam-timer.is-warn strong { color: var(--amber-600); }
.exam-timer.is-danger { background: var(--red-100); animation: pulse 1.4s infinite; }
.exam-timer.is-danger strong { color: var(--red-700); }

@keyframes pulse { 50% { opacity: .68; } }

.exam-progress { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-500); margin-left: auto; }

.progress-track { width: 120px; height: 7px; border-radius: 999px; background: var(--ink-200); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--red-500), var(--red-600)); transition: width .3s; }

.exam-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 22px; align-items: start; }

.answer-sheet {
    position: sticky;
    top: 150px;
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.sheet-title { margin: 0 0 12px; font-size: 14px; font-weight: 700; color: var(--ink-700); }
.sheet-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 14px; }

.sheet-cell {
    aspect-ratio: 1;
    border-radius: 6px;
    border: 1px solid var(--ink-200);
    background: var(--white);
    color: var(--ink-700);
    font-size: 12px;
    font-weight: 600;
    display: grid;
    place-items: center;
    cursor: pointer;
    font-family: inherit;
    transition: background .12s, border-color .12s, color .12s;
}

.sheet-cell:hover { border-color: var(--ink-500); }
.sheet-cell.done { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.sheet-cell.current { outline: 2px solid var(--red-600); outline-offset: 1px; }

.sheet-legend { display: flex; gap: 10px; font-size: 11px; color: var(--ink-500); margin-bottom: 14px; flex-wrap: wrap; }
.lg::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 4px; }
.lg-done::before { background: var(--green-600); }
.lg-todo::before { background: var(--white); border: 1px solid var(--ink-300); }
.lg-cur::before { background: var(--white); border: 2px solid var(--red-600); }

.sheet-tips { margin: 0; padding-left: 16px; font-size: 12px; color: var(--ink-500); }
.sheet-tips li { margin-bottom: 4px; }

.question-panel { min-width: 0; }

.q-page { display: none; }
.q-page.is-active { display: block; animation: fade .18s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.question {
    background: var(--white);
    border: 1px solid var(--ink-200);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}

.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.q-no { font-weight: 700; font-size: 14px; color: var(--red-700); }
.q-type { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--ink-100); color: var(--ink-700); }

.q-stem { margin: 0 0 16px; font-size: 15.5px; line-height: 1.75; color: var(--ink-900); word-break: break-word; }

.q-options { display: flex; flex-direction: column; gap: 9px; }

.option {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 11px 14px;
    border: 1px solid var(--ink-200);
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--white);
    transition: border-color .13s, background .13s;
}

.option:hover { border-color: var(--ink-300); background: var(--ink-100); }
.option input { position: absolute; opacity: 0; pointer-events: none; }

.option-mark {
    flex: 0 0 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--ink-300);
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-700);
    background: var(--white);
    transition: background .13s, border-color .13s, color .13s;
}

.option-text { flex: 1; font-size: 14.5px; line-height: 1.65; word-break: break-word; }

.option:has(input:checked) { border-color: var(--red-500); background: var(--red-50); }
.option:has(input:checked) .option-mark { background: var(--red-600); border-color: var(--red-600); color: #fff; }

.option.static { cursor: default; }
.option.static:hover { background: var(--white); border-color: var(--ink-200); }
.option.opt-chosen { border-color: var(--red-400, #f87171); background: var(--red-50); }
.option.opt-answer { border-color: var(--green-600); background: var(--green-50); }
.option.opt-answer .option-mark { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.option.opt-chosen:not(.opt-answer) .option-mark { background: var(--red-500); border-color: var(--red-500); color: #fff; }

.opt-tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--red-100); color: var(--red-700); align-self: center; white-space: nowrap; }
.opt-tag.ans { background: #dcfce7; color: var(--green-700); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 2px 20px; }
.pager span { font-size: 13px; color: var(--ink-500); }

/* ---------- 结果页 ---------- */
.result-hero { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 30px; align-items: center; padding: 30px; }
.result-score-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.result-ring {
    --rate: 0;
    width: 176px;
    height: 176px;
    border-radius: 50%;
    display: grid;
    place-content: center;
    text-align: center;
    background:
        radial-gradient(closest-side, var(--white) 78%, transparent 79% 100%),
        conic-gradient(var(--red-600) calc(var(--rate) * 1%), var(--ink-200) 0);
}

.result-score { font-size: 46px; font-weight: 800; color: var(--red-700); line-height: 1; }
.result-total { font-size: 13px; color: var(--ink-500); margin-top: 4px; }

.level-chip {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
}

.level-chip.sm { font-size: 12px; padding: 3px 10px; }
.level-excellent { background: #dcfce7; color: var(--green-700); }
.level-good { background: var(--blue-50); color: var(--blue-600); }
.level-pass { background: var(--amber-50); color: var(--amber-600); }
.level-fail { background: var(--red-100); color: var(--red-700); }

.result-summary h1 { margin: 0 0 4px; font-size: 24px; }
.result-paper { margin: 0 0 18px; color: var(--ink-500); font-size: 14px; }

.result-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 14px; margin: 0 0 6px; }
.result-stats div { background: var(--ink-100); border-radius: var(--radius); padding: 10px 12px; }
.result-stats dt { font-size: 12px; color: var(--ink-500); }
.result-stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 700; white-space: nowrap; }
.result-stats .stat-time { grid-column: span 2; }
.result-stats dd.ok { color: var(--green-700); }
.result-stats dd.err { color: var(--red-700); }

.review-item {
    border: 1px solid var(--ink-200);
    border-left: 4px solid var(--ink-300);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    background: var(--white);
}

.review-item.is-correct { border-left-color: var(--green-600); }
.review-item.is-wrong { border-left-color: var(--red-600); background: #fffbfb; }
.review-item.is-skipped { border-left-color: var(--amber-600); background: var(--amber-50); }

.verdict { margin-left: auto; font-size: 12px; font-weight: 700; }
.is-correct .verdict { color: var(--green-700); }
.is-wrong .verdict { color: var(--red-700); }
.is-skipped .verdict { color: var(--amber-600); }

.review-note { margin: 12px 0 0; font-size: 13px; color: var(--red-700); font-weight: 600; }
.empty { color: var(--ink-500); text-align: center; padding: 26px 0; }

/* ---------- 榜单 ---------- */
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head p { margin: 0; color: var(--ink-500); font-size: 14px; }
.page-head.with-actions { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.page-head.with-actions form { flex: 0 0 auto; margin-top: 2px; }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 16px; }
.filter-bar .input { flex: 1 1 220px; max-width: 320px; }

.table-wrap { padding: 0; overflow-x: auto; }

.result-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.result-table th, .result-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--ink-200); white-space: nowrap; }
.result-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-500); background: var(--ink-100); }
.result-table tbody tr:last-child td { border-bottom: none; }
.result-table tbody tr:hover { background: var(--ink-100); }
.cell-name { font-weight: 700; }
.score-num { color: var(--red-700); font-size: 15px; }
.link { color: var(--blue-600); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }

.empty-state { text-align: center; padding: 44px 22px; color: var(--ink-500); }

/* ---------- 弹窗 ---------- */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 23, .5);
    display: grid;
    place-items: center;
    z-index: 60;
    padding: 20px;
    backdrop-filter: blur(2px);
}

.modal-mask.hidden { display: none; }

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 26px;
    max-width: 420px;
    width: 100%;
}

.modal h3 { margin: 0 0 8px; font-size: 18px; }
.modal p { margin: 0 0 20px; color: var(--ink-700); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
    .exam-layout { grid-template-columns: 1fr; }
    .answer-sheet { position: static; order: 2; }
    .sheet-grid { grid-template-columns: repeat(10, 1fr); }
    .result-hero { grid-template-columns: 1fr; text-align: center; }
    .result-summary .actions { justify-content: center; }
    .exam-layout .question-panel { order: 1; }
}

@media (max-width: 640px) {
    .hero { padding: 30px 22px; }
    .hero h1 { font-size: 24px; }
    .card { padding: 20px; }
    .exam-topbar { top: 62px; }
    .exam-progress { margin-left: 0; width: 100%; }
    .progress-track { flex: 1; width: auto; }
    .header-inner { height: 56px; }
    .site-nav a { padding: 7px 10px; font-size: 13px; }
    .sheet-grid { grid-template-columns: repeat(8, 1fr); }
    .q-stem { font-size: 15px; }
    .result-ring { width: 140px; height: 140px; }
    .result-score { font-size: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
