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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
#app {
    min-height: 100vh;
    position: relative;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* Container */
.container {
    width: 100%;
    max-width: 480px;
    padding: 20px;
    margin: 0 auto;
}

/* Password Screen */
.logo {
    text-align: center;
    margin-bottom: 40px;
}

.logo h1 {
    font-size: 2rem;
    color: white;
    margin-bottom: 8px;
    font-weight: 600;
}

.logo p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
}

.password-form {
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

#password-input {
    width: 100%;
    padding: 16px;
    border: 2px solid #e1e5e9;
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 20px;
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
    position: relative;
    z-index: 10;
    user-select: text;
    -webkit-user-select: text;
}

#password-input:focus {
    outline: none;
    border-color: #667eea;
}

#unlock-btn {
    width: 100%;
    padding: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    position: relative;
    min-height: 52px;
    z-index: 100;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#unlock-btn:hover {
    background: #5a6fd8;
}

#unlock-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-loading {
    font-size: 20px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Error Message */
.error-message {
    background: #ff4757;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
}

/* Flashcard Screen */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 16px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.progress-info {
    display: flex;
    flex-direction: column;
    color: white;
    font-size: 14px;
    font-weight: 500;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Flashcard */
.flashcard {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    height: 500px;
    position: relative;
    overflow: hidden;
}

.card-state {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.card-state.active {
    opacity: 1;
    visibility: visible;
}

.card-content {
    padding: 25px 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Question */
.question-text {
    flex: 1;
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 24px;
    color: #333;
    padding-bottom: 24px;
    border-bottom: 1px solid #e1e5e9;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.question-text pre {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 16px -10px;
    border-left: 4px solid #667eea;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: calc(100% + 20px);
    font-size: 13px;
    line-height: 1.4;
}

.question-text pre code {
    background: none;
    padding: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 13px;
}

.question-text code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    word-wrap: break-word;
}

/* Choices */
.choices {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.choice-btn {
    padding: 16px;
    border: 2px solid #e1e5e9;
    background: white;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 15px;
    min-height: 56px;
}

.choice-btn:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.choice-btn.selected {
    border-color: #667eea;
    background: #667eea;
    color: white;
}

.choice-btn.correct {
    border-color: #2ed573;
    background: #2ed573;
    color: white;
}

.choice-btn.incorrect {
    border-color: #ff4757;
    background: #ff4757;
    color: white;
}

.choice-btn:disabled {
    cursor: not-allowed;
}

/* Answer State */
.result-indicator {
    text-align: center;
    margin-bottom: 24px;
    padding: 20px;
    border-radius: 12px;
}

.result-indicator.correct {
    background: #d4edda;
    color: #155724;
}

.result-indicator.incorrect {
    background: #f8d7da;
    color: #721c24;
}

#result-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}

#result-text {
    font-size: 18px;
    font-weight: 600;
}

.explanation-text {
    flex: 1;
    font-size: 16px;
    line-height: 1.6;
    color: #555;
    margin-bottom: 24px;
}

.next-btn {
    width: 100%;
    padding: 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.next-btn:hover {
    background: #5a6fd8;
}

/* Navigation */
.nav {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.nav-btn {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    backdrop-filter: blur(10px);
}

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

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading Screen */
.loading {
    text-align: center;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

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

/* Mobile Optimizations */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }
    
    .flashcard {
        height: 500px;
    }
    
    .card-content {
        padding: 20px 15px;
    }
    
    .question-text pre {
        margin: 16px -5px;
        max-width: calc(100% + 10px);
        font-size: 12px;
        padding: 10px;
    }
    
    .question-text {
        font-size: 15px;
    }
    
    .choice-btn {
        padding: 14px;
        font-size: 14px;
    }
    
    .logo h1 {
        font-size: 1.75rem;
    }
    
    /* Ensure unlock button is properly touchable on mobile */
    #unlock-btn {
        min-height: 56px;
        font-size: 18px;
        touch-action: manipulation;
    }
    
    .password-form {
        padding: 25px;
    }
}

/* Touch improvements for iOS */
.choice-btn,
.next-btn,
#unlock-btn,
.nav-btn,
.icon-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Safe area adjustments for iOS */
@supports (padding-top: env(safe-area-inset-top)) {
    .container {
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}