/* =============================================================================
   Glos-Kingdom Builder - Main Stylesheet
   Mario-inspired bright and cheerful design
   ============================================================================= */

:root {
    /* Mario-inspired Color Palette */
    --primary-red: #E74C3C;
    --primary-blue: #3498DB;
    --bright-yellow: #F1C40F;
    --grass-green: #2ECC71;
    --sky-blue: #87CEEB;
    --gold: #FFD700;
    --orange: #FF8C00;
    --purple: #9B59B6;
    --white: #FFFFFF;
    --light-gray: #ECF0F1;
    --dark-gray: #34495E;
    --shadow: rgba(0, 0, 0, 0.2);
    
    /* Responsive breakpoints */
    --mobile: 768px;
    --tablet: 1024px;
    --desktop: 1200px;
}

/* =============================================================================
   Base Styles
   ============================================================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, var(--sky-blue) 0%, #98E4FF 100%);
    min-height: 100vh;
    overflow: hidden;
}

/* =============================================================================
   Screen Management
   ============================================================================= */

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 1;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* =============================================================================
   Main Menu Styles
   ============================================================================= */

#mainMenu {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--sky-blue) 0%, #98E4FF 50%, var(--grass-green) 100%);
}

.menu-container {
    background: var(--white);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 10px 30px var(--shadow);
    max-width: 600px;
    width: 90%;
    text-align: center;
    animation: menuAppear 0.6s ease-out;
}

@keyframes menuAppear {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.game-title {
    font-size: 2.5rem;
    color: var(--primary-red);
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px var(--shadow);
}

.game-subtitle {
    font-size: 1.2rem;
    color: var(--dark-gray);
    margin-bottom: 2rem;
}

.menu-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Kingdom Preview */
.kingdom-preview {
    margin: 1rem 0;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 200px;
    margin: 0 auto;
}

.preview-tile {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    animation: tileFloat 2s ease-in-out infinite;
}

.preview-tile:nth-child(2) { animation-delay: 0.5s; }
.preview-tile:nth-child(3) { animation-delay: 1s; }
.preview-tile:nth-child(4) { animation-delay: 1.5s; }

.preview-tile.grass {
    background: linear-gradient(135deg, var(--grass-green), #27AE60);
    color: var(--white);
}

.preview-tile.house {
    background: linear-gradient(135deg, var(--orange), #E67E22);
    color: var(--white);
}

.preview-tile.tree {
    background: linear-gradient(135deg, #228B22, var(--grass-green));
    color: var(--white);
}

.preview-tile.castle {
    background: linear-gradient(135deg, var(--purple), #8E44AD);
    color: var(--white);
}

@keyframes tileFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Game Info */
.game-info {
    background: var(--light-gray);
    border-radius: 12px;
    padding: 1rem;
    text-align: left;
}

.game-info h3 {
    color: var(--primary-blue);
    margin-bottom: 0.5rem;
}

.game-info ul {
    list-style: none;
    padding-left: 0;
}

.game-info li {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
}

/* Lesson Selector */
.lesson-selector {
    margin: 1rem 0;
}

.lesson-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
    color: var(--dark-gray);
}

.lesson-selector select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--primary-blue);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--white);
}

/* Save Selector */
.save-selector {
    background: var(--light-gray);
    border-radius: 12px;
    padding: 1rem;
}

.save-selector h4 {
    color: var(--primary-blue);
    margin-bottom: 1rem;
}

#saveSlots {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.save-slot {
    background: var(--white);
    border: 2px solid var(--primary-blue);
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-slot:hover {
    background: var(--primary-blue);
    color: var(--white);
    transform: translateY(-2px);
}

.save-slot.selected {
    background: var(--grass-green);
    color: var(--white);
    border-color: var(--grass-green);
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.menu-btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.menu-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 8px 15px var(--shadow);
}

.menu-btn:active:not(:disabled) {
    transform: translateY(0);
}

.menu-btn.primary {
    background: linear-gradient(135deg, var(--primary-red), #C0392B);
    color: var(--white);
}

.menu-btn.secondary {
    background: linear-gradient(135deg, var(--primary-blue), #2980B9);
    color: var(--white);
}

.menu-btn:disabled {
    background: var(--light-gray);
    color: var(--dark-gray);
    cursor: not-allowed;
    opacity: 0.6;
}

/* =============================================================================
   Game Screen Styles
   ============================================================================= */

#gameScreen {
    background: linear-gradient(135deg, var(--sky-blue) 0%, #98E4FF 100%);
}

/* Game Header */
.game-header {
    background: var(--white);
    box-shadow: 0 2px 10px var(--shadow);
    padding: 1rem;
    z-index: 100;
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Resources */
.resources {
    display: flex;
    gap: 1rem;
}

.resource {
    background: linear-gradient(135deg, var(--gold), #F39C12);
    color: var(--white);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: bold;
    box-shadow: 0 2px 8px var(--shadow);
}

.resource i {
    font-size: 1.2rem;
}

/* Lesson Info */
.lesson-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#gameLessonSelect {
    padding: 0.5rem;
    border: 2px solid var(--primary-blue);
    border-radius: 6px;
    background: var(--white);
}

/* Game Controls */
.game-controls {
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    background: var(--primary-blue);
    color: var(--white);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-small:hover {
    background: #2980B9;
    transform: translateY(-2px);
}

/* =============================================================================
   Game Main Area
   ============================================================================= */

.game-main {
    display: flex;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
    overflow: hidden;
}

/* Kingdom Container */
.kingdom-container {
    flex: 1;
    background: var(--white);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 15px var(--shadow);
    overflow: auto;
    position: relative;
}

/* Kingdom Grid */
.kingdom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
    gap: 2px;
    padding: 1rem;
    background: linear-gradient(45deg, #E8F5E8, #F0F8E8);
    border-radius: 8px;
    min-height: 600px;
}

.grid-tile {
    width: 48px;
    height: 48px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.grid-tile.empty {
    background: linear-gradient(135deg, #E8F5E8, #F0F8E8);
}

.grid-tile.empty:hover {
    background: var(--bright-yellow);
    transform: scale(1.1);
    box-shadow: 0 4px 8px var(--shadow);
}

.grid-tile.occupied {
    background: var(--white);
    box-shadow: 0 2px 8px var(--shadow);
}

.building {
    font-size: 1.5rem;
    animation: buildingSpawn 0.5s ease-out;
}

@keyframes buildingSpawn {
    from {
        opacity: 0;
        transform: scale(0) rotate(180deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

/* Sidebar */
.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Building Palette */
.building-palette {
    background: var(--white);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 15px var(--shadow);
}

.building-palette h3 {
    color: var(--primary-blue);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.building-list {
    display: grid;
    gap: 0.5rem;
}

.building-item {
    background: var(--light-gray);
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.building-item:hover {
    background: var(--primary-blue);
    color: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.building-item.selected {
    background: var(--grass-green);
    color: var(--white);
    border-color: var(--grass-green);
}

.building-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.building-item i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

.building-item .name {
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.building-item .cost {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Kingdom Stats */
.kingdom-stats {
    background: var(--white);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 4px 15px var(--shadow);
}

.kingdom-stats h3 {
    color: var(--primary-blue);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    background: var(--light-gray);
    border-radius: 6px;
}

/* Stat Animation */
.stat-anim {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(1.2);
    background: rgba(255,255,255,0.95);
    color: #222;
    border-radius: 12px;
    padding: 4px 12px;
    font-size: 1.1em;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    pointer-events: none;
    z-index: 10;
    animation: statAnimUp 1.2s ease-out forwards;
}

@keyframes statAnimUp {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
    10% { opacity: 1; }
    80% { opacity: 1; transform: translate(-50%, -80%) scale(1.0); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(0.9); }
}

/* =============================================================================
   Modal Styles
   ============================================================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--white);
    border-radius: 15px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: modalAppear 0.3s ease-out;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--light-gray);
    padding-bottom: 1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--dark-gray);
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: var(--primary-red);
    color: var(--white);
}

/* =============================================================================
   Quiz Modal Styles
   ============================================================================= */

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.quiz-header h3 {
    color: var(--primary-blue);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.quiz-progress {
    background: var(--light-gray);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: bold;
}

.question-display {
    text-align: center;
    margin-bottom: 2rem;
}

.question-display h4 {
    font-size: 1.3rem;
    color: var(--dark-gray);
    margin-bottom: 1rem;
}

.language-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.language-indicator span {
    background: var(--light-gray);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: bold;
}

.answer-options {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
}

.answer-btn {
    padding: 1rem;
    border: 2px solid var(--primary-blue);
    border-radius: 10px;
    background: var(--white);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.answer-btn:hover {
    background: var(--primary-blue);
    color: var(--white);
    transform: translateY(-2px);
}

.answer-btn.correct {
    background: var(--grass-green);
    border-color: var(--grass-green);
    color: var(--white);
}

.answer-btn.incorrect {
    background: var(--primary-red);
    border-color: var(--primary-red);
    color: var(--white);
}

.quiz-feedback {
    text-align: center;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-weight: bold;
    display: none;
}

.quiz-feedback.correct {
    background: var(--grass-green);
    color: var(--white);
}

.quiz-feedback.incorrect {
    background: var(--primary-red);
    color: var(--white);
}

.quiz-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.quiz-reward {
    background: var(--gold);
    color: var(--white);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: bold;
}

/* =============================================================================
   Building Modal Styles
   ============================================================================= */

.building-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.building-header h3 {
    color: var(--primary-blue);
}

.building-info {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

.building-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-blue), #2980B9);
    color: var(--white);
    border-radius: 15px;
    font-size: 2rem;
}

.building-details {
    flex: 1;
}

.building-details p {
    margin-bottom: 1rem;
    color: var(--dark-gray);
}

.building-cost,
.building-effects {
    margin-bottom: 1rem;
}

.building-cost span:first-child,
.building-effects span:first-child {
    font-weight: bold;
    display: block;
    margin-bottom: 0.5rem;
}

.cost-breakdown,
.effect-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cost-breakdown span,
.effect-list span {
    background: var(--light-gray);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.9rem;
}

.building-actions {
    display: flex;
    gap: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--grass-green), #27AE60);
    color: var(--white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn-secondary {
    background: var(--light-gray);
    color: var(--dark-gray);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: var(--dark-gray);
    color: var(--white);
}

/* =============================================================================
   Instructions Modal
   ============================================================================= */

.instructions-content {
    max-height: 400px;
    overflow-y: auto;
}

.instruction-section {
    margin-bottom: 2rem;
}

.instruction-section h4 {
    color: var(--primary-blue);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.instruction-section ul {
    list-style: none;
    padding-left: 0;
}

.instruction-section li {
    margin: 0.5rem 0;
    padding: 0.5rem;
    background: var(--light-gray);
    border-radius: 6px;
}

/* =============================================================================
   Loading Screen
   ============================================================================= */

#loadingScreen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--sky-blue) 0%, var(--grass-green) 100%);
}

.loading-content {
    text-align: center;
    color: var(--white);
}

.loading-spinner {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.loading-content h2 {
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px var(--shadow);
}

/* =============================================================================
   Notification System
   ============================================================================= */

#notificationContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.notification {
    background: var(--white);
    border-left: 4px solid var(--primary-blue);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    max-width: 300px;
    animation: notificationSlide 0.3s ease-out;
}

.notification.success {
    border-left-color: var(--grass-green);
}

.notification.error {
    border-left-color: var(--primary-red);
}

.notification.warning {
    border-left-color: var(--bright-yellow);
}

@keyframes notificationSlide {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* =============================================================================
   Responsive Design
   ============================================================================= */

@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
    }
    
    .kingdom-grid {
        grid-template-columns: repeat(8, 1fr);
        gap: 1px;
    }
    
    .grid-tile {
        width: 32px;
        height: 32px;
    }
    
    .modal-content {
        padding: 1rem;
        margin: 1rem;
    }
    
    .resources {
        flex-wrap: wrap;
    }
    
    .game-info {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 1.8rem;
    }
    
    .menu-container {
        padding: 1rem;
    }
    
    .kingdom-grid {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .grid-tile {
        width: 28px;
        height: 28px;
    }
}

/* =============================================================================
   Special Effects & Animations
   ============================================================================= */

.sparkle {
    animation: sparkle 1s ease-in-out;
}

@keyframes sparkle {
    0%, 100% { 
        filter: brightness(1) hue-rotate(0deg);
    }
    50% { 
        filter: brightness(1.5) hue-rotate(180deg);
        transform: scale(1.1);
    }
}

.coin-effect {
    animation: coinCollect 0.8s ease-out;
}

@keyframes coinCollect {
    0% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px) scale(1.5);
        opacity: 0;
    }
}

.knowledge-boost {
    animation: knowledgeGlow 1s ease-in-out;
}

@keyframes knowledgeGlow {
    0%, 100% { 
        box-shadow: 0 0 5px var(--primary-blue);
    }
    50% { 
        box-shadow: 0 0 20px var(--primary-blue), 0 0 30px var(--primary-blue);
    }
}

/* =============================================================================
   Print Styles
   ============================================================================= */

@media print {
    .screen:not(.active) {
        display: none !important;
    }
    
    .modal {
        display: none !important;
    }
    
    body {
        background: white !important;
    }
}