/* 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, #e8f5e8 0%, #d4f1d4 100%);
    overflow: hidden;
}

/* Main container - responsive to iframe vs full screen */
#gameContainer {
    width: 100%;
    height: 450px; /* Default iframe height */
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 8px;
}

/* Full screen mode detection */
@media (min-height: 500px) {
    #gameContainer {
        height: 90vh;
        padding: 12px;
    }
}

/* Progress bar */
#progressBar {
    width: 100%;
    height: 25px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    position: relative;
    margin-bottom: 8px;
    cursor: pointer;
}

#progressFill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #45a049);
    border-radius: 12px;
    width: 25%; /* Level 1 progress */
    transition: width 0.5s ease;
}

#progressText {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #2c5530;
    font-weight: bold;
    font-size: 12px;
}

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

#headerTooltip {
    top: 35px;
    left: 50%;
    transform: translateX(-50%);
}

/* Game mascot */
#gameMascot {
    position: absolute;
    top: 35px;
    right: 15px;
    z-index: 100;
}

#mascotCharacter {
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s ease;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
}

#mascotCharacter:hover {
    transform: scale(1.1);
}

#mascotSpeech {
    position: absolute;
    top: -40px;
    right: 30px;
    background: white;
    border: 2px solid #4CAF50;
    border-radius: 15px;
    padding: 8px 12px;
    max-width: 180px;
    font-size: 11px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

#mascotSpeech.show {
    opacity: 1;
    transform: translateY(0);
}

#mascotSpeech::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 15px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid white;
}

/* Instructions panel */
#instructionsPanel {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#instructionText {
    flex: 1;
    font-size: 14px;
    color: #2c5530;
    font-weight: 500;
}

/* Buttons */
.button {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    white-space: nowrap;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.button:active {
    transform: translateY(0);
}

.button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Main game area */
#gameArea {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Food chain builder */
#foodChainBuilder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 15px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.chain-slot {
    width: 80px;
    height: 80px;
    border: 3px dashed #4CAF50;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
    position: relative;
}

.chain-slot.drag-over {
    border-color: #2196F3;
    background: rgba(33, 150, 243, 0.1);
    transform: scale(1.05);
}

.chain-slot.filled {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.1);
}

.chain-slot.correct {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.2);
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.5);
}

.chain-slot.incorrect {
    border-color: #f44336;
    background: rgba(244, 67, 54, 0.1);
    animation: shake 0.5s ease-in-out;
}

.slot-hint {
    font-size: 10px;
    color: #666;
    text-align: center;
    margin-top: 4px;
}

.arrow {
    font-size: 20px;
    color: #4CAF50;
    font-weight: bold;
}

/* Organism bank */
#organismBank {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#organismBank h3 {
    font-size: 14px;
    color: #2c5530;
    margin-bottom: 8px;
    text-align: center;
}

#organisms {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.organism {
    width: 70px;
    height: 70px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.organism:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    border-color: #4CAF50;
}

.organism:active {
    cursor: grabbing;
}

.organism.dragging {
    opacity: 0.7;
    transform: rotate(5deg);
}

.organism-icon {
    font-size: 24px;
    margin-bottom: 2px;
}

.organism-name {
    font-size: 10px;
    font-weight: bold;
    color: #2c5530;
    text-align: center;
}

.organism-tooltip {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.organism:hover .organism-tooltip {
    opacity: 1;
}

/* Feedback panel */
#feedbackPanel {
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 8px 0;
}

#feedbackMessage {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#feedbackMessage.show {
    opacity: 1;
    transform: translateY(0);
}

#feedbackMessage.success {
    background: rgba(76, 175, 80, 0.9);
    color: white;
}

#feedbackMessage.error {
    background: rgba(244, 67, 54, 0.9);
    color: white;
}

/* Control panel */
#controlPanel {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

/* Glossary */
#glossaryPanel {
    position: absolute;
    bottom: 15px;
    left: 15px;
    z-index: 200;
}

#glossaryContent {
    position: absolute;
    bottom: 45px;
    left: 0;
    background: white;
    border: 2px solid #4CAF50;
    border-radius: 10px;
    padding: 12px;
    width: 250px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#glossaryContent.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.glossary-item {
    margin-bottom: 8px;
    font-size: 11px;
    line-height: 1.4;
}

.glossary-item:last-child {
    margin-bottom: 0;
}

/* Success modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 24px;
    text-align: center;
    max-width: 300px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    color: #4CAF50;
    margin-bottom: 12px;
    font-size: 20px;
}

.modal-content p {
    margin-bottom: 12px;
    color: #666;
    font-size: 14px;
}

#starRating {
    font-size: 24px;
    margin: 12px 0;
}

.modal-content .button {
    margin: 6px;
    min-width: 120px;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

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

@keyframes celebration {
    0% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(5deg); }
    50% { transform: scale(1.2) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); }
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    #gameContainer {
        padding: 6px;
    }
    
    .chain-slot {
        width: 60px;
        height: 60px;
    }
    
    .organism {
        width: 55px;
        height: 55px;
    }
    
    .organism-icon {
        font-size: 20px;
    }
    
    .organism-name {
        font-size: 9px;
    }
    
    .button {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    #instructionText {
        font-size: 12px;
    }
}

/* Touch-friendly enhancements */
@media (hover: none) and (pointer: coarse) {
    .organism {
        min-height: 44px;
        min-width: 44px;
    }
    
    .button {
        min-height: 44px;
        min-width: 44px;
    }
    
    .chain-slot {
        min-width: 60px;
        min-height: 60px;
    }
}