:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --passage-bg: #f8f9fa;
    --questions-bg: #ffffff;
    --border-color: #e0e0e0;
    --accent-color: #29b6f6;
    --header-bg: #ff0000;
    --header-text: #ffffff;
    --button-bg: #29b6f6;
    --button-hover: #0288d1;
    --progress-complete: #29b6f6;
    --progress-incomplete: #bdbdbd;
    --timer-bg: #E1F5FE;
    --timer-text: #0288d1;
    --footer-bg: #f5f5f5;
}

.night-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --passage-bg: #1e1e1e;
    --questions-bg: #1e1e1e;
    --border-color: #424242;
    --accent-color: #29b6f6;
    --header-bg: #ff0000;
    --header-text: #ffffff;
    --button-bg: #29b6f6;
    --button-hover: #0288d1;
    --progress-complete: #29b6f6;
    --progress-incomplete: #616161;
    --timer-bg: #01579b;
    --timer-text: #B3E5FC;
    --footer-bg: #121212;
}

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

html, body {
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 15px;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    z-index: 100;
    height: 60px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.telegram-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    text-decoration: none;
    font-weight: bold;
    padding: 6px 12px;
    border-radius: 20px;
    transition: background-color 0.3s;
}

.telegram-link:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.timer-container {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--timer-bg);
    padding: 6px 12px;
    border-radius: 20px;
}

.timer-display {
    font-weight: bold;
    font-size: 16px;
    color: var(--timer-text);
    min-width: 60px;
    text-align: center;
}

.timer-button {
    background-color: transparent;
    border: none;
    color: var(--timer-text);
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.timer-button:hover {
    background-color: rgba(41, 182, 246, 0.2);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.font-size-control {
    display: flex;
    gap: 5px;
}

.font-size-button {
    background: none;
    border: 2px solid #ffffff;
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s;
}

.font-size-button:hover {
    background-color: #ffffff;
    color: #ff0000;
}

.night-mode-toggle {
    background: none;
    border: 2px solid #ffffff;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    transition: all 0.3s;
}

.night-mode-toggle:hover {
    background-color: #ffffff;
    color: #ff0000;
}

/* SPLIT SCREEN LAYOUT */
.container {
    position: fixed;
    top: 60px;
    bottom: 100px;
    left: 0;
    right: 0;
    display: flex;
    width: 100%;
}

.passage-section {
    width: 50%;
    background-color: var(--passage-bg);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 30px;
    height: 100%;
}

.questions-section {
    width: 50%;
    background-color: var(--questions-bg);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 30px;
    height: 100%;
}

.passage-section h1, .passage-section h2, .questions-section h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-color);
}

.passage-subheading {
    text-align: center;
    font-style: italic;
    font-size: 16px;
    opacity: 0.9;
    margin-bottom: 20px;
}

.passage-instructions {
    margin-bottom: 25px;
    padding: 15px;
    background-color: rgba(41, 182, 246, 0.1);
    border-radius: 8px;
}

.passage-number {
    font-size: 14px;
    font-weight: bold;
    color: var(--accent-color);
    margin-bottom: 8px;
}

.passage-time-info {
    font-size: 13px;
    font-style: italic;
    opacity: 0.8;
}

.passage-text {
    line-height: 1.8;
    text-align: justify;
}

.passage-text p {
    margin-bottom: 15px;
}

/* Ensure paragraphs have proper spacing everywhere */
p {
    margin-bottom: 15px;
}

p:last-child {
    margin-bottom: 0;
}

/* Line breaks should create visible spacing */
br {
    display: block;
    content: "";
    margin: 8px 0;
}

/* Passage/Questions Wrappers */
.passage-content-wrapper,
.questions-content-wrapper {
    display: block;
}

/* Questions Styling */
.question-group {
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--passage-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* Question Header with Flag Button */
.question-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.question-header > div:first-child {
    flex: 1;
}

.flag-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px 10px;
    color: #9e9e9e;
    font-size: 18px;
    transition: all 0.3s;
    flex-shrink: 0;
}

.flag-button:hover {
    color: #ff5252;
    transform: scale(1.1);
}

.flag-button.flagged {
    color: #ff0000;
}

.flag-button.flagged i {
    animation: flagPulse 0.3s ease-out;
}

@keyframes flagPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

.instructions {
    margin-bottom: 20px;
    padding: 15px;
    background-color: rgba(41, 182, 246, 0.1);
    border-left: 4px solid var(--accent-color);
    border-radius: 4px;
    font-size: 14px;
}

.question {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

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

.options {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.options label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    padding: 10px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.options label:hover {
    background-color: var(--passage-bg);
}

.options input[type="radio"],
.options input[type="checkbox"] {
    margin-top: 4px;
    cursor: pointer;
}

.option-text {
    flex: 1;
}

select {
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    margin-top: 10px;
    cursor: pointer;
    width: 100%;
}

input[type="text"].fill-in-the-blank {
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    text-align: center;
    transition: all 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

input[type="text"].fill-in-the-blank:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 2px 6px rgba(41, 182, 246, 0.3);
}

input[type="text"].fill-in-the-blank:hover {
    border-color: var(--accent-color);
}

/* Word Bank */
.word-bank-container {
    margin: 20px 0;
}

.word-bank-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 10px;
    border: 2px solid #dee2e6;
}

@media (max-width: 768px) {
    .word-bank-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .word-bank-grid {
        grid-template-columns: 1fr;
    }
}

.word-bank-option {
    padding: 12px 15px;
    background-color: white;
    border-radius: 6px;
    border: 2px solid #dee2e6;
    font-size: 14px;
    line-height: 1.5;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 8px;
}

.word-bank-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    border-color: #007bff;
}

.word-bank-option strong {
    color: #007bff;
    font-weight: 700;
    min-width: 20px;
}

/* Matching Tables */
.matching-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    table-layout: fixed;
}

.matching-table th,
.matching-table td {
    border: 1px solid var(--border-color);
    padding: 12px;
    text-align: center;
    /* Safari fix: ensure cells are visible */
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

.matching-table th.header-cell {
    min-width: 40px;
    width: 40px;
    background-color: var(--passage-bg);
    font-weight: bold;
}

.matching-table th.header-cell:first-child {
    width: auto;
    min-width: 200px;
}

.matching-table .question-cell {
    text-align: left;
    font-weight: normal;
    width: auto;
}

.matching-table td[data-answer] {
    cursor: pointer;
    transition: background-color 0.2s;
    /* Safari fix: ensure empty cells render properly */
    min-width: 40px;
    min-height: 40px;
    height: 40px;
    width: 40px;
    position: relative;
    /* Add visible content placeholder for empty cells */
    -webkit-user-select: none;
    user-select: none;
}

/* Safari fix: ensure empty cells are clickable */
.matching-table td[data-answer]::after {
    content: '';
    display: block;
    min-height: 20px;
}

.matching-table td[data-answer]:hover {
    background-color: var(--passage-bg);
}

.matching-table td.selected {
    background-color: var(--accent-color);
    color: white;
}

/* Safari fix: ensure selected cells show checkmark */
.matching-table td.selected::after {
    content: '✓';
    display: block;
    font-size: 18px;
    font-weight: bold;
    color: white;
    min-height: auto;
}

/* Matching Headings */
.matching-headings-container {
    margin: 20px 0;
}

.headings-list {
    background-color: var(--passage-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.heading-option {
    padding: 8px;
    margin: 5px 0;
}

.matching-heading-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin: 10px 0;
    background-color: var(--passage-bg);
    border-radius: 4px;
}

.matching-heading-question select {
    width: 200px;
    margin: 0;
}

/* Matching Options List */
.matching-options-list {
    background-color: var(--passage-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.matching-options-list ul {
    list-style: none;
    padding: 0;
}

.matching-options-list li {
    padding: 8px 0;
}

/* Passage Navigation - Bottom Right */
.passage-navigation {
    position: fixed;
    bottom: 120px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--header-bg);
    padding: 10px 15px;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 50;
}

.nav-button {
    background-color: rgba(255, 255, 255, 0.2);
    border: none;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.nav-button:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.3);
}

.nav-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.passage-indicator {
    color: #ffffff;
    font-weight: bold;
    font-size: 14px;
    min-width: 40px;
    text-align: center;
}

/* Footer */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--footer-bg);
    padding: 8px 15px;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
    z-index: 90;
    height: auto;
    min-height: 80px;
    max-height: 100px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.progress-container {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    justify-content: center;
    max-height: 50px;
    overflow-x: auto;
}

.progress-indicator {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background-color: var(--progress-incomplete);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.progress-indicator.completed {
    background-color: var(--progress-complete);
}

.progress-indicator:hover {
    transform: scale(1.1);
}

/* Flag Indicators Below Progress Bar */
.flag-indicators-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 3px;
    height: 4px;
}

.flag-indicator {
    width: 24px;
    height: 3px;
    background-color: transparent;
    border-radius: 2px;
    transition: all 0.3s;
}

.flag-indicator.active {
    background-color: #ff0000;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.6);
    animation: flagGlow 1.5s ease-in-out infinite;
}

@keyframes flagGlow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.submit-button {
    width: 100%;
    padding: 10px 16px;
    background-color: var(--button-bg);
    color: #ffffff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s;
    flex-shrink: 0;
    min-height: 40px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.submit-button:hover {
    background-color: var(--button-hover);
}

.submit-button:active {
    transform: scale(0.98);
}

/* Dual Choice Info */
.dual-choice-info {
    font-style: italic;
    color: var(--accent-color);
    margin: 10px 0;
    font-size: 13px;
}

/* Highlight styles */
.highlighted-text {
    padding: 2px 0;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .container {
        flex-direction: column;
    }

    .passage-section,
    .questions-section {
        width: 100%;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .questions-section {
        border-bottom: none;
    }
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 10px;
    }

    .header-left,
    .header-right {
        width: 100%;
        justify-content: space-between;
    }

    .container {
        top: 80px;
    }

    .passage-section,
    .questions-section {
        padding: 15px;
    }

    .passage-navigation {
        bottom: 70px;
        right: 10px;
    }

    .progress-indicator {
        width: 20px;
        height: 20px;
        font-size: 9px;
    }

    .flag-indicator {
        width: 20px;
    }

    footer {
        padding: 6px 10px;
        min-height: 70px;
    }

    .submit-button {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    .container {
        bottom: 90px;
    }
}

@media (max-width: 480px) {
    .progress-container {
        gap: 2px;
    }

    .progress-indicator {
        width: 18px;
        height: 18px;
        font-size: 8px;
        border-radius: 3px;
    }

    .flag-indicator {
        width: 18px;
    }

    footer {
        padding: 5px 8px;
        min-height: 65px;
    }

    .submit-button {
        padding: 10px 12px;
        font-size: 13px;
        min-height: 40px;
    }

    .container {
        bottom: 85px;
    }
}
