/* --- Global Styles --- */
body {
    font-family: 'Inter', sans-serif;
    min-height: 100vh; /* Changed from height: 100vh to allow content to push past 100% of viewport */
    overflow-y: auto; /* Allows vertical scrolling when content is too long */
    overflow-x: hidden; /* Prevent horizontal scrolling */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Aligned to the top, then centered by margin/padding */
    /* Vibrant blue gradient background from the video */
    background: #424658;
}

h1.memorypath {
  font-family: sans-serif !important;
  text-align: center;
  color: #E0CDB2 !important;
  font-size: clamp(0.2rem, 5vw, 2.5rem) !important;
  font-weight: 700 !important;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  margin: 0 !important;
  line-height: 1.2 !important;
  white-space: nowrap; /* Keep title and link on one line */
}

.memorypath a {
  margin-left: 0.5rem;
  font-family: sans-serif;
  font-size: 0.4em;
  font-style: italic;
  text-decoration: underline;
  color: #E0CDB2;
  transition: color 0.3s ease;
}

.memorypath a:hover {
  color: rgb(0, 123, 255);
}

.game-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.2rem 1rem 2rem 1rem;
    min-height: 100vh;
    background: #424658;
    margin: 0 auto;
}

/* --- Game Title --- */
.game-title {
    text-align: center;
    margin-bottom: 1.5rem;
    color: white;
    margin-left: auto;
    margin-right: auto;
}

/* --- Header Bar & Controls --- */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    margin-left: auto;
    margin-right: auto;
    color: white;
    flex-wrap: nowrap; /* Keep items on one line */
    gap: 0.5rem;
}

@media (max-width: 480px) {
    .header-bar {
        max-width: 100%;
    }
}

.header-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 0.25rem; /* Reduced padding for more compact layout */
    flex-grow: 1;
    min-width: 0; /* Allow shrinking */
}

.stat-label {
    font-size: 0.65rem;
    opacity: 0.75;
    color: #E0CDB2;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: bold;
    color: #E0CDB2;
}

.reset-button {
    background-color: #fca5a5;
    color: #991b1b;
    border: none;
    border-radius: 50%;
    width: 36px; /* Slightly smaller */
    height: 36px; /* Slightly smaller */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem; /* Slightly smaller icon */
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: background-color 0.15s, transform 0.15s;
    margin: 0 0.5rem; /* Reduced margin */
    flex-shrink: 0; /* Don't shrink the button */
}

.reset-button:hover {
    background-color: #f87171;
    transform: scale(1.05);
}

.game-controls {
    display: flex;
    flex-wrap: nowrap; /* Keep controls on one line */
    justify-content: center;
    gap: 0.35rem; /* Even smaller gap */
    margin-bottom: 1.5rem;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 480px) {
    .game-controls {
        gap: 0.5rem;
    }

    .control-group {
        font-size: 0.85rem;
    }
}

.control-group {
    display: flex;
    align-items: center;
    white-space: nowrap; /* Prevent text wrapping */
}

.control-label {
    color: #E0CDB2;
    margin-right: 0.3rem;
    font-weight: 600;
    font-size: 0.7rem; /* Smaller font */
}

.control-separator {
    color: white;
    margin: 0 0.15rem;
    font-weight: bold;
    font-size: 0.85rem;
}

.control-select, .control-input {
    padding: 0.3rem 0.4rem; /* Reduced padding */
    border-radius: 0.375rem;
    background-color: white;
    color: #1f2937;
    font-weight: 500;
    font-size: 0.85rem; /* Smaller font */
    border: 1px solid #d1d5db;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    width: 2rem; /* 2.8 * 0.6 = 1.68rem (40% narrower) */
}

.control-input {
    text-align: center;
}

.control-input:focus {
    outline: none;
    border-color: #81a3c6;
}

/* --- Game Grid Container (Responsive) --- */
#game-grid {
    width: auto;
    height: auto;
    max-width: 72vw; /* 90vw * 0.8 = 72vw (20% smaller) */
    max-height: 64vh; /* 80vh * 0.8 = 64vh (20% smaller) */
    display: grid;
    padding: clamp(8px, 2vmin, 15px);
    background-color: #E0CDB2;
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    position: relative;
    margin-bottom: 1rem; /* 2rem * 0.5 = 1rem (50% narrower gap) */
}

/* Adjust grid for smaller screens */
@media (max-width: 768px) {
    #game-grid {
        max-width: 76vw; /* 95vw * 0.8 = 76vw (20% smaller) */
        max-height: 56vh; /* 70vh * 0.8 = 56vh (20% smaller) */
    }
}

/* Countdown Overlay */
#countdown-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 6.4vmin; /* 8vmin * 0.8 = 6.4vmin (20% smaller) */
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 24px;
    z-index: 25;
}


/* --- Node Styling --- */
.node {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background-color: #81a3c6;
    cursor: pointer;
    transition: all 0.15s ease-out;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    position: relative;
    box-sizing: border-box;
    aspect-ratio: 1 / 1;
    margin: auto;
    container-type: inline-size;
}

.node:hover:not(.active) {
    transform: scale(1.05);
    background-color: #81a3c6;
}

#game-grid.memory-mode .node:not(.active) {
    cursor: not-allowed; 
}
#game-grid.memory-mode .node.active {
    cursor: pointer;
}

/* Player's successful path */
.node.active {
    background-color: #ffc107;
    border-color: #424658;
    z-index: 10;
}

/* Nodes that must be hit to complete the path */
.node.target {
    background-color: #2c6aa8;
    border-color: #2c6aa8;
    /* animation: pulse 1.5s infinite; */
}

/* --- New Wrong Node Style --- */
.node.wrong {
    background-color: #ef4444; /* red-500 */
    border-color: #b91c1c; /* red-800 */
    animation: shake 0.4s;
}

/* --- New Shake Animation --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

/* @keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(123, 117, 255, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(123, 117, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(123, 117, 255, 0); }
} */

/* Visually hide the target path after the display time */
.node.hidden-target:not(.active) {
    background-color: #81a3c6 !important;
    border-color: #81a3c6 !important;
    animation: none !important;
}


.goal-node {
    background-color: #ff6f00;
    border-color: #ff4400;
}

.node-icon {
    color: #424658;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-size: clamp(0.5rem, 35cqw, 3rem);
}

.node-icon.start-text {
    color: #3b3e4d;
    font-weight: bold;
    font-size: clamp(0.4rem, 28cqw, 2rem);
}

/* Responsive adjustments for very small nodes */
@media (max-width: 480px) {
    .node-icon {
        font-size: clamp(0.4rem, 32cqw, 2rem);
    }

    .node-icon.start-text {
        font-size: clamp(0.3rem, 25cqw, 1.5rem);
    }
}

/* --- Score Animation --- */
.score-anim {
    position: absolute;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: floatUp 1s ease-out forwards;
    pointer-events: none;
    z-index: 20;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0);
        font-size: 1.5rem;
    }
    100% {
        opacity: 0;
        transform: translateY(-50px);
        font-size: 2rem;
    }
}

/* --- Modal Styling --- */
.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    text-align: center;
    max-width: 350px;
    margin: 0 1rem;
    transform: scale(1);
    transition: transform 0.3s;
}

.modal-title-text {
    font-size: 1.875rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: #4f46e5;
}

.modal-text {
    color: #4b5563;
    margin-bottom: 1.5rem;
}

.modal-button {
    padding: 0.75rem 1.5rem;
    background-color: #E0CDB2;
    color: #424658;
    font-weight: bold;
    border-radius: 9999px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transition: background-color 0.15s, transform 0.15s;
    border: none;
    cursor: pointer;
}

.modal-button:hover {
    background-color: #81a3c6;
    transform: scale(1.05);
}

/* --- Instructions Section --- */
.instructions {
    text-align: center;
    color: white;
    padding: 0.75rem 1.5rem 1.5rem 1.5rem; /* Reduced top padding, keep others */
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-top: 0; /* Already has gap from grid's margin-bottom */
    margin-left: auto;
    margin-right: auto;
}

.instructions h3 {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: 700;
    margin: 0 0 0.5rem 0; /* Reduced bottom margin */
    color: #E0CDB2;
}

.instructions p {
    font-size: clamp(0.9rem, 2vw, 1rem);
    line-height: 1.6;
    margin: 0.5rem 0; /* Reduced margin */
    color: rgba(255, 255, 255, 0.95);
}

.instructions strong {
    color: #E0CDB2;
    font-weight: 600;
}

/* Mobile responsiveness for instructions */
@media (max-width: 768px) {
    .instructions {
        padding: 1rem;
        margin-top: 1.5rem;
    }
}
