/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
}

/* Main container - responsive to iframe vs full window */
.game-container {
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Detect if in iframe and adjust height */
@media screen and (max-height: 500px) {
    .game-container {
        height: 450px;
    }
}

/* Screen management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease-in-out;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

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

.screen-content {
    padding: 20px;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Home Screen Styles */
.home-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.game-title {
    font-size: 2.5rem;
    color: #4a5568;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    font-size: 1.1rem;
    color: #718096;
    margin-bottom: 40px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 300px;
}

.menu-btn {
    padding: 15px 25px;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 50px;
}

.menu-btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.menu-btn.secondary {
    background: white;
    color: #4a5568;
    border: 2px solid #e2e8f0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

/* Avatar Selection */
.avatar-selection, .cca-selection, .goal-selection {
    margin: 20px 0;
    width: 100%;
    max-width: 500px;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

.avatar-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.avatar-option:hover, .avatar-option.selected {
    border-color: #667eea;
    background: #f7fafc;
    transform: translateY(-2px);
}

.avatar-img {
    font-size: 2rem;
    margin-bottom: 8px;
}

.cca-dropdown {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
}

.goal-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.goal-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.goal-option:hover {
    background: #f7fafc;
}

.start-btn {
    padding: 15px 30px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.start-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.start-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(72, 187, 120, 0.4);
}

/* Game Screen HUD */
.hud {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.meters {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.meter {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
    cursor: help;
}

.meter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 5px;
}

.meter-bar {
    width: 60px;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 3px;
}

.meter-fill {
    height: 100%;
    background: linear-gradient(90deg, #48bb78, #38a169);
    transition: width 0.5s ease;
    width: 50%;
}

.meter-value {
    font-size: 0.7rem;
    color: #718096;
}

.scene-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

#sceneTitle {
    font-weight: 600;
    color: #4a5568;
}

#dayCounter {
    font-size: 0.9rem;
    color: #718096;
}

/* Scene Panel */
.scene-panel {
    height: calc(100% - 80px);
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

.scene-image {
    flex: 0 0 150px;
    margin-bottom: 20px;
}

.scene-visual {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    border: 2px solid #e2e8f0;
}

.scene-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.scene-text {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
    line-height: 1.6;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.dialogue-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialogue-option {
    padding: 15px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    font-size: 1rem;
}

.dialogue-option:hover {
    border-color: #667eea;
    background: #f7fafc;
    transform: translateX(5px);
}

/* Task Panel */
.task-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 1000;
    max-height: 80%;
    overflow: hidden;
}

.task-panel.hidden {
    display: none;
}

.task-content {
    padding: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.task-area {
    flex: 1;
    overflow-y: auto;
    margin: 15px 0;
    padding: 15px;
    background: #f7fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.task-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.task-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.task-btn:not(.secondary) {
    background: #667eea;
    color: white;
}

.task-btn.secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.task-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Instructions and Glossary */
.instructions-content, .glossary-content {
    width: 100%;
    max-width: 600px;
}

.instruction-item {
    background: white;
    padding: 20px;
    margin: 15px 0;
    border-radius: 12px;
    border-left: 4px solid #667eea;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.instruction-item h3 {
    color: #4a5568;
    margin-bottom: 10px;
}

.glossary-search {
    margin-bottom: 20px;
}

.glossary-search input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
}

.glossary-list {
    display: grid;
    gap: 10px;
}

.glossary-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.glossary-term {
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 5px;
}

.glossary-definition {
    color: #718096;
    line-height: 1.5;
}

.back-btn {
    padding: 12px 24px;
    background: #4a5568;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 20px;
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: #2d3748;
    transform: translateY(-1px);
}

/* Restart button styling - added for end game functionality */
.restart-btn {
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* Final stats styling for end game */
.final-stats {
    background: #f7fafc;
    padding: 20px;
    border-radius: 12px;
    margin: 15px 0;
    border: 1px solid #e2e8f0;
}

.final-stats h3 {
    color: #4a5568;
    margin-bottom: 15px;
}

.final-stats p {
    margin: 8px 0;
    padding: 8px 12px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid #667eea;
}

.reflection {
    margin: 20px 0;
}

.reflection h3 {
    color: #4a5568;
    margin-bottom: 10px;
}

.reflection textarea {
    width: 100%;
    margin: 10px 0;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
}

.reflection textarea:focus {
    outline: none;
    border-color: #667eea;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 2000;
    max-width: 200px;
    word-wrap: break-word;
    transition: opacity 0.3s ease;
}

.tooltip.hidden {
    opacity: 0;
}

/* 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: 3000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

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

.modal-body {
    padding: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.modal-actions {
    padding: 20px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #718096;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .game-title {
        font-size: 2rem;
    }
    
    .hud {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .meters {
        justify-content: space-around;
    }
    
    .scene-panel {
        padding: 15px;
    }
    
    .scene-image {
        flex: 0 0 120px;
    }
    
    .avatar-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .menu-btn, .dialogue-option {
        font-size: 1rem;
        padding: 12px 20px;
    }
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
    .menu-btn, .dialogue-option, .avatar-option {
        min-height: 48px;
        padding: 15px;
    }
    
    .task-btn {
        min-height: 44px;
        padding: 12px 20px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .screen {
        background: white;
    }
    
    .menu-btn.secondary, .dialogue-option {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}