/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    font-size: 18px;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Container */
#app {
    width: 100%;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
    background: white;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* Navigation */
.nav-buttons {
    padding: 15px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

/* Buttons */
.btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:active {
    background: #5568d3;
    transform: scale(0.98);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:active {
    background: #d0d0d0;
    transform: scale(0.98);
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:active {
    background: #c0392b;
    transform: scale(0.98);
}

.btn-large {
    width: 100%;
    font-size: 20px;
    padding: 16px;
}

.btn-full {
    width: 100%;
    display: block;
}

.mt-10 {
    margin-top: 10px;
}

/* Content Area */
.content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* Important for nested flex scrolling */
}

.content.full-height {
    padding: 0;
    height: 100%;
}

/* Home Page - Lesson Selector */
.lesson-selector {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.lesson-selector h2 {
    font-size: 22px;
    margin: 15px 20px;
    color: #667eea;
    display: none;
    /* Hide H2 in fullscreen mode layout */
}

/* Split Layout */
.lesson-selection-container {
    display: flex;
    flex: 1;
    height: 100%;
    /* Take full remaining height */
    overflow: hidden;
}

/* Left Panel */
.selection-sidebar {
    width: 33.33%;
    min-width: 280px;
    max-width: 350px;
    /* Fixed width */
    background: #f8f8f8;
    padding: 20px;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    flex-shrink: 0;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-label {
    font-weight: 600;
    font-size: 16px;
    color: #555;
}

.filter-select {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    background: white;
}

.selection-stats {
    padding: 15px 0;
    border-top: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
}

.selection-stats p {
    margin-bottom: 10px;
    font-weight: 600;
    color: #667eea;
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    width: 100%;
}

/* Right Panel */
.selection-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: white;
}

/* Sidebar Test Config */
.test-config-sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.config-section-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.config-row-sidebar {
    margin-bottom: 10px;
}

.config-label-small {
    font-weight: 600;
    font-size: 14px;
    display: block;
    margin-bottom: 5px;
    color: #666;
}

.config-input-small {
    width: 100%;
    padding: 8px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.radio-group-sidebar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-item-small {
    display: flex;
    align-items: center;
    font-size: 15px;
    cursor: pointer;
}

.radio-item-small input {
    margin-right: 8px;
    width: 18px;
    height: 18px;
}

/* Mobile Responsiveness */
@media (max-width: 767px) {
    #app {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .lesson-selection-container {
        flex-direction: column;
        height: auto;
    }

    .selection-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }

    .selection-content {
        height: 500px;
        /* Limit height on mobile */
    }

    .lesson-selector h2 {
        display: block;
        /* Show title on mobile */
    }
}

.grade-group {
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.grade-header {
    background: #f8f8f8;
    padding: 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

.grade-header:active {
    background: #efefef;
}

.grade-title {
    font-weight: 600;
    font-size: 18px;
}

.grade-arrow {
    font-size: 20px;
    transition: transform 0.3s;
}

.grade-arrow.expanded {
    transform: rotate(90deg);
}

.semester-group {
    border-top: 1px solid #ddd;
}

.semester-header {
    background: #fafafa;
    padding: 12px 15px 12px 30px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

.semester-header:active {
    background: #f0f0f0;
}

.book-group {
    border-top: 1px solid #eee;
}

.book-header {
    background: #fcfcfc;
    padding: 10px 15px 10px 45px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
}

.book-header:active {
    background: #f5f5f5;
}

.lesson-list {
    padding: 10px 15px 10px 60px;
}

.lesson-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    min-height: 44px;
    cursor: pointer;
}

.lesson-item:active {
    background: #f9f9f9;
}

.lesson-checkbox {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

.lesson-label {
    font-size: 16px;
    flex: 1;
}

/* Test Configuration */
.test-config {
    background: #f8f8f8;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.config-row {
    margin-bottom: 20px;
}

.config-row:last-child {
    margin-bottom: 0;
}

.config-label {
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
    font-size: 18px;
}

.config-input {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    cursor: pointer;
}

.radio-item input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
}

/* Test Page Container Wrapper */
.test-container-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Test Page */
.test-container {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px);
}

.progress-bar {
    background: #f0f0f0;
    padding: 15px 20px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: #667eea;
}

.question-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 30px 20px;
}

.question-word {
    font-size: 48px;
    text-align: center;
    margin-bottom: 30px;
    line-height: 1.5;
}

.test-item {
    color: #e74c3c;
    text-decoration: underline;
    text-decoration-thickness: 3px;
    text-underline-offset: 4px;
    font-weight: 600;
}

/* Canvas Container */
.canvas-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.canvas-wrapper {
    border: 2px solid #667eea;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

canvas {
    display: block;
    touch-action: none;
    background: white;
}

/* Test Actions */
.test-actions {
    display: flex;
    gap: 15px;
    padding: 20px;
}

.test-actions .btn {
    flex: 1;
}

/* Review Page */
.session-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.session-item {
    background: #f8f8f8;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.session-date {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #667eea;
}

.session-info {
    font-size: 16px;
    color: #666;
    margin-bottom: 12px;
}

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

.session-actions .btn {
    flex: 1;
}

/* Answer Grid */
.answer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.answer-card {
    background: #f8f8f8;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.answer-question {
    font-size: 24px;
    margin-bottom: 8px;
    font-weight: 600;
}

.answer-type {
    font-size: 14px;
    color: #666;
    margin-bottom: 12px;
}

.answer-image {
    width: 100%;
    height: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.empty-state-text {
    font-size: 20px;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    font-size: 20px;
    color: #667eea;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* iPad Landscape Optimizations */
@media (min-width: 768px) {
    .answer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    canvas {
        width: 400px;
        height: 400px;
    }
}

/* Prevent text selection during touch */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}