/* CSS Variables */
:root {
    /* Colors */
    --primary: #0a66c2;
    --primary-light: #378fe9;
    --primary-dark: #004182;

    --path-color: #0d9488;
    --path-light: #14b8a6;
    --path-dark: #0f766e;

    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;

    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;

    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #9ca3af;

    --border-color: #d1d5db;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Grid */
    --cell-size: 48px;
    --cell-gap: 0px;
    --wall-thickness: 5px;
    --border-radius: 8px;
    --border-radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;

    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #6b7280;

    --border-color: #4b5563;
}

/* Path Colors - Gradient based colors */
[data-path-color="teal"] {
    --path-start: #0d9488;
    --path-end: #065f46;
    --path-color: #0d9488;
    --path-light: #14b8a6;
    --path-dark: #0f766e;
}
[data-path-color="blue"] {
    --path-start: #3b82f6;
    --path-end: #1e40af;
    --path-color: #0a66c2;
    --path-light: #378fe9;
    --path-dark: #004182;
}
[data-path-color="purple"] {
    --path-start: #8b5cf6;
    --path-end: #5b21b6;
    --path-color: #7c3aed;
    --path-light: #a78bfa;
    --path-dark: #5b21b6;
}
[data-path-color="orange"] {
    --path-start: #f97316;
    --path-end: #c2410c;
    --path-color: #ea580c;
    --path-light: #fb923c;
    --path-dark: #c2410c;
}
[data-path-color="pink"] {
    --path-start: #ec4899;
    --path-end: #be185d;
    --path-color: #db2777;
    --path-light: #f472b6;
    --path-dark: #be185d;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.25rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tab-nav {
    display: flex;
    gap: 0.25rem;
}

.tab-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.tab-btn:hover {
    background: var(--bg-secondary);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Views */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* Level Select */
.level-select-header {
    padding: 1rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.level-select-header h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

.difficulty-filters {
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 9999px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Level Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    padding: 1rem;
    overflow-y: auto;
}

.level-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition-normal);
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    display: block;
    color: inherit;
}

.level-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.level-card.completed {
    border-color: var(--success);
}

.level-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    gap: 0.25rem;
}

.level-number {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.level-hash-small {
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--text-tertiary, #888);
    background: var(--bg-tertiary, #f0f0f0);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: monospace;
}

.level-card .difficulty-badge {
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
}

.level-card-preview {
    aspect-ratio: 1;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.level-card-preview .preview-grid {
    display: grid;
    gap: 0;
    /* Width fills container, height from aspect-ratio (set inline) */
    width: 100%;
    max-height: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 2px;
}

.level-card-preview .preview-cell {
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7px;
    font-weight: 700;
    color: var(--text-primary);
    position: relative;
    aspect-ratio: 1;
    border: 0.5px solid var(--border-color);
}

.level-card-preview .preview-cell.blocked {
    background:
        repeating-linear-gradient(
            45deg,
            var(--bg-tertiary),
            var(--bg-tertiary) 2px,
            var(--bg-secondary) 2px,
            var(--bg-secondary) 4px
        );
}

.level-card-preview .preview-cell.has-node {
    background: transparent;
    border-color: var(--border-color);
}

.level-card-preview .preview-cell.has-node span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 70%;
    height: 70%;
    background: var(--text-primary);
    color: white;
    border-radius: 50%;
    font-size: 7px;
    font-weight: 700;
}

/* Preview cell walls - using border for walls */
.level-card-preview .preview-cell.wall-top {
    border-top: 2px solid var(--text-primary);
}
.level-card-preview .preview-cell.wall-right {
    border-right: 2px solid var(--text-primary);
}
.level-card-preview .preview-cell.wall-bottom {
    border-bottom: 2px solid var(--text-primary);
}
.level-card-preview .preview-cell.wall-left {
    border-left: 2px solid var(--text-primary);
}

.level-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    min-height: 1.5rem;
}

.level-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.best-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.completion-check {
    color: var(--success);
    font-size: 1rem;
    font-weight: bold;
}

/* Level Tabs */
.level-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.level-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition-fast);
}

.level-tab:hover {
    color: var(--primary);
}

.level-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Level Filters */
.level-filters {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.community-filters {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.filter-checkbox input {
    accent-color: var(--primary);
}

/* Community Level Card */
.level-card.community-level {
    position: relative;
}

.level-hash {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    font-family: monospace;
}

.level-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.375rem;
    font-size: 0.6875rem;
    color: var(--text-tertiary);
}

.level-author {
    font-style: italic;
}

.level-plays {
    opacity: 0.8;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Loading State */
.loading {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
}

.error {
    padding: 2rem;
    text-align: center;
    color: var(--error);
}

/* Difficulty Badges */
.difficulty-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: capitalize;
}

.difficulty-badge.easy {
    background: #dcfce7;
    color: #166534;
}

.difficulty-badge.medium {
    background: #fef3c7;
    color: #92400e;
}

.difficulty-badge.hard {
    background: #fee2e2;
    color: #991b1b;
}

[data-theme="dark"] .difficulty-badge.easy {
    background: #166534;
    color: #dcfce7;
}

[data-theme="dark"] .difficulty-badge.medium {
    background: #92400e;
    color: #fef3c7;
}

[data-theme="dark"] .difficulty-badge.hard {
    background: #991b1b;
    color: #fee2e2;
}

/* Game View */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.level-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.level-info .level-name {
    font-weight: 600;
}

.level-hash-badge {
    font-size: 0.6875rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--primary);
    background: var(--primary-light);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
}

.timer {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: right;
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
}

/* Game Board Wrapper - positions SVG overlay */
.game-board-wrapper {
    position: relative;
    display: inline-block;
}

/* SVG Path Overlay */
.path-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: visible;
}

.path-line {
    fill: none;
    stroke: url(#path-gradient);
    stroke-linecap: round;
    stroke-linejoin: round;
    /* stroke-width is set dynamically in JS based on cell size */
}

/* Game Board */
.game-board {
    display: grid;
    gap: 0;
    background: var(--bg-primary);
    padding: calc(var(--wall-thickness) / 2 + 2px);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    touch-action: none;
    user-select: none;
    position: relative;
    overflow: visible;
    border: 2px solid var(--bg-tertiary);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--bg-primary);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    overflow: visible;
    /* Subtle grid lines using pseudo-element */
    border: none;
}

.cell::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 0.5px solid var(--border-color);
    pointer-events: none;
    z-index: 1;
}

.cell.blocked {
    /* Diagonal stripes pattern for blocked cells */
    background:
        repeating-linear-gradient(
            45deg,
            var(--bg-tertiary),
            var(--bg-tertiary) 4px,
            var(--bg-secondary) 4px,
            var(--bg-secondary) 8px
        );
    cursor: default;
}

.cell.blocked::before {
    border-width: 1px;
}

/* Path cells - SVG handles the path line, background shows halo effect */
.cell.filled,
.cell.current {
    /* Halo effect - transparent background matching path color at this position */
    background: var(--cell-halo-color, rgba(13, 148, 136, 0.15));
}

.cell.invalid {
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Hint highlight - LinkedIn style: shows next correct step */
.cell.hint {
    animation: hint-glow 0.4s ease-out forwards, hint-pulse 0.6s ease-in-out 0.4s infinite alternate;
    z-index: 10;
}

@keyframes hint-glow {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 var(--primary);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 20px 8px var(--primary);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 12px 4px var(--primary);
    }
}

@keyframes hint-pulse {
    0% {
        box-shadow: 0 0 8px 3px var(--primary);
        background: rgba(var(--primary-rgb, 13, 148, 136), 0.25);
    }
    100% {
        box-shadow: 0 0 14px 5px var(--primary);
        background: rgba(var(--primary-rgb, 13, 148, 136), 0.4);
    }
}

/* Hint error - shows where player went wrong */
.cell.hint-error {
    animation: hint-error-shake 0.4s ease-out;
    background: rgba(220, 38, 38, 0.3) !important;
    box-shadow: 0 0 12px 4px rgba(220, 38, 38, 0.6);
}

@keyframes hint-error-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Solving animation - cell being filled during auto-solve */
.cell.solving {
    animation: solve-pop 0.2s ease-out;
}

@keyframes solve-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 10px 3px var(--path-color);
    }
    100% {
        transform: scale(1);
    }
}

/* Solution animation in builder */
.cell.solution-path {
    background: var(--success) !important;
    opacity: 0.6;
}

.cell.solution-current {
    background: var(--primary) !important;
    box-shadow: 0 0 10px 3px var(--primary);
    opacity: 1;
}

/* Validation message info state */
.validation-message.info {
    background: var(--bg-secondary);
    color: var(--primary);
    border: 1px solid var(--primary);
}

/* Cell Walls - using ::after pseudo-element positioned ON the cell edge */
.cell::after {
    content: '';
    position: absolute;
    inset: calc(-0.5 * var(--wall-thickness));
    border: 0 solid var(--text-primary);
    pointer-events: none;
    z-index: 15;
}

/* Wall sides - each adds a border to the ::after element */
.cell.wall-top::after {
    border-top-width: var(--wall-thickness);
}

.cell.wall-right::after {
    border-right-width: var(--wall-thickness);
}

.cell.wall-bottom::after {
    border-bottom-width: var(--wall-thickness);
}

.cell.wall-left::after {
    border-left-width: var(--wall-thickness);
}

/* Node Numbers - black circle with white text */
.node-number {
    width: 26px;
    height: 26px;
    background: var(--text-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    border: none;
    position: relative;
}

.cell.filled .node-number,
.cell.current .node-number {
    background: var(--text-primary);
    color: white;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}


/* Game Footer */
.game-footer {
    padding: 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.progress-indicator {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-secondary);
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    min-width: 70px;
}

.control-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn span {
    font-size: 0.75rem;
    font-weight: 500;
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
}

.close-modal {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--border-radius);
}

.close-modal:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 1rem;
}

/* Small Modal */
.modal-content.modal-sm {
    max-width: 320px;
}

/* Save Modal */
.save-option {
    margin-bottom: 1rem;
}

.save-option label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

.save-option input,
.save-option select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.save-option input:focus,
.save-option select:focus {
    outline: none;
    border-color: var(--primary);
}

.difficulty-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.difficulty-reason {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.save-error {
    padding: 0.75rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--border-radius);
    color: var(--error);
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

.save-actions,
.confirm-actions,
.alert-actions,
.success-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Success Modal */
.success-content {
    text-align: center;
    padding: 1.5rem 1rem;
}

.success-icon {
    width: 60px;
    height: 60px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
    animation: popIn 0.5s ease;
}

.hash-code-display {
    margin: 1.5rem 0;
}

.hash-code-display label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    display: block;
    margin-bottom: 0.5rem;
}

.hash-code-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.hash-code {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--primary);
    letter-spacing: 0.1em;
}

.success-actions {
    justify-content: center;
}

/* Confirm/Alert Modal */
#confirm-message,
#alert-message {
    color: var(--text-primary);
    line-height: 1.5;
}

/* Win Modal */
.win-content {
    text-align: center;
    padding: 2rem 1.5rem;
}

.win-animation {
    position: relative;
    margin-bottom: 1rem;
}

.win-icon {
    width: 80px;
    height: 80px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto;
    animation: popIn 0.5s ease;
}

@keyframes popIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.win-content h2 {
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.win-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.win-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Confetti */
.confetti {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn.primary {
    background: var(--primary);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn.secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn.secondary:hover {
    background: var(--bg-tertiary);
}

.btn.danger {
    background: var(--danger);
    color: white;
}

.btn.danger:hover {
    background: #b91c1c;
}

.btn.small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Builder */
.builder-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.builder-toolbar {
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tool-group label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.tool-group select {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.mode-toggle {
    display: flex;
    gap: 0.25rem;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.mode-btn:hover {
    border-color: var(--primary);
}

.mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.builder-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
}

.builder-board {
    display: grid;
    gap: 0;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
}

.builder-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: background-color var(--transition-fast);
}

.builder-cell:hover {
    background: var(--bg-secondary);
}

.builder-cell.blocked {
    background: var(--bg-tertiary);
}

.builder-cell.blocked::before {
    content: '#';
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-tertiary);
}

.builder-cell .node-number {
    font-size: 0.75rem;
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* Builder Wall Indicators */
.builder-cell .wall-indicator {
    position: absolute;
    background: var(--primary);
    z-index: 20;
    pointer-events: none;
}

.builder-cell .wall-indicator.top {
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.builder-cell .wall-indicator.right {
    top: 0;
    right: 0;
    bottom: 0;
    width: 4px;
}

.builder-cell .wall-indicator.bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.builder-cell .wall-indicator.left {
    top: 0;
    left: 0;
    bottom: 0;
    width: 4px;
}

/* Builder mode visual hints */
.builder-board[data-mode="walls"] .builder-cell:not(.blocked)::before {
    content: '+';
    position: absolute;
    font-size: 1.5rem;
    color: var(--text-tertiary);
    opacity: 0.3;
    pointer-events: none;
}

.builder-board[data-mode="walls"] .builder-cell:hover::before {
    opacity: 0.6;
}

.builder-board[data-mode="blocked"] .builder-cell:hover:not(.blocked) {
    background: var(--bg-tertiary);
}

.builder-board[data-mode="numbers"] .builder-cell:hover:not(.blocked) {
    background: var(--path-light);
    opacity: 0.7;
}

/* Drag and Drop Styles */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    transform: translate(-50%, -50%);
    opacity: 0.9;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 4px;
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--primary);
}

.drag-ghost.blocked {
    background: var(--bg-tertiary);
    border-color: var(--text-tertiary);
}

.drag-ghost.blocked span {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-tertiary);
}

.drag-ghost .node-number {
    width: 28px;
    height: 28px;
    font-size: 0.875rem;
}

.builder-cell.dragging {
    opacity: 0.4;
}

.builder-cell.drag-over {
    background: var(--primary-light) !important;
    box-shadow: inset 0 0 0 2px var(--primary);
}

.builder-info {
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.validation-message {
    font-size: 0.875rem;
    padding: 0.25rem;
    min-height: 1.5rem;
}

.validation-message.success {
    color: var(--success);
}

.validation-message.error {
    color: var(--danger);
}

.validation-message.warning {
    color: var(--warning);
}

.node-count {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* Toolbar Action Button (Clear) */
.toolbar-actions {
    margin-left: auto;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
}

.toolbar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.toolbar-btn.danger:hover {
    background: rgba(220, 38, 38, 0.1);
    color: var(--danger);
}

/* Builder Actions - Icon Only */
.builder-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    gap: 1rem;
}

.action-group {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
}

.action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.highlight {
    background: var(--path-light);
    background: linear-gradient(135deg, var(--path-light) 0%, var(--path-color) 100%);
    color: white;
}

.action-btn.highlight:hover {
    filter: brightness(1.1);
    color: white;
}

.action-btn.primary {
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    gap: 2px;
}

.action-btn.primary:hover {
    filter: brightness(1.1);
    color: white;
}

.action-btn.primary .icon-cloud {
    width: 16px;
    height: 16px;
    margin-left: -4px;
}

/* Tooltip for action buttons */
.action-btn::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.375rem 0.625rem;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 100;
}

.action-btn::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--text-primary);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 100;
}

.action-btn:hover::after,
.action-btn:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Toolbar button tooltip */
.toolbar-btn::after {
    content: attr(title);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.375rem 0.625rem;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 100;
}

.toolbar-btn::before {
    content: '';
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-bottom-color: var(--text-primary);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 100;
}

.toolbar-btn:hover::after,
.toolbar-btn:hover::before {
    opacity: 1;
    visibility: visible;
}

/* Export/Import Options */
.export-option,
.import-option {
    margin-bottom: 1rem;
}

.export-option label,
.import-option label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.export-option input,
.export-option textarea,
.import-option textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.export-option textarea,
.import-option textarea {
    min-height: 80px;
    resize: vertical;
}

.export-option .btn {
    margin-top: 0.375rem;
    margin-right: 0.25rem;
}

/* Help Modal Content */
.help-content {
    max-height: 60vh;
    overflow-y: auto;
}

.help-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.help-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.help-section h4 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.help-section p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    line-height: 1.5;
}

.help-section em {
    color: var(--text-tertiary);
    font-size: 0.8125rem;
}

.help-section.tips {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
    border-bottom: none;
}

.help-section.tips h4 {
    margin-bottom: 0.75rem;
}

.help-section ul {
    margin: 0;
    padding-left: 1.25rem;
}

.help-section li {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    line-height: 1.4;
}

.help-section li:last-child {
    margin-bottom: 0;
}

/* Settings */
.settings-container {
    padding: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

.settings-container h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.settings-group {
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 1rem;
    margin-bottom: 1rem;
}

.settings-group h3 {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    font-size: 0.9375rem;
    color: var(--text-primary);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    display: inline-block;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 14px;
    transition: var(--transition-normal);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* Color Options */
.color-options {
    display: flex;
    gap: 0.5rem;
}

.color-btn {
    width: 32px;
    height: 32px;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition-fast);
}

.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-primary);
}

.settings-footer {
    text-align: center;
    padding: 1rem;
    color: var(--text-tertiary);
    font-size: 0.8125rem;
}

.version {
    font-weight: 500;
}

.credits {
    margin-top: 0.25rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
}

.toast.success {
    background: var(--success);
    color: white;
}

.toast.error {
    background: var(--danger);
    color: white;
}

@keyframes toastIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toastOut {
    to {
        transform: translateY(-20px);
        opacity: 0;
    }
}

/* Responsive Design */
@media (min-width: 640px) {
    .app-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .logo {
        margin-bottom: 0;
    }

    .tab-nav {
        flex: 0 0 auto;
    }

    .tab-btn {
        flex: 0 0 auto;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    :root {
        --cell-size: 56px;
    }
}

@media (min-width: 768px) {
    :root {
        --cell-size: 60px;
    }

    .game-controls {
        gap: 1.5rem;
    }

    .control-btn {
        flex-direction: row;
        padding: 0.75rem 1.5rem;
    }

    .builder-actions .btn {
        max-width: none;
    }
}

@media (max-width: 480px) {
    :root {
        --cell-size: 44px;
    }

    .mode-btn span:not(:first-child) {
        display: none;
    }

    .mode-btn {
        padding: 0.5rem;
    }

    /* Smaller action buttons on mobile */
    .action-btn {
        width: 42px;
        height: 42px;
        border-radius: 10px;
    }

    .action-btn svg {
        width: 20px;
        height: 20px;
    }

    .action-btn.primary .icon-cloud {
        width: 14px;
        height: 14px;
    }

    /* Hide tooltips on mobile (use touch instead) */
    .action-btn::after,
    .action-btn::before,
    .toolbar-btn::after,
    .toolbar-btn::before {
        display: none;
    }

    .builder-actions {
        padding: 0.5rem 0.75rem;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --wall-thickness: 6px;
    }

    .cell {
        border: 1px solid var(--text-primary);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .app-header,
    .game-footer,
    .modal {
        display: none !important;
    }
}
