/* ===== CSS Variables (Material Design Colors) ===== */
:root {
    /* Colors matching the Java app */
    --color-start: #4A90E2;
    --color-end: #FF6B6B;
    --color-wall: #2D3748;
    --color-empty: #ECEFF1;
    --color-solution: #7E57C2;
    --color-visited: #B39DDB;

    /* UI Colors */
    --color-primary: #4A90E2;
    --color-success: #4CAF50;
    --color-secondary: #757575;
    --color-background: #FAFAFA;
    --color-card: #FFFFFF;
    --color-text: #212121;
    --color-text-light: #757575;
    --color-border: #E0E0E0;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    --shadow-md: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ===== Global Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    padding: var(--spacing-md);
}

/* ===== Container ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--color-background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ===== Header ===== */
.header {
    background: linear-gradient(135deg, var(--color-primary) 0%, #667eea 100%);
    color: white;
    padding: var(--spacing-xl);
    text-align: center;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: var(--spacing-sm);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 400;
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: var(--spacing-lg);
    padding: var(--spacing-lg);
    min-height: 600px;
}

@media (max-width: 968px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* ===== Sidebar ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.control-section {
    background: var(--color-card);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Input Groups ===== */
.input-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.input-group label {
    font-weight: 500;
    color: var(--color-text-light);
}

.input-group input[type="number"] {
    width: 80px;
    padding: var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    text-align: center;
}

/* ===== Buttons ===== */
.btn {
    width: 100%;
    padding: var(--spacing-md);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    font-family: inherit;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: #3d7cc9;
}

.btn-success {
    background: var(--color-success);
    color: white;
    margin-bottom: var(--spacing-sm);
}

.btn-success:hover {
    background: #43a047;
}

.btn-secondary {
    background: var(--color-secondary);
    color: white;
    margin-bottom: var(--spacing-sm);
}

.btn-secondary:hover {
    background: #616161;
}

/* ===== Tool Buttons ===== */
.tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

.btn-tool {
    padding: var(--spacing-md);
    background: var(--color-empty);
    color: var(--color-text);
    border: 2px solid transparent;
}

.btn-tool:hover {
    background: #CFD8DC;
}

.btn-tool.active {
    border-color: var(--color-primary);
    background: #E3F2FD;
    color: var(--color-primary);
}

/* ===== Speed Slider ===== */
#speed-slider {
    width: 100%;
    margin: var(--spacing-sm) 0;
}

.speed-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* ===== Statistics ===== */
.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
    padding: var(--spacing-sm);
    background: var(--color-background);
    border-radius: var(--radius-sm);
}

.stat-label {
    font-weight: 500;
    color: var(--color-text-light);
}

.stat-value {
    font-weight: 700;
    color: var(--color-primary);
}

/* ===== Instructions ===== */
.instructions {
    font-size: 0.9rem;
    color: var(--color-text-light);
}

.instructions p {
    margin-bottom: var(--spacing-sm);
}

/* ===== Maze Container ===== */
.maze-container {
    position: relative;
    background: var(--color-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
}

.maze-grid {
    display: grid;
    gap: 2px;
    background: var(--color-border);
    padding: 2px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

/* ===== Maze Cells ===== */
.cell {
    aspect-ratio: 1;
    min-width: 20px;
    max-width: 40px;
    background: var(--color-empty);
    border: 1px solid var(--color-border);
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.cell:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-sm);
}

.cell.wall {
    background: var(--color-wall);
}

.cell.start {
    background: var(--color-start);
    box-shadow: 0 0 10px rgba(74, 144, 226, 0.5);
}

.cell.start::after {
    content: "🏁";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2em;
}

.cell.end {
    background: var(--color-end);
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

.cell.end::after {
    content: "🎯";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2em;
}

.cell.visited {
    background: var(--color-visited);
    animation: fadeIn 0.3s ease;
}

.cell.solution {
    background: var(--color-solution);
    animation: pulse 0.5s ease;
    box-shadow: 0 0 10px rgba(126, 87, 194, 0.5);
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

/* ===== Loading Spinner ===== */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: var(--spacing-xl);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-border);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--spacing-md);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== Footer ===== */
.footer {
    background: var(--color-card);
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--color-text-light);
    border-top: 1px solid var(--color-border);
}

.footer a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .title {
        font-size: 2rem;
    }

    .tool-buttons {
        grid-template-columns: 1fr;
    }

    .cell {
        min-width: 15px;
        max-width: 30px;
    }
}
