/* --- Variables --- */
:root {
    --primary-color: #0077b6; /* Deep Blue */
    --secondary-color: #00b4d8; /* Lighter Blue/Teal */
    --accent-color: #ffc300; /* Yellow/Gold Accent */
    --light-bg: #edf6f9;
    --dark-bg: #0d1b2a; /* Dark Navy */
    --light-card-bg: #ffffff;
    --dark-card-bg: #1b263b; /* Darker Card BG */
    --light-text: #212529;
    --dark-text: #e9ecef; /* Light Gray for Dark Mode Text */
    --correct-color: #2a9d8f; /* Tealish Green */
    --incorrect-color: #e76f51; /* Coral Red */
    --border-color-light: #dee2e6;
    --border-color-dark: #495057;
    --shadow-color-light: rgba(0, 0, 0, 0.1);
    --shadow-color-dark: rgba(0, 0, 0, 0.3);
    --font-family: 'Poppins', sans-serif;
}

/* --- Base Styles --- */
body {
    font-family: var(--font-family);
    text-align: center;
    margin: 0;
    padding: 20px;
    background: linear-gradient(135deg, var(--light-bg), var(--secondary-color));
    color: var(--light-text);
    transition: background 0.4s ease, color 0.4s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
}

body.dark-mode {
    background: linear-gradient(135deg, var(--dark-bg), #243b55); /* Slightly less intense dark gradient */
    color: var(--dark-text);
}

*, *:before, *:after {
    box-sizing: inherit;
}

main {
    max-width: 900px;
    margin: 20px auto;
    padding: 25px 30px; /* Slightly more padding */
    background-color: var(--light-card-bg);
    border-radius: 15px;
    box-shadow: 0 8px 25px var(--shadow-color-light);
    transition: background-color 0.4s ease, box-shadow 0.4s ease;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
body.dark-mode main {
    background-color: var(--dark-card-bg);
    box-shadow: 0 8px 25px var(--shadow-color-dark);
}

h1 {
    color: var(--primary-color);
    margin-top: 0; /* Remove default top margin */
    margin-bottom: 20px;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 2.5rem); /* Responsive font size */
}
body.dark-mode h1 {
    color: var(--secondary-color);
}

h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color-light);
    padding-bottom: 10px;
}
body.dark-mode h2 {
    color: var(--secondary-color);
    border-bottom-color: var(--border-color-dark);
}

h3 {
     margin-top: 0;
     margin-bottom: 15px;
     color: var(--primary-color);
     font-weight: 700;
     border-bottom: 1px solid var(--border-color-light);
     padding-bottom: 8px;
 }
body.dark-mode h3 {
      color: var(--secondary-color);
      border-bottom-color: var(--border-color-dark);
}


/* --- Toggles & Controls --- */
.toggles-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px 30px; /* Row gap, column gap */
    flex-wrap: wrap;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color-light);
}
body.dark-mode .toggles-container {
     border-bottom: 1px solid var(--border-color-dark);
}
.toggle-group {
     display: flex;
     flex-direction: column;
     align-items: center;
     gap: 6px;
     font-size: 0.9em;
     font-weight: 600; /* Make label slightly bolder */
}

.dark-mode-toggle {
     position: absolute;
     top: 15px;
     right: 15px;
     background-color: var(--light-card-bg);
     padding: 8px;
     border-radius: 50%;
     box-shadow: 0 2px 5px var(--shadow-color-light);
     z-index: 100;
     display: flex; /* Center the switch */
     align-items: center;
     justify-content: center;
}
 body.dark-mode .dark-mode-toggle {
      background-color: var(--dark-card-bg);
      box-shadow: 0 2px 5px var(--shadow-color-dark);
 }

/* Switch Styles */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary-color); }
 body.dark-mode input:checked + .slider { background-color: var(--secondary-color); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- Quiz Area --- */
#quiz-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    position: relative;
    width: 100%; /* Take full width within main */
    transition: opacity 0.3s ease-in-out; /* For loading dim */
}

#guess-timer {
    position: absolute;
    top: -15px; /* Position above image */
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.7em; /* Larger timer */
    font-weight: 700;
    color: var(--primary-color);
    background-color: rgba(255, 255, 255, 0.9); /* Slightly more opaque */
    padding: 4px 18px;
    border-radius: 20px;
    z-index: 10;
    border: 1px solid var(--border-color-light);
    min-width: 60px; /* Ensure it doesn't jump size too much */
    text-align: center;
}
 body.dark-mode #guess-timer {
      color: var(--secondary-color);
      background-color: rgba(27, 38, 59, 0.9);
      border: 1px solid var(--border-color-dark);
 }

#coaster-image {
    display: block; /* Remove extra space below image */
    max-width: 100%;
    width: clamp(300px, 60vw, 500px); /* Slightly wider max */
    /* height: clamp(300px, 60vw, 500px); Use aspect-ratio instead */
    aspect-ratio: 1 / 1; /* Maintain square */
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 6px 15px var(--shadow-color-light);
    background-color: #e0e0e0;
    margin-top: 35px; /* Ensure space below timer */
    margin-bottom: 10px;
    border: 4px solid white;
    transition: opacity 0.3s ease-in-out;
}
body.dark-mode #coaster-image {
     box-shadow: 0 6px 15px var(--shadow-color-dark);
      border-color: var(--dark-card-bg);
}

/* Input & Options Styling */
#input-container { display: flex; width: clamp(280px, 90%, 550px); margin-top: 10px; } /* Use flex for button */
#options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Always 2 columns */
    gap: 12px;
    width: clamp(280px, 90%, 550px);
    margin-top: 10px;
}

input[type="text"]#manufacturer-input {
    flex-grow: 1; /* Take remaining space */
    padding: 14px 18px;
    border: 1px solid var(--border-color-light);
    border-right: none; /* Remove right border */
    border-radius: 8px 0 0 8px; /* Round left corners */
    font-size: 1rem;
    background-color: var(--light-bg);
    color: var(--light-text);
    transition: border-color 0.3s, background-color 0.3s;
}
body.dark-mode input[type="text"]#manufacturer-input {
     border-color: var(--border-color-dark);
     background-color: #2b3a5e; /* Input dark background */
     color: var(--dark-text);
}
input[type="text"]#manufacturer-input:focus {
     outline: none;
     border-color: var(--primary-color);
     box-shadow: 0 0 0 2px rgba(0, 119, 182, 0.2);
     position: relative; /* Prevent focus shadow clipping */
     z-index: 2;
}
 body.dark-mode input[type="text"]#manufacturer-input:focus {
     border-color: var(--secondary-color);
     box-shadow: 0 0 0 2px rgba(0, 180, 216, 0.2);
 }

/* General Button Style */
button {
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    transition: background-color 0.2s, transform 0.1s ease-out;
    white-space: nowrap; /* Prevent text wrapping */
}
button:not(:disabled):hover {
    background-color: #005f8a; /* Darker primary */
    transform: translateY(-1px); /* Subtle lift */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button:not(:disabled):active {
    transform: translateY(0);
    box-shadow: none;
}
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

body.dark-mode button {
     background-color: var(--secondary-color); /* Dark mode button primary */
}
body.dark-mode button:not(:disabled):hover {
      background-color: #009fbf;
 }

/* Specific Button Styles */
button#check-button {
     border-radius: 0 8px 8px 0; /* Round right corners */
     padding: 14px 20px; /* Match input height */
}

#options-container button {
    width: 100%; /* Fill grid cell */
    background-color: var(--secondary-color); /* Lighter for options */
    padding: 12px 10px; /* Slightly less padding for options */
}
 body.dark-mode #options-container button { background-color: #007ea7; }
 body.dark-mode #options-container button:hover:not(:disabled) { background-color: #00a8cc; }


button#next-button {
     background-color: var(--accent-color);
     color: #333;
     margin: 20px auto 0;
     padding: 12px 25px;
}
 body.dark-mode button#next-button {
     background-color: var(--accent-color);
      color: var(--dark-bg);
 }
 body.dark-mode button#next-button:hover { background-color: #e6b800;}


button#hint-button {
     background-color: #6c757d;
     font-size: 0.9rem;
     padding: 8px 15px;
}
 body.dark-mode button#hint-button { background-color: #495057; }
 body.dark-mode button#hint-button:hover:not(:disabled) { background-color: #5a6268; }


button.small-button { /* For refresh etc. */
     padding: 6px 12px;
     font-size: 0.85rem;
     font-weight: 400;
     border-radius: 5px;
     margin-top: 10px;
     background-color: #6c757d;
}
 body.dark-mode .small-button { background-color: #495057; }
 body.dark-mode .small-button:hover:not(:disabled) { background-color: #5a6268; }

/* --- Feedback & Result --- */
.correct-flash { animation: flash-correct 0.6s ease-out; }
.incorrect-flash { animation: flash-incorrect 0.6s ease-out; }
@keyframes flash-correct {
    50% { background-color: rgba(42, 157, 143, 0.3); }
}
@keyframes flash-incorrect {
    50% { background-color: rgba(231, 111, 81, 0.3); }
}

.result {
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 1.2em;
    font-weight: 600;
    min-height: 1.5em;
    transition: color 0.3s ease;
}
.result.correct { color: var(--correct-color); }
.result.incorrect { color: var(--incorrect-color); }

/* --- Stats & Info Card --- */
.stats-info-container {
    display: flex;
    justify-content: space-around; /* Distribute space */
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 25px;
    margin-top: 25px;
    width: 100%;
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 1em;
    text-align: left;
    background-color: rgba(0, 119, 182, 0.05); /* Subtle primary background */
    padding: 15px 20px;
    border-radius: 8px;
    min-width: 200px;
    border: 1px solid var(--border-color-light);
}
body.dark-mode .stats-container {
    background-color: rgba(0, 180, 216, 0.1); /* Subtle secondary background */
     border-color: var(--border-color-dark);
}
.stats-container div { font-weight: 600; }
.stats-container span { font-weight: 400; padding-left: 8px;}
.streak { color: var(--accent-color); font-size: 1.1em;} /* Highlight streak */
.highest-streak { color: var(--primary-color); }
.avg-time { color: var(--secondary-color); }
 body.dark-mode .highest-streak { color: var(--secondary-color); }
 body.dark-mode .avg-time { color: #ade8f4; }

.info-card {
    background-color: var(--light-card-bg);
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    padding: 20px;
    text-align: left;
    box-shadow: 0 4px 10px var(--shadow-color-light);
    transition: opacity 0.4s ease, transform 0.4s ease;
    opacity: 0;
    transform: scale(0.95) translateY(10px); /* Start slightly scaled down and shifted */
    pointer-events: none;
    max-width: 380px;
    width: 100%;
    order: 1; /* Default order */
}
 .info-card.show {
     opacity: 1;
     transform: scale(1) translateY(0);
     pointer-events: auto;
 }
 body.dark-mode .info-card {
     background-color: var(--dark-card-bg);
     border-color: var(--border-color-dark);
     box-shadow: 0 4px 10px var(--shadow-color-dark);
 }

.info-card ul { list-style: none; padding: 0; margin: 0; }
.info-card li { margin-bottom: 10px; font-size: 0.95em; display: flex; gap: 5px; }
.info-card li strong { color: var(--light-text); font-weight: 600; min-width: 70px; flex-shrink: 0;}
body.dark-mode .info-card li strong { color: var(--dark-text);}
.info-card li span { color: #555; word-break: break-word; } /* Allow long park names to wrap */
 body.dark-mode .info-card li span { color: #bbb; }

/* Hint Area */
.hint-container { margin: 10px 0; min-height: 40px; }
#hint-display {
    margin-top: 8px;
    color: #666;
    font-style: italic;
    font-size: 0.9em;
    line-height: 1.4;
}
 body.dark-mode #hint-display { color: #aaa;}

/* --- Leaderboard Section --- */
#leaderboard-section {
     margin-top: 35px;
     padding-top: 20px;
     border-top: 1px solid var(--border-color-light);
     width: 100%;
}
 body.dark-mode #leaderboard-section {
      border-top-color: var(--border-color-dark);
 }

 #leaderboard-list {
     list-style: none;
     padding: 0;
     margin: 0 0 15px 0; /* Space below list */
     max-height: 300px;
     overflow-y: auto;
     border: 1px solid var(--border-color-light);
     border-radius: 8px;
     background-color: rgba(0, 0, 0, 0.02);
 }
  body.dark-mode #leaderboard-list {
      border-color: var(--border-color-dark);
      background-color: rgba(255, 255, 255, 0.03);
 }
 #leaderboard-list li {
      display: flex;
      justify-content: space-between;
      align-items: center; /* Vertically align */
      padding: 10px 15px;
      border-bottom: 1px dashed var(--border-color-light);
      font-size: 0.95em;
      transition: background-color 0.2s ease;
  }
   body.dark-mode #leaderboard-list li { border-bottom-color: var(--border-color-dark); }
   #leaderboard-list li:last-child { border-bottom: none; }
   #leaderboard-list li:nth-child(odd) { background-color: rgba(0,0,0,0.015);} /* Subtle striping */
   body.dark-mode #leaderboard-list li:nth-child(odd) { background-color: rgba(255,255,255,0.02); }

  #leaderboard-list .leader-name { font-weight: 600; word-break: break-all; padding-right: 10px;} /* Allow long names to break */
  #leaderboard-list .leader-score { font-weight: 700; color: var(--accent-color); flex-shrink: 0; }

 /* Score Submission Area */
 #submit-score-area {
      margin-top: 15px;
      padding: 15px;
      background-color: rgba(42, 157, 143, 0.1); /* Subtle correct color background */
      border-radius: 8px;
      border: 1px solid rgba(42, 157, 143, 0.2);
  }
  body.dark-mode #submit-score-area {
      background-color: rgba(42, 157, 143, 0.15);
      border-color: rgba(42, 157, 143, 0.3);
  }
 #submit-score-area p { margin: 0 0 10px 0; font-weight: 600; }
 #submit-score-area input[type="text"] { /* Specific styling for this input */
    padding: 10px 14px;
    width: calc(100% - 150px); /* Adjust based on button width */
    max-width: 300px;
    border-radius: 6px 0 0 6px;
    border: 1px solid var(--border-color-light);
    margin-right: -1px; /* Overlap border */
 }
 body.dark-mode #submit-score-area input[type="text"] {
     background-color: var(--dark-card-bg);
     border-color: var(--border-color-dark);
     color: var(--dark-text);
 }
 #submit-score-area button {
    padding: 10px 18px;
    width: 140px;
    border-radius: 0 6px 6px 0;
    background-color: var(--correct-color); /* Use correct color */
    font-size: 0.95rem;
 }
 body.dark-mode #submit-score-area button { background-color: var(--correct-color); }
 body.dark-mode #submit-score-area button:hover:not(:disabled) { background-color: #248a7e; }

/* --- Footer --- */
footer {
    margin-top: 40px;
    padding: 20px;
    font-size: 0.85em;
    color: rgba(0, 0, 0, 0.7);
    border-top: 1px solid var(--border-color-light);
    width: 100%;
    text-align: center;
    line-height: 1.5;
}
 body.dark-mode footer {
    color: rgba(255, 255, 255, 0.7);
    border-top-color: var(--border-color-dark);
}
 footer a { color: var(--primary-color); text-decoration: none; font-weight: 600;}
 body.dark-mode footer a { color: var(--secondary-color); }
 footer a:hover { text-decoration: underline; }

 /* Link-like button for footer actions */
button.link-button {
    background: none;
    border: none;
    color: var(--primary-color);
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font-size: 1em; /* Inherit size */
    font-family: inherit;
    font-weight: 600;
    vertical-align: baseline; /* Align with text */
}
body.dark-mode button.link-button {
     color: var(--secondary-color);
}
button.link-button:hover {
     text-decoration: none; /* Remove underline on hover */
     transform: none; /* No lift effect */
     box-shadow: none;
}

/* Manufacturer List Popup */
.manufacturer-list {
    margin: 10px auto 0; /* Center below footer text */
    padding: 15px;
    background-color: var(--light-bg);
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    max-height: 150px;
    overflow-y: auto;
    text-align: left;
    line-height: 1.6;
    max-width: 500px;
    font-size: 0.9em;
    box-shadow: 0 2px 5px var(--shadow-color-light);
}
body.dark-mode .manufacturer-list {
    background-color: var(--dark-card-bg);
    border-color: var(--border-color-dark);
     box-shadow: 0 2px 5px var(--shadow-color-dark);
}

/* --- Utility Classes --- */
.hidden {
    display: none !important; /* Ensure hidden overrides display: flex/grid */
}

/* --- Loading Indicator Styles --- */
#loading-indicator {
    font-size: 1.2em;
    color: #555;
    padding: 50px 0; /* Add padding when shown */
    width: 100%;
    text-align: center;
}
body.dark-mode #loading-indicator { color: #ccc; }

/* Style for list loading placeholder */
#leaderboard-list li .loading {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-left-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
body.dark-mode #leaderboard-list li .loading {
   border: 2px solid rgba(255, 255, 255, 0.1);
   border-left-color: var(--secondary-color);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    body { padding: 15px; }
    main { padding: 20px 15px; max-width: 100%;}
    h1 { font-size: clamp(1.6rem, 5vw, 2rem); } /* Adjust heading size */

    .stats-info-container { flex-direction: column; align-items: center; gap: 20px;}
    .info-card { order: 0; max-width: 95%; margin-bottom: 0;} /* Show details first */
    .stats-container { order: 1; min-width: 250px; text-align: center; align-items: center;}

     #input-container { flex-direction: column; gap: 8px; align-items: stretch;}
     input[type="text"]#manufacturer-input { border-radius: 8px; border-right: 1px solid var(--border-color-light);}
      body.dark-mode input[type="text"]#manufacturer-input { border-right-color: var(--border-color-dark); }
     button#check-button { width: 100%; border-radius: 8px; }

     #submit-score-area { display: flex; flex-direction: column; gap: 8px; align-items: stretch;}
     #submit-score-area input[type="text"] { width: 100%; border-radius: 6px; }
     #submit-score-area button { width: 100%; border-radius: 6px;}
}

@media (max-width: 480px) {
    body { padding: 10px; }
    main { padding: 15px 10px; border-radius: 10px; }
    h1 { font-size: 1.5em; }
    #coaster-image { width: 95%; } /* More width on small screens */
    .toggles-container { gap: 10px 15px; padding-bottom: 15px; margin-bottom: 20px; }
    #guess-timer { font-size: 1.5em; padding: 3px 12px; top: -10px;}
    #options-container { grid-template-columns: 1fr; } /* Single column options */
    #leaderboard-list li { flex-direction: column; align-items: flex-start; gap: 3px; padding: 8px 10px;}
    .info-card ul { font-size: 0.9em; } /* Slightly smaller text in card */
    footer { font-size: 0.8em;}
}

// Adjust buttons for 2x2 layout in Easy mode
function adjustButtonsForEasyMode() {
    const optionsContainer = document.getElementById('options-container');
    const buttons = Array.from(optionsContainer.children);

    // Ensure only 4 buttons are shown in Easy mode
    buttons.forEach((button, index) => {
        button.style.display = index < 4 ? 'block' : 'none';
    });
}

// Call this function when switching to Easy mode
adjustButtonsForEasyMode();