* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Ensure all images and media are responsive */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* Prevent horizontal scrolling on mobile */
html {
    overflow-x: hidden;
}

:root {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;
    --border-color: #d2d2d7;
    --accent-color: #0071e3;
    --success-color: #28a745;
    --error-color: #dc3545;
    --hover-bg: #f5f5f7;
    --modal-backdrop: rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --text-primary: #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary: #636366;
    --border-color: #38383a;
    --accent-color: #0a84ff;
    --success-color: #30d158;
    --error-color: #ff453a;
    --hover-bg: #2c2c2e;
    --modal-backdrop: rgba(0, 0, 0, 0.7);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.topbar {
    width: 100%;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative;
}

.topbar-logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-color);
    letter-spacing: -0.02em;
}

/* Logo link inside topbar: keep icon and site name on a single line */
.topbar-logo .logo-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.topbar-logo .logo-icon {
    width: 28px;
    height: 28px;
    display: block;
}

.topbar-logo .site-name {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

/* Ensure topbar doesn't overflow on small screens */
@media (max-width: 480px) {
    .topbar {
        padding: 12px 12px;
    }
    
    .topbar-logo .logo-icon {
        width: 24px;
        height: 24px;
    }
    
    .topbar-logo .site-name {
        font-size: 1rem;
    }
}

/* Focus Mode button styling */
.focus-mode-btn {
    background: #007AFF;
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.focus-mode-btn:hover { 
    background: #0051D5;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
    transform: translateY(-1px);
}

.settings-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
    min-width: 44px;
    min-height: 44px;
}

.settings-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-backdrop);
    backdrop-filter: blur(10px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.settings-modal.show {
    display: flex;
}

.settings-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    max-height: 80vh;
    overflow-y: auto;
    transition: background-color 0.3s ease;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s ease;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.close-settings {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-settings:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.settings-body {
    padding: 24px;
}

.setting-item {
    margin-bottom: 24px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.setting-item select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.3s ease;
}

.setting-item select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.setting-description {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

body > * {
    margin-top: 40px;
}

body > .topbar {
    margin-top: 0;
}

h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 30px;
    color: var(--text-primary);
}

h2 {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 15px;
    color: var(--text-primary);
}

#questionForm {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
    width: calc(100% - 40px);
    max-width: 1100px;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

#classSelect {
    width: 280px;
    min-width: 280px;
    flex-shrink: 0;
    padding: 12px 16px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, background-color 0.3s ease;
    font-family: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

#classSelect:focus {
    outline: none;
    border-color: var(--accent-color);
}

#classSelect optgroup {
    font-weight: 600;
    color: var(--text-primary);
    font-style: normal;
    background: var(--bg-secondary);
}

#classSelect option {
    font-weight: 400;
    padding: 8px;
}

#unitSelect {
    width: 280px;
    min-width: 280px;
    flex-shrink: 0;
    padding: 12px 16px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s, background-color 0.3s ease;
    font-family: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

#unitSelect:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#rangeSliderContainer {
    width: 100%;
    max-width: 600px;
    margin: 0 auto 15px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
    transform: translateY(-10px);
}

@media (max-width: 768px) {
    #rangeSliderContainer {
        padding: 12px;
        margin-left: 16px;
        margin-right: 16px;
        width: calc(100% - 32px);
    }
}

#rangeSliderContainer.show {
    opacity: 1;
    transform: translateY(0);
}

.range-slider-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.range-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.range-label {
    font-weight: 500;
    color: var(--accent-color);
    padding: 2px 8px;
    background: var(--hover-bg);
    border-radius: 4px;
    font-size: 0.75rem;
}

.range-separator {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.75rem;
}

.slider-track {
    position: relative;
    height: 24px;
    margin: 4px 0;
}

.slider-range {
    position: absolute;
    height: 4px;
    background: var(--accent-color);
    border-radius: 2px;
    top: 13px;
    transition: all 0.1s ease;
}

.slider {
    position: absolute;
    width: 100%;
    height: 4px;
    background: transparent;
    pointer-events: none;
    appearance: none;
    -webkit-appearance: none;
    top: 13px;
}

.slider::-webkit-slider-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.slider::-moz-range-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-color);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent-color);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.15);
}



#unitSelect:focus {
    outline: none;
    border-color: var(--accent-color);
}

#unitSelect option {
    font-weight: 400;
    padding: 8px;
}

.fade-in {
    animation: fadeIn 0.6s ease-in;
}
.provider-badge {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.small-h1-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    text-align: center;
    width: min(720px, 70%);
    pointer-events: none;
    margin: 0;
}

/* When the small heading is used inside the How to Use section,
   make it flow normally instead of absolutely positioned so it
   doesn't overlap form elements. */
.how-to-use .small-h1-text {
    position: static;
    left: auto;
    top: auto;
    -webkit-transform: none;
    transform: none;
    width: 100%;
    text-align: left;
    pointer-events: auto;
    font-size: 1.6rem;
    margin: 0 0 22px 0;
}

@-webkit-keyframes fadeIn {
    from {
        opacity: 0;
        -webkit-transform: translateY(10px);
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        -webkit-transform: translateY(10px);
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }
}

button {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
    white-space: nowrap;
    min-height: 44px; /* Minimum touch target size */
}

button:hover {
    opacity: 0.9;
}

button:active {
    opacity: 0.8;
}

#questionForm button[type="submit"] {
    flex-shrink: 0;
}

#answerSection {
    margin: 30px auto 0;
    width: 100%;
    max-width: calc(100vw - 40px);
    padding: 0 20px;
    box-sizing: border-box;
}

/* Progress sidebar */
.progress-panel {
    position: fixed;
    right: 16px;
    top: 110px;
    width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    padding: 12px;
    z-index: 900;
}

/* Hidden by default; shown only when a question is present */
.progress-panel { display: none; }
.progress-panel.show { display: block; }

.progress-panel h3 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    color: var(--accent-color);
}

.progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 4px 0;
    font-size: 0.9rem;
}

.progress-subtext {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#answerOutput {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 1rem;
    min-height: 100px;
    color: var(--text-primary);
    line-height: 1.8;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#answerOutput h1, #answerOutput h2, #answerOutput h3 {
    margin-top: 20px;
    margin-bottom: 10px;
}

#answerOutput h1 {
    font-size: 1.8rem;
}

#answerOutput h2 {
    font-size: 1.5rem;
}

#answerOutput h3 {
    font-size: 1.2rem;
}

#answerOutput p {
    margin-bottom: 15px;
}

#answerOutput code {
    background: var(--hover-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
    color: var(--text-primary);
}

#answerOutput pre {
    background: var(--hover-bg);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 15px 0;
}

#answerOutput pre code {
    background: none;
    padding: 0;
}

#answerOutput ul, #answerOutput ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

#answerOutput li {
    margin-bottom: 8px;
}

#answerOutput strong {
    font-weight: 600;
}

#answerOutput em {
    font-style: italic;
}

.question-container {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: calc(100% - 40px);
    max-width: 700px;
    margin: 0 auto;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    box-sizing: border-box;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
}

.loading p {
    margin-bottom: 20px;
    font-size: 1rem;
}

.loading-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--accent-color), var(--accent-color));
    background-size: 200% 100%;
    border-radius: 4px;
    animation: loadingBar 1.5s ease-in-out infinite;
}

@-webkit-keyframes loadingBar {
    0% {
        width: 0%;
        background-position: 0% 50%;
    }
    50% {
        width: 70%;
        background-position: 100% 50%;
    }
    100% {
        width: 0%;
        background-position: 0% 50%;
    }
}

@keyframes loadingBar {
    0% {
        width: 0%;
        background-position: 0% 50%;
    }
    50% {
        width: 70%;
        background-position: 100% 50%;
    }
    100% {
        width: 0%;
        background-position: 0% 50%;
    }
}

.question-section, .answer-section, .explanation-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
}

.question-section {
    border-bottom: 2px solid var(--border-color);
}

/* Two-column layout for long questions on desktop */
.question-container.has-long-question {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 20px;
    grid-template-areas: 
        "badge badge"
        "question options"
        "actions actions";
    align-items: start;
    width: 100%;
    max-width: 1800px; /* widen container in two-column mode */
    /* Establish a predictable overall height so inner panes can scroll */
    /* Use viewport-based height to keep the box within screen */
    max-height: calc(100vh - 240px);
    margin: 0 auto;
    overflow: hidden; /* ensure inner scrolling stays visually inside container */
}

.question-container.has-long-question .provider-badge {
    grid-area: badge;
}

.question-container.has-long-question .question-section {
    grid-area: question;
    border-bottom: none;
    border-right: 2px solid var(--border-color);
    padding-right: 20px;
    margin-bottom: 0;
    min-width: 0;
    /* Make the left pane scroll inside */
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
    /* Leave room for badge at top and actions at bottom */
    max-height: calc(100vh - 300px);
}

.question-container.has-long-question .options-section {
    grid-area: options;
    margin-top: 0;
    /* Independent scrolling for the options pane */
    overflow-y: auto;
    max-height: calc(100vh - 300px);
}

.question-container.has-long-question .question-actions {
    grid-area: actions;
    border-top: 2px solid var(--border-color);
    padding-top: 20px;
}

.question-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.question-action-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 400;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.question-action-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
    border-color: var(--text-tertiary);
}

.answer-section {
    border-bottom: 2px solid var(--border-color);
}

.question-section h3, .answer-section h3, .explanation-section h3 {
    color: var(--accent-color);
    font-size: 1.1rem;
    margin-top: 0;
    margin-bottom: 12px;
}

.options-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.option-btn {
    padding: 6px 12px;
    font-size: 1rem;
    text-align: left;
    background: var(--hover-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-height: 44px; /* Minimum touch target size for mobile */
}

.option-btn .option-label {
    font-weight: 600;
    flex-shrink: 0;
}

.option-btn .option-text {
    flex: 1;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.option-btn .option-label {
    transition: color 0.2s ease;
}

/* Pre tag styling for formatted content */
pre.question-text,
pre.option-text,
pre.explanation-text {
    font-family: inherit;
    font-size: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    padding: 12px 0;
    background: none;
    border: none;
    overflow-x: auto;
}

pre.option-text {
    display: inline;
    margin: 0 !important;
}

/* Remove margins from paragraphs inside pre tags */
pre.question-text p,
pre.option-text p,
pre.explanation-text p {
    margin: 0;
    padding: 0;
}

/* Remove extra spacing from nested elements */
pre.question-text > :first-child,
pre.option-text > :first-child,
pre.explanation-text > :first-child {
    margin-top: 0;
}

pre.question-text > :last-child,
pre.option-text > :last-child,
pre.explanation-text > :last-child {
    margin-bottom: 0;
}

/* Code blocks inside pre tags */
pre code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', 'Source Code Pro', monospace;
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 6px;
    display: block;
    overflow-x: auto;
    font-size: 0.9em;
    line-height: 1.5;
}

pre code.hljs {
    padding: 12px;
    background: #282c34;
    color: #abb2bf;
    border-radius: 6px;
}

[data-theme="light"] pre code.hljs {
    background: #f5f5f5;
    color: #383a42;
}

/* Inline code */
pre :not(pre) > code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* KaTeX math rendering */
pre .katex {
    font-size: 1em;
    padding: 0 2px;
}

pre .katex-display {
    display: block;
    margin: 8px 0;
    overflow-x: auto;
}

.katex-display-wrapper {
    display: block;
    margin: 12px 0;
    overflow-x: auto;
    text-align: center;
}

.option-btn .option-text .katex {
    font-size: 1em;
}

.option-btn .option-text code {
    background: var(--bg-primary);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Ensure code blocks display properly */
pre.question-text code,
pre.option-text code,
pre.explanation-text code {
    background: var(--bg-primary);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Droid Sans Mono', 'Source Code Pro', monospace;
}

.option-btn:hover:not(:disabled) {
    /* Improved hover: stronger contrast and clearer readability */
    background: #0a62c9; /* slightly darker accent for better contrast */
    border-color: #084fa8;
    color: #ffffff;
    box-shadow: 0 6px 18px rgba(10,98,201,0.18);
    transform: translateY(-1px);
}

/* Ensure all inner text and code become white and any inner light backgrounds are removed */
.option-btn:hover:not(:disabled) .option-label,
.option-btn:hover:not(:disabled) .option-text,
.option-btn:hover:not(:disabled) .option-text pre,
.option-btn:hover:not(:disabled) .option-text code {
    color: #ffffff !important;
    background: transparent !important;
}

.option-btn:hover:not(:disabled) .option-text {
    /* remove any inner rounded light box so text sits directly on accent background */
    background: transparent !important;
}

/* Light theme: use a subtle darker gray hover instead of blue */
html:not([data-theme="dark"]) .option-btn:hover:not(:disabled) {
    background: #e6e7ea; /* slightly darker than default hover-bg */
    border-color: #d1d3d6;
    color: var(--text-primary);
    box-shadow: 0 4px 10px rgba(0,0,0,0.06);
    transform: none;
}

html:not([data-theme="dark"]) .option-btn:hover:not(:disabled) .option-label,
html:not([data-theme="dark"]) .option-btn:hover:not(:disabled) .option-text,
html:not([data-theme="dark"]) .option-btn:hover:not(:disabled) .option-text code {
    color: var(--text-primary) !important;
    background: transparent !important;
}

/* Make sure disabled styles remain unchanged */

.option-btn:disabled {
    cursor: not-allowed;
}

.option-btn.correct {
    background: rgba(48, 209, 88, 0.15);
    border-color: var(--success-color);
    color: var(--success-color);
}

.option-btn.incorrect {
    background: rgba(255, 69, 58, 0.15);
    border-color: var(--error-color);
    color: var(--error-color);
}

/* Dark theme: use a slightly lighter gray hover for better readability */
html[data-theme="dark"] .option-btn:hover:not(:disabled) {
    background: #38383b; /* slightly lighter than dark hover-bg */
    border-color: #454548;
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transform: none;
}

html[data-theme="dark"] .option-btn:hover:not(:disabled) .option-label,
html[data-theme="dark"] .option-btn:hover:not(:disabled) .option-text,
html[data-theme="dark"] .option-btn:hover:not(:disabled) .option-text code {
    color: var(--text-primary) !important;
    background: transparent !important;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 12px;
    box-sizing: border-box;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transition: background-color 0.3s ease;
    color: var(--text-primary);
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.8rem;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

.modal-content .explanation {
    margin: 20px 0;
}

.modal-content .explanation p {
    margin-bottom: 15px;
    line-height: 1.8;
}

.modal-content .explanation code {
    background: var(--hover-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
    color: var(--text-primary);
}

.modal-content .explanation pre {
    background: var(--hover-bg);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 15px 0;
}

.modal-content .explanation pre code {
    background: none;
    padding: 0;
}

.bug-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    padding: 20px;
}

.bug-modal.show {
    display: flex;
}

.bug-modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    width: min(480px, 100%);
    box-shadow: var(--shadow-lg);
    position: relative;
}

.bug-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-tertiary);
}

.bug-modal-content h3 {
    margin-top: 0;
}

.bug-modal-content textarea {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
    padding: 10px;
    font-family: inherit;
    margin-bottom: 12px;
}

.bug-modal-content button[type="submit"] {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    background: var(--accent-color);
    border: none;
    color: #fff;
    font-weight: 600;
}

.bug-report-feedback {
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.modal-content .explanation ul, .modal-content .explanation ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-content .explanation li {
    margin-bottom: 8px;
}

.modal-content .explanation strong {
    font-weight: 600;
}

.modal-content .explanation em {
    font-style: italic;
}

.modal-content .explanation h4 {
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 1rem;
}

.close-modal {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.2s;
    width: 100%;
}

.close-modal:hover {
    opacity: 0.9;
}

.next-question-btn {
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 500;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.2s;
    width: 100%;
    margin-top: 20px;
}

.next-question-btn:hover {
    opacity: 0.9;
}

.next-question-btn:active {
    opacity: 0.8;
}
footer {
    width: 100vw;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 24px;
    margin-top: auto;
    margin-left: calc(-50vw + 50%);
    text-align: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

footer p {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    line-height: 1.5;
    margin: 0;
}

footer a {
    color: var(--accent-color);
    text-decoration: none;
    transition: opacity 0.2s;
}

footer a:hover {
    opacity: 0.8;
}

hr {
    width: calc(100% - 40px);
    max-width: 800px;
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 60px auto;
    transition: border-color 0.3s ease;
}

.faq {
    width: calc(100% - 40px);
    max-width: 800px;
    margin: 60px auto 40px;
    padding: 0 20px;
    box-sizing: border-box;
}

@media (max-width: 640px) {
    .faq {
        margin: 40px auto 30px;
        padding: 0 16px;
        width: calc(100% - 32px);
    }
}

.faq h2 {
    font-size: 2rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 40px;
    color: var(--text-primary);
}

.faq-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.faq-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

.faq-item:hover {
    box-shadow: var(--shadow-md);
}

.faq-question {
    width: 100%;
    padding: 20px 24px;
    background: none;
    border: none;
    text-align: left;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: inherit;
    transition: background 0.2s;
}

.faq-question:hover {
    background: var(--hover-bg);
}

.faq-icon {
    font-size: 1.5rem;
    color: var(--accent-color);
    font-weight: 300;
    transition: transform 0.3s;
}

.faq-item.active .faq-icon {
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 24px;
}

.faq-item.active .faq-answer {
    max-height: 500px;
    padding: 0 24px 20px;
}

.faq-answer p {
    margin: 0;
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Scroll to Top Button */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 999;
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
    -webkit-transform: translateY(0);
    transform: translateY(0);
}

.scroll-to-top:hover {
    -webkit-transform: translateY(-3px);
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-to-top:active {
    -webkit-transform: translateY(-1px);
    transform: translateY(-1px);
}

.scroll-to-top svg {
    width: 24px;
    height: 24px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .topbar {
        padding: 12px 16px;
        flex-wrap: nowrap;
        gap: 8px;
    }
    
    .topbar-logo {
        font-size: 1.1rem;
    }
    
    .settings-btn {
        padding: 6px;
    }
    
    .settings-content {
        width: 95%;
        max-width: none;
        border-radius: 12px;
        margin: 10px;
    }
    
    .settings-header {
        padding: 16px 20px;
    }
    
    .settings-header h2 {
        font-size: 1.25rem;
    }
    
    .settings-body {
        padding: 20px;
    }
    
    h1 {
        font-size: 1.75rem;
        margin-bottom: 20px;
        padding: 0 16px;
        text-align: center;
    }
    
    h2 {
        font-size: 1.25rem;
        padding: 0 16px;
    }
    
    /* Disable two-column layout on mobile */
    .question-container.has-long-question {
        display: block;
        grid-template-columns: none;
        grid-template-areas: none;
    }
    
    .question-container.has-long-question .question-section {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        padding-right: 0;
        margin-bottom: 25px;
    }
    
    .question-container.has-long-question .options-section {
        margin-top: 20px;
    }
    
    #questionForm {
        flex-direction: column;
        gap: 12px;
        padding: 0 16px;
        max-width: 100%;
    }
    
    #classSelect {
        width: 100%;
        padding: 14px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    #unitSelect {
        width: 100%;
        padding: 14px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    #generateBtn {
        width: 100%;
        padding: 14px 16px;
        font-size: 1rem;
    }
    
    #answerOutput {
        padding: 12px 14px;
        width: calc(100% - 28px);
        margin: 0 14px;
        overflow-x: auto;
        font-size: 0.95rem;
        line-height: 1.6;
    }
    
    #answerOutput h1 {
        font-size: 1.4rem;
    }
    
    #answerOutput h2 {
        font-size: 1.2rem;
    }
    
    #answerOutput h3 {
        font-size: 1.05rem;
    }
    
    #answerSection {
        padding: 0;
        width: 100%;
    }

    /* Hide fixed sidebar on mobile to avoid overlap */
    .progress-panel {
        display: none;
    }
    
    .question-container {
        padding: 16px 14px;
        max-width: 100%;
        width: calc(100% - 28px);
    }
    
    .question-section,
    .answer-section,
    .explanation-section {
        margin-bottom: 18px;
        padding-bottom: 14px;
    }
    
    .question-section h3,
    .answer-section h3,
    .explanation-section h3 {
        font-size: 1rem;
        margin-bottom: 10px;
    }
    
    .provider-badge {
        font-size: 0.75rem;
        padding: 6px 10px;
    }
    
    .question-section h3 {
        font-size: 1.05rem;
    }
    
    .option-btn {
        padding: 12px 14px;
        font-size: 0.95rem;
        line-height: 1.4;
        text-align: left;
    }
    
    .option-btn .option-text {
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    .modal {
        padding: 16px;
        align-items: flex-start;
        padding-top: 40px;
    }
    
    .modal-content {
        width: 95%;
        max-width: none;
        padding: 20px;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    .bug-modal-content {
        width: 95%;
        max-width: none;
        padding: 20px;
        margin: 20px auto;
    }
    
    .bug-modal-content textarea {
        font-size: 16px;
        min-height: 120px;
    }
    
    .modal-content h2 {
        font-size: 1.25rem;
        padding: 0;
    }
    
    .close-modal {
        top: 12px;
        right: 12px;
        font-size: 1.75rem;
    }
    
    .faq, .faq-section {
        padding: 40px 16px;
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
    
    .faq-container {
        width: 100%;
    }
    
    .faq-question {
        padding: 16px 20px;
        font-size: 0.95rem;
        gap: 8px;
    }
    
    .faq-icon {
        font-size: 1.25rem;
    }
    
    .faq-answer {
        padding: 0 20px;
    }
    
    .faq-item.active .faq-answer {
        padding: 0 20px 16px;
    }
    
    .faq-answer p {
        font-size: 0.9rem;
    }
    
    footer {
        padding: 24px 16px;
        font-size: 0.85rem;
        text-align: center;
    }
    
    footer p {
        margin: 8px 0;
    }
    
    footer a {
        display: inline-block;
        margin: 4px 8px;
    }
    
    /* Loading bar adjustments */
    .loading-bar-container {
        margin: 20px 16px;
    }
    
    /* Scroll to top button on mobile */
    .scroll-to-top {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
    }
    
    .scroll-to-top svg {
        width: 20px;
        height: 20px;
    }
}

/* Extra small devices (phones, less than 375px) */
@media (max-width: 374px) {
    .topbar {
        padding: 10px 12px;
    }
    
    .topbar-logo {
        font-size: 0.9rem;
    }
    
    .topbar-logo .logo-icon {
        width: 22px;
        height: 22px;
    }
    
    .topbar-logo .site-name {
        font-size: 0.9rem;
    }
    
    h1 {
        font-size: 1.5rem;
        display: none;
    }
    
    h2 {
        font-size: 1.1rem;
    }
    
    .settings-header h2 {
        font-size: 1.1rem;
    }
    
    .option-btn {
        padding: 12px 14px;
        font-size: 0.9rem;
    }
    
    .modal-content {
        padding: 16px;
    }
    
    .faq-question {
        padding: 14px 16px;
        font-size: 0.9rem;
    }
    
    button {
        padding: 10px 18px;
        font-size: 0.95rem;
    }
    
    .step {
        padding: 20px 16px;
    }
}

/* Landscape orientation for mobile phones */
@media (max-width: 896px) and (max-height: 414px) and (orientation: landscape) {
    .topbar {
        padding: 8px 16px;
    }
    
    .how-to-use {
        margin: 20px auto 15px;
    }
    
    body > * {
        margin-top: 20px;
    }
    
    .steps-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .step {
        padding: 16px;
    }
    
    #questionForm {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    #classSelect, #unitSelect {
        width: calc(50% - 5px);
        min-width: 0;
    }
    
    button[type="submit"] {
        width: 100%;
    }
}

/* Tablet and medium devices */
/* How to Use Section */
.how-to-use {
    width: calc(100% - 40px);
    max-width: 1200px;
    margin: 40px auto 30px;
    padding: 0 20px;
    box-sizing: border-box;
}

.how-to-use h1 {
    font-size: 2.2rem;
    margin-bottom: 30px;
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
}

.how-to-use h2 {
    font-size: 1.5rem;
    margin-bottom: 30px;
    color: var(--text-primary);
    font-weight: 600;
    text-align: center;
}

.steps-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.step {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    text-align: center;
    transition: all 0.3s ease;
}

.step:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.step p {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin: 0;
}

.step p strong {
    display: block;
    color: var(--accent-color);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 1rem;
}

@media (max-width: 1024px) {
    .steps-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .steps-container {
        grid-template-columns: 1fr;
    }
    
    .how-to-use {
        margin: 30px auto 20px;
    }
    
    .how-to-use h2 {
        font-size: 1.3rem;
    }
    
    .step {
        padding: 24px 20px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    h1 {
        font-size: 2rem;
    }
    
    #questionForm {
        max-width: 90%;
        padding: 0 20px;
    }
    
    .question-container {
        max-width: 90%;
        padding: 25px;
    }
    
    .faq, .faq-section {
        width: 90%;
        max-width: 90%;
        padding: 40px 20px;
    }
    
    #answerSection {
        padding: 0 20px;
    }
    
    /* Tablet: Keep single column for questions */
    .question-container.has-long-question {
        display: block;
        grid-template-columns: none;
        max-width: 90%;
    }
    
    .question-container.has-long-question .question-section {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        padding-right: 0;
        margin-bottom: 20px;
    }
}