/* =========================================================
   行测押题 · 图形推理篇 — 答题页样式
   移动端优先，>=640px 平板，>=960px 桌面；自动适配深色模式
   ========================================================= */

:root {
    --c-primary: #2f6fed;
    --c-primary-strong: #1e56c8;
    --c-primary-soft: #e8effd;
    --c-accent: #f5a623;
    --c-text: #1c2333;
    --c-text-sub: #66708a;
    --c-line: #e3e7f0;
    --c-bg: #f4f6fb;
    --c-card: #ffffff;
    --c-right: #18a058;
    --c-right-soft: #e3f6ec;
    --c-wrong: #d64541;
    --c-wrong-soft: #fdeceb;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(23, 32, 61, .06), 0 8px 24px -12px rgba(23, 32, 61, .14);
    --topbar-h: 96px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --c-primary: #5b8cf5;
        --c-primary-strong: #7ba3f8;
        --c-primary-soft: #1d2a45;
        --c-text: #e7ebf4;
        --c-text-sub: #97a1ba;
        --c-line: #2a3247;
        --c-bg: #12161f;
        --c-card: #1a2030;
        --c-right: #35b573;
        --c-right-soft: #12291d;
        --c-wrong: #ef6a66;
        --c-wrong-soft: #321a1a;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .5);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--c-bg);
    color: var(--c-text);
    font-family: system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC",
                 "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ---------------- 顶栏 ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--c-card);
    border-bottom: 1px solid var(--c-line);
}

.topbar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.site-title {
    font-size: clamp(16px, 2.5vw, 19px);
    margin: 0;
    font-weight: 700;
    letter-spacing: .5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.progress-wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px 10px;
    width: 100%;
}

.progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--c-text-sub);
    margin-bottom: 6px;
}

.progress-track {
    height: 6px;
    border-radius: 3px;
    background: var(--c-line);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
    transition: width .25s ease;
}

/* ---------------- 主体 ---------------- */

.main {
    flex: 1;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
}

.q-card {
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.q-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px 0;
}

.q-no { font-size: 17px; font-weight: 700; }

.q-type {
    font-size: 12px;
    color: var(--c-text-sub);
    background: var(--c-primary-soft);
    color: var(--c-primary);
    padding: 2px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.q-figure {
    padding: 12px 18px 16px;
}

.q-figure img {
    display: block;
    width: 100%;
    max-height: min(62vh, 760px);
    object-fit: contain;
    cursor: zoom-in;
    background: #fff;
    border-radius: 10px;
}

@media (prefers-color-scheme: dark) {
    .q-figure img { background: #fff; } /* 题图为白底，保持白底避免视觉断裂 */
}

.q-hint {
    margin: 10px 18px 0;
    font-size: 12.5px;
    color: var(--c-text-sub);
}

/* ---------------- 选项 ---------------- */

.options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 14px 18px 18px;
}

.options.options-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.option {
    appearance: none;
    border: 1.5px solid var(--c-line);
    background: var(--c-card);
    color: var(--c-text);
    border-radius: 12px;
    padding: 12px 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: border-color .15s, background .15s, color .15s, transform .1s;
    min-height: 60px;
    justify-content: center;
}

.option .opt-letter {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid var(--c-line);
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--c-text-sub);
}

.option:active { transform: scale(.97); }

.option.selected {
    border-color: var(--c-primary);
    background: var(--c-primary-soft);
    color: var(--c-primary);
}

.option.selected .opt-letter {
    border-color: var(--c-primary);
    background: var(--c-primary);
    color: #fff;
}

/* 批改后的状态（查看模式） */
.option.is-right {
    border-color: var(--c-right);
    background: var(--c-right-soft);
    color: var(--c-right);
}
.option.is-right .opt-letter {
    border-color: var(--c-right);
    background: var(--c-right);
    color: #fff;
}
.option.is-wrong {
    border-color: var(--c-wrong);
    background: var(--c-wrong-soft);
    color: var(--c-wrong);
}
.option.is-wrong .opt-letter {
    border-color: var(--c-wrong);
    background: var(--c-wrong);
    color: #fff;
}
.option:disabled { cursor: default; }
.option:disabled:active { transform: none; }

.opt-mark { font-size: 12px; font-weight: 600; }

/* ---------------- 底部操作栏 ---------------- */

.actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--c-card);
    border-top: 1px solid var(--c-line);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* ---------------- 按钮 ---------------- */

.btn {
    appearance: none;
    border: 1.5px solid transparent;
    border-radius: 10px;
    padding: 10px 22px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity .15s, background .15s, color .15s;
}

.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
    background: var(--c-primary);
    color: #fff;
    min-width: 108px;
}
.btn-primary:not(:disabled):hover { background: var(--c-primary-strong); }

.btn-secondary {
    background: var(--c-card);
    border-color: var(--c-line);
    color: var(--c-text);
    min-width: 108px;
}
.btn-secondary:not(:disabled):hover { border-color: var(--c-primary); color: var(--c-primary); }

.btn-ghost {
    background: transparent;
    color: var(--c-text-sub);
    border-color: var(--c-line);
    padding: 6px 14px;
    font-size: 13.5px;
}
.btn-ghost:hover { color: var(--c-primary); border-color: var(--c-primary); }

.btn-icon {
    background: transparent;
    color: var(--c-text-sub);
    border: none;
    padding: 6px 10px;
    font-size: 15px;
}
.btn-icon:hover { color: var(--c-text); }

/* ---------------- 答题卡弹层 ---------------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(15, 20, 34, .55);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.overlay[hidden] { display: none; }

@media (min-width: 640px) {
    .overlay { align-items: center; padding: 24px; }
}

.dialog {
    background: var(--c-card);
    width: 100%;
    max-width: 520px;
    border-radius: 18px 18px 0 0;
    padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
    max-height: 82dvh;
    overflow: auto;
}

@media (min-width: 640px) {
    .dialog { border-radius: 18px; padding: 20px 24px; }
}

.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.dialog-head h2 { margin: 0; font-size: 17px; }

.palette-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12.5px;
    color: var(--c-text-sub);
    margin-bottom: 14px;
}
.palette-legend span { display: inline-flex; align-items: center; gap: 5px; }

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}
.dot-current { background: transparent; border: 2px solid var(--c-primary); }
.dot-done    { background: var(--c-primary); }
.dot-blank   { background: var(--c-line); }
.dot-right   { background: var(--c-right); }
.dot-wrong   { background: var(--c-wrong); }

.palette-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.palette-cell {
    appearance: none;
    font-family: inherit;
    height: 46px;
    border-radius: 10px;
    border: 1.5px solid var(--c-line);
    background: var(--c-card);
    color: var(--c-text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
}

.palette-cell.done   { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.palette-cell.right  { background: var(--c-right); border-color: var(--c-right); color: #fff; }
.palette-cell.wrong  { background: var(--c-wrong); border-color: var(--c-wrong); color: #fff; }
.palette-cell.current { box-shadow: 0 0 0 2.5px var(--c-card), 0 0 0 5px var(--c-primary); }

/* ---------------- 图片放大层 ---------------- */

.overlay-lightbox {
    align-items: stretch;
    flex-direction: column;
    background: rgba(10, 13, 22, .92);
    padding: 0;
}

.lightbox-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    color: #dfe4ee;
    font-size: 14px;
    flex-shrink: 0;
}

.lightbox-bar .btn-icon { color: #dfe4ee; }

.lightbox-scroll {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
}

.lightbox-scroll img {
    margin: auto;
    max-width: none;
    width: max(100vw, auto);
    height: auto;
}

/* ---------------- 成绩页 ---------------- */

.result-card {
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 20px;
    text-align: center;
}

.result-score { font-size: 15px; color: var(--c-text-sub); }

.result-score strong {
    display: block;
    font-size: 44px;
    line-height: 1.15;
    color: var(--c-primary);
    font-weight: 800;
}

.result-note { font-size: 13px; color: var(--c-text-sub); margin-top: 6px; }

.result-list {
    margin-top: 16px;
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.result-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--c-line);
    font-size: 14.5px;
}
.result-row:last-child { border-bottom: none; }

.result-row .r-no { width: 44px; font-weight: 700; flex-shrink: 0; }
.result-row .r-ans { flex: 1; color: var(--c-text-sub); }
.result-row .r-ans b { color: var(--c-text); }
.result-row .r-tag {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
}
.r-tag.tag-right  { background: var(--c-right-soft); color: var(--c-right); }
.r-tag.tag-wrong  { background: var(--c-wrong-soft); color: var(--c-wrong); }
.r-tag.tag-none   { background: var(--c-primary-soft); color: var(--c-primary); }

.result-actions {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* ---------------- 响应式微调 ---------------- */

@media (min-width: 640px) {
    .options { gap: 14px; padding: 18px 22px 22px; }
    .option { min-height: 68px; }
    .q-head, .q-figure { padding-left: 22px; padding-right: 22px; }
    .q-hint { margin-left: 22px; margin-right: 22px; }
}

@media (max-width: 400px) {
    .options.options-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
    .option { padding: 10px 2px; min-height: 54px; font-size: 13.5px; }
}

/* 窄横屏（如手机横屏）：限制图片高度避免选项被挤出视口 */
@media (max-height: 480px) and (orientation: landscape) {
    .q-figure img { max-height: 46vh; }
}
