:root {
    --primary-blue: #4A90E2;
    --primary-orange: #FF9F43;
    --bg-light: #F8FAFF;
    --text-main: #333333;
    --text-muted: #888888;
    --card-shadow: 0 8px 24px rgba(149, 157, 165, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', 'Noto Sans SC', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
    line-height: 1.5;
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 100px;
    /* Space for bottom nav */
}

/* Header */
.main-header {
    padding: 24px 20px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-right .mdi {
    font-size: 22px;
    color: var(--text-main);
}

/* View Management */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

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

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

.view-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.view-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.back-btn {
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
}

/* Common Buttons */
.primary-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 16px;
    width: 100%;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(74, 144, 226, 0.3);
    transition: all 0.2s;
}

.primary-btn:active {
    transform: scale(0.98);
}

.secondary-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid #ddd;
    padding: 16px;
    border-radius: 16px;
    width: 100%;
    font-size: 16px;
    margin-top: 10px;
    cursor: pointer;
}

/* Upload Area */
.upload-area {
    margin: 0 20px;
    background: white;
    border: 2px dashed #E0E6ED;
    border-radius: 24px;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.upload-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
}

.upload-prompt i {
    font-size: 48px;
    margin-bottom: 10px;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.manual-input-box {
    padding: 24px 20px;
}

.manual-input-box p {
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--text-muted);
}

textarea {
    width: 100%;
    height: 120px;
    border: 1px solid #E0E6ED;
    border-radius: 16px;
    padding: 15px;
    font-family: inherit;
    margin-bottom: 20px;
    resize: none;
}

/* Tags View Content */
.tags-content {
    padding: 20px;
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 20px 0 40px;
}

.tag-badge {
    background: #F0F4FF;
    color: var(--primary-blue);
    padding: 10px 18px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 500;
}

/* Quiz Styles */
.quiz-content {
    padding: 0 20px;
}

.quiz-progress {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.question-box {
    background: white;
    padding: 24px;
    border-radius: 24px;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 24px;
    box-shadow: var(--card-shadow);
}

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

.option {
    background: white;
    border: 1px solid #E0E6ED;
    padding: 18px;
    border-radius: 18px;
    text-align: left;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.option.selected {
    background: var(--primary-blue);
    color: white;
    border-color: var(--primary-blue);
}

.option.correct {
    background: #27AE60;
    color: white;
    border-color: #27AE60;
}

.option.incorrect {
    background: #E74C3C;
    color: white;
    border-color: #E74C3C;
}

.result-container {
    margin-top: 24px;
    padding: 20px;
    background: #f8faff;
    border-radius: 18px;
    border-left: 4px solid var(--primary-blue);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.loader {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* Action Cards */
.main-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    padding: 15px 20px;
}

.action-card {
    border-radius: 18px;
    padding: 20px;
    height: 140px;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.action-card:active {
    transform: scale(0.96);
}

.scan-card {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 10px 20px rgba(79, 172, 254, 0.3);
}

.book-card {
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    background: linear-gradient(135deg, #FF9F43 0%, #FFC371 100%);
    box-shadow: 0 10px 20px rgba(255, 159, 67, 0.3);
}

.card-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 5px;
}

.card-content p {
    font-size: 13px;
    opacity: 0.9;
    line-height: 1.3;
}

.card-icon {
    position: absolute;
    right: -10px;
    bottom: -10px;
    opacity: 0.2;
    font-size: 80px;
}

.scan-card .card-icon {
    right: 20px;
    bottom: 20px;
    opacity: 1;
}

/* Specific Camera Icon Stylings for Scan Card */
.camera-outer {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.camera-inner {
    width: 35px;
    height: 35px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-inner .mdi {
    color: var(--primary-blue);
    font-size: 20px;
}

/* Subjects Section */
.subjects-section {
    background: white;
    margin: 15px 20px;
    border-radius: 24px;
    padding: 20px;
    box-shadow: var(--card-shadow);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.section-header .mdi {
    color: var(--text-muted);
}

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
}

.subject-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 5px;
    border-radius: 15px;
    transition: background 0.2s;
    cursor: pointer;
}

.subject-item:hover {
    background: #F4F7FF;
}

.subject-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    font-size: 24px;
}

/* Subject Colors */
.icon-chinese {
    color: #E67E22;
    background: #FEF5ED;
}

.icon-math {
    color: #3498DB;
    background: #EBF5FB;
}

.icon-english {
    color: #9B59B6;
    background: #F5EEF8;
}

.icon-physics {
    color: #34495E;
    background: #EBEDEF;
}

.icon-chemistry {
    color: #1ABC9C;
    background: #E8F8F5;
}

.icon-biology {
    color: #27AE60;
    background: #E9F7EF;
}

.icon-politics {
    color: #E74C3C;
    background: #FDEDEC;
}

.icon-history {
    color: #D35400;
    background: #FBEBDD;
}

.icon-geography {
    color: #2980B9;
    background: #EAF2F8;
}

.icon-plus {
    color: #3498DB;
    border: 1.5px dashed #3498DB;
    background: transparent;
}

.subject-name {
    font-size: 14px;
    font-weight: 500;
}

.subject-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.toggle-expand {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

/* Skeleton Loading */
.skeleton {
    background: #eee;
    background: linear-gradient(110deg, #ececec 8%, #f5f5f5 18%, #ececec 33%);
    border-radius: 12px;
    background-size: 200% 100%;
    animation: 1.5s shine linear infinite;
    height: 80px;
}

@keyframes shine {
    to {
        background-position-x: -200%;
    }
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    height: 70px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: var(--safe-area-bottom);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
}

.nav-item.active {
    color: var(--primary-blue);
}

.nav-item i {
    font-size: 24px;
}

.nav-camera {
    position: relative;
    top: -20px;
}

.camera-btn {
    width: 60px;
    height: 60px;
    background: var(--primary-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(74, 144, 226, 0.4);
    color: white;
    font-size: 28px;
    border: 5px solid white;
}

/* Mistake List */
.mistake-list-content {
    padding: 0 0 120px 0;
}

.mistake-list-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
}

.mistake-card {
    background: white;
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: transform 0.2s;
}

.mistake-card:active {
    transform: scale(0.98);
}

.mistake-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.mistake-tag {
    background: #F0F4FF;
    color: var(--primary-blue);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
}

.mistake-date {
    font-size: 12px;
    color: var(--text-muted);
}

.mistake-card-body {
    font-size: 15px;
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-main);
}

/* Mistake Details */
.mistake-detail-content {
    padding: 0 20px 120px 20px;
}

.detail-tags {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.detail-question {
    background: white;
    padding: 20px;
    border-radius: 16px;
    font-size: 18px;
    font-weight: 600;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
}

.detail-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}

.detail-option {
    padding: 16px;
    border: 1px solid #E0E6ED;
    border-radius: 16px;
    background: white;
    font-size: 15px;
}

.detail-option.is-wrong {
    border-color: #E74C3C;
    background: #FDEDEC;
}

.detail-option.is-correct {
    border-color: #27AE60;
    background: #E9F7EF;
}

.detail-analysis {
    background: #F8FAFF;
    padding: 20px;
    border-radius: 16px;
    border-left: 4px solid var(--primary-blue);
    margin-bottom: 20px;
}

.analysis-title {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 600;
}

.mistakeDetailView .action-footer {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    padding: 20px;
    background: linear-gradient(to top, var(--bg-light) 60%, transparent);
    z-index: 10;
}