/* ==========================================================================
   ระบบฝึกทำข้อสอบเสมือนจริง O-NET วิชาภาษาไทย ม.3 v2.0
   Modern Thai Educational UX/UI — Responsive PC & Mobile + Print A4 + Themes
   ========================================================================== */

:root {
    --royal-900: #0f172a;
    --royal-800: #1e3a8a;
    --royal-700: #1d4ed8;
    --royal-600: #2563eb;
    --royal-50:  #eff6ff;
    --gold-500:  #f59e0b;
    --gold-600:  #d97706;
    --teal-600:  #0d9488;
    --purple-600:#7c3aed;
    --bg-app:    #f1f5f9;
    --card-radius: 16px;
}

html, body {
    min-height: 100%;
    font-family: 'Sarabun', 'Prompt', -apple-system, BlinkMacSystemFont, Tahoma, sans-serif;
    color: #1e293b;
    background-color: var(--bg-app);
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6, .font-heading, .navbar-brand, .btn, .badge {
    font-family: 'Prompt', 'Sarabun', sans-serif;
}

.thai-no-break {
    word-break: keep-all;
    overflow-wrap: break-word;
}

/* Navbar & Brand (Single-Row Crisp Layout) */
.bg-royal {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%) !important;
}

.nav-school-logo {
    width: 38px;
    height: 38px;
    object-fit: contain;
}

.nav-brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #ffffff;
    font-size: 1.15rem;
}

.navbar .nav-link {
    border-radius: 10px;
    padding: 0.4rem 0.7rem !important;
    transition: background-color 0.2s ease;
    font-size: 0.88rem;
    white-space: nowrap;
}

.navbar .nav-link:hover,
.navbar .nav-link.active {
    background-color: rgba(255, 255, 255, 0.16);
}

/* Custom Soft Badges */
.bg-purple-subtle { background-color: #f3e8ff !important; border-color: #d8b4fe !important; }
.text-purple { color: #6d28d9 !important; }

/* Cards & Surfaces */
.card-modern {
    border: 1px solid #e2e8f0;
    border-radius: var(--card-radius);
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-hover:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

/* Hero Banner */
.hero-banner {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #0369a1 100%);
    color: #ffffff;
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.hero-banner::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -60px;
    width: 260px;
    height: 260px;
    background: radial-gradient(circle, rgba(245, 158, 11, 0.28) 0%, rgba(245, 158, 11, 0) 70%);
    pointer-events: none;
}

/* KPI Cards */
.kpi-card {
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: #ffffff;
    padding: 1.05rem 1.15rem;
    position: relative;
    overflow: hidden;
    height: 100%;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.kpi-value {
    font-family: 'Prompt', sans-serif;
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.15;
}

/* Login Page */
.login-page-bg {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 45%, #1d4ed8 100%);
    min-height: 100vh;
}

.login-card {
    border-radius: 22px;
    border: none;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
    overflow: hidden;
}

.login-tabs .nav-link {
    border-radius: 12px;
    font-weight: 600;
    color: #475569;
    font-size: 0.92rem;
}

.login-tabs .nav-link.active {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.student-code-input {
    font-family: 'Prompt', sans-serif;
    font-size: 1.35rem;
    letter-spacing: 0.06em;
    font-weight: 600;
    text-align: center;
    padding: 0.7rem 1rem;
    border: 2px solid #cbd5e1;
    border-radius: 14px;
}

.student-code-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.18);
}

/* ==========================================================================
   Exam Runner Interface v2.0 (30-Q Single-Viewport Palette, Themes, Zoom, Highlighter)
   ========================================================================== */
.exam-sticky-header {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: rgba(15, 23, 42, 0.97);
    backdrop-filter: blur(8px);
    color: #ffffff;
    border-bottom: 3px solid #f59e0b;
}

.timer-pill {
    font-family: 'Prompt', monospace;
    font-size: 1.15rem;
    font-weight: 700;
    padding: 0.3rem 0.85rem;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.14);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.timer-pill.timer-warning { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.timer-pill.timer-danger  { background: #dc2626; color: #ffffff; border-color: #fca5a5; animation: pulseDanger 1s infinite; }

@keyframes pulseDanger {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55); }
    50%      { transform: scale(1.03); box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}

/* Exam Accessibility Font Scaling */
.exam-font-sm { --exam-fs: 0.94rem; }
.exam-font-md { --exam-fs: 1.06rem; }
.exam-font-lg { --exam-fs: 1.22rem; }
.exam-font-xl { --exam-fs: 1.38rem; }

/* Exam Eye-Comfort Themes */
body.exam-theme-sepia { background-color: #f4ecd8 !important; color: #3d2c1e !important; }
body.exam-theme-sepia .card-modern { background: #fbf6e9 !important; border-color: #e2d4b7 !important; color: #3d2c1e; }
body.exam-theme-sepia .exam-passage-box { background: #f3e8ce !important; border-left-color: #b45309 !important; color: #3d2c1e !important; }
body.exam-theme-sepia .choice-card { background: #fffdf7 !important; border-color: #dfd2b5 !important; }
body.exam-theme-sepia .choice-card.selected { background: #fef3c7 !important; border-color: #d97706 !important; }

body.exam-theme-dark { background-color: #0f172a !important; color: #e2e8f0 !important; }
body.exam-theme-dark .card-modern { background: #1e293b !important; border-color: #334155 !important; color: #e2e8f0; }
body.exam-theme-dark .exam-passage-box { background: #0f172a !important; border-left-color: #38bdf8 !important; color: #f1f5f9 !important; }
body.exam-theme-dark .exam-question-text,
body.exam-theme-dark .choice-label-text { color: #f8fafc !important; }
body.exam-theme-dark .choice-card { background: #0f172a !important; border-color: #334155 !important; }
body.exam-theme-dark .choice-card.selected { background: #1e3a8a !important; border-color: #60a5fa !important; }
body.exam-theme-dark .bg-light { background-color: #0f172a !important; color: #e2e8f0 !important; }
body.exam-theme-dark .essay-textarea { background: #0f172a; color: #f8fafc; border-color: #475569; }
body.exam-theme-dark .q-nav-btn { background: #0f172a; border-color: #475569; color: #cbd5e1; }
body.exam-theme-dark .text-dark { color: #f1f5f9 !important; }
body.exam-theme-dark .text-secondary { color: #94a3b8 !important; }

/* Passage Highlighter */
.exam-passage-box {
    background: #f8fafc;
    border-left: 5px solid #2563eb;
    border-radius: 12px;
    padding: 1.1rem 1.3rem;
    font-size: var(--exam-fs, 1.06rem);
    line-height: 1.85;
    color: #1e293b;
}

.exam-passage-box.hl-active {
    cursor: text;
    outline: 2px dashed #f59e0b;
}

mark.exam-hl {
    background: #fde047;
    color: #1e293b;
    padding: 0 3px;
    border-radius: 4px;
}

.exam-question-text {
    font-size: calc(var(--exam-fs, 1.06rem) + 0.08rem);
    font-weight: 600;
    line-height: 1.7;
    color: #0f172a;
}

.exam-infographic-wrap {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 0.75rem;
    text-align: center;
}

.exam-infographic-wrap img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    cursor: zoom-in;
}

/* Interactive Choice Cards */
.choice-card {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 0.85rem 1.05rem;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    background: #ffffff;
    cursor: pointer;
    transition: all 0.16s ease;
    margin-bottom: 0.6rem;
    user-select: none;
}

.choice-card:hover { border-color: #93c5fd; background: #f8fafc; }
.choice-card.selected { border-color: #2563eb; background: #eff6ff; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12); }

.choice-card input[type="radio"],
.choice-card input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    margin-top: 0.25rem;
    flex-shrink: 0;
    accent-color: #2563eb;
    cursor: pointer;
}

.choice-key-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 0.4rem;
    border-radius: 8px;
    background: #e2e8f0;
    color: #334155;
    font-family: 'Prompt', sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.choice-card.selected .choice-key-badge { background: #2563eb; color: #ffffff; }

.choice-label-text {
    font-size: var(--exam-fs, 1.04rem);
    line-height: 1.65;
    color: #1e293b;
}

/* Compact 6-Column Question Navigator Grid (Fits all 30 questions in 1 Desktop screen!) */
.q-palette-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.35rem;
}

.q-nav-btn {
    position: relative;
    height: 34px;
    border-radius: 8px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    font-family: 'Prompt', sans-serif;
    font-weight: 600;
    font-size: 0.84rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    padding: 0;
}

.q-nav-btn:hover { border-color: #2563eb; transform: translateY(-1px); }
.q-nav-btn.state-complete { background: #dcfce7; border-color: #22c55e; color: #166534; }
.q-nav-btn.state-partial  { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.q-nav-btn.is-current     { background: #2563eb !important; border-color: #1e3a8a !important; color: #ffffff !important; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25); }

.q-nav-btn .flag-dot {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #ffffff;
    display: none;
}

.q-nav-btn.is-flagged .flag-dot { display: block; }

/* Thai Essay Editor */
.essay-textarea {
    font-family: 'Sarabun', sans-serif;
    font-size: var(--exam-fs, 1.08rem);
    line-height: 1.85;
    border: 2px solid #cbd5e1;
    border-radius: 14px;
    padding: 1rem 1.15rem;
    min-height: 220px;
    resize: vertical;
}

.essay-textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.15); }

/* Tables */
.table-modern thead th {
    background-color: #f8fafc;
    color: #334155;
    font-family: 'Prompt', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.table-modern tbody td { vertical-align: middle; }

/* E-Certificate Landscape Sheet */
.cert-frame {
    max-width: 1040px;
    margin: 0 auto;
    background: linear-gradient(180deg, #fffdf7 0%, #ffffff 50%, #fffbeb 100%);
    border: 12px solid #1e3a8a;
    outline: 3px solid #d97706;
    outline-offset: -18px;
    border-radius: 10px;
    padding: 46px 56px;
    position: relative;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.15);
}

.cert-corner-gold {
    position: absolute;
    width: 48px;
    height: 48px;
    border: 4px solid #d97706;
}
.cert-tl { top: 20px; left: 20px; border-right: none; border-bottom: none; }
.cert-tr { top: 20px; right: 20px; border-left: none; border-bottom: none; }
.cert-bl { bottom: 20px; left: 20px; border-right: none; border-top: none; }
.cert-br { bottom: 20px; right: 20px; border-left: none; border-top: none; }

/* Research Report & Print A4 */
.research-paper {
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
}

@media print {
    @page { size: A4 portrait; margin: 14mm 12mm; }
    body.print-landscape { background: #ffffff !important; }
    body { background: #ffffff !important; font-size: 11pt; color: #000000 !important; }
    .d-print-none { display: none !important; }
    .card-modern, .research-paper, .kpi-card {
        box-shadow: none !important;
        border: 1px solid #94a3b8 !important;
        border-radius: 6px !important;
        break-inside: avoid;
    }
    .page-break-before { page-break-before: always; }
    .table { font-size: 9.5pt !important; }
    .badge { border: 1px solid #64748b !important; color: #000000 !important; background: transparent !important; }
    .cert-frame { box-shadow: none !important; margin: 0 auto !important; page-break-inside: avoid; }
}

@media (max-width: 767.98px) {
    .kpi-value { font-size: 1.35rem; }
    .timer-pill { font-size: 0.95rem; padding: 0.25rem 0.6rem; }
    .exam-passage-box { padding: 0.9rem 1rem; }
    .choice-card { padding: 0.72rem 0.85rem; }
}
