/* ═══════════════════════════════════════════════════════════════════
   base.css — Global PSC Master stylesheet
   Extracted from templates/base.html (Issue 18).
   Served by WhiteNoise with far-future Cache-Control headers so the
   browser re-parses it once per deploy, not on every page load.
═══════════════════════════════════════════════════════════════════ */

/* Google Fonts are loaded via <link rel="preconnect">/<link rel="stylesheet">
   in templates/base.html instead of a render-blocking @import here. */

/* ── Dark theme (default) ── */
:root, [data-theme="dark"] {
    --study-font-scale: 1;
    --bg-color: #121212;
    --card-color: #1e1e1e;
    --card-color-alt: #2a2a2a;
    --card-color-deep: #1c1c1c;
    --text-color: #e0e0e0;
    --text-muted: #888;
    --text-subtle: #aaa;
    --text-light: #ccc;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --border-color: #444;
    --border-subtle: #555;
    --tab-inactive-bg: #2a2a2a;
    --tab-inactive-text: #aaa;
    --ring-track: #2a2a2a;
    --shadow: rgba(0,0,0,0.3);
    --header-shadow: rgba(0,0,0,0.5);
    --legend-bg: #1e1e1e;
    --chart-grid: rgba(255,255,255,0.05);
    /* inputs & form elements */
    --input-bg: #2d2d2d;
    --input-color: #e0e0e0;
    --input-border: #444;
    /* option/answer blocks */
    --option-bg: #2d2d2d;
    --option-hover: #3d3d3d;
    --option-color: #e0e0e0;
    --answer-reveal-bg: #1e2e1e;
    --answer-section-bg: #252526;
    --explanation-color: #ccc;
    /* dropdown menu */
    --dropdown-bg: #1e1e1e;
    --dropdown-item-color: #ddd;
    --dropdown-item-hover: #2d2d2d;
    --dropdown-divider: #333;
    --menu-btn-hover: #333;
    /* modal */
    --modal-bg: #252526;
    /* metadata strip */
    --meta-strip-bg: #1c1c1c;
    --meta-strip-border: #2a2a2a;
    /* misc */
    --divider-color: #333;
    --state-new-bg: #37474f;
    --state-new-color: #b0bec5;
    --undo-btn-bg: #333;
    --undo-btn-color: #ccc;
    --undo-btn-border: #555;
    --bury-btn-bg: #1a3a4a;
    --bury-btn-color: #4fc3f7;
    --bury-btn-border: #235;
    --topic-toggle-bg: #3d3d3d;
    --topic-label-color: #e0e0e0;
    --order-row-bg: #2d2d2d;
    /* errors / destructive */
    --danger-color: #ff6b6b;
    --danger-bg: rgba(220, 53, 69, 0.15);
    --danger-border: rgba(220, 53, 69, 0.4);
}

/* ── Light theme ── */
[data-theme="light"] {
    --study-font-scale: 1;
    --bg-color: #f0f0f0;
    --card-color: #f7f7f7;
    --card-color-alt: #e4e4e4;
    --card-color-deep: #ebebeb;
    --text-color: #1a1a2e;
    --text-muted: #666;
    --text-subtle: #555;
    --text-light: #444;
    --primary-color: #6200ea;
    --secondary-color: #00796b;
    --border-color: #c8c8c8;
    --border-subtle: #b0b0b0;
    --tab-inactive-bg: #e4e4e4;
    --tab-inactive-text: #555;
    --ring-track: #d8d8d8;
    --shadow: rgba(0,0,0,0.08);
    --header-shadow: rgba(0,0,0,0.12);
    --legend-bg: #f7f7f7;
    --chart-grid: rgba(0,0,0,0.06);
    /* inputs & form elements */
    --input-bg: #e8e8e8;
    --input-color: #1a1a2e;
    --input-border: #c0c0c0;
    /* option/answer blocks */
    --option-bg: #e8e8e8;
    --option-hover: #dcdcdc;
    --option-color: #1a1a2e;
    --answer-reveal-bg: #e8f5e9;
    --answer-section-bg: #ececec;
    --explanation-color: #333;
    /* dropdown menu */
    --dropdown-bg: #f7f7f7;
    --dropdown-item-color: #1a1a2e;
    --dropdown-item-hover: #e4e4e4;
    --dropdown-divider: #d0d0d0;
    --menu-btn-hover: #e0e0e0;
    /* modal */
    --modal-bg: #f0f0f0;
    /* metadata strip */
    --meta-strip-bg: #e8e8e8;
    --meta-strip-border: #d4d4d4;
    /* misc */
    --divider-color: #d0d0d0;
    --state-new-bg: #cfd8dc;
    --state-new-color: #37474f;
    --undo-btn-bg: #e0e0e0;
    --undo-btn-color: #333;
    --undo-btn-border: #b0b0b0;
    --bury-btn-bg: #e3f2fd;
    --bury-btn-color: #0277bd;
    --bury-btn-border: #90caf9;
    --topic-toggle-bg: #d8d8d8;
    --topic-label-color: #1a1a2e;
    --order-row-bg: #e8e8e8;
    /* errors / destructive */
    --danger-color: #c62828;
    --danger-bg: rgba(220, 53, 69, 0.08);
    --danger-border: rgba(220, 53, 69, 0.35);
}

body {
    font-family: 'Noto Sans Malayalam', 'Noto Sans', 'AnjaliOldLipi', 'Kartika', 'Rachana', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* Google OAuth entry point shared by login and signup. */
.social-auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    text-transform: uppercase;
}

.social-auth-divider::before,
.social-auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--divider-color);
}

.social-auth-form {
    margin: 0;
}

.google-auth-button {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    background: var(--card-color-alt);
    color: var(--text-color);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, transform 0.1s;
}

.google-auth-button:hover {
    background: var(--option-hover);
    border-color: var(--border-subtle);
}

.google-auth-button:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}

.google-auth-button:active {
    transform: translateY(1px);
}

.google-auth-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
}

/* ── Header – single row ── */
header {
    background-color: var(--card-color);
    padding: 0 1rem;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 6px var(--header-shadow);
    position: relative;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.header-logo h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Header right-side action buttons ── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-nav-link {
    box-sizing: border-box;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-color-alt);
    color: var(--text-color);
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.15s;
}

.header-nav-link:hover,
.header-nav-link:focus-visible {
    background: var(--card-color-deep);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.font-size-controls {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background: var(--card-color-alt);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-sizing: border-box;
    height: 36px;
}

.font-size-btn {
    width: 32px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-color);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
}

.font-size-btn:hover:not(:disabled) {
    background: var(--card-color-deep);
    color: var(--primary-color);
}

.font-size-btn:disabled {
    cursor: default;
    opacity: 0.38;
}

.font-size-value {
    min-width: 38px;
    text-align: center;
    color: var(--text-subtle);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.hdr-btn {
    background: var(--card-color-alt);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-sizing: border-box;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.05rem;
    color: var(--text-color);
    transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.15s;
    position: relative;
    text-decoration: none;
}

.hdr-btn:hover {
    background: var(--card-color-deep);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.whatsapp-header-btn {
    color: #25d366;
}

.whatsapp-header-btn svg {
    width: 20px;
    height: 20px;
    display: block;
}

.whatsapp-header-btn:hover,
.whatsapp-header-btn:focus-visible {
    border-color: #25d366;
    color: #25d366;
}

/* ── Profile dropdown ── */
.profile-wrap {
    position: relative;
}

.profile-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--dropdown-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    min-width: 180px;
    box-shadow: 0 8px 24px var(--shadow);
    overflow: hidden;
    z-index: 999;
}

.profile-dropdown.open {
    display: block;
    animation: dropFadeIn 0.18s ease;
}

@keyframes dropFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.profile-dropdown .dd-header {
    padding: 10px 14px 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--dropdown-divider);
}

.profile-dropdown .dd-header-link {
    display: block;
    text-decoration: none;
}

.profile-dropdown .dd-header-link:hover .dd-header {
    color: var(--primary-color);
}

.profile-dropdown a,
.profile-dropdown button.dd-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    color: var(--dropdown-item-color);
    text-decoration: none;
    font-size: 0.88rem;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.profile-dropdown a:hover,
.profile-dropdown button.dd-item:hover {
    background: var(--dropdown-item-hover);
}

.profile-dropdown .dd-divider {
    height: 1px;
    background: var(--dropdown-divider);
    margin: 3px 0;
}

@media (max-width: 480px) {
    header { padding: 0 0.5rem; }
    .header-logo h1 { font-size: 1rem; }
    .header-actions { gap: 4px; }
    .font-size-value { display: none; }
    .font-size-btn { width: 28px; }
    .font-size-controls { height: 34px; }
    .hdr-btn { width: 34px; height: 34px; font-size: 1rem; }
    .header-nav-link {
        min-height: 34px;
        padding: 0 7px;
        font-size: 0.7rem;
    }
}

html[data-font-size="small"]  { --study-font-scale: 0.92; }
html[data-font-size="normal"] { --study-font-scale: 1; }
html[data-font-size="large"]  { --study-font-scale: 1.14; }
html[data-font-size="xlarge"] { --study-font-scale: 1.28; }

/* Practice mode — lightweight question wrapper */
#practice-container > .question-content > h3,
#practice-container > .question-content .option,
#practice-container > .question-content .recall-options-list,
#practice-container > .question-content .answer-reveal,
#practice-container > .question-content .answer-section,
#practice-container > .question-content .explanation,
/* Practice mode — new exam-style classes (AJAX-swapped cards) */
#practice-container .qn-text,
#practice-container .exam-option,
#practice-container .instant-feedback,
#practice-container .explanation-box,
/* question-card (AJAX rendered) */
#question-card h3,
#question-card .option,
#question-card .qn-text,
#question-card .exam-option,
#question-card .instant-feedback,
#question-card .explanation-box,
#question-card .recall-options-list,
#question-card .answer-reveal,
#question-card .answer-section,
#question-card .explanation,
/* Exam attend mode */
.exam-qcard .qn-text,
.exam-qcard .exam-option,
.exam-qcard .instant-feedback,
.exam-qcard .explanation-box {
    font-size: calc(1rem * var(--study-font-scale)) !important;
    line-height: 1.65;
}

/* Readable Markdown blocks in every question/explanation surface. Single
   newlines render as <br> and intentionally keep the normal line height. */
:where(.qn-text, .explanation-box, .fp-question, .fp-explain) > :where(p, ul, ol) {
    margin-block: 0 0.65em;
}

:where(.qn-text, .explanation-box, .fp-question, .fp-explain) > :first-child {
    margin-block-start: 0;
}

:where(.qn-text, .explanation-box, .fp-question, .fp-explain) > :last-child {
    margin-block-end: 0;
}

:where(.qn-text, .explanation-box, .fp-question, .fp-explain) li + li {
    margin-block-start: 0.3em;
}

:where(.qn-text, .explanation-box, .fp-question, .fp-explain) li > :where(ul, ol) {
    margin-block: 0.3em 0;
}

/* Keep list-first explanations flush with regular explanation text while
   retaining a hanging indent for wrapped list items. */
.explanation-box > ul:first-child,
.explanation-box > ol:first-child {
    margin-block-start: 0;
}

.explanation-box > ul:first-child {
    padding-inline-start: 1.1em;
}

.explanation-box > ol:first-child {
    padding-inline-start: 1.5em;
}

#practice-container > .question-content img,
#question-card img,
.exam-qcard img,
.ans-qtext img,
.choice-tag img,
.explanation-result img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

img.qimg-block,
#practice-container > .question-content img:not(.qimg),
#question-card img:not(.qimg),
.exam-qcard img:not(.qimg),
.ans-qtext img:not(.qimg),
.choice-tag img:not(.qimg),
.explanation-result img:not(.qimg) {
    display: block;
    margin: 10px 0;
}

img.qimg-inline {
    display: inline-block;
    width: auto;
    max-width: min(100%, 260px);
    margin: 0 4px;
    vertical-align: middle;
}

img.qimg-left {
    float: left;
    margin: 4px 14px 10px 0;
}

img.qimg-right {
    float: right;
    margin: 4px 0 10px 14px;
}

.qcrop-frame {
    display: inline-block;
    overflow: hidden;
    max-width: 100%;
    vertical-align: middle;
    border-radius: 6px;
}

.qcrop-frame > img.qimg {
    display: block !important;
    max-width: none !important;
    float: none !important;
    object-fit: cover;
}

img.qimg-crop {
    aspect-ratio: 1 / 1;
    height: auto;
    object-fit: cover;
    object-position: center center;
}

main {
    flex: 1;
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: #fff;
    text-decoration: none;
    border-radius: 5px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    transition: background 0.3s;
}

[data-theme="dark"] .btn {
    color: #000;
}

/* ── Global input/select/textarea theming ── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
    background: var(--input-bg);
    color: var(--input-color);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    padding: 10px 12px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 1rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
input[type="text"]::placeholder,
input[type="password"]::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

/* ── Password show/hide toggle (login, signup, change password) ── */
.pw-wrap { position: relative; }
.pw-wrap input[type="password"],
.pw-wrap input[type="text"] { padding-right: 44px; }
.pw-toggle {
    position: absolute;
    top: 50%; right: 6px;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    line-height: 1;
    padding: 6px;
    color: var(--text-muted);
}

.btn:hover {
    opacity: 0.85;
}

.card {
    background-color: var(--card-color);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px var(--shadow);
    margin-bottom: 20px;
    transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

/* ── PWA Install Banner ── */
.pwa-banner {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background-color: var(--card-color);
    border: 1px solid var(--primary-color);
    box-shadow: 0 4px 12px var(--shadow);
    border-radius: 10px;
    padding: 15px 20px;
    z-index: 1000;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    animation: slideUp 0.3s ease-out;
}

.pwa-banner.show {
    display: flex;
}

.pwa-banner-text {
    flex: 1;
    font-size: 0.95rem;
    color: var(--text-color);
}

.pwa-banner-actions {
    display: flex;
    gap: 10px;
}

.pwa-banner-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}

.pwa-banner-btn.install {
    background-color: var(--primary-color);
    color: #fff;
}

[data-theme="dark"] .pwa-banner-btn.install {
    color: #000;
}

.pwa-banner-btn.dismiss {
    background-color: var(--card-color-alt);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.pwa-banner-btn:hover {
    opacity: 0.85;
}

@keyframes slideUp {
    from { transform: translateY(100px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 480px) {
    .pwa-banner {
        flex-direction: column;
        text-align: center;
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
    .pwa-banner-actions {
        width: 100%;
        justify-content: center;
    }
}
