body {
    font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    line-height: 1.6;
    color: #333;
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
}

button, .btn-exam, .btn-status, .calc-btn, .header-btn, .choice-btn, .subjective-nav-btn, .btn-check-answer, a {
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.main-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    align-items: start;
}

.category-item {
    min-width: 0;
    /* Prevent overflow */
}

.category-item.expanded {
    grid-column: 1 / -1;
    width: 100%;
}


h1 {
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
}

h2 {
    background-color: #e9ecef;
    padding: 10px;
    border-radius: 5px;
    margin-top: 0;
    color: #495057;
    border-left: 5px solid #6c757d;
    font-size: 1.1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
}

.category-title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-grow: 1;
    margin-right: 10px;
}

.problems-container {
    margin-bottom: 30px;
    display: none;
    /* Collapsed by default */
}


.problem-box {
    padding: 10px 20px;
    border-bottom: none;
    background-color: #fff;
    margin-bottom: 0;
}


.problem-box:last-child {
    border-bottom: none;
}

.problem-title {
    font-size: 1.1em;
    font-weight: bold;
    color: #0056b3;
    margin-bottom: 0;
    display: flex;
    justify-content: flex-start;
    /* Left align */
    gap: 15px;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 10px 0;
}

.problem-title:hover {
    background-color: #f8f9fa;
}

.problem-box:has(.problem-content[style*="display: block"]) .problem-title {
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}




.header-btn-group {
    display: flex;
    gap: 10px;
}

.header-btn {
    padding: 0;
    cursor: pointer;
    border: none;
    background: none;
    /* No background */
    transition: transform 0.2s;
    height: 30px;
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    transform: scale(1.1);
}

.header-btn img {
    display: block;
    width: 20px;
    /* Slightly larger icons */
    height: 20px;
}




.btn-hint:hover {
    background-color: #5a6268;
}

.btn-hint.open {
    background-color: #28a745;
}

.problem-statement-box {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 1.1em;
    line-height: 1.5;
}

.section-label {
    font-weight: bold;
    color: #444;
    margin-top: 15px;
    display: block;
}

.calc-input {
    background-color: #f4f4f4;
    padding: 8px 15px;
    border-radius: 4px;
    font-family: monospace;
    color: #c7254e;
    display: inline-block;
    font-size: 1.05em;
    font-weight: bold;
}

.step-box {
    background-color: #fdfdfd;
    border: 1px solid #f1f1f1;
    padding: 15px;
    border-radius: 5px;
    margin-top: 10px;
}

.memo-box {
    background-color: #fff3cd;
    border-left: 5px solid #ffc107;
    padding: 10px;
    margin-top: 15px;
    font-size: 0.9em;
}

ul {
    margin-top: 5px;
    margin-bottom: 5px;
    padding-left: 20px;
}

li {
    margin-bottom: 5px;
}

.step-box ul ul {
    list-style-type: circle;
    margin-top: 5px;
    margin-bottom: 10px;
}

.hint-container {
    margin-top: 15px;
    border: 1px solid #17a2b8;
    padding: 20px;
    border-radius: 8px;
    background-color: #fff;
    text-align: left;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    animation: fadeIn 0.3s ease-in-out;
}

.hint-container .section-label {
    color: #333;
    font-size: 1.1em;
    font-weight: bold;
    margin-bottom: 10px;
    display: block;
}

.hint-container ul {
    margin-top: 10px;
    list-style-type: disc;
    padding-left: 25px;
    line-height: 1.8;
}

.hint-container li {
    margin-bottom: 8px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.btn-exam {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 5px;
    font-size: 0.6em;
    cursor: pointer;
    vertical-align: middle;
    transition: background-color 0.2s;
    flex-shrink: 0;
    touch-action: manipulation;
}

.toggle-icon {
    flex-shrink: 0;
}

.btn-exam:hover {
    background-color: #c82333;
}

/* Hint Display Styles */
.hint-display-box {
    margin-top: 15px;
    border: 1px solid #17a2b8;
    padding: 20px;
    border-radius: 8px;
    background-color: #fff;
    text-align: left;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.hint-section-title {
    color: #333;
    font-size: 1.1em;
    font-weight: bold;
    margin-bottom: 10px;
    display: block;
}

.hint-formula-container {
    text-align: center;
    margin: 20px 0;
    font-size: 1.3em;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.hint-variable-list {
    margin-top: 10px;
    list-style-type: disc;
    padding-left: 25px;
    line-height: 1.8;
}

.hint-variable-list li {
    margin-bottom: 8px;
}

/* Layout for Exam with Calculator */
.main-layout {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    max-width: 1200px;
    margin: 0 auto;
}

#exam-container {
    flex: 1;
    min-width: 0;
}

/* Calculator Styles */
.calculator {
    width: 300px;
    background: #2c3e50;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 20px;
    color: white;
}

.calc-display {
    background: #1a252f;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    text-align: right;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.calc-memory-storage {
    background: #34495e;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 15px;
    min-height: 40px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    border: 1px dashed #3498db;
}

.memory-item {
    background: #3498db;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: bold;
    cursor: pointer;
}

.memory-item:hover {
    background: #2980b9;
}

.calc-history {
    font-size: 0.9em;
    color: #95a5a6;
    margin-bottom: 5px;
    word-break: break-all;
}

.calc-result {
    font-size: 1.6em;
    font-weight: bold;
    color: #ecf0f1;
    word-break: break-all;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: wrap;
    min-height: 1.5em;
}

.visual-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
    font-size: 0.85em;
}

.vis-num,
.vis-den {
    padding: 2px 6px;
    min-width: 30px;
    min-height: 1.2em;
    text-align: center;
    transition: all 0.2s;
}

.vis-num {
    border-bottom: 2px solid #ecf0f1;
}

.active-part {
    background: rgba(52, 152, 219, 0.4);
    border-radius: 4px;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.8);
}

.empty-box {
    color: #7f8c8d;
    font-style: italic;
}

.calc-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.calc-btn {
    height: 50px;
    border: none;
    border-radius: 8px;
    background: #34495e;
    color: white;
    font-size: 1.22em;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    min-height: 48px; /* Standard touch target height */
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.calc-btn:hover {
    background: #4e6a85;
    transform: translateY(-2px);
}

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

.btn-op {
    background: #f39c12;
}

.btn-op:hover {
    background: #e67e22;
}

.btn-equal {
    background: #27ae60;
}

.btn-equal:hover {
    background: #2ecc71;
}

.btn-clear {
    background: #e74c3c;
}

.btn-clear:hover {
    background: #c0392b;
}

.btn-del {
    background: #7f8c8d;
}

.btn-del:hover {
    background: #95a5a6;
}

.btn-zero {
    grid-column: span 2;
}

.btn-transfer {
    background: #3498db;
}

.btn-transfer:hover {
    background: #2980b9;
}

.calc-info {
    margin-top: 15px;
    font-size: 0.8em;
    color: #bdc3c7;
    text-align: center;
}

/* Responsive adjustment */
@media (max-width: 1000px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
    }

    .calculator {
        position: static;
        width: 100%;
        max-width: 350px;
        margin-top: 30px;
    }
}

/* Exam Timer */
#exam-timer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    color: #333;
    padding: 2px 10px;
    border-radius: 6px;
    font-family: 'Consola', 'Monaco', 'Courier New', monospace;
    font-size: 1.2em; /* Match problem counter size */
    font-weight: bold;
    border: 1px solid #ddd;
    margin-left: 15px;
    min-width: 90px;
}

#exam-timer.active {
    display: inline-flex;
}

.lap-time {
    font-size: 0.8em;
    color: #e67e22;
    font-weight: bold;
    margin-left: 4px;
    background: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid #ffe8cc;
}

/* Statistics Modal - Premium Redesign */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.75); /* Modern blue-ish dark */
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(8px);
    padding: 20px;
}

.modal-content {
    background: #ffffff;
    width: 100%;
    max-width: 950px;
    max-height: 90vh;
    border-radius: 20px;
    padding: 40px;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #94a3b8;
    transition: color 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f1f5f9;
}

.modal-close:hover {
    color: #475569;
    background: #e2e8f0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: #ffffff;
    padding: 24px;
    border-radius: 16px;
    text-align: left;
    border: 1px solid #f1f5f9;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.stat-card h3 {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: #64748b;
    font-weight: 600;
}

.stat-card .value {
    font-size: 1.875rem;
    font-weight: 800;
    color: #1e293b;
    line-height: 1;
}

/* Chart Components */
.chart-container {
    background: #f8fafc;
    border-radius: 16px;
    padding: 30px;
    border: 1px solid #f1f5f9;
}

.v-bar-wrapper {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.v-bar-wrapper:hover {
    transform: scale(1.05);
}

.v-bar {
    border-radius: 6px 6px 2px 2px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    background-image: linear-gradient(to top, rgba(0,0,0,0.1), transparent);
}

.legend-card {
    background: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Wrong Problems Redesign */
.wrong-problem-card {
    transition: all 0.2s;
}

.wrong-problem-card:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-color: #ffb3c1 !important;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .modal-content {
        padding: 20px;
        width: 100%;
        border-radius: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card .value {
        font-size: 1.25rem;
    }

    .chart-container {
        padding: 30px 10px 40px;
        overflow-x: auto; /* Enable horizontal scroll for chart if needed */
        justify-content: flex-start !important;
        gap: 10px;
    }

    .v-bar-wrapper {
        min-width: 60px !important;
    }

    .legend-card {
        width: 100%; /* Stack info cards on mobile */
    }

    /* Modal Header Adjustments */
    .modal-content h2 {
        font-size: 1.1rem !important;
    }

    .modal-content button {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
    }
}

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

    .modal-content {
        padding: 15px;
    }

    .wrong-problem-card {
        padding: 10px;
        gap: 10px;
    }
}

.btn-status {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(230, 126, 34, 0.3);
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    margin: 10px 0;
}

.btn-status:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(230, 126, 34, 0.4);
}

/* Page Layout Responsiveness */
@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
    .main-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    .main-header h1 {
        font-size: 1.25rem !important;
        margin-top: 0 !important;
    }
    .hide-on-mobile {
        display: none !important;
    }
    
    /* Force remove top margins on mobile */
    body, #exam-container, .exam-header, .problem-box {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
}