/* ==========================================================================
   HKSI Quiz Frontend Styles
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    --hksi-primary: #2563eb;
    --hksi-primary-light: #3b82f6;
    --hksi-primary-dark: #1d4ed8;
    --hksi-success: #16a34a;
    --hksi-success-light: #22c55e;
    --hksi-danger: #dc2626;
    --hksi-danger-light: #ef4444;
    --hksi-warning: #f59e0b;
    --hksi-warning-light: #fbbf24;
    --hksi-gray: #6b7280;
    --hksi-gray-light: #9ca3af;
    --hksi-gray-lighter: #e5e7eb;
    --hksi-gray-lightest: #f3f4f6;
    --hksi-bg: #f9fafb;
    --hksi-card-bg: #ffffff;
    --hksi-text: #1f2937;
    --hksi-text-light: #4b5563;
    --hksi-radius: 8px;
    --hksi-radius-lg: 12px;
    --hksi-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --hksi-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --hksi-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --hksi-transition: 0.2s ease;
}

/* ---------- Wrapper ---------- */
.hksi-quiz-wrapper {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--hksi-text);
    background: var(--hksi-bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.hksi-quiz-wrapper *,
.hksi-quiz-wrapper *::before,
.hksi-quiz-wrapper *::after {
    box-sizing: border-box;
}

/* ---------- Setup Screen ---------- */
.hksi-setup-screen {
    background: var(--hksi-card-bg);
    padding: 32px;
    border-radius: var(--hksi-radius-lg);
    box-shadow: var(--hksi-shadow-md);
    max-width: 600px;
    margin: 40px auto;
    text-align: center;
}

.hksi-setup-screen h2 {
    font-size: 1.5em;
    margin: 0 0 8px;
    color: var(--hksi-text);
}

.hksi-setup-screen p {
    color: var(--hksi-text-light);
    margin: 0 0 24px;
}

/* ---- Mode banner (setup screen, when mode is locked by shortcode) ---- */
.hksi-mode-banner {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    border-radius: 8px;
    border-left: 4px solid #3b82f6;
    background: rgba(59, 130, 246, 0.08);
    margin: 0 0 16px;
}
.hksi-mode-banner--study { border-left-color: #10b981; background: rgba(16, 185, 129, 0.08); }
.hksi-mode-banner--exam  { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.10); }
.hksi-mode-banner--drill { border-left-color: #8b5cf6; background: rgba(139, 92, 246, 0.10); }
.hksi-mode-banner-label { font-weight: 600; color: var(--hksi-text); font-size: 1rem; }
.hksi-mode-banner-desc  { color: var(--hksi-text-light); font-size: 0.9rem; }

/* ---- Mode chip (top bar during the quiz) ---- */
.hksi-mode-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
}
.hksi-mode-chip--study { background: rgba(16, 185, 129, 0.15); color: #047857; }
.hksi-mode-chip--exam  { background: rgba(245, 158, 11, 0.18); color: #b45309; }
.hksi-mode-chip--drill { background: rgba(139, 92, 246, 0.18); color: #6d28d9; }

.hksi-setup-screen label,
.hksi-size-label {
    display: block;
    text-align: left;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--hksi-text);
}

.hksi-size-label {
    text-align: center;
}

.hksi-setup-screen select,
.hksi-setup-screen input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    font-size: 1em;
    color: var(--hksi-text);
    background: var(--hksi-card-bg);
    margin-bottom: 16px;
    transition: border-color var(--hksi-transition);
}

.hksi-setup-screen select:focus,
.hksi-setup-screen input:focus {
    outline: none;
    border-color: var(--hksi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hksi-setup-group {
    margin-bottom: 20px;
    text-align: left;
}

/* ---------- Size Options (pill/chip selectors) ---------- */
.hksi-size-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 24px;
}

.hksi-size-options input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.hksi-size-options label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border: 2px solid var(--hksi-gray-lighter);
    border-radius: 999px;
    font-size: 0.95em;
    font-weight: 500;
    color: var(--hksi-text-light);
    cursor: pointer;
    transition: all var(--hksi-transition);
    user-select: none;
    margin-bottom: 0;
    text-align: center;
}

.hksi-size-options label:hover {
    border-color: var(--hksi-primary-light);
    color: var(--hksi-primary);
    background: rgba(37, 99, 235, 0.04);
}

.hksi-size-options input[type="radio"]:checked + label {
    border-color: var(--hksi-primary);
    background: var(--hksi-primary);
    color: #ffffff;
}

/* ---------- Buttons ---------- */
.hksi-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 24px;
    border: none;
    border-radius: var(--hksi-radius);
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--hksi-transition);
    text-decoration: none;
    line-height: 1.4;
}

.hksi-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--hksi-shadow-md);
}

.hksi-btn:active {
    transform: translateY(0);
}

.hksi-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.hksi-btn-primary {
    background: var(--hksi-primary);
    color: #ffffff;
}

.hksi-btn-primary:hover {
    background: var(--hksi-primary-dark);
}

.hksi-btn-save {
    background: var(--hksi-gray);
    color: #ffffff;
}

.hksi-btn-save:hover {
    background: #4b5563;
}

.hksi-save-status {
    font-size: 0.85em;
    line-height: 1.2;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    align-self: center;
}

.hksi-save-status--pending {
    color: var(--hksi-text-light);
}

.hksi-save-status--ok {
    color: #15803d;
    background: rgba(34, 197, 94, 0.12);
}

.hksi-save-status--error {
    color: #b91c1c;
    background: rgba(239, 68, 68, 0.12);
}

.hksi-session-expired {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 0;
    padding: 10px 14px;
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.12);
    color: #991b1b;
    font-size: 0.95em;
}

.hksi-session-expired__link {
    font-weight: 600;
    text-decoration: underline;
    color: #7f1d1d;
}

.hksi-btn-submit {
    background: var(--hksi-success);
    color: #ffffff;
}

.hksi-btn-submit:hover {
    background: #15803d;
}

.hksi-btn-resume {
    background: var(--hksi-warning);
    color: #ffffff;
}

.hksi-btn-resume:hover {
    background: #d97706;
}

.hksi-btn-outline {
    background: transparent;
    border: 2px solid var(--hksi-gray-lighter);
    color: var(--hksi-text-light);
}

.hksi-btn-outline:hover {
    border-color: var(--hksi-primary);
    color: var(--hksi-primary);
}

.hksi-btn-sm {
    padding: 6px 14px;
    font-size: 0.85em;
}

.hksi-btn-lg {
    padding: 14px 32px;
    font-size: 1.05em;
}

/* ---------- Top Bar ---------- */
.hksi-top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--hksi-card-bg);
    border-bottom: 1px solid var(--hksi-gray-lighter);
    box-shadow: var(--hksi-shadow);
    border-radius: var(--hksi-radius) var(--hksi-radius) 0 0;
    flex-wrap: wrap;
}

.hksi-top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hksi-top-bar-center {
    flex: 1;
    min-width: 120px;
    max-width: 320px;
}

.hksi-top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Timer ---------- */
.hksi-timer {
    font-size: 1.25em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--hksi-text);
    white-space: nowrap;
}

.hksi-timer-urgent {
    color: var(--hksi-danger) !important;
    animation: hksi-timer-blink 1s ease-in-out infinite;
}

@keyframes hksi-timer-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---------- Progress Bar ---------- */
.hksi-progress-bar {
    position: relative;
    height: 8px;
    background: var(--hksi-gray-lighter);
    border-radius: 999px;
    overflow: hidden;
}

.hksi-progress-fill {
    height: 100%;
    background: var(--hksi-primary);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.hksi-progress-text {
    font-size: 0.8em;
    color: var(--hksi-text-light);
    text-align: center;
    margin-top: 4px;
}

/* ---------- Navigator ---------- */
.hksi-navigator {
    background: var(--hksi-card-bg);
    border-bottom: 1px solid var(--hksi-gray-lighter);
}

.hksi-navigator-grid.collapsed {
    display: none;
}

.hksi-navigator-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--hksi-primary);
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
}

.hksi-navigator-toggle:hover {
    color: var(--hksi-primary-dark);
}

.hksi-navigator-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 6px;
    padding: 12px 16px;
}

.nav-item {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 6px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--hksi-transition);
    user-select: none;
    background: var(--hksi-card-bg);
    color: var(--hksi-text);
}

.nav-item:hover {
    border-color: var(--hksi-primary);
    box-shadow: var(--hksi-shadow);
}

.nav-unanswered {
    background: var(--hksi-gray-lighter);
    color: var(--hksi-gray);
}

.nav-answered {
    background: var(--hksi-primary);
    color: #ffffff;
    border-color: var(--hksi-primary);
}

.nav-flagged {
    background: var(--hksi-warning);
    color: #ffffff;
    border-color: var(--hksi-warning);
}

.nav-correct {
    background: var(--hksi-success);
    color: #ffffff;
    border-color: var(--hksi-success);
}

.nav-wrong {
    background: var(--hksi-danger);
    color: #ffffff;
    border-color: var(--hksi-danger);
}

.nav-active {
    outline: 3px solid var(--hksi-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.15);
}

/* ---------- Question Card ---------- */
.hksi-question-card {
    background: var(--hksi-card-bg);
    padding: 24px;
    margin-bottom: 16px;
    border-radius: var(--hksi-radius);
    box-shadow: var(--hksi-shadow);
}

.hksi-question-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.hksi-question-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    background: var(--hksi-primary);
    color: #ffffff;
    font-size: 0.8em;
    font-weight: 700;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.hksi-question-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hksi-hint-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 14px;
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 999px;
    cursor: pointer;
    color: var(--hksi-text-light);
    font-size: 0.8em;
    font-weight: 600;
    transition: all var(--hksi-transition);
}

.hksi-hint-btn:hover {
    border-color: var(--hksi-warning);
    color: var(--hksi-warning);
    background: rgba(245, 158, 11, 0.08);
}

.hksi-flag-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 50%;
    cursor: pointer;
    color: var(--hksi-gray-light);
    font-size: 1.1em;
    transition: all var(--hksi-transition);
}

.hksi-flag-btn:hover {
    border-color: var(--hksi-warning);
    color: var(--hksi-warning);
}

.hksi-flag-btn.flagged {
    background: var(--hksi-warning);
    border-color: var(--hksi-warning);
    color: #ffffff;
}

.hksi-question-text {
    font-size: 1.1em;
    line-height: 1.7;
    margin-bottom: 20px;
    color: var(--hksi-text);
}

/* ---------- Options ---------- */
.hksi-options-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.hksi-option {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 2px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    cursor: pointer;
    transition: all var(--hksi-transition);
    background: var(--hksi-card-bg);
}

.hksi-option:hover {
    border-color: var(--hksi-primary-light);
    background: rgba(37, 99, 235, 0.02);
}

.hksi-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.hksi-option-radio {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-width: 24px;
    border: 2px solid var(--hksi-gray-lighter);
    border-radius: 50%;
    font-size: 0.75em;
    font-weight: 700;
    color: var(--hksi-gray);
    transition: all var(--hksi-transition);
    margin-top: 1px;
}

.hksi-option-text {
    flex: 1;
    font-size: 1em;
    line-height: 1.5;
    color: var(--hksi-text);
}

/* Selected option */
.option-selected {
    border-color: var(--hksi-primary);
    border-left-width: 4px;
    background: rgba(37, 99, 235, 0.04);
}

.option-selected .hksi-option-radio {
    border-color: var(--hksi-primary);
    background: var(--hksi-primary);
    color: #ffffff;
}

/* Correct option (after reveal) */
.option-correct {
    border-color: var(--hksi-success);
    background: rgba(22, 163, 74, 0.08);
}

.option-correct .hksi-option-radio {
    border-color: var(--hksi-success);
    background: var(--hksi-success);
    color: #ffffff;
}

/* Wrong option (after reveal) */
.option-wrong {
    border-color: var(--hksi-danger);
    background: rgba(220, 38, 38, 0.08);
}

.option-wrong .hksi-option-radio {
    border-color: var(--hksi-danger);
    background: var(--hksi-danger);
    color: #ffffff;
}

/* Disabled options (after answer submitted) */
.hksi-option.disabled {
    cursor: default;
    pointer-events: none;
}

/* ---------- Explanation ---------- */
.hksi-explanation {
    display: none;
    margin-top: 16px;
    padding: 16px 20px;
    background: var(--hksi-gray-lightest);
    border-left: 4px solid var(--hksi-success);
    border-radius: 0 var(--hksi-radius) var(--hksi-radius) 0;
    font-size: 0.95em;
    line-height: 1.6;
    color: var(--hksi-text-light);
}

.hksi-explanation.visible {
    display: block;
}

.hksi-explanation strong {
    color: var(--hksi-text);
}

/* ---------- Question Navigation Buttons ---------- */
.hksi-question-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    gap: 12px;
}

.hksi-question-counter {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--hksi-text-light);
    white-space: nowrap;
}

/* ---------- Results Summary ---------- */
.hksi-results-summary {
    background: var(--hksi-card-bg);
    padding: 40px 32px;
    border-radius: var(--hksi-radius-lg);
    box-shadow: var(--hksi-shadow-lg);
    text-align: center;
    max-width: 640px;
    margin: 40px auto;
}

.hksi-results-score-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    margin: 0 auto 24px;
    font-size: 2.5em;
    font-weight: 800;
    color: #ffffff;
}

.hksi-results-score-circle.score-pass {
    background: var(--hksi-success);
    box-shadow: 0 0 0 8px rgba(22, 163, 74, 0.15);
}

.hksi-results-score-circle.score-fail {
    background: var(--hksi-danger);
    box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.15);
}

.hksi-results-title {
    font-size: 1.5em;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--hksi-text);
}

.hksi-results-subtitle {
    color: var(--hksi-text-light);
    margin: 0 0 32px;
    font-size: 1em;
}

.hksi-results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.hksi-results-stat {
    padding: 16px 12px;
    background: var(--hksi-gray-lightest);
    border-radius: var(--hksi-radius);
}

.hksi-results-stat-value {
    display: block;
    font-size: 1.5em;
    font-weight: 700;
    color: var(--hksi-text);
}

.hksi-results-stat-label {
    display: block;
    font-size: 0.8em;
    color: var(--hksi-text-light);
    margin-top: 4px;
}

.hksi-results-stat-value.stat-correct {
    color: var(--hksi-success);
}

.hksi-results-stat-value.stat-wrong {
    color: var(--hksi-danger);
}

.hksi-results-stat-value.stat-unanswered {
    color: var(--hksi-gray);
}

/* ---------- Results Actions ---------- */
.hksi-results-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
}

/* ---------- Resume Banner ---------- */
.hksi-resume-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--hksi-warning-light);
    border-radius: var(--hksi-radius);
    margin-bottom: 20px;
}

.hksi-resume-banner-text {
    color: var(--hksi-text);
    font-size: 0.95em;
}

.hksi-resume-banner-text strong {
    color: #92400e;
}

/* Dynamic setup: one row per saved attempt. */
.hksi-resume-banner--list {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.hksi-resume-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hksi-resume-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
    padding: 0;
}

.hksi-resume-item-text {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--hksi-text);
    font-size: 0.9em;
    text-align: left;
}

/* Keep Resume on one line: CJK text may break between any two characters,
   so a shrinkable button collapsed to one glyph per line (繼 / 續). */
.hksi-resume-item .hksi-btn-resume,
.hksi-resume-banner > .hksi-btn-resume {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* ---------- Loading / Spinner ---------- */
.hksi-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.hksi-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--hksi-gray-lighter);
    border-top-color: var(--hksi-primary);
    border-radius: 50%;
    animation: hksi-spin 0.7s linear infinite;
}

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

.hksi-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: var(--hksi-radius);
}

[data-hksi-theme="dark"] .hksi-loading-overlay {
    background: rgba(30, 30, 30, 0.85);
}

.hksi-loading-text {
    margin-top: 16px;
    font-size: 1rem;
    color: var(--hksi-text-secondary);
}

/* ---------- Messages / Notices ---------- */
.hksi-notice {
    padding: 12px 16px;
    border-radius: var(--hksi-radius);
    font-size: 0.9em;
    margin-bottom: 16px;
}

.hksi-notice-info {
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--hksi-primary-dark);
}

.hksi-notice-success {
    background: rgba(22, 163, 74, 0.08);
    border: 1px solid rgba(22, 163, 74, 0.2);
    color: #15803d;
}

.hksi-notice-error {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.2);
    color: #b91c1c;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* ---------- Tablet and below ---------- */
@media (max-width: 768px) {
    .hksi-quiz-wrapper {
        padding: 8px;
    }

    .hksi-setup-screen {
        padding: 24px 16px;
        margin: 20px auto;
    }

    .hksi-top-bar {
        padding: 10px 12px;
        gap: 8px;
    }

    .hksi-top-bar-center {
        order: 3;
        flex: 0 0 100%;
        max-width: 100%;
    }

    .hksi-timer {
        font-size: 1.1em;
    }

    .hksi-navigator-grid {
        grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
        gap: 4px;
        padding: 8px 12px;
    }

    .nav-item {
        width: 34px;
        height: 34px;
        font-size: 0.75em;
    }

    .hksi-question-card {
        padding: 16px;
        margin-bottom: 12px;
    }

    .hksi-question-text {
        font-size: 1em;
    }

    .hksi-option {
        padding: 12px;
    }

    .hksi-results-summary {
        padding: 28px 20px;
        margin: 20px auto;
    }

    .hksi-results-score-circle {
        width: 110px;
        height: 110px;
        font-size: 2em;
    }

    .hksi-results-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .hksi-results-actions {
        flex-direction: column;
    }

    .hksi-results-actions .hksi-btn {
        width: 100%;
    }
}

/* ---------- Mobile small ---------- */
@media (max-width: 480px) {
    .hksi-quiz-wrapper {
        padding: 4px;
    }

    .hksi-setup-screen {
        padding: 20px 12px;
        border-radius: var(--hksi-radius);
    }

    .hksi-size-options {
        flex-direction: column;
        align-items: stretch;
    }

    .hksi-size-options label {
        padding: 10px 16px;
    }

    .hksi-top-bar {
        padding: 8px 10px;
        border-radius: 0;
    }

    .hksi-navigator-grid {
        grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
        gap: 3px;
        padding: 6px 8px;
    }

    .nav-item {
        width: 30px;
        height: 30px;
        font-size: 0.7em;
        border-radius: 4px;
    }

    .hksi-question-card {
        padding: 12px;
        border-radius: 6px;
    }

    .hksi-question-header {
        margin-bottom: 12px;
    }

    .hksi-option {
        padding: 10px;
        gap: 8px;
    }

    .hksi-option-radio {
        width: 20px;
        height: 20px;
        min-width: 20px;
        font-size: 0.7em;
    }

    .hksi-explanation {
        padding: 12px 14px;
        font-size: 0.9em;
    }

    .hksi-question-nav {
        padding: 12px 0;
    }

    .hksi-btn {
        padding: 8px 16px;
        font-size: 0.9em;
    }

    .hksi-btn-lg {
        padding: 12px 24px;
        font-size: 1em;
    }

    .hksi-resume-banner {
        flex-direction: column;
        text-align: center;
        padding: 12px 14px;
    }

    .hksi-resume-item {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .hksi-resume-item-text {
        text-align: center;
    }

    .hksi-results-score-circle {
        width: 100px;
        height: 100px;
        font-size: 1.75em;
    }

    .hksi-results-stats {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .hksi-results-stat {
        padding: 12px 8px;
    }

    .hksi-results-stat-value {
        font-size: 1.25em;
    }
}

/* ==========================================================================
   Dark Mode
   ========================================================================== */
.hksi-quiz-wrapper[data-hksi-theme="dark"] {
    --hksi-bg: #1a1a2e;
    --hksi-card-bg: #16213e;
    --hksi-text: #e2e8f0;
    --hksi-text-light: #a0aec0;
    --hksi-gray: #718096;
    --hksi-gray-light: #4a5568;
    --hksi-gray-lighter: #2d3748;
    --hksi-gray-lightest: #1e293b;
    --hksi-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --hksi-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.2);
    --hksi-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3), 0 4px 6px rgba(0, 0, 0, 0.2);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-option:hover {
    background: rgba(37, 99, 235, 0.1);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .option-selected {
    background: rgba(37, 99, 235, 0.15);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .option-correct {
    background: rgba(22, 163, 74, 0.15);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .option-wrong {
    background: rgba(220, 38, 38, 0.15);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-resume-banner {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.3);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-size-options label:hover {
    background: rgba(37, 99, 235, 0.1);
}

/* ---------- Theme switch performance guard ----------
 * When the theme flips, hundreds of elements with `transition: all 0.2s`
 * would otherwise animate their colour change simultaneously, causing
 * visible lag on 50/100-question quizzes. JS sets this marker on the
 * wrapper during the flip and clears it on the next frame, so the swap
 * repaints instantly. Hover/focus transitions still animate normally
 * afterwards. */
.hksi-quiz-wrapper[data-hksi-theme-switching] *,
.hksi-quiz-wrapper[data-hksi-theme-switching] *::before,
.hksi-quiz-wrapper[data-hksi-theme-switching] *::after {
    transition: none !important;
}

/* ---------- Theme Toggle ---------- */
.hksi-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.15em;
    line-height: 1;
    transition: all var(--hksi-transition);
    color: var(--hksi-text-light);
}

.hksi-theme-toggle:hover {
    border-color: var(--hksi-primary);
    color: var(--hksi-primary);
    background: rgba(37, 99, 235, 0.08);
}

/* ---------- Per-Question Notes ---------- */
.hksi-note-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 14px;
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 999px;
    cursor: pointer;
    color: var(--hksi-text-light);
    font-size: 0.8em;
    font-weight: 600;
    transition: all var(--hksi-transition);
}

.hksi-note-btn:hover {
    border-color: var(--hksi-primary);
    color: var(--hksi-primary);
    background: rgba(37, 99, 235, 0.08);
}

.hksi-note-btn.has-note {
    border-color: var(--hksi-primary);
    color: var(--hksi-primary);
}

.hksi-note-area {
    display: none;
    margin-top: 12px;
    padding: 12px;
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
}

.hksi-note-area.visible {
    display: block;
}

.hksi-note-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    font-family: inherit;
    font-size: 0.9em;
    line-height: 1.5;
    color: var(--hksi-text);
    background: var(--hksi-card-bg);
    resize: vertical;
    transition: border-color var(--hksi-transition);
}

.hksi-note-textarea:focus {
    outline: none;
    border-color: var(--hksi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hksi-note-status {
    font-size: 0.75em;
    color: var(--hksi-text-light);
    margin-top: 4px;
    min-height: 1.2em;
}

/* ---------- Topic Reference Badge ---------- */
.hksi-topic-ref {
    font-size: 0.75em;
    color: var(--hksi-text-light);
    margin-bottom: 8px;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    letter-spacing: 0.02em;
}

/* ---------- Report Button ---------- */
.hksi-report-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 14px;
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: 999px;
    cursor: pointer;
    color: var(--hksi-warning);
    font-size: 0.8em;
    font-weight: 600;
    line-height: 1;
    transition: all var(--hksi-transition);
}

.hksi-report-btn:hover {
    border-color: var(--hksi-warning);
    background: rgba(245, 158, 11, 0.1);
}

.hksi-report-btn.reported {
    opacity: 0.4;
    cursor: default;
    color: var(--hksi-gray);
}

.hksi-report-btn.reported:hover {
    border-color: var(--hksi-gray-lighter);
    background: var(--hksi-gray-lightest);
}

/* ---------- Report Modal ---------- */
.hksi-report-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.hksi-report-modal {
    background: var(--hksi-card-bg);
    border-radius: var(--hksi-radius-lg);
    box-shadow: var(--hksi-shadow-lg);
    padding: 24px;
    max-width: 420px;
    width: 90%;
    color: var(--hksi-text);
}

.hksi-report-modal h3 {
    margin: 0 0 12px;
    font-size: 1.1em;
}

.hksi-report-modal p {
    margin: 0 0 16px;
    color: var(--hksi-text-light);
    font-size: 0.9em;
}

.hksi-report-reasons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.hksi-report-reasons label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    padding: 6px 10px;
    border-radius: var(--hksi-radius);
    transition: background var(--hksi-transition);
}

.hksi-report-reasons label:hover {
    background: var(--hksi-gray-lightest);
}

.hksi-report-comment {
    width: 100%;
    min-height: 60px;
    padding: 10px 12px;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    font-family: inherit;
    font-size: 0.9em;
    line-height: 1.5;
    color: var(--hksi-text);
    background: var(--hksi-card-bg);
    resize: vertical;
    margin-bottom: 16px;
    transition: border-color var(--hksi-transition);
    box-sizing: border-box;
}

.hksi-report-comment:focus {
    outline: none;
    border-color: var(--hksi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hksi-report-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.hksi-report-cancel {
    background: var(--hksi-gray-lightest);
    border: 1px solid var(--hksi-gray-lighter);
    color: var(--hksi-text-light);
}

/* ---------- Toast Notification ---------- */
.hksi-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--hksi-success);
    color: #fff;
    padding: 10px 24px;
    border-radius: var(--hksi-radius);
    font-size: 0.9em;
    font-weight: 600;
    z-index: 10001;
    box-shadow: var(--hksi-shadow-md);
    transition: opacity 0.3s;
}

.hksi-toast-fade {
    opacity: 0;
}

/* ---------- Dark Mode: Report & Topic Ref ---------- */
.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-report-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-report-comment {
    background: var(--hksi-gray-lightest);
    border-color: var(--hksi-gray-light);
}

/* ==========================================================================
   Dynamic Setup Screen
   ========================================================================== */

/* ---------- Setup Group ---------- */
.hksi-dynamic-setup {
    text-align: left;
    margin-bottom: 24px;
}

.hksi-setup-group {
    margin-bottom: 20px;
}

.hksi-setup-label {
    display: block;
    font-weight: 600;
    font-size: 0.9em;
    color: var(--hksi-text);
    margin-bottom: 8px;
}

/* ---------- Pill Group (mode picker) ---------- */
.hksi-pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.hksi-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border: 2px solid var(--hksi-gray-lighter);
    border-radius: 999px;
    font-size: 0.95em;
    font-weight: 500;
    color: var(--hksi-text-light);
    background: transparent;
    cursor: pointer;
    transition: all var(--hksi-transition);
    user-select: none;
}

.hksi-pill:hover {
    border-color: var(--hksi-primary-light);
    color: var(--hksi-primary);
    background: rgba(37, 99, 235, 0.04);
}

.hksi-pill.active {
    border-color: var(--hksi-primary);
    background: var(--hksi-primary);
    color: #ffffff;
}

/* ---------- Mode Pills (with descriptions) ---------- */
.hksi-mode-pill {
    flex-direction: column;
    border-radius: 12px;
    padding: 12px 20px 10px;
    min-width: 140px;
    text-align: center;
}

.hksi-mode-pill-label {
    font-size: 1.05em;
    font-weight: 600;
}

.hksi-mode-pill-desc {
    font-size: 0.78em;
    font-weight: 400;
    opacity: 0.8;
    margin-top: 3px;
    line-height: 1.3;
}

.hksi-mode-pill.active .hksi-mode-pill-desc {
    opacity: 0.9;
}

/* ---------- Timer & Count Inputs ---------- */
.hksi-timer-input-wrap,
.hksi-count-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hksi-timer-input,
.hksi-count-input {
    width: 100px;
    padding: 10px 12px;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    font-size: 1em;
    color: var(--hksi-text);
    background: var(--hksi-card-bg);
    transition: border-color var(--hksi-transition);
    text-align: center;
}

.hksi-timer-input:focus,
.hksi-count-input:focus {
    outline: none;
    border-color: var(--hksi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.hksi-timer-unit {
    font-size: 0.95em;
    color: var(--hksi-text-light);
}

.hksi-count-hint {
    font-size: 0.85em;
    color: var(--hksi-text-light);
}

/* ---------- Randomize Toggle ---------- */
.hksi-randomize-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--hksi-text);
    user-select: none;
    padding: 8px 0 0;
}

.hksi-randomize-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--hksi-primary);
    cursor: pointer;
}

.hksi-randomize-desc {
    font-size: 0.82em;
    color: var(--hksi-text-light);
    margin: 4px 0 0;
    line-height: 1.4;
}

/* ---------- Dynamic Setup Dropdowns ---------- */
.hksi-topic-select,
.hksi-chapter-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--hksi-gray-lighter);
    border-radius: var(--hksi-radius);
    font-size: 1em;
    color: var(--hksi-text);
    background: var(--hksi-card-bg);
    transition: border-color var(--hksi-transition);
    appearance: auto;
}

.hksi-topic-select:focus,
.hksi-chapter-select:focus {
    outline: none;
    border-color: var(--hksi-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ---------- Hot Toggle ---------- */
.hksi-hot-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95em;
    color: var(--hksi-text);
    user-select: none;
    padding: 8px 0;
}

.hksi-hot-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--hksi-warning);
    cursor: pointer;
}

/* ---------- Drill Info ---------- */
.hksi-drill-info-text {
    font-size: 0.95em;
    color: var(--hksi-text-light);
    margin: 0;
    padding: 12px 16px;
    background: var(--hksi-gray-lightest);
    border-radius: var(--hksi-radius);
    text-align: center;
}

/* ---------- Dark Mode: Dynamic Setup ---------- */
.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-pill:hover {
    background: rgba(37, 99, 235, 0.1);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-topic-select,
.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-chapter-select {
    background: var(--hksi-gray-lightest);
    border-color: var(--hksi-gray-light);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-timer-input,
.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-count-input {
    background: var(--hksi-gray-lightest);
    border-color: var(--hksi-gray-light);
}

/* ---------- Responsive: Dynamic Setup ---------- */
@media (max-width: 480px) {
    .hksi-pill-group {
        flex-direction: column;
        align-items: stretch;
    }

    .hksi-pill {
        padding: 10px 16px;
        text-align: center;
    }

    .hksi-mode-pill {
        min-width: auto;
    }
}

/* ---------- Case study stem (EAQE / SQE) ---------- */
.hksi-case-stem {
    margin: 12px 0 16px;
    border: 1px solid var(--hksi-gray-light, #d8dfea);
    border-radius: 8px;
    background: var(--hksi-gray-lightest, #f6f8fb);
    overflow: hidden;
}

.hksi-case-stem-heading {
    padding: 8px 12px;
    font-weight: 600;
    background: var(--hksi-primary, #2271b1);
    color: #fff;
    font-size: 0.95em;
}

.hksi-case-stem-loading,
.hksi-case-stem-error {
    padding: 12px;
    color: var(--hksi-gray, #6b7785);
    font-style: italic;
}

.hksi-case-stem-error {
    color: #b32d2e;
}

.hksi-case-stem-frame {
    display: block;
    width: 100%;
    min-height: 120px;
    border: 0;
    background: #fff;
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-case-stem {
    background: var(--hksi-gray-lightest);
    border-color: var(--hksi-gray-light);
}

.hksi-quiz-wrapper[data-hksi-theme="dark"] .hksi-case-stem-frame {
    background: #fff; /* iframe content keeps its own light background */
}
