/* ===========================
   GLOBAL STYLES & RESET
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* ===========================
   MAIN GAME CONTAINER
   =========================== */
#gameContainer {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Check if running in iframe */
@media (max-height: 500px) {
    #gameContainer {
        height: 450px;
    }
}

/* ===========================
   TITLE BAR (COLLAPSIBLE)
   =========================== */
.title-bar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    z-index: 100;
}

.title-bar.collapsed {
    padding: 4px 16px;
    font-size: 0;
}

.title-bar.collapsed #titleText {
    display: none;
}

.icon-btn {
    background: rgba(255,255,255,0.3);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
}

.icon-btn:active {
    background: rgba(255,255,255,0.5);
    transform: scale(0.95);
}

/* ===========================
   GAME CANVAS (MAP AREA)
   =========================== */
.game-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(180deg, #87CEEB 0%, #98D8C8 50%, #F7DC6F 100%);
}

.map-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 20% 30%, rgba(46, 204, 113, 0.4) 0%, transparent 50%),
        radial-gradient(circle at 80% 60%, rgba(52, 152, 219, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(241, 196, 15, 0.3) 0%, transparent 50%);
    pointer-events: none;
}

/* ===========================
   AVATAR CHARACTER
   =========================== */
.avatar {
    position: absolute;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #FF6B6B 0%, #FFE66D 100%);
    border-radius: 50%;
    border: 4px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.avatar::before {
    content: '🐱';
}

.avatar.moving {
    animation: bounce 0.5s ease;
}

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

/* ===========================
   PROGRESS TRACKER
   =========================== */
.progress-tracker {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(255,255,255,0.95);
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 50;
}

.progress-label {
    font-weight: bold;
    color: #2c3e50;
    font-size: 14px;
}

.progress-bar-container {
    width: 120px;
    height: 20px;
    background: #ecf0f1;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid #bdc3c7;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #56CCF2 0%, #2F80ED 100%);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 8px;
}

.progress-text {
    font-weight: bold;
    color: #2c3e50;
    font-size: 14px;
}

/* ===========================
   SCORE DISPLAY
   =========================== */
.score-display {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.95);
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 50;
}

.score-icon {
    font-size: 24px;
}

#scoreValue {
    font-weight: bold;
    font-size: 20px;
    color: #f39c12;
}

/* ===========================
   LEVEL INDICATOR
   =========================== */
.level-indicator {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 50;
}

/* ===========================
   CHECKPOINTS (ISLANDS)
   =========================== */
.checkpoints-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.checkpoint {
    position: absolute;
    width: 70px;
    height: 70px;
    cursor: pointer;
    pointer-events: all;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
    min-width: 48px;
    min-height: 48px;
}

.checkpoint:active {
    transform: scale(1.1);
}

.checkpoint.locked {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%) drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.checkpoint.completed {
    opacity: 0.6;
}

.checkpoint.current {
    animation: pulse 1.5s infinite;
}

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

.checkpoint-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.9);
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: bold;
    color: #2c3e50;
    white-space: nowrap;
    pointer-events: none;
}

/* ===========================
   QUESTION PANEL (MCQ)
   =========================== */
.question-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-width: 90%;
    width: 600px;
    max-height: 80%;
    overflow-y: auto;
    z-index: 200;
    transition: all 0.3s ease;
}

.question-panel.hidden,
.drag-drop-panel.hidden {
    display: none;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #ecf0f1;
}

#questionNumber,
#paragraphNumber {
    font-weight: bold;
    color: #2c3e50;
    font-size: 16px;
}

.close-btn {
    background: #e74c3c;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:active {
    background: #c0392b;
    transform: scale(0.95);
}

.question-text {
    font-size: 16px;
    line-height: 1.6;
    color: #2c3e50;
    margin-bottom: 20px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid #3498db;
}

.options-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    min-height: 52px;
    line-height: 1.4;
}

.option-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.option-btn.correct {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    animation: correctPulse 0.5s ease;
}

.option-btn.wrong {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    animation: shake 0.5s ease;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* ===========================
   FEEDBACK PANEL
   =========================== */
.feedback-panel {
    margin-top: 20px;
    padding: 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    animation: slideIn 0.3s ease;
}

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

.feedback-panel.correct {
    background: #d4edda;
    color: #155724;
    border: 2px solid #c3e6cb;
}

.feedback-panel.wrong {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #f5c6cb;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===========================
   DRAG-DROP PANEL (LEVEL 2)
   =========================== */
.drag-drop-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    max-width: 90%;
    width: 700px;
    max-height: 85%;
    overflow-y: auto;
    z-index: 200;
}

.paragraph-text {
    font-size: 16px;
    line-height: 1.8;
    color: #2c3e50;
    margin-bottom: 20px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 12px;
    border-left: 4px solid #9b59b6;
}

.drop-zone {
    display: inline-block;
    min-width: 180px;
    min-height: 40px;
    padding: 8px 12px;
    margin: 0 4px;
    background: #fff3cd;
    border: 2px dashed #ffc107;
    border-radius: 8px;
    vertical-align: middle;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.drop-zone.filled {
    background: #d1ecf1;
    border: 2px solid #17a2b8;
}

.drop-zone.correct {
    background: #d4edda;
    border: 2px solid #28a745;
}

.drop-zone.wrong {
    background: #f8d7da;
    border: 2px solid #dc3545;
}

.drop-zone.drag-over {
    background: #e2e3e5;
    border-color: #6c757d;
    transform: scale(1.05);
}

.drop-zone-content {
    font-weight: bold;
    color: #495057;
    font-size: 14px;
    text-align: center;
}

.drag-options-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
    padding: 16px;
    background: #f1f3f5;
    border-radius: 12px;
}

.drag-option {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 10px;
    cursor: move;
    user-select: none;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    font-size: 14px;
    font-weight: 500;
    min-width: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.drag-option:active {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
    cursor: grabbing;
}

.drag-option.dragging {
    opacity: 0.5;
}

.drag-option.used {
    opacity: 0.3;
    cursor: not-allowed;
}

.drag-option.selected {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(240, 147, 251, 0.6);
}

.check-btn {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    min-height: 48px;
    width: 100%;
}

.check-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.check-btn.hidden {
    display: none;
}

/* ===========================
   CELEBRATION OVERLAY
   =========================== */
.celebration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    animation: fadeIn 0.5s ease;
}

.celebration-overlay.hidden {
    display: none;
}

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

.celebration-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 500px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.4);
    animation: zoomIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes zoomIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.celebration-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotate 1s ease-in-out infinite;
}

@keyframes rotate {
    0%, 100% { transform: rotate(-10deg); }
    50% { transform: rotate(10deg); }
}

.celebration-content h2 {
    color: #2c3e50;
    font-size: 32px;
    margin-bottom: 16px;
}

.celebration-content p {
    color: #7f8c8d;
    font-size: 18px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    min-height: 52px;
}

.primary-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.victory-content {
    width: 600px;
}

.final-score {
    font-size: 24px;
    font-weight: bold;
    color: #f39c12;
    margin: 20px 0;
}

.badges-earned {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 20px 0;
    font-size: 48px;
}

/* ===========================
   ANALYTICS PANEL
   =========================== */
.analytics-panel {
    background: rgba(255,255,255,0.98);
    border-top: 3px solid #3498db;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    z-index: 150;
    max-height: 200px;
}

.analytics-panel.collapsed {
    max-height: 44px;
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #ecf0f1;
    font-weight: bold;
    color: #2c3e50;
    cursor: pointer;
}

.analytics-controls {
    display: flex;
    gap: 8px;
}

.analytics-btn {
    background: rgba(52, 152, 219, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.analytics-btn:active {
    background: rgba(52, 152, 219, 0.4);
    transform: scale(0.95);
}

.analytics-content {
    padding: 12px 16px;
    overflow-y: auto;
    max-height: 150px;
}

.device-info {
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}

.action-log {
    font-size: 13px;
    line-height: 1.6;
    color: #2c3e50;
}

.log-entry {
    padding: 6px 8px;
    margin-bottom: 4px;
    background: #f8f9fa;
    border-left: 3px solid #3498db;
    border-radius: 4px;
}

.log-entry.correct {
    border-left-color: #27ae60;
    background: #d4edda;
}

.log-entry.wrong {
    border-left-color: #e74c3c;
    background: #f8d7da;
}

.log-timestamp {
    font-weight: bold;
    color: #7f8c8d;
    margin-right: 8px;
}

/* ===========================
   TOOLTIP (LEARNING HINTS)
   =========================== */
.tooltip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    max-width: 90%;
    width: 400px;
    z-index: 400;
    animation: fadeIn 0.3s ease;
}

.tooltip.hidden {
    display: none;
}

.tooltip-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #e74c3c;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tooltip-close-btn:active {
    background: #c0392b;
    transform: scale(0.95);
}

.tooltip-content {
    font-size: 15px;
    line-height: 1.6;
    color: #2c3e50;
    padding-right: 24px;
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (max-width: 768px) {
    .question-panel,
    .drag-drop-panel {
        width: 95%;
        padding: 16px;
    }
    
    .celebration-content {
        padding: 24px;
        width: 90%;
    }
    
    .progress-bar-container {
        width: 80px;
    }
    
    .checkpoint {
        width: 60px;
        height: 60px;
        font-size: 32px;
    }
}

@media (hover: none) and (pointer: coarse) {
    /* Touch device optimizations */
    .option-btn,
    .drag-option,
    .check-btn,
    .primary-btn {
        min-height: 52px;
        padding: 16px 20px;
    }
    
    .checkpoint {
        min-width: 54px;
        min-height: 54px;
    }
}

/* ===========================
   ACCESSIBILITY
   =========================== */
:focus {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

button:focus-visible {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .option-btn,
    .drag-option,
    .primary-btn {
        border: 2px solid currentColor;
    }
}