/* ============ KAT Quiz Frontend ============ */
.kat-quiz-wrapper {
    max-width: 1320px; margin: 24px auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: #1f2937;
}
.kat-quiz-wrapper *, .kat-quiz-wrapper *::before, .kat-quiz-wrapper *::after { box-sizing: border-box; }

/* ===== Start screen ===== */
.kat-start-screen {
    display: flex; justify-content: center; padding: 40px 16px;
}
.kat-start-card {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 16px; padding: 32px; text-align: center; max-width: 560px; width: 100%;
    box-shadow: 0 6px 24px rgba(0,0,0,0.08);
}
.kat-start-card h2 { margin: 0 0 16px; font-size: 26px; color: #92400e; }
.kat-start-card .kat-intro { color: #525252; margin-bottom: 20px; line-height: 1.6; }
.kat-start-card .kat-meta { list-style: none; padding: 0; margin: 0 0 24px; }
.kat-start-card .kat-meta li { padding: 6px 0; font-size: 15px; }

/* ===== Buttons ===== */
.kat-btn {
    display: inline-block; padding: 8px 18px; border-radius: 8px;
    border: 1px solid #e5e7eb; background: #fff; color: #1f2937;
    font-size: 14px; cursor: pointer; text-decoration: none; transition: all .15s;
}
.kat-btn:hover { background: #f3f4f6; }
.kat-btn-primary { background: #2563eb; color: #fff; border-color: #1d4ed8; }
.kat-btn-primary:hover { background: #1d4ed8; color: #fff; }
.kat-btn-large { padding: 12px 28px; font-size: 16px; font-weight: 600; }

/* ===== Top bar ===== */
.kat-quiz-topbar {
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    color: #fff; padding: 14px 20px; border-radius: 12px 12px 0 0;
    display: flex; align-items: center; gap: 16px;
    position: sticky; top: 0; z-index: 50;
}
.kat-quiz-title { font-size: 18px; font-weight: 600; flex: 1; }
.kat-timer {
    background: rgba(255,255,255,0.18); padding: 6px 14px; border-radius: 999px;
    font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.kat-quiz-topbar .kat-btn { background: #fff; color: #1f2937; }
.kat-quiz-topbar .kat-btn-primary { background: #fff; color: #2563eb; font-weight: 600; }
.kat-fullscreen { padding: 6px 12px !important; font-size: 18px !important; }

/* ===== Quiz body layout: form + sidebar nav ===== */
.kat-quiz-body {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 16px;
    align-items: start;
}
@media (max-width: 1024px) {
    .kat-quiz-body { grid-template-columns: 1fr; }
}

/* ===== Quiz form layout ===== */
.kat-quiz-form { background: #fff; border-radius: 0 0 12px 12px; padding: 24px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }

/* ===== Sidebar nav ===== */
.kat-quiz-nav {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
@media (max-width: 1024px) {
    .kat-quiz-nav { position: relative; top: 0; max-height: none; border-radius: 0 0 12px 12px; }
}
.kat-nav-inner { padding: 16px 14px; }
.kat-nav-header {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    font-size: 13px; font-weight: 700; color: #4b5563; text-transform: uppercase; letter-spacing: .4px;
    padding-bottom: 10px; margin-bottom: 12px; border-bottom: 1px solid #f3f4f6;
}
.kat-nav-header > span:first-child { flex: 1; }
.kat-nav-progress {
    background: #dbeafe; color: #1e40af; padding: 2px 10px;
    border-radius: 999px; font-size: 12px; letter-spacing: 0;
}
.kat-nav-section { margin-bottom: 18px; }
.kat-nav-section:last-child { margin-bottom: 8px; }
.kat-nav-section-title {
    font-size: 12px; font-weight: 700; color: #6b7280; margin-bottom: 8px;
    line-height: 1.4; padding-left: 4px;
}
.kat-nav-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
    gap: 6px;
}
.kat-nav-item {
    width: 100%; min-width: 32px; height: 34px;
    border: 1.5px solid #e5e7eb; background: #fff;
    border-radius: 6px; font-size: 13px; font-weight: 600;
    color: #4b5563; cursor: pointer; padding: 0;
    transition: all .12s; font-family: inherit;
}
.kat-nav-item:hover { border-color: #93c5fd; color: #2563eb; }
.kat-nav-item.is-answered {
    background: #16a34a; border-color: #15803d; color: #fff;
}
.kat-nav-item.is-answered:hover { background: #15803d; color: #fff; }
.kat-nav-item.is-active {
    border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}
.kat-nav-item.is-answered.is-active {
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.25);
}
.kat-nav-legend {
    display: flex; flex-wrap: wrap; gap: 10px;
    font-size: 11px; color: #6b7280;
    padding-top: 12px; margin-top: 8px; border-top: 1px solid #f3f4f6;
}
.kat-nav-legend span { display: inline-flex; align-items: center; gap: 5px; }
.kat-dot {
    display: inline-block; width: 12px; height: 12px; border-radius: 4px;
    border: 1.5px solid #e5e7eb; background: #fff;
}
.kat-dot-answered { background: #16a34a; border-color: #15803d; }
.kat-dot-active { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2); }

/* Drawer mode (mobile/tablet) */
.kat-nav-toggle {
    display: none;
    align-items: center; gap: 6px;
    background: rgba(255,255,255,0.18) !important; color: #fff !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
}
.kat-nav-toggle-icon { font-size: 18px; line-height: 1; }
.kat-nav-toggle-label { font-size: 13px; font-weight: 600; }
.kat-nav-close {
    display: none; background: transparent; border: 0; cursor: pointer;
    font-size: 28px; line-height: 1; color: #6b7280; padding: 0 4px;
    width: 30px; height: 30px;
}
.kat-nav-close:hover { color: #1f2937; }
.kat-nav-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(15,23,42,0.55); backdrop-filter: blur(2px);
    z-index: 998;
}

@media (max-width: 1024px) {
    .kat-nav-toggle { display: inline-flex; }
    .kat-nav-close { display: inline-flex; align-items: center; justify-content: center; }
    .kat-quiz-nav {
        position: fixed !important;
        top: 0 !important; right: 0; bottom: 0;
        width: 86%; max-width: 360px;
        max-height: 100vh; height: 100vh;
        z-index: 999;
        transform: translateX(105%);
        transition: transform .28s ease;
        border-radius: 0;
        box-shadow: -8px 0 32px rgba(0,0,0,0.18);
    }
    .kat-quiz-wrapper.kat-nav-open .kat-quiz-nav { transform: translateX(0); }
    .kat-quiz-wrapper.kat-nav-open .kat-nav-backdrop { display: block; animation: katFadeIn .25s ease; }
    .kat-nav-inner { padding-top: 20px; }
    .kat-quiz-body { display: block; }
    .kat-quiz-form { border-radius: 0 0 12px 12px; }
}

@media (max-width: 640px) {
    .kat-nav-toggle-label { display: none; }
}

/* Flash highlight when sidebar item clicked */
.kat-question.kat-q-flash {
    animation: katFlash 1.2s ease;
}
@keyframes katFlash {
    0% { background: #fef3c7; border-color: #f59e0b; }
    100% { background: #fff; border-color: #e5e7eb; }
}
.kat-section { margin-bottom: 36px; padding-bottom: 24px; border-bottom: 1px solid #e5e7eb; }
.kat-section:last-child { border-bottom: 0; }
.kat-section-instruction {
    background: #eff6ff; border-left: 4px solid #2563eb; padding: 10px 16px;
    border-radius: 4px; margin-bottom: 16px; font-style: italic; color: #1e40af;
}

.kat-section-body { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.kat-section-body:not(:has(.kat-passage-pane)) { grid-template-columns: 1fr; }
@media (max-width: 900px) {
    .kat-section-body { grid-template-columns: 1fr; }
}
.kat-passage-pane {
    background: #fafafa; border: 1px solid #e5e7eb; border-radius: 8px; padding: 18px;
    font-size: 16px; line-height: 1.8; max-height: 70vh; overflow-y: auto;
    position: sticky; top: 80px;
}
.kat-passage-pane audio { width: 100%; margin-bottom: 12px; }
.kat-passage-text { white-space: pre-line; color: #111827; }
.kat-passage-pinyin { margin-top: 12px; }
.kat-passage-pinyin summary { cursor: pointer; color: #2563eb; }

/* ===== Question ===== */
.kat-question {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
    padding: 16px 18px; margin-bottom: 14px;
}
.kat-question-header { margin-bottom: 12px; }
.kat-q-number { font-weight: 700; color: #2563eb; margin-right: 6px; }
.kat-q-text { font-size: 15px; line-height: 1.6; }

.kat-hanzi-display {
    font-size: 36px; font-weight: 600; color: #111827; text-align: center;
    padding: 14px; background: #fef3c7; border-radius: 8px; margin: 12px 0;
    font-family: "PingFang SC", "Microsoft YaHei", "STHeiti", sans-serif; letter-spacing: 4px;
}
.kat-pinyin-display {
    font-size: 22px; font-style: italic; text-align: center;
    padding: 12px; background: #dcfce7; border-radius: 8px; margin: 12px 0; color: #166534;
}

.kat-audio-wrap { margin: 10px 0; }
.kat-audio-wrap audio { width: 100%; }

/* ===== MCQ options ===== */
.kat-options { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.kat-option {
    display: flex; align-items: center; gap: 10px;
    border: 1.5px solid #e5e7eb; border-radius: 8px; padding: 10px 14px;
    cursor: pointer; transition: all .15s; background: #fff;
}
.kat-option:hover { border-color: #2563eb; background: #eff6ff; }
.kat-option input[type=radio] { width: 18px; height: 18px; accent-color: #2563eb; }
.kat-option input[type=radio]:checked + .kat-option-letter { color: #2563eb; }
.kat-option:has(input:checked) { border-color: #2563eb; background: #dbeafe; }
.kat-option-letter { font-weight: 700; color: #4b5563; min-width: 22px; }
.kat-option-text { flex: 1; }

/* ===== Word bank (选词填空 chips) ===== */
.kat-word-bank {
    background: linear-gradient(135deg, #fff7ed, #fef3c7);
    border: 1.5px solid #fcd34d; border-radius: 10px;
    padding: 14px 16px; margin: 12px 0 18px;
}
.kat-word-bank-label { display: block; font-size: 13px; color: #92400e; font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .4px; }
.kat-word-bank-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.kat-chip {
    background: #fff; border: 1.5px solid #f59e0b; color: #92400e;
    border-radius: 999px; padding: 6px 14px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: all .15s;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}
.kat-chip:hover { background: #fef3c7; transform: translateY(-1px); box-shadow: 0 2px 6px rgba(245, 158, 11, .25); }
.kat-chip:active { transform: translateY(0); }

/* ===== Fill blank (inline + stacked) ===== */
.kat-fill-inline {
    font-size: 18px; line-height: 2.4; margin-top: 8px;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    display: block;
}
.kat-fill-inline .kat-fill-piece {
    display: inline !important;
    white-space: pre-wrap;
}
.kat-fill-inline .kat-blank-input {
    display: inline-block !important;
    width: 110px !important;
    min-width: 80px !important;
    max-width: 200px !important;
    margin: 0 4px !important;
    vertical-align: baseline !important;
    box-sizing: border-box !important;
    float: none !important;
}
.kat-fill-blanks { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.kat-blank-row { display: flex; align-items: center; gap: 10px; }
.kat-blank-row label { min-width: 110px; color: #6b7280; }

.kat-blank-input {
    padding: 4px 8px !important;
    border: 0;
    border-bottom: 2px solid #2563eb !important;
    border-radius: 0 !important;
    background: transparent;
    font-size: 18px;
    font-weight: 600; color: #1e40af;
    text-align: center;
    font-family: inherit; outline: none;
    transition: background .15s, border-color .15s;
    height: auto !important;
    line-height: 1.5 !important;
}
.kat-blank-input:focus { background: #eff6ff; outline: none !important; box-shadow: none !important; }
.kat-blank-input.is-bank { cursor: pointer; caret-color: transparent; }
.kat-blank-input.is-bank.active { background: #fef3c7; border-bottom-color: #f59e0b !important; box-shadow: 0 2px 0 #f59e0b !important; }
.kat-blank-input.is-bank.filled { background: #dbeafe; }
.kat-fill-blanks .kat-blank-input {
    width: auto !important;
    max-width: 360px !important;
    min-width: 200px !important;
    flex: 1;
    text-align: left;
    border: 1.5px solid #d1d5db !important;
    border-radius: 6px !important;
    padding: 8px 12px !important;
}
.kat-fill-blanks .kat-blank-input:focus { border-color: #2563eb !important; }

/* ===== Sentence/paragraph order ===== */
.kat-sentence-order, .kat-paragraph-order { margin-top: 10px; }
.kat-token-pool, .kat-token-arrange,
.kat-paragraph-pool, .kat-paragraph-arrange {
    border: 1.5px dashed #d1d5db; border-radius: 8px;
    padding: 10px; min-height: 56px; margin-bottom: 8px;
    display: flex; flex-wrap: wrap; gap: 8px;
}
.kat-token-arrange, .kat-paragraph-arrange { border-style: solid; border-color: #2563eb; background: #eff6ff; }
.kat-token {
    background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 6px;
    padding: 8px 14px; cursor: pointer; font-size: 16px; font-weight: 500;
}
.kat-token:hover { background: #e5e7eb; }
.kat-token-arrange .kat-token { background: #dbeafe; border-color: #2563eb; color: #1e40af; }

.kat-paragraph-item {
    background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 6px;
    padding: 10px 14px; cursor: pointer; text-align: left; width: 100%;
    display: block; font-size: 14px;
}
.kat-paragraph-arrange .kat-paragraph-item { background: #dbeafe; border-color: #2563eb; }
.kat-paragraph-label { font-weight: 700; color: #2563eb; margin-right: 6px; }

.kat-reset-order {
    background: transparent; border: 0; color: #6b7280; cursor: pointer;
    font-size: 13px; padding: 4px 0; text-decoration: underline;
}

/* ===== Submit area ===== */
.kat-quiz-actions { text-align: center; margin: 30px 0 10px; }

/* ===== Result ===== */
.kat-result-screen { padding: 24px; }
.kat-result-card {
    background: #fff; border-radius: 16px; padding: 32px;
    text-align: center; box-shadow: 0 4px 18px rgba(0,0,0,0.08); margin-bottom: 24px;
    border-top: 6px solid #2563eb;
}
.kat-result-card.pass { border-top-color: #16a34a; }
.kat-result-card.fail { border-top-color: #dc2626; }
.kat-score-big {
    font-size: 64px; font-weight: 700; line-height: 1;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.kat-result-card.pass .kat-score-big { background: linear-gradient(135deg, #16a34a, #15803d); -webkit-background-clip: text; background-clip: text; }
.kat-result-card.fail .kat-score-big { background: linear-gradient(135deg, #dc2626, #b91c1c); -webkit-background-clip: text; background-clip: text; }
.kat-score-detail { font-size: 18px; color: #4b5563; margin: 12px 0; }
.kat-pass-status { font-size: 16px; font-weight: 600; margin-bottom: 18px; }
.kat-result-card.pass .kat-pass-status { color: #16a34a; }
.kat-result-card.fail .kat-pass-status { color: #dc2626; }
.kat-result-actions { display: flex; justify-content: center; gap: 12px; }

.kat-review-heading { font-size: 20px; font-weight: 600; margin: 24px 0 12px; color: #1f2937; }
.kat-review-list { display: flex; flex-direction: column; gap: 12px; }
.kat-review-item {
    background: #fff; border-radius: 10px; padding: 16px 18px;
    border-left: 4px solid #d1d5db; box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.kat-review-item.is-correct { border-left-color: #16a34a; background: #f0fdf4; }
.kat-review-item.is-wrong { border-left-color: #dc2626; background: #fef2f2; }
.kat-review-header { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; }
.kat-review-item.is-correct .kat-review-status { color: #16a34a; }
.kat-review-item.is-wrong .kat-review-status { color: #dc2626; }
.kat-review-q { font-size: 15px; line-height: 1.6; margin-bottom: 8px; }
.kat-review-answers { font-size: 14px; line-height: 1.7; margin: 8px 0; }
.kat-explanation { background: #fffbeb; border-left: 3px solid #f59e0b; padding: 8px 12px; border-radius: 4px; font-size: 14px; line-height: 1.6; color: #78350f; margin-top: 8px; }

/* ===== Login required ===== */
.kat-login-gate {
    display: flex; justify-content: center; align-items: center;
    padding: 48px 16px; min-height: 60vh;
    background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
}
.kat-login-card {
    background: #fff; border-radius: 20px; padding: 40px 36px;
    max-width: 520px; width: 100%; text-align: center;
    box-shadow: 0 20px 60px rgba(37, 99, 235, 0.12), 0 4px 16px rgba(0,0,0,0.04);
    position: relative; overflow: hidden;
}
.kat-login-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
    background: linear-gradient(90deg, #2563eb, #7c3aed, #ec4899);
}
.kat-login-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 88px; height: 88px; margin: 0 auto 20px;
    background: linear-gradient(135deg, #dbeafe, #ede9fe);
    border-radius: 50%; color: #2563eb;
}
.kat-login-title {
    font-size: 24px; font-weight: 700; margin: 0 0 12px;
    color: #1f2937; line-height: 1.35;
}
.kat-login-sub { color: #4b5563; font-size: 15px; line-height: 1.65; margin: 0 0 24px; }
.kat-login-sub strong { color: #2563eb; }

.kat-login-meta {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px; margin: 0 0 24px; padding: 16px;
    background: #f9fafb; border-radius: 12px;
}
.kat-login-meta-item { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.kat-meta-label { font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.kat-meta-value { font-size: 16px; font-weight: 700; color: #1f2937; }

.kat-login-perks {
    list-style: none; padding: 0; margin: 0 0 28px;
    text-align: left; display: inline-block;
}
.kat-login-perks li {
    padding: 6px 0; font-size: 14px; color: #374151;
    display: flex; align-items: center; gap: 10px;
}
.kat-tick {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; background: #dcfce7; color: #16a34a;
    border-radius: 50%; font-weight: 700; font-size: 13px;
}

.kat-login-actions {
    display: flex; gap: 12px; justify-content: center; flex-wrap: wrap;
}
.kat-login-actions .kat-btn { min-width: 160px; }
.kat-btn-outline {
    background: #fff !important; color: #2563eb !important;
    border: 2px solid #2563eb !important;
}
.kat-btn-outline:hover { background: #eff6ff !important; }

@media (max-width: 540px) {
    .kat-login-card { padding: 28px 20px; border-radius: 16px; }
    .kat-login-title { font-size: 20px; }
    .kat-login-actions .kat-btn { width: 100%; }
}

/* ===== History page ===== */
.kat-history-wrapper { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.kat-history-wrapper h2 { font-size: 22px; margin-bottom: 16px; }
.kat-history-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
@media (max-width: 700px) { .kat-history-stats { grid-template-columns: 1fr; } }
.kat-stat-card {
    background: linear-gradient(135deg, #dbeafe, #ede9fe);
    border-radius: 12px; padding: 20px; text-align: center;
}
.kat-stat-label { font-size: 13px; color: #4b5563; text-transform: uppercase; letter-spacing: .5px; }
.kat-stat-value { font-size: 30px; font-weight: 700; color: #1e40af; margin-top: 6px; }

.kat-history-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 6px rgba(0,0,0,0.06); }
.kat-history-table th, .kat-history-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #f3f4f6; font-size: 14px; }
.kat-history-table th { background: #f9fafb; font-weight: 600; color: #4b5563; }
.kat-history-table tbody tr:hover { background: #f9fafb; }
.kat-history-table .kat-score { font-weight: 700; color: #2563eb; }

.kat-attempt-detail { max-width: 900px; margin: 24px auto; padding: 0 16px; }
.kat-result-summary {
    display: flex; gap: 24px; align-items: center;
    background: #fff; border-radius: 12px; padding: 20px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.06); margin-bottom: 24px;
}
.kat-result-summary .kat-score-big { font-size: 56px; }
.kat-result-summary > div:last-child { font-size: 14px; color: #4b5563; line-height: 1.8; }

.kat-quiz-empty { text-align: center; padding: 40px; color: #6b7280; }

/* ============================================
   MOBILE / TABLET OPTIMIZATIONS
   ============================================ */
@media (max-width: 1024px) {
    .kat-quiz-wrapper { margin: 12px auto; padding: 0 8px; }
    .kat-section-body { grid-template-columns: 1fr !important; }
    .kat-passage-pane { position: static !important; max-height: none !important; }
}

@media (max-width: 768px) {
    .kat-quiz-topbar {
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 10px;
        border-radius: 10px 10px 0 0;
    }
    .kat-quiz-title {
        font-size: 15px;
        flex: 1 1 100%;
        order: -1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .kat-timer { font-size: 14px; padding: 5px 12px; flex: 1; text-align: center; }
    .kat-quiz-topbar .kat-btn { padding: 6px 12px !important; font-size: 13px !important; }
    .kat-fullscreen { display: none; }

    .kat-quiz-form { padding: 14px; border-radius: 0 0 10px 10px; }
    .kat-section { margin-bottom: 24px; padding-bottom: 16px; }
    .kat-section-instruction { padding: 8px 12px; font-size: 14px; }

    .kat-question { padding: 12px 14px; border-radius: 8px; }
    .kat-q-number { font-size: 15px; }
    .kat-q-text { font-size: 14px; }

    .kat-hanzi-display { font-size: 28px; padding: 10px; letter-spacing: 2px; }
    .kat-pinyin-display { font-size: 18px; padding: 10px; }

    .kat-options { gap: 6px; }
    .kat-option { padding: 8px 12px; font-size: 14px; }
    .kat-option input[type=radio] { width: 16px; height: 16px; }

    .kat-fill-inline { font-size: 16px; line-height: 2.2; }
    .kat-fill-inline .kat-blank-input {
        width: 90px !important; min-width: 70px !important; font-size: 16px !important;
    }
    .kat-fill-blanks .kat-blank-input { min-width: 140px !important; }

    .kat-word-bank { padding: 10px 12px; }
    .kat-chip { font-size: 14px; padding: 5px 12px; }

    .kat-token, .kat-paragraph-item { font-size: 14px; padding: 7px 12px; }

    .kat-quiz-actions { margin: 20px 0 8px; }
    .kat-quiz-actions .kat-btn-large { padding: 12px 24px; font-size: 15px; }

    /* Start screen */
    .kat-start-card { padding: 24px 18px; border-radius: 14px; }
    .kat-start-card h2 { font-size: 22px; }

    /* Result */
    .kat-result-screen { padding: 12px; }
    .kat-result-card { padding: 24px 18px; border-radius: 12px; }
    .kat-score-big { font-size: 48px; }
    .kat-result-actions { flex-direction: column; }
    .kat-result-actions .kat-btn { width: 100%; }

    /* Review items */
    .kat-review-item { padding: 12px 14px; }
    .kat-review-header { font-size: 14px; }
    .kat-review-q { font-size: 14px; }
    .kat-review-answers { font-size: 13px; }

    /* History page */
    .kat-history-wrapper { padding: 0 8px; }
    .kat-history-stats { gap: 8px; }
    .kat-stat-card { padding: 14px 10px; }
    .kat-stat-value { font-size: 24px; }
    .kat-history-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .kat-history-table th, .kat-history-table td { padding: 8px 10px; font-size: 13px; white-space: nowrap; }

    /* Attempt detail */
    .kat-result-summary { flex-direction: column; gap: 12px; text-align: center; padding: 16px; }
    .kat-result-summary .kat-score-big { font-size: 44px; }

    /* In-progress block */
    .kat-inprogress-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .kat-quiz-wrapper { padding: 0 4px; }
    .kat-quiz-title { font-size: 14px; }
    .kat-timer { font-size: 13px; padding: 4px 10px; }
    .kat-quiz-topbar .kat-btn-primary { padding: 6px 10px !important; }

    .kat-hanzi-display { font-size: 24px; letter-spacing: 1px; }
    .kat-pinyin-display { font-size: 16px; }
    .kat-q-number { font-size: 14px; }
    .kat-q-text { font-size: 13px; }
    .kat-option { padding: 7px 10px; font-size: 13px; }
    .kat-option-letter { font-size: 13px; min-width: 18px; }

    .kat-fill-inline .kat-blank-input { width: 80px !important; min-width: 60px !important; }
    .kat-chip { font-size: 13px; padding: 4px 10px; }

    /* Word bank wraps better on small */
    .kat-word-bank-chips { gap: 6px; }

    /* Drawer takes more of screen on small mobile */
    .kat-quiz-nav { width: 92%; }
}

/* ===== Leave-page modal ===== */
.kat-leave-modal {
    position: fixed; inset: 0; z-index: 99999;
    background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; animation: katFadeIn .2s ease;
}
@keyframes katFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes katSlideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.kat-leave-card {
    background: #fff; border-radius: 16px; padding: 32px 28px;
    max-width: 460px; width: 100%; text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: katSlideUp .25s ease;
}
.kat-leave-icon { font-size: 48px; margin-bottom: 12px; }
.kat-leave-title { font-size: 20px; font-weight: 700; margin: 0 0 8px; color: #111827; }
.kat-leave-desc { color: #4b5563; font-size: 14px; line-height: 1.6; margin: 0 0 24px; }
.kat-leave-actions { display: flex; flex-direction: column; gap: 10px; }
.kat-leave-actions .kat-btn { width: 100%; justify-content: center; }
.kat-btn-link {
    background: transparent !important; border: 0 !important;
    color: #dc2626 !important; text-decoration: underline; padding: 6px 12px !important;
    font-size: 13px;
}
.kat-btn-link:hover { color: #991b1b !important; background: transparent !important; }
.kat-leave-status { margin-top: 14px; font-size: 13px; color: #2563eb; min-height: 18px; }

/* ===== In-progress section in My Account ===== */
.kat-inprogress-block {
    background: linear-gradient(135deg, #fff7ed, #fef3c7);
    border: 1.5px solid #fcd34d; border-radius: 12px;
    padding: 18px 20px; margin-bottom: 24px;
}
.kat-inprogress-heading { margin: 0 0 12px; font-size: 17px; color: #92400e; }
.kat-history-heading { margin: 24px 0 12px; font-size: 17px; color: #1f2937; }
.kat-inprogress-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}
.kat-inprogress-card {
    background: #fff; border-radius: 10px; padding: 14px 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.kat-inprogress-title { font-weight: 700; color: #1f2937; margin-bottom: 8px; }
.kat-inprogress-meta {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12px; color: #6b7280; margin-bottom: 12px;
}
.kat-inprogress-meta strong { color: #ea580c; font-size: 14px; }
.kat-inprogress-card .kat-btn { width: 100%; text-align: center; padding: 8px 12px; }

/* ===== Resume badge ===== */
.kat-resume-badge {
    background: rgba(16, 185, 129, 0.18); color: #fff;
    padding: 4px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
    border: 1px solid rgba(255,255,255,0.3);
}
