:root {
    --bg-color: #f0f4f8;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --card-bg: #ffffff;
    --primary-color: #4299e1;
    --primary-hover: #3182ce;
    --success-color: #48bb78;
    --warning-color: #ed8936;
    --danger-color: #e53e3e;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none; /* Prevent all default browser gestures on background */
}

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.app-container {
    width: 100%;
    max-width: 600px;
    height: 90vh;
    max-height: 850px;
    display: flex;
    flex-direction: column;
    background: transparent;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.stat-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

.stat-new { background-color: #ebf8ff; color: #2b6cb0; }
.stat-review { background-color: #feebc8; color: #c05621; }
.stat-learned { background-color: #f0fff4; color: #2f855a; }

/* Main Card Area */
.card-container {
    flex: 1;
    perspective: 1000px;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* For absolute positioning of nav arrows */
}

/* Nav Arrows (PC Browse Mode) */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    z-index: 10;
    transition: background 0.3s ease, transform 0.2s ease;
}

.nav-arrow:hover {
    background: rgba(0, 0, 0, 0.15);
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow:active {
    transform: translateY(-50%) scale(0.95);
}

.nav-arrow-left {
    left: -50px;
}

.nav-arrow-right {
    right: -50px;
}

@media (max-width: 600px) {
    /* Hide arrows on mobile devices, rely on swipe instead */
    .nav-arrow {
        display: none !important;
    }
}

.card {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    cursor: pointer;
}

.card.is-flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: var(--shadow-md);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
}

.card-front {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.card-back {
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Card Content */
.card-category {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 1rem;
}

.card-question {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-hint {
    margin-top: 2rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.card-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.answer-section {
    margin-bottom: 0.25rem;
}

.memory-section, .exam-section {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.icon-indicator {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.35rem;
}

.answer-text, .memory-text, .exam-text {
    font-size: 1rem;
    line-height: 1.5;
}

.answer-text {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.memory-text {
    color: #2b6cb0;
    background-color: #ebf8ff;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--primary-color);
    width: 100%;
}

.exam-text {
    color: #c53030;
    background-color: #fff5f5;
    padding: 0.75rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--danger-color);
    width: 100%;
}

/* Controls */
.controls-container {
    min-height: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.controls {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.controls.hidden {
    display: none;
}

.btn {
    border: none;
    border-radius: 0.5rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

.btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.125rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

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

.btn-secondary {
    background-color: white;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
}

.feedback-prompt {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.assessment-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    width: 100%;
}

.btn-assessment {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    gap: 0.25rem;
    background-color: white;
    border: 1px solid var(--border-color);
}

.grade-label {
    font-size: 0.875rem;
}

.grade-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.btn-again { color: var(--danger-color); border-bottom: 3px solid var(--danger-color); }
.btn-hard { color: var(--warning-color); border-bottom: 3px solid var(--warning-color); }
.btn-good { color: var(--primary-color); border-bottom: 3px solid var(--primary-color); }
.btn-easy { color: var(--success-color); border-bottom: 3px solid var(--success-color); }

.btn-assessment:hover {
    background-color: #f7fafc;
}

.completion-message {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success-color);
    text-align: center;
}

/* Scrollbar styling for cards */
.card-face::-webkit-scrollbar {
    width: 6px;
}
.card-face::-webkit-scrollbar-track {
    background: transparent;
}
.card-face::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.1);
    border-radius: 10px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-face {
    animation: fadeIn 0.4s ease-out;
}

/* Header UI Additions */
.header-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.btn-mode {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    padding: 0.4rem 1rem;
    font-size: 0.875rem;
    border-radius: 9999px;
    margin-bottom: 0.5rem;
}

.btn-mode:hover {
    background-color: #ebf8ff;
}

/* Browse Mode Additions */
.hidden { display: none !important; }

.browse-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
}
.browse-buttons .btn {
    flex: 1;
}

.swipe-hint {
    color: var(--primary-color);
    font-weight: 500;
    margin-bottom: 0.75rem;
    animation: bounceX 2s infinite;
}

/* Swipe Animations */
@keyframes bounceX {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

.slide-out-left {
    animation: slideOutLeft 0.3s forwards;
}
.slide-in-right {
    animation: slideInRight 0.3s forwards;
}
.slide-out-right {
    animation: slideOutRight 0.3s forwards;
}
.slide-in-left {
    animation: slideInLeft 0.3s forwards;
}

@keyframes slideOutLeft {
    to { transform: translateX(-100%); opacity: 0; }
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutRight {
    to { transform: translateX(100%); opacity: 0; }
}
@keyframes slideInLeft {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Floating Help, Menu & Stats Buttons */
.btn-help-floating, .btn-menu-floating, .btn-stats-floating {
    position: absolute;
    top: 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
    z-index: 100;
}
.btn-help-floating { right: 1rem; }
.btn-stats-floating { right: 3.5rem; }
.btn-menu-floating { left: 1rem; }

.btn-help-floating:hover, .btn-menu-floating:hover, .btn-stats-floating:hover {
    background: #e2e8f0;
    color: var(--text-primary);
}

/* Help Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    padding: 2rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    font-weight: bold;
}

.modal-desc {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.help-list {
    list-style: none;
    margin-bottom: 1.5rem;
}

.help-list li {
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.4;
}

.help-badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.8rem;
    font-weight: bold;
    margin-right: 0.5rem;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
}

.help-tip {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: #ebf8ff;
    padding: 0.75rem;
    border-radius: 0.5rem;
}

/* Category Menu List */
.category-list, .module-stats-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 50vh;
    overflow-y: auto;
}

.category-list-item, .module-stat-item {
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    color: var(--text-primary);
    text-align: left;
    transition: var(--transition);
}
.category-list-item { cursor: pointer; }

.category-list-item:hover, .category-list-item.active {
    background: #ebf8ff;
    border-color: #bee3f8;
    color: var(--primary-color);
    font-weight: 600;
}

/* Subject Tabs */
.subject-tabs {
    display: flex;
    background: #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.25rem;
    margin-bottom: 1rem;
}

.subject-tab {
    flex: 1;
    text-align: center;
    padding: 0.5rem;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: var(--transition);
}

.subject-tab.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Stats Modal Specific Styles */
.stats-section {
    margin-bottom: 1.5rem;
}
.stats-section-title {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}
.progress-bar-container {
    display: flex;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    background: #e2e8f0;
    margin-bottom: 0.5rem;
}
.progress-bar-segment {
    height: 100%;
    transition: width 0.3s ease;
}
.stats-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}
.module-stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.module-stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.module-stat-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.module-stat-warning {
    font-size: 0.8rem;
    color: #e53e3e;
    background: #fed7d7;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}
