/* ===================================
   GLOBAL STYLES & RESET
   =================================== */

* {
    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-x: hidden;
    touch-action: manipulation; /* Optimize for touch */
}

/* ===================================
   MAIN CONTAINER
   =================================== */

#main-container {
    width: 100%;
    height: 450px; /* Default for iframe */
    display: flex;
    flex-direction: column;
    background: #ffffff;
    position: relative;
    overflow: hidden;
}

/* Detect if opened in new tab (use 90vh) */
@media (min-height: 600px) {
    body:not(.iframe-mode) #main-container {
        height: 90vh;
    }
}

/* ===================================
   HEADER TOOLTIP
   =================================== */

#header-tooltip {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
    white-space: nowrap;
}

#game-area:hover ~ #header-tooltip {
    opacity: 1;
}

/* ===================================
   GAME AREA
   =================================== */

#game-area {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* ===================================
   SCENARIO PANEL
   =================================== */

#scenario-panel {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-height: 60px;
}

#scenario-icon {
    font-size: 36px;
    flex-shrink: 0;
}

#scenario-text {
    font-size: 15px;
    line-height: 1.4;
    flex: 1;
}

/* ===================================
   CHALLENGE CARDS CONTAINER
   =================================== */

#challenge-cards-container {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 10px;
    border: 2px dashed #dee2e6;
}

#challenge-cards-container h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #495057;
}

#challenge-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 80px;
}

/* Challenge Card Styles */
.challenge-card {
    background: white;
    border: 2px solid #007bff;
    border-radius: 8px;
    padding: 10px 15px;
    cursor: move;
    cursor: grab;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    user-select: none;
    touch-action: none;
    min-width: 150px;
    max-width: 100%;
    font-size: 13px;
    line-height: 1.4;
}

.challenge-card:active {
    cursor: grabbing;
}

.challenge-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.challenge-card.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

.challenge-card.correct {
    border-color: #28a745;
    background: #d4edda;
}

.challenge-card.incorrect {
    border-color: #dc3545;
    background: #f8d7da;
    animation: shake 0.5s;
}

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

/* ===================================
   DROP ZONES CONTAINER
   =================================== */

#drop-zones-container {
    background: #e9ecef;
    padding: 12px;
    border-radius: 10px;
}

#drop-zones-container h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #495057;
}

#drop-zones {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

/* Drop Zone Styles */
.drop-zone {
    background: white;
    border: 3px dashed #6c757d;
    border-radius: 10px;
    padding: 12px;
    min-height: 100px;
    transition: all 0.3s ease;
}

.drop-zone-header {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 6px;
}

.drop-zone-icon {
    font-size: 18px;
}

.drop-zone-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 60px;
}

.drop-zone.drag-over {
    background: #e7f3ff;
    border-color: #007bff;
    border-style: solid;
    transform: scale(1.02);
}

/* ===================================
   CONTROLS
   =================================== */

#controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px; /* Touch-friendly */
    min-width: 100px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 36px;
    min-width: 80px;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 5px;
    min-height: 30px;
    min-width: 30px;
}

/* ===================================
   SCORE PANEL
   =================================== */

#score-panel {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
    background: #f8f9fa;
    padding: 12px;
    border-radius: 10px;
    border: 2px solid #dee2e6;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.score-label {
    font-size: 12px;
    color: #6c757d;
    font-weight: 600;
}

#score-value,
#level-value,
#progress-value {
    font-size: 20px;
    font-weight: 700;
    color: #007bff;
}

/* ===================================
   FEEDBACK MESSAGE
   =================================== */

#feedback-message {
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    display: none;
    animation: slideIn 0.3s ease;
}

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

#feedback-message.success {
    background: #d4edda;
    color: #155724;
    border: 2px solid #28a745;
    display: block;
}

#feedback-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 2px solid #dc3545;
    display: block;
}

#feedback-message.info {
    background: #d1ecf1;
    color: #0c5460;
    border: 2px solid #17a2b8;
    display: block;
}

/* ===================================
   ANALYTICS PANEL
   =================================== */

#analytics-panel {
    background: #f8f9fa;
    border-top: 3px solid #007bff;
    max-height: 200px;
    transition: max-height 0.3s ease;
    overflow: hidden;
}

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

#analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #e9ecef;
    cursor: pointer;
}

#analytics-header h3 {
    font-size: 14px;
    color: #495057;
    margin: 0;
}

#analytics-content {
    padding: 10px 15px;
    overflow-y: auto;
    max-height: 140px;
}

#analytics-log {
    font-size: 12px;
    line-height: 1.6;
    margin-bottom: 10px;
}

.analytics-entry {
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: white;
    border-left: 4px solid #007bff;
}

.analytics-entry.correct {
    border-left-color: #28a745;
    background: #d4edda;
}

.analytics-entry.incorrect {
    border-left-color: #dc3545;
    background: #f8d7da;
}

.analytics-entry-header {
    font-weight: 600;
    margin-bottom: 4px;
}

.analytics-entry-detail {
    font-size: 11px;
    color: #6c757d;
}

/* ===================================
   MODAL
   =================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.3s ease;
}

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

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 12px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    animation: slideDown 0.3s ease;
}

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

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-modal:hover {
    color: #000;
}

.modal-content h2 {
    margin-bottom: 15px;
    color: #007bff;
}

.modal-content h3 {
    margin-top: 15px;
    margin-bottom: 10px;
    color: #495057;
    font-size: 16px;
}

.instructions {
    font-size: 14px;
    line-height: 1.6;
}

.instructions ol,
.instructions ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.instructions li {
    margin-bottom: 8px;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */

@media (max-width: 768px) {
    #game-area {
        padding: 10px;
        gap: 10px;
    }

    #scenario-panel {
        padding: 12px;
        flex-direction: column;
        text-align: center;
    }

    #scenario-icon {
        font-size: 28px;
    }

    #scenario-text {
        font-size: 13px;
    }

    #drop-zones {
        grid-template-columns: 1fr;
    }

    .challenge-card {
        font-size: 12px;
        padding: 8px 12px;
    }

    .btn {
        font-size: 13px;
        padding: 8px 16px;
        min-width: 90px;
    }

    #score-panel {
        gap: 10px;
    }

    .score-label {
        font-size: 11px;
    }

    #score-value,
    #level-value,
    #progress-value {
        font-size: 18px;
    }

    .modal-content {
        margin: 20px;
        padding: 20px;
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    #controls {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        width: 100%;
    }

    #challenge-cards {
        flex-direction: column;
    }

    .challenge-card {
        width: 100%;
    }
}

/* ===================================
   ACCESSIBILITY
   =================================== */

/* Focus styles for keyboard navigation */
button:focus,
.challenge-card:focus {
    outline: 3px solid #007bff;
    outline-offset: 2px;
}

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

    .challenge-card {
        border-width: 3px;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}