/* CSS Variables for Theming */
:root {
    --board-size: 40vh;
    --cell-gap: 2px;
    --transition-speed: 0.2s;
}

/* Day Theme */
.day-theme {
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-board: #e8ecf1;
    --text-primary: #1a1a2e;
    --text-secondary: #64748b;
    --cell-bg: #ffffff;
    --cell-border: #d1d5db;
    --cell-number: #374151;
    --cell-number-highlight: #e91e9c;
    --wall-color: #1a1a2e;
    --btn-bg: #ffffff;
    --btn-hover: #f1f5f9;
    --btn-border: #e2e8f0;
    --btn-primary-bg: linear-gradient(135deg, #e91e9c 0%, #00d4aa 100%);
    --btn-primary-text: #ffffff;
    --menu-bg: #ffffff;
    --overlay-bg: rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Night Theme */
.night-theme {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-board: #252540;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --cell-bg: #2a2a45;
    --cell-border: #3d3d5c;
    --cell-number: #e2e8f0;
    --cell-number-highlight: #ff6bc6;
    --wall-color: #f1f5f9;
    --btn-bg: #2a2a45;
    --btn-hover: #3d3d5c;
    --btn-border: #3d3d5c;
    --btn-primary-bg: linear-gradient(135deg, #ff6bc6 0%, #00ffcc 100%);
    --btn-primary-text: #0f0f1a;
    --menu-bg: #1a1a2e;
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background var(--transition-speed), color var(--transition-speed);
    overflow-x: hidden;
}

/* Menu Toggle */
.menu-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    z-index: 100;
    box-shadow: var(--shadow);
    transition: all var(--transition-speed);
}

.menu-toggle:hover {
    background: var(--btn-hover);
}

.menu-toggle span {
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all var(--transition-speed);
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Menu Overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-speed);
    z-index: 150;
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: var(--menu-bg);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 200;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.side-menu.active {
    transform: translateX(0);
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-menu {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all var(--transition-speed);
}

.close-menu:hover {
    background: var(--btn-hover);
    color: var(--text-primary);
}

.menu-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.size-btn,
.diff-btn {
    flex: 1;
    min-width: calc(50% - 4px);
    padding: 10px 12px;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.diff-btn {
    min-width: auto;
}

.size-btn:hover,
.diff-btn:hover {
    background: var(--btn-hover);
}

.size-btn.active,
.diff-btn.active {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border-color: transparent;
}

/* Seed Input */
.menu-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: 'Space Grotesk', monospace;
    outline: none;
    transition: border-color var(--transition-speed);
}

.menu-input:focus {
    border-color: #e91e9c;
}

.menu-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* Sliders */
.menu-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--btn-border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.menu-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--btn-primary-bg);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.menu-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.menu-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e91e9c, #00d4aa);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Theme Toggle */
.theme-toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.theme-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.theme-switch {
    position: relative;
    width: 52px;
    height: 28px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--btn-border);
    border-radius: 28px;
    transition: all var(--transition-speed);
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: var(--bg-secondary);
    border-radius: 50%;
    transition: all var(--transition-speed);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.theme-switch input:checked + .slider {
    background: linear-gradient(135deg, #e91e9c, #00d4aa);
}

.theme-switch input:checked + .slider:before {
    transform: translateX(24px);
}

.menu-new-game {
    margin-top: auto;
    padding: 14px 24px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.menu-new-game:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

/* Game Container */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    gap: 20px;
}

/* Game Header */
.game-header {
    text-align: center;
}

.game-title {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #e91e9c 0%, #00d4aa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.domain {
    -webkit-text-fill-color: var(--text-secondary);
    opacity: 0.8;
}

.game-subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
    -webkit-text-fill-color: var(--text-secondary);
    margin-left: 8px;
}

/* Board Wrapper */
.board-wrapper {
    background: var(--bg-board);
    padding: 12px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

/* Game Canvas */
#gameCanvas {
    display: block;
    width: var(--board-size);
    height: var(--board-size);
    cursor: pointer;
    border-radius: 4px;
}

/* Cell Styles */
.cell {
    background: var(--cell-bg);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: calc(var(--board-size) / 18);
    color: var(--cell-number);
    cursor: pointer;
    position: relative;
    transition: all 0.15s ease;
    user-select: none;
}

.cell:hover:not(.visited):not(.current) {
    background: var(--btn-hover);
    transform: scale(1.02);
}

/* Start cell - pulsing highlight */
.cell.start-cell {
    color: var(--cell-number-highlight);
    font-weight: 700;
    background: linear-gradient(135deg, rgba(233, 30, 156, 0.15) 0%, rgba(233, 30, 156, 0.05) 100%);
    box-shadow: inset 0 0 0 2px var(--cell-number-highlight);
    animation: pulseStart 2s ease-in-out infinite;
}

@keyframes pulseStart {
    0%, 100% {
        box-shadow: inset 0 0 0 2px var(--cell-number-highlight), 0 0 8px rgba(233, 30, 156, 0.3);
    }
    50% {
        box-shadow: inset 0 0 0 2px var(--cell-number-highlight), 0 0 20px rgba(233, 30, 156, 0.6);
    }
}

/* Stop animation when path has started */
.board-wrapper.path-active .cell.start-cell {
    animation: none;
    box-shadow: none;
    background: var(--cell-bg);
}

.cell.end-cell {
    color: var(--cell-number-highlight);
    font-weight: 700;
}

/* Visited cells - numbers stay visible above snake */
.cell.visited {
    z-index: 15;
    color: var(--text-primary);
    font-weight: 700;
    text-shadow:
        0 0 3px var(--cell-bg),
        0 0 6px var(--cell-bg),
        0 0 9px var(--cell-bg);
}

/* Current cell */
.cell.current {
    box-shadow: 0 0 0 3px #00d4aa;
    z-index: 15;
}

/* Wall Styles */
.cell.wall-top::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 2px;
    right: 2px;
    height: 4px;
    background: var(--wall-color);
    border-radius: 2px;
    z-index: 20;
}

.cell.wall-right::after {
    content: '';
    position: absolute;
    right: -2px;
    top: 2px;
    bottom: 2px;
    width: 4px;
    background: var(--wall-color);
    border-radius: 2px;
    z-index: 20;
}

.cell[data-wall-bottom="true"]::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 2px;
    right: 2px;
    height: 4px;
    background: var(--wall-color);
    border-radius: 2px;
    z-index: 20;
}

.cell[data-wall-left="true"]::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 2px;
    bottom: 2px;
    width: 4px;
    background: var(--wall-color);
    border-radius: 2px;
    z-index: 20;
}

/* Game Info (difficulty + timer) */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: var(--board-size);
    padding: 0 4px;
    margin-top: 8px;
}

.game-seed {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'Space Grotesk', monospace;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background var(--transition-speed);
}

.game-seed:hover {
    background: var(--btn-hover);
}

.game-timer {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Game Status */
.game-status {
    text-align: center;
    min-height: 28px;
}

.status-text {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.status-text.success {
    color: #00d4aa;
}

.status-text.error {
    color: #ef4444;
}

/* Control Buttons */
.controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow);
}

.control-btn:hover:not(:disabled) {
    background: var(--btn-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.control-btn.primary {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border: none;
}

.control-btn.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(233, 30, 156, 0.4);
}

/* New Game button enabled animation */
.control-btn.primary:not(:disabled) {
    animation: newGamePulse 2s ease-in-out infinite;
}

@keyframes newGamePulse {
    0%, 100% {
        box-shadow: 0 2px 10px rgba(233, 30, 156, 0.3);
    }
    50% {
        box-shadow: 0 4px 20px rgba(233, 30, 156, 0.5), 0 0 30px rgba(0, 212, 170, 0.3);
    }
}

/* Snake glow when game complete */
.board-wrapper.game-complete .snake-svg path {
    filter: drop-shadow(0 0 8px rgba(233, 30, 156, 0.6)) drop-shadow(0 0 16px rgba(0, 212, 170, 0.4));
}

.board-wrapper.game-complete .snake-svg circle {
    filter: drop-shadow(0 0 10px rgba(0, 212, 170, 0.8));
}

/* Win Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-speed);
    z-index: 300;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: rgba(255, 255, 255, 0.85);
    padding: 48px 40px 40px;
    border-radius: 28px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.9);
    transition: all 0.3s ease;
    max-width: 90%;
    width: 360px;
    min-height: 340px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.night-theme .modal {
    background: rgba(26, 26, 46, 0.85);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-icon {
    font-size: 5rem;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #e91e9c, #00d4aa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-text {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal-time {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-variant-numeric: tabular-nums;
}

.modal-countdown {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 24px;
    opacity: 0.8;
}

.modal-btn {
    padding: 16px 36px;
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    border: none;
    border-radius: 14px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    animation: pulseButton 1.5s ease-in-out infinite;
}

@keyframes pulseButton {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(233, 30, 156, 0.4);
    }
    50% {
        box-shadow: 0 4px 25px rgba(233, 30, 156, 0.6), 0 0 40px rgba(0, 212, 170, 0.3);
    }
}

.modal-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(233, 30, 156, 0.5);
}

/* Game Rules */
.game-rules {
    max-width: 400px;
    margin-top: 24px;
    padding: 20px 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--btn-border);
}

.game-rules h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.game-rules ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-rules li {
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding-left: 16px;
    position: relative;
}

.game-rules li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--cell-number-highlight);
}

.game-rules li strong {
    color: var(--cell-number-highlight);
    font-weight: 600;
}

/* Share Buttons */
.share-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.share-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    color: white;
}

.share-btn:hover {
    transform: scale(1.1);
}

.share-btn.facebook {
    background: #1877f2;
}

.share-btn.twitter {
    background: #000000;
}

.share-btn.linkedin {
    background: #0a66c2;
}

/* Site Footer */
.site-footer {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-top: 1px solid var(--btn-border);
    margin-top: 32px;
}

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

.footer-separator {
    margin: 0 8px;
    opacity: 0.5;
}

.footer-hosting a {
    color: var(--cell-number-highlight);
    text-decoration: none;
    font-weight: 500;
    transition: opacity var(--transition-speed);
}

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

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

    .controls {
        gap: 8px;
    }

    .control-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .side-menu {
        width: 100%;
    }
}
