/* 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;
    height: 100vh;
    font-size: 14px;
}

/* Responsive height handling */
@media (max-height: 500px) {
    body {
        height: 450px;
    }
}

@media (min-height: 501px) and (min-width: 768px) {
    body {
        height: 90vh;
    }
}

/* Game Container */
#gameContainer {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "mode progress settings"
        "map map map"
        "challenge challenge challenge";
    gap: 8px;
    padding: 8px;
}

/* Panel Base Styles */
.panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Mode Panel */
#modePanel {
    grid-area: mode;
}

.mode-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-height: 40px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(145deg, #f0f0f0, #e0e0e0);
    color: #333;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.mode-btn.active {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

/* Progress Panel */
#progressPanel {
    grid-area: progress;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.stat-item {
    text-align: center;
    flex: 1;
}

.stat-label {
    display: block;
    font-size: 10px;
    color: #666;
    margin-bottom: 2px;
}

.stat-item span:last-child {
    font-weight: bold;
    font-size: 14px;
    color: #2196F3;
}

.badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.badge {
    background: linear-gradient(145deg, #FFD700, #FFA500);
    color: #333;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Map Container */
#mapContainer {
    grid-area: map;
    overflow: hidden;
}

.mrt-map {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 10px;
    padding: 10px;
}

.mrt-line {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    position: relative;
    padding: 10px;
    border-radius: 8px;
}

.ns-line {
    background: linear-gradient(180deg, rgba(255, 0, 0, 0.1), rgba(255, 0, 0, 0.05));
    border-left: 4px solid #FF0000;
}

.ew-line {
    background: linear-gradient(180deg, rgba(0, 128, 0, 0.1), rgba(0, 128, 0, 0.05));
    border-left: 4px solid #008000;
}

.cc-line {
    background: linear-gradient(180deg, rgba(255, 165, 0, 0.1), rgba(255, 165, 0, 0.05));
    border-left: 4px solid #FFA500;
}

.dt-line {
    background: linear-gradient(180deg, rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.05));
    border-left: 4px solid #0000FF;
}

.station-node {
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 4px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.station-node:hover {
    transform: scale(1.05);
}

.station-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    border: 3px solid;
    margin-right: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ns-line .station-dot { border-color: #FF0000; }
.ew-line .station-dot { border-color: #008000; }
.cc-line .station-dot { border-color: #FFA500; }
.dt-line .station-dot { border-color: #0000FF; }

.station-label {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    color: #333;
}

.station-node.completed .station-dot {
    background: #4CAF50;
}

.station-node.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Challenge Panel */
#challengePanel {
    grid-area: challenge;
    position: relative;
}

.challenge-content {
    text-align: center;
}

.question-text {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    color: #2196F3;
}

.sound-btn {
    background: linear-gradient(145deg, #FF9800, #F57C00);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    margin-bottom: 15px;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.sound-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 152, 0, 0.3);
}

.input-container {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
}

#answerInput {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    width: 200px;
    text-align: center;
}

#answerInput:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
}

.submit-btn, .next-btn, .back-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    min-height: 40px;
}

.submit-btn {
    background: linear-gradient(145deg, #2196F3, #1976D2);
    color: white;
}

.next-btn {
    background: linear-gradient(145deg, #4CAF50, #45a049);
    color: white;
}

.back-btn {
    background: linear-gradient(145deg, #757575, #616161);
    color: white;
}

.submit-btn:hover, .next-btn:hover, .back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.mcq-container {
    margin-bottom: 15px;
}

.mcq-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
}

.mcq-option {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    text-align: center;
    font-size: 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mcq-option:hover {
    border-color: #2196F3;
    background: #f0f8ff;
}

.mcq-option.selected {
    background: #2196F3;
    color: white;
    border-color: #1976D2;
}

.feedback {
    margin: 15px 0;
    padding: 10px;
    border-radius: 8px;
    font-weight: bold;
    min-height: 20px;
}

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

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Settings Panel */
.settings-toggle {
    grid-area: settings;
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
}

#settingsBtn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#settingsBtn:hover {
    transform: rotate(90deg);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.settings-menu {
    position: absolute;
    top: 45px;
    right: 0;
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    z-index: 1000;
}

.settings-menu label {
    display: block;
    margin-bottom: 10px;
    font-size: 12px;
    color: #333;
}

.settings-menu input[type="checkbox"] {
    margin-right: 8px;
}

.settings-menu input[type="range"] {
    width: 100%;
    margin-top: 5px;
}

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

/* Utility Classes */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

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

/* High Contrast Mode */
.high-contrast {
    filter: contrast(150%) brightness(120%);
}

.high-contrast .panel {
    background: #ffffff;
    border: 2px solid #000000;
}

.high-contrast .station-node {
    border: 2px solid #000000;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #gameContainer {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "mode"
            "progress"
            "map"
            "challenge"
            "settings";
    }
    
    .mode-buttons {
        justify-content: center;
    }
    
    .mode-btn {
        min-width: 80px;
        font-size: 11px;
    }
    
    .mrt-map {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, 1fr);
    }
    
    .mrt-line {
        flex-direction: row;
        padding: 5px;
    }
    
    .station-label {
        font-size: 10px;
    }
    
    .question-text {
        font-size: 16px;
    }
    
    #answerInput {
        width: 150px;
        font-size: 14px;
    }
}

/* Touch-friendly sizing */
@media (pointer: coarse) {
    .station-node {
        min-height: 48px;
        padding: 4px;
    }
    
    .mode-btn {
        min-height: 48px;
    }
    
    .mcq-option {
        min-height: 48px;
        padding: 15px;
    }
    
    .submit-btn, .next-btn, .back-btn {
        min-height: 48px;
        padding: 12px 24px;
    }
}