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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

/* Layout */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page {
    display: none;
    flex: 1;
}

.page.active {
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 300;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.story-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    max-width: 1200px;
    margin: 0 auto;
}

.story-header h2 {
    font-size: 1.8rem;
    font-weight: 400;
}

.progress-indicator {
    font-size: 0.9rem;
    opacity: 0.8;
}

.header-controls {
    margin-top: 1rem;
}

/* Main Content */
main {
    flex: 1;
    padding: 2rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Setup Container */
.setup-container {
    max-width: 600px;
    margin: 2rem auto;
}

.setup-card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.setup-card h3 {
    color: #667eea;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.api-input-section {
    margin: 2rem 0;
    display: flex;
    gap: 1rem;
    flex-direction: column;
}

.voice-selection {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.voice-selection label {
    font-weight: 500;
    color: #333;
    min-width: 100px;
}

#voice-select {
    flex: 1;
    padding: 0.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    min-width: 200px;
}

#voice-select:focus {
    outline: none;
    border-color: #667eea;
}

#refresh-voices {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

#api-key-input {
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

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

.api-status {
    margin: 1rem 0;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    min-height: 20px;
}

.setup-info {
    text-align: left;
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    margin: 2rem 0;
}

.setup-info h4 {
    color: #333;
    margin-bottom: 1rem;
}

.setup-info ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.setup-info li {
    margin-bottom: 0.5rem;
}

.setup-info a {
    color: #667eea;
    text-decoration: none;
}

.setup-info a:hover {
    text-decoration: underline;
}

.note {
    font-size: 0.9rem;
    color: #666;
    font-style: italic;
}

/* Story Grid */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.story-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.story-card h3 {
    color: #667eea;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.story-card p {
    color: #666;
    margin-bottom: 1rem;
}

.story-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #888;
}

/* Learning Container */
.learning-container {
    max-width: 800px;
    margin: 0 auto;
}

.phase {
    display: none;
}

.phase.active {
    display: block;
}

/* Audio Section */
.audio-section {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.audio-status {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #666;
}

/* Response Section */
.response-section {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#speech-input {
    text-align: center;
    margin-bottom: 2rem;
}

.recording-status {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #666;
}

.countdown {
    font-size: 3rem;
    font-weight: bold;
    color: #e74c3c;
    margin-top: 1rem;
}

.user-response {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

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

.result-message {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 8px;
}

.result-message.correct {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.result-message.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.result-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Text Review */
.text-review {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.text-review h3 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.story-text {
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 2rem;
}

.story-text .clickable-word {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.story-text .clickable-word:hover {
    background-color: #e3f2fd;
    color: #1976d2;
}

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

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

.loading {
    text-align: center;
    color: #666;
    font-style: italic;
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        padding: 1.5rem 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .story-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    main {
        padding: 1rem;
    }
    
    .story-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .result-actions {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .audio-section,
    .response-section,
    .text-review {
        padding: 1.5rem;
    }
    
    .countdown {
        font-size: 2rem;
    }
}