/* Spell Quest - Magical Storytelling Platform Styles */
/* Following LEGENDARY UI Design System for consistency with Math Star */

/* Design System Tokens - Enchanted Forest Theme */
:root {
  /* Brand Colors - Forest Theme */
  --color-forest-primary: #48bb78;
  --color-forest-dark: #2d5016;
  --color-forest-light: #68d391;
  --color-magic-purple: #667eea;
  --color-magic-violet: #764ba2;
  --color-spark-red: #ff6b6b;
  --color-wonder-teal: #4ecdc4;
  --color-star-gold: #ffd700;
  
  /* Gradients - Simplified */
  --gradient-forest: linear-gradient(135deg, #48bb78 0%, #68d391 100%);
  --gradient-magical: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-warm: linear-gradient(45deg, #ff6b6b, #ffa500);
  
  /* Text Colors */
  --color-text-primary: #2d3748;
  --color-text-light: #718096;
  --color-text-white: #ffffff;
  
  /* Background Colors */
  --bg-magical: var(--gradient-magical);
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-glass: rgba(255, 255, 255, 0.1);
  
  /* Typography */
  --font-primary: 'Comic Sans MS', 'Chalkboard SE', 'Chalkboard', 'Marker Felt', 'Bradley Hand ITC', 'Trebuchet MS', 'Helvetica Neue', 'Arial', sans-serif;
  
  /* Spacing - 8pt Grid */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  
  /* Border & Shadow */
  --radius-xl: 1.25rem;    /* 20px - consistent with Math Star */
  --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.15);
  --shadow-magical: 0 8px 16px rgba(102, 126, 234, 0.2);
  
  /* Transitions */
  --transition-magical: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

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

body {
    font-family: var(--font-primary);
    background: var(--bg-magical);
    min-height: 100vh;
    color: var(--color-text-primary);
    margin: 0;
    padding: 0;
}

/* Magical Background Particles */
.magic-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: -1;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 107, 107, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(78, 205, 196, 0.1) 0%, transparent 50%);
    animation: floatParticles 20s ease-in-out infinite;
}

@keyframes floatParticles {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg);
        opacity: 0.7;
    }
    33% { 
        transform: translateY(-20px) rotate(120deg);
        opacity: 1;
    }
    66% { 
        transform: translateY(10px) rotate(240deg);
        opacity: 0.8;
    }
}

/* Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--text-primary);
    color: var(--text-white);
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
    transition: var(--transition-magic);
}

.skip-link:focus {
    top: 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Main App Container */
#app {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-5);
}

/* Screen Management */
.screen {
    /* CRITICAL FIX: Hide inactive screens completely */
    display: none;
    background: white;
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    box-shadow: var(--shadow-lg);
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transform: translate3d(0, 20px, 0);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0s 0.3s;
}

.screen.active {
    /* CRITICAL FIX: Show active screen in layout */
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translate3d(0, 0, 0);
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Magical Frame Container */
.magical-frame {
    background: var(--background-card);
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow-magic);
    border: 1px solid var(--border-magic);
    position: relative;
    backdrop-filter: blur(10px);
    overflow: hidden;
}

.magical-frame::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-magic);
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Typography */
h1, .title-sparkle {
    font-size: 2.5em;
    color: var(--color-spark-red);
    margin-bottom: var(--space-5);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    font-family: var(--font-primary);
}

h2, .subtitle {
    font-size: 2em;
    color: var(--color-spark-red);
    margin-bottom: var(--space-8);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    font-family: var(--font-primary);
}

h3 {
    font-size: 1.5em;
    color: var(--color-text-primary);
    margin-bottom: var(--space-5);
}

/* Buttons */
.big-btn, .magical-btn {
    background: var(--gradient-warm);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    border-radius: 25px;
    cursor: pointer;
    margin: var(--space-3);
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    font-weight: bold;
    transform: translate3d(0, 0, 0);
}

.big-btn:hover, .magical-btn:hover {
    transform: translate3d(0, -2px, 0);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.big-btn:active, .magical-btn:active {
    transform: translate3d(0, 0, 0);
    transition: transform 0.1s;
}

.secondary-btn {
    background: var(--gradient-forest);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-xl);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition-magical);
    margin: var(--space-2);
    font-family: inherit;
    font-weight: bold;
}

.secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.back-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    margin-top: var(--space-5);
    font-family: inherit;
    transition: background 0.2s;
}

.back-btn:hover {
    background: #5a6268;
}

/* Profile Section */
.profiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.profile-card {
    background: var(--background-card);
    border: 2px solid var(--border-magic);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-magic);
    position: relative;
}

.profile-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
    border-color: #ff6b6b;
}

.profile-card.selected {
    background: var(--magic-purple);
    color: var(--text-white);
    transform: scale(1.05);
}

.profile-avatar {
    font-size: 3rem;
    margin-bottom: 10px;
    display: block;
}

.profile-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.profile-stats {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Avatar Selection */
.avatar-selection {
    margin: 20px 0;
}

.avatar-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin: 16px 0;
}

.avatar-btn {
    background: #f8f9fa;
    border: 3px solid #ddd;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 2em;
    cursor: pointer;
    transition: all 0.2s;
}

.avatar-btn:hover {
    transform: scale(1.1);
    border-color: var(--color-wonder-teal);
}

.avatar-btn.selected {
    border-color: var(--color-spark-red);
    background: #fff5f5;
    transform: scale(1.1);
}

@keyframes selectedPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(255, 107, 107, 0); }
}

/* Player Info Display */
.welcome-header {
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}

.player-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-5);
    margin: var(--space-5) 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 15px;
}

.avatar-large {
    font-size: 4rem;
    animation: gentleBob 2s ease-in-out infinite;
}

@keyframes gentleBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.player-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Story Sprite Companion */
.story-sprite {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 300px;
}

.sprite-character {
    font-size: 2.5rem;
    animation: spriteFloat 3s ease-in-out infinite;
}

@keyframes spriteFloat {
    0%, 100% { 
        transform: translateY(0) rotate(0deg);
    }
    33% { 
        transform: translateY(-8px) rotate(-5deg);
    }
    66% { 
        transform: translateY(4px) rotate(5deg);
    }
}

.sprite-speech-bubble {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--magic-pink);
    border-radius: 20px 20px 20px 5px;
    padding: 12px 16px;
    position: relative;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-magic);
    animation: bubblePulse 4s ease-in-out infinite;
}

@keyframes bubblePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.sprite-speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 15px;
    width: 0;
    height: 0;
    border: 10px solid transparent;
    border-top-color: var(--magic-pink);
}

.sprite-speech-bubble p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-primary);
}

/* Menu Buttons Layout */
.menu-buttons {
    display: grid;
    gap: 15px;
    max-width: 400px;
    margin: 0 auto var(--space-8) auto;
}

.magical-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-5);
    min-height: 100px;
}

.btn-description {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 8px;
    font-weight: 400;
    font-style: italic;
}

.settings-row, .nav-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.setting-btn {
    background: var(--magic-green);
    color: var(--text-white);
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition-magic);
}

.setting-btn:hover {
    background: var(--magic-gold);
    transform: scale(1.05);
}

.setting-btn[aria-pressed="false"] {
    background: var(--text-light);
}

/* Form Elements */
.magical-input {
    padding: 15px;
    font-size: 1.2em;
    border: 3px solid #ddd;
    border-radius: 10px;
    text-align: center;
    margin: var(--space-5);
    width: 250px;
    font-family: inherit;
}

.magical-input:focus {
    outline: none;
    border-color: var(--color-wonder-teal);
}

.magical-select {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--border-magic);
    border-radius: var(--border-radius);
    padding: 12px 16px;
    font-size: 1rem;
    width: 100%;
    cursor: pointer;
    transition: var(--transition-magic);
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.help-text {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 6px;
    font-style: italic;
}

/* Game Headers */
.game-header, .creator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.game-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.game-progress {
    width: 100%;
    margin-top: 15px;
}

.progress-bar {
    background: rgba(255, 255, 255, 0.2);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--magic-gold);
    transition: width 0.5s ease;
}

.magical-progress {
    background: var(--primary-magic);
    background-size: 20px 20px;
    animation: progressShimmer 1s linear infinite;
}

@keyframes progressShimmer {
    0% { background-position: 0 0; }
    100% { background-position: 20px 0; }
}

.progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-light);
}

/* Word Weaver Specific Styles */
.spell-area {
    text-align: center;
    padding: var(--space-12) var(--space-8);
    background: #f8f9fa;
    border: 3px solid #ddd;
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-8);
    min-height: 200px;
}

.target-word {
    font-size: 3rem;
    font-weight: bold;
    color: var(--color-forest-primary);
    margin-bottom: var(--space-5);
    font-family: var(--font-primary);
}

.word-definition {
    font-size: 1.2rem;
    color: var(--color-text-light);
    margin-bottom: var(--space-5);
    font-style: italic;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    padding: var(--space-4);
}

.audio-controls {
    display: flex;
    gap: var(--space-4);
    justify-content: center;
    margin-bottom: var(--space-8);
    flex-wrap: wrap;
}

.audio-btn {
    background: var(--gradient-forest);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    transition: var(--transition-magical);
    font-size: 1rem;
    font-family: inherit;
    font-weight: bold;
}

.audio-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.spell-input-area {
    margin-top: 30px;
}

.spell-effects-area {
    min-height: 100px;
    margin-top: 20px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Grammar Gardens Styles */
.garden-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.garden-visual {
    background: linear-gradient(to bottom, #87ceeb 0%, #98fb98 100%);
    border-radius: var(--border-radius);
    padding: 20px;
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

.garden-ground {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to top, #8B4513, #DEB887);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.grown-elements {
    position: relative;
    z-index: 2;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    padding-bottom: 60px;
}

.sentence-building {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    padding: 20px;
    backdrop-filter: blur(5px);
}

.word-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    min-height: 80px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border: 2px dashed var(--border-magic);
}

.word-chip {
    background: var(--gradient-forest);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: grab;
    transition: var(--transition-magical);
    font-weight: 500;
    user-select: none;
    font-family: inherit;
}

.word-chip:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(72, 187, 120, 0.3);
}

.word-chip.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

.sentence-builder {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.drop-zone {
    background: #f8f9fa;
    border: 2px dashed #ddd;
    border-radius: 10px;
    padding: 15px 20px;
    min-width: 120px;
    min-height: 50px;
    text-align: center;
    transition: var(--transition-magical);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone.drag-over {
    background: rgba(255, 107, 107, 0.1);
    border-color: var(--color-spark-red);
    transform: scale(1.05);
}

.drop-zone.filled {
    background: var(--color-wonder-teal);
    color: white;
    border-color: transparent;
}

.drop-zone.optional {
    opacity: 0.7;
    border-style: dotted;
}

/* Story Creator Styles */
.creator-tools {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.tool-btn {
    background: var(--magic-blue);
    color: var(--text-white);
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition-magic);
    font-size: 0.9rem;
}

.tool-btn:hover {
    background: var(--magic-pink);
    transform: translateY(-1px);
}

.story-workspace {
    margin-bottom: 30px;
}

.story-metadata {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.chapter-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
    overflow-x: auto;
}

.chapter-tab {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 8px 16px;
    border-radius: 20px 20px 0 0;
    cursor: pointer;
    transition: var(--transition-magic);
    white-space: nowrap;
    font-size: 0.9rem;
}

.chapter-tab.active {
    background: var(--magic-purple);
    color: var(--text-white);
}

.editor-panel {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    min-height: 500px;
}

.writing-area {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    padding: 20px;
}

.story-textarea {
    width: 100%;
    min-height: 300px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--border-magic);
    border-radius: var(--border-radius);
    padding: 16px;
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    transition: var(--transition-magic);
    font-family: 'Georgia', serif;
}

.story-textarea:focus {
    outline: none;
    border-color: #ff6b6b;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2);
}

.writing-tools {
    margin-top: 20px;
}

.word-suggestions {
    margin-bottom: 15px;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.suggestion-chip {
    background: var(--magic-gold);
    color: var(--text-white);
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-magic);
}

.suggestion-chip:hover {
    background: var(--magic-pink);
    transform: scale(1.1);
}

.prompt-btn {
    background: var(--magic-green);
    color: var(--text-white);
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition-magic);
    font-size: 0.9rem;
}

.prompt-text {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 12px;
    margin-top: 10px;
    font-style: italic;
    color: var(--text-light);
    min-height: 50px;
    display: flex;
    align-items: center;
}

.illustration-area {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    padding: 20px;
}

.drawing-canvas {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    padding: 15px;
}

.canvas-tools {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.tool-btn.active {
    background: var(--magic-pink);
    transform: scale(1.1);
}

#drawing-canvas {
    display: block;
    border: 2px solid var(--border-magic);
    border-radius: 8px;
    cursor: crosshair;
    width: 100%;
    max-width: 400px;
    height: auto;
}

/* Story Portal Styles */
.portal-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.story-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-btn {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border-magic);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition-magic);
    font-size: 0.9rem;
}

.filter-btn.active {
    background: var(--magic-purple);
    color: var(--text-white);
    border-color: transparent;
}

.filter-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.search-area {
    min-width: 250px;
}

.search-input {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--border-magic);
    border-radius: 25px;
    padding: 10px 20px;
    font-size: 1rem;
    width: 100%;
    transition: var(--transition-magic);
}

.story-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    min-height: 400px;
}

.story-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    padding: 20px;
    cursor: pointer;
    transition: var(--transition-magic);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.story-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-glow);
    border-color: #ff6b6b;
}

.story-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary-magic);
}

.story-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.story-author {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 12px;
}

.story-preview {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin-bottom: 15px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.story-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-light);
}

.story-genre {
    background: var(--magic-blue);
    color: var(--text-white);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
}

/* Voice Theater Styles */
.theater-stage {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.story-reader {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    padding: 30px;
    backdrop-filter: blur(5px);
}

.story-text {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--border-radius);
    padding: 20px;
    font-size: 1.1rem;
    line-height: 1.8;
    min-height: 300px;
    margin-bottom: 20px;
    font-family: 'Georgia', serif;
}

.highlighted-sentence {
    background: linear-gradient(120deg, #a8e6cf 0%, #dcedc8 100%);
    padding: 4px 8px;
    border-radius: 8px;
    animation: highlightPulse 2s ease-in-out infinite;
}

@keyframes highlightPulse {
    0%, 100% { background: linear-gradient(120deg, #a8e6cf 0%, #dcedc8 100%); }
    50% { background: linear-gradient(120deg, #ffab91 0%, #ffcc02 100%); }
}

.reading-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    align-items: center;
}

.nav-btn, .play-btn {
    background: var(--magic-blue);
    color: var(--text-white);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition-magic);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.play-btn {
    width: 60px;
    height: 60px;
    background: var(--magic-pink);
    font-size: 1.5rem;
}

.nav-btn:hover, .play-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-glow);
}

.voice-controls {
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius);
    padding: 20px;
}

.expression-meter h4 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.meter-bars {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.meter {
    display: flex;
    align-items: center;
    gap: 12px;
}

.meter label {
    min-width: 80px;
    font-size: 0.9rem;
    font-weight: 500;
}

.meter-fill {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.meter-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--fill-width, 0%);
    background: var(--primary-magic);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.voice-feedback {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    margin-top: 20px;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Achievement and Results Styles */
.achievement-display {
    text-align: center;
    padding: 40px 20px;
}

.achievement-icon {
    font-size: 6rem;
    margin-bottom: 20px;
    animation: achievementBounce 1s var(--animation-bounce);
}

@keyframes achievementBounce {
    0% { transform: scale(0) rotate(180deg); }
    50% { transform: scale(1.2) rotate(0deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.achievement-text {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 20px;
    background: var(--primary-magic);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.rewards-display {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.reward-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px 20px;
    border-radius: var(--border-radius);
    font-weight: 600;
    backdrop-filter: blur(5px);
}

.celebration-effects {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-magic);
    animation: confettiFall 3s linear;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

.results-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--background-card);
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-magic);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from { 
        transform: scale(0.8) translateY(-20px);
        opacity: 0;
    }
    to { 
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-magic);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    color: var(--text-light);
    transition: var(--transition-magic);
}

.close-btn:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.modal-body {
    padding: 20px;
}

.help-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.help-section {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 16px;
}

.help-section h4 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.help-section p {
    color: var(--text-light);
    line-height: 1.5;
    margin: 0;
}

/* Game Navigation */
.game-nav, .creator-nav, .portal-nav, .theater-nav {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 20px;
}

/* Special Effects */
.spell-effect {
    position: absolute;
    pointer-events: none;
    font-size: 2rem;
    animation: spellCast 2s ease-out forwards;
}

@keyframes spellCast {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: scale(1.5) rotate(360deg);
        opacity: 0;
    }
}

.magic-sparkle {
    position: absolute;
    color: #ffd700;
    animation: sparkle 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes sparkle {
    0%, 100% {
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: scale(1) rotate(180deg);
        opacity: 1;
    }
}

/* Plant Growth Animation for Grammar Gardens */
.plant-growth {
    animation: plantGrow 1.5s var(--animation-bounce) forwards;
    transform-origin: bottom center;
}

@keyframes plantGrow {
    0% { transform: scale(0) translateY(20px); }
    60% { transform: scale(1.1) translateY(-5px); }
    100% { transform: scale(1) translateY(0); }
}

/* Loading States */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--magic-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

/* User Messages */
.user-message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 20px;
    border-radius: var(--border-radius);
    color: var(--text-white);
    font-weight: 500;
    box-shadow: var(--shadow-magic);
    z-index: 1001;
    max-width: 400px;
    animation: messageSlideIn 0.3s ease;
    cursor: pointer;
}

@keyframes messageSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.user-message--error {
    background: linear-gradient(135deg, #e17055 0%, #d63031 100%);
}

.user-message--success {
    background: linear-gradient(135deg, #00b894 0%, #00a085 100%);
}

.user-message--warning {
    background: linear-gradient(135deg, #fdcb6e 0%, #f39c12 100%);
}

.user-message--info {
    background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
}

/* Responsive Design */
@media (max-width: 768px) {
    #app {
        padding: 10px;
    }
    
    .magical-frame {
        padding: 20px;
    }
    
    .title-sparkle {
        font-size: 2rem;
    }
    
    .menu-buttons {
        grid-template-columns: 1fr;
    }
    
    .game-header, .creator-header {
        flex-direction: column;
        text-align: center;
    }
    
    .story-metadata {
        grid-template-columns: 1fr;
    }
    
    .editor-panel {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .theater-stage {
        grid-template-columns: 1fr;
    }
    
    .garden-area {
        grid-template-columns: 1fr;
    }
    
    .portal-navigation {
        flex-direction: column;
        align-items: stretch;
    }
    
    .story-sprite {
        position: static;
        margin: 20px 0;
        max-width: none;
    }
    
    .player-info {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .magical-frame {
        padding: 15px;
    }
    
    .title-sparkle {
        font-size: 1.8rem;
    }
    
    .big-btn, .magical-btn {
        min-width: auto;
        width: 100%;
        font-size: 1rem;
        padding: 14px 20px;
    }
    
    .story-gallery {
        grid-template-columns: 1fr;
    }
    
    .avatar-options {
        gap: 8px;
    }
    
    .avatar-btn {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
    
    .game-stats {
        justify-content: center;
        text-align: center;
    }
    
    .modal-content {
        width: 95%;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --text-primary: #000000;
        --text-light: #333333;
        --background-card: #ffffff;
        --border-magic: #000000;
        --shadow-magic: 0 4px 8px rgba(0, 0, 0, 0.3);
    }
    
    .magical-btn, .big-btn {
        border: 2px solid #000000;
    }
    
    .spell-effects-area {
        border: 2px solid #000000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .magic-particles {
        animation: none;
    }
    
    .title-sparkle::after {
        animation: none;
    }
    
    .sprite-character {
        animation: none;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .screen:not(.active) {
        display: none !important;
    }
    
    .back-btn, .big-btn, .magical-btn {
        display: none;
    }
    
    .magic-particles {
        display: none;
    }
}

/* Focus Management for Accessibility */
.focus-trap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--magic-purple);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--magic-pink);
}

/* 🔧 CRITICAL VIEWPORT POSITIONING FIXES */
/* These fixes ensure content always appears at the top of the viewport when screens change */
html, body {
    margin: 0 !important;
    padding-top: 20px !important;
    padding-bottom: 0 !important;
}

.screen.active {
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
    align-self: flex-start !important;
    justify-self: center !important;
}

/* Fix for screens appearing below the viewport */
.screen {
    position: relative !important;
    top: 0 !important;
}

/* Additional viewport safety overrides */
#app {
    position: relative !important;
    top: 0 !important;
}

/* Force container positioning to prevent layout drift */
.magical-frame {
    position: relative !important;
    top: 0 !important;
    margin-top: 0 !important;
}