* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #fff;
    min-height: 100vh;
    padding: 16px;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 32px);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    flex-shrink: 0;
}

.page-header h1 {
    font-size: 2.1rem;
    letter-spacing: 0.02em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header-controls button {
    padding: 12px;
    font-size: 1.5rem;
    min-width: 60px;
    text-align: center;
}

.main-content {
    display: flex;
    gap: 18px;
    flex-grow: 1;
    overflow: hidden;
}

.game-container {
    position: relative;
    display: flex;
    flex-grow: 1;
}

#gameCanvas {
    background: #1a1a1a;
    border: 3px solid #fff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    cursor: crosshair;
    width: 100%;
    height: 100%;
}

.sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 5px;
}

/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.stats-panel,
.track-selector,
.button-panel,
.network-visualizer-panel {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 15px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.panel-header.collapsible {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.panel-header.collapsible:hover {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    margin: -5px -5px 12px -5px;
    padding: 5px 5px 8px 5px;
}

.panel-header h3 {
    font-size: 1.2rem;
    margin: 0;
}

.collapse-icon {
    font-size: 0.9rem;
    transition: transform 0.3s ease;
}

.panel-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.panel-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.panel-content.collapsed {
    max-height: 0;
    opacity: 0;
}

.stats-panel p {
    margin: 5px 0;
    font-size: 0.95rem;
}

.stats-panel span {
    color: #4CAF50;
    font-weight: bold;
    font-size: 1.1rem;
}

/* Network Visualizer Panel */
.network-visualizer-panel {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 15px;
    margin-top: 18px;
}

.network-viz-container {
    position: relative;
    width: 100%;
    height: 350px;
    background: rgba(20, 20, 30, 0.8);
    border-radius: 8px;
    overflow: hidden;
}

#networkCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.network-viz-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.95rem;
    text-align: center;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
    max-width: 90%;
}

.network-viz-hint p {
    margin: 8px 0;
    line-height: 1.5;
}

.network-viz-hint strong {
    color: #4CAF50;
}

.network-viz-container.active .network-viz-hint {
    opacity: 0;
}

.button-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: center;
}

button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 25px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

button.secondary {
    background: linear-gradient(135deg, #34c759 0%, #2f9e44 100%);
}

button.ghost {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow: none;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

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

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.active {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    box-shadow: 0 0 20px rgba(40, 167, 69, 0.6);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 20px rgba(40, 167, 69, 0.6); }
    50% { box-shadow: 0 0 30px rgba(40, 167, 69, 0.8); }
}

button.shake {
    animation: button-shake 0.35s ease;
}

/* Track Selector Styles */
.track-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.track-selector select {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 10px;
    font-size: 0.95rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.track-selector select:hover {
    background: rgba(255, 255, 255, 0.2);
}

.track-selector select option {
    background: #2a5298;
    color: white;
}

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

.track-change-btn,
.track-reset-btn {
    padding: 10px 15px;
    font-size: 0.9rem;
    margin-top: 5px;
}

.track-change-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    padding: 2px 10px;
    font-size: 0.95rem;
    flex: 1;
}

.track-reset-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 12px 16px;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

.track-reset-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes button-shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    50% { transform: translateX(4px); }
    75% { transform: translateX(-3px); }
    100% { transform: translateX(0); }
}

@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .track-selector, .stats-panel, .button-panel, .network-visualizer-panel {
        flex-basis: 300px;
        flex-grow: 1;
    }
    
    .network-visualizer-panel {
        width: 100%;
        flex-basis: 100%;
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        gap: 12px;
    }
    .page-header h1 {
        font-size: 1.7rem;
    }
    
    .sidebar {
        flex-direction: column;
    }
    
    .track-selector, .stats-panel, .button-panel, .network-visualizer-panel {
        width: 100%;
    }
    
    .network-viz-container {
        height: 300px;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease;
}

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

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

.modal-content {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    background: rgba(255, 255, 255, 0.1);
    padding: 25px 30px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 15px;
    position: relative;
}

.modal-header h2 {
    margin: 0;
    color: white;
    font-size: 1.8rem;
}

.success-icon,
.settings-icon {
    font-size: 2.5rem;
}

.close-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 30px;
}

/* Success Modal */
.success-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin: 25px 0;
}

.stat-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-label {
    display: block;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    color: #4CAF50;
    font-size: 2rem;
    font-weight: bold;
}

.success-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
    line-height: 1.6;
    margin: 20px 0;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.modal-btn {
    flex: 1;
    min-width: 120px;
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-btn.secondary {
    background: linear-gradient(135deg, #34c759 0%, #2f9e44 100%);
    color: white;
}

.modal-btn:not(.primary):not(.secondary) {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

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

/* Settings Modal */
.settings-modal {
    max-width: 700px;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h3 {
    color: white;
    font-size: 1.3rem;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.setting-item {
    margin-bottom: 25px;
}

.setting-item label {
    display: block;
    color: white;
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 8px;
}

.setting-item input[type="number"],
.setting-item input[type="range"] {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
}

.setting-item input[type="number"]:focus,
.setting-item input[type="range"]:focus {
    outline: none;
    border-color: #667eea;
    background: rgba(255, 255, 255, 0.2);
}

.setting-item input[type="range"] {
    padding: 0;
    height: 8px;
}

.setting-hint {
    display: block;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    margin-top: 5px;
    font-style: italic;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.checkbox-label span {
    color: white;
    font-weight: normal;
}

@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .modal-header {
        padding: 20px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-btn {
        width: 100%;
    }
    
    .success-stats {
        grid-template-columns: 1fr;
    }
}
