/**
 * quiz.css - 刷题页面专用样式
 *
 * 包含：题目卡片、选项按钮、判断题按钮、反馈区、移动端底栏、
 *       桌面端导航提示、题库管理、信息/编辑弹窗等布局。
 */

/* ===================== 页面骨架 ===================== */

.pack-progress-bar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10000;
    width: 100%;
    height: 2px;
    display: flex;
    background: var(--border);
}

.pack-progress-bar .pp-seg {
    height: 100%;
    transition: width 0.2s;
}

.pp-primary { background: var(--primary); }
.pp-secondary { background: var(--text-sec); }
.pp-wrong { background: var(--error); }
.pp-empty { background: transparent; }

.pack-progress-bar .pp-current-marker {
    position: absolute;
    bottom: 0;
    height: 4px;
    background: var(--text);
    border-radius: 0 0 2px 2px;
    transition: left 0.2s, width 0.2s;
    opacity: 0.7;
}

/* 不支持 overflow:clip 的浏览器回退，防止 body 自身可滚动消费触摸事件 */
html {
    overflow: hidden;
}

body {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    /* overflow: clip 裁剪内容但不创建滚动容器，与 overflow: hidden 不同，
       触摸事件可穿透到子级 overflow-y:auto 元素，Android Chrome 必须。 */
    overflow: clip;
    overscroll-behavior: none;
    position: fixed;
    top: 0;
    left: 0;
}

.app-layer {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
    overscroll-behavior-y: none;
    position: relative;
    cursor: default;
    /* Android Chrome 在父级 overflow:hidden 时不会自动将触摸滚动传递给子级 overflow-y:auto，
       pan-y 显式声明该元素处理垂直触摸滚动。 */
    touch-action: pan-y;
}

@media (max-width: 768px) {
    .app-layer {
        -webkit-user-select: none;
        user-select: none;
    }
}

.app-layer .q-text,
.app-layer .option-inner {
    -webkit-user-select: text;
    user-select: text;
}

.app-layer input,
.app-layer textarea,
.app-layer [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
}

.content-wrapper {
    padding-bottom: 120px;
    min-height: 100%;
}

/* ===================== 题目卡片 ===================== */

.card {
    background: var(--card);
    padding: 30px;
    border-radius: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    border: 1px solid var(--border);
    transition: 0.2s;
    position: relative;
}

.q-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

.q-text {
    font-size: 1.4em;
    font-weight: 700;
    margin-bottom: 30px;
    white-space: pre-wrap;
    line-height: 1.6;
    user-select: text;
}

/* ===================== 选项按钮 ===================== */

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.option-btn {
    text-align: left;
    background: var(--opt-bg);
    color: var(--text);
    border-radius: 12px;
    border: 2px solid var(--border);
    transition: 0.1s;
    position: relative;
    width: 100%;
    cursor: pointer;
    font-size: 1.05em;
    line-height: 1.5;
    overflow: hidden;
    touch-action: manipulation;
}

.option-inner {
    display: block;
    padding: 18px 22px;
    width: 100%;
    height: 100%;
    user-select: text;
}

.options-grid.compact-smooth .option-inner,
.options-grid.compact-smooth .option-btn,
.options-grid.compact-smooth .q-text,
.options-grid.compact-smooth ~ .q-text,
.options-grid.compact-smooth {
    transition: padding 0.2s ease, gap 0.2s ease, margin 0.2s ease, line-height 0.2s ease, font-size 0.2s ease;
}

.card.compact-smooth .q-text,
.card.compact-smooth .q-meta {
    transition: margin-bottom 0.2s ease, line-height 0.2s ease, font-size 0.2s ease;
}

/* 待选态 - 仅边框高亮，不改变背景 */
@media (hover: hover) {
    .option-btn:hover {
        border-color: var(--primary);
    }
}

.options-grid.kb-active .option-btn:hover:not(.kb-hover) {
    border-color: var(--border);
}

.option-btn.kb-hover {
    border-color: var(--primary);
}

/* 选中态 - 边框+背景+左侧竖线 */
.option-btn.selected {
    border-color: var(--primary);
    background: var(--opt-hover);
    box-shadow: inset 4px 0 0 var(--primary);
}

@media (hover: hover) {
    .option-btn.selected:hover {
        border-color: var(--primary);
        background: var(--opt-hover);
    }
}

/* 判对态 - 覆盖待选和选中 */
.option-btn.correct,
.option-btn.correct:hover {
    border-color: var(--success);
    background: var(--success-bg);
    color: #064e3b;
    box-shadow: none;
}

/* 判错态 - 覆盖待选和选中 */
.option-btn.wrong,
.option-btn.wrong:hover {
    border-color: var(--error);
    background: var(--error-bg);
    color: #7f1d1d;
    box-shadow: none;
}

/* 揭示态 - 偷看或判错后标注正确选项，覆盖一切 */
.option-btn.reveal,
.option-btn.reveal:hover {
    border-color: var(--warning);
    background: var(--warning-bg);
    border-style: dashed;
    box-shadow: none;
}

.option-btn.reveal .option-inner:after {
    content: " ✔";
    color: var(--warning);
    font-weight: bold;
}

/* 多选方框指示器 */
.option-btn .opt-check {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 2px solid var(--border);
    vertical-align: middle;
    margin-right: 8px;
    text-align: center;
    line-height: 18px;
    font-size: 0.8em;
    transition: 0.15s;
}

.option-btn.selected .opt-check {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* ===================== 判断题按钮 ===================== */

.tf-grid {
    position: relative;
    height: 160px;
    border: 2px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

.tf-btn {
    position: absolute;
    top: 0;
    height: 100%;
    border: none;
    background: var(--opt-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 1.3em;
    font-weight: 700;
    touch-action: manipulation;
    transition: background 0.15s, color 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px 10px;
}

#tf-true {
    left: 0;
}

#tf-false {
    right: 0;
}

/* 判断题 - 待选态 */
@media (hover: hover) {
    .tf-btn:hover {
        filter: brightness(0.95);
    }
}

.tf-grid.kb-active .tf-btn:hover:not(.kb-hover) {
    filter: none;
}

.tf-btn.kb-hover {
    filter: brightness(0.95);
}

.tf-btn .tf-icon {
    font-size: 2.5em;
    margin-bottom: 10px;
}

/* 判断题 - 选中态 */
.tf-btn.tf-selected {
    background: var(--opt-hover);
    filter: brightness(0.92);
}

/* 判断题 - 判对态 */
.tf-btn.tf-correct,
.tf-btn.tf-correct:hover {
    background: var(--success-bg);
    color: #064e3b;
    filter: none;
}

/* 判断题 - 判错态 */
.tf-btn.tf-wrong,
.tf-btn.tf-wrong:hover {
    background: var(--error-bg);
    color: #7f1d1d;
    filter: none;
}

/* 判断题 - 揭示态 */
.tf-btn.tf-reveal,
.tf-btn.tf-reveal:hover {
    background: var(--warning-bg);
    filter: none;
}

/* ===================== 卡片翻页动画 ===================== */

@keyframes slide-out-left {
    0% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(-40%); opacity: 0; }
}

@keyframes slide-out-right {
    0% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(40%); opacity: 0; }
}

@keyframes slide-in-left {
    0% { transform: translateX(40%); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

@keyframes slide-in-right {
    0% { transform: translateX(-40%); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

.slide-out-left, .slide-out-right { animation-duration: 0.12s; animation-timing-function: ease-in; animation-fill-mode: forwards; }
.slide-in-left, .slide-in-right { animation-duration: 0.12s; animation-timing-function: ease-out; animation-fill-mode: forwards; }
.slide-out-left { animation-name: slide-out-left; }
.slide-out-right { animation-name: slide-out-right; }
.slide-in-left { animation-name: slide-in-left; }
.slide-in-right { animation-name: slide-in-right; }

/* ===================== 反馈与控制区 ===================== */

.desk-controls {
    display: flex;
}

/* ===================== 题库管理 ===================== */

.lib-item {
    background: var(--opt-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: 0.15s;
}

.lib-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 18px;
    cursor: pointer;
    font-weight: 600;
}

.lib-header:hover {
    background: var(--opt-hover);
}

.lib-body {
    padding: 10px 18px;
    border-top: 1px solid var(--border);
}

.pack-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: 0.15s;
    background: var(--card);
    border: 1px solid var(--border);
}

.pack-item:hover {
    border-color: var(--primary);
    background: var(--opt-hover);
}

.pack-item.pack-selected {
    border-color: var(--primary);
    background: var(--opt-hover);
    box-shadow: inset 3px 0 0 var(--primary);
}

.pack-item.pack-selected::before {
    content: "✓ ";
    color: var(--primary);
    font-weight: 700;
}

.pack-count {
    font-size: 0.85em;
    color: var(--text-sec);
}

/* ===================== 信息弹窗 ===================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 15px 0;
    text-align: center;
}

.stat-box {
    background: var(--opt-bg);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.stat-val {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--primary);
}

/* ===================== 桌面端导航提示 ===================== */

.nav-hint {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    color: var(--text);
    opacity: 0;
    pointer-events: none;
    transition: 0.3s;
    z-index: 0;
}

.nav-hint.show {
    opacity: 0.15;
}

.nav-hint-left {
    left: 40px;
}

.nav-hint-right {
    right: 40px;
}

/* ===================== 移动端底栏 ===================== */

.mobile-bottom-bar {
    display: none;
}

@media (max-width: 768px) {
    .nav-hint {
        display: none !important;
    }

    .card {
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0;
        margin-bottom: 0;
    }

    .content-wrapper {
        padding: 15px;
        padding-bottom: 80px;
    }

    .q-meta {
        border-bottom: none;
        margin-bottom: 10px;
    }

    #idxBadge {
        cursor: pointer;
        transition: 0.15s;
    }

    #idxBadge:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .q-text {
        font-size: 1.25em;
        margin-bottom: 20px;
    }

    .q-meta { margin-bottom: 10px; }

    .option-btn {
        width: 94%;
    }

    .option-btn.selected {
        animation: opt-pulse 1.5s ease-in-out infinite;
    }

    @keyframes opt-pulse {
        0%, 100% { box-shadow: inset 4px 0 0 var(--primary); }
        50% { box-shadow: inset 4px 0 0 var(--primary), 0 0 0 2px var(--primary); }
    }

    .tf-btn.tf-selected {
        animation: tf-pulse 1.5s ease-in-out infinite;
    }

    @keyframes tf-pulse {
        0%, 100% { filter: brightness(0.92); }
        50% { filter: brightness(0.88); }
    }

    .desk-controls {
        display: none !important;
    }

    .tf-grid {
        height: 120px;
    }

    .tf-btn {
        padding: 15px 8px;
    }

    .tf-btn .tf-icon {
        font-size: 2em;
    }

    .mobile-bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--card);
        border-top: 1px solid var(--border);
        align-items: center;
        justify-content: space-around;
        z-index: 100;
        box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.05);
        padding: 0 5px;
    }

    .mob-action-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: transparent;
        color: var(--text-sec);
        font-size: 0.7em;
        gap: 2px;
        height: 100%;
        border-radius: 0;
        white-space: nowrap;
        overflow: hidden;
    }

    .mob-action-btn span {
        font-size: 1.4em;
    }

    .mob-action-btn.active {
        color: var(--primary);
    }

    .mob-action-btn.active-wrong {
        color: var(--error);
    }

    #mobileConfirmFloat {
        position: fixed;
        bottom: 75px;
        left: 15px;
        right: 15px;
        z-index: 101;
    }
}

@media (min-width: 769px) {
    #mobileConfirmFloat {
        display: none !important;
    }

    .mob-only {
        display: none !important;
    }
}

/* ===================== 模式激活态 ===================== */

.mode-active {
    color: var(--primary) !important;
    background: var(--opt-hover) !important;
    border-color: var(--primary) !important;
}

.reshuffle-icon {
    display: none;
    margin-left: 4px;
    cursor: pointer;
    font-size: 0.85em;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.reshuffle-icon:hover {
    opacity: 1;
}

.mode-active .reshuffle-icon,
.active .reshuffle-icon {
    display: inline;
}

.wrong-active {
    color: var(--error) !important;
    background: var(--error-bg) !important;
    border-color: var(--error) !important;
}
