/* Global Box Sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Root Variables for Theming (Light Mode Defaults) */
:root {
  --primary-color: #2c3e50; /* Dark blue-gray for headings/accents */
  --text-color: #34495e;    /* Slightly lighter dark blue-gray for body text */
  --background-color: #ecf0f1; /* Light gray for overall page background */
  --container-bg-color: #ffffff; /* White for the main content container */

  --header-footer-bg: var(--primary-color);
  --header-footer-text: #ffffff;
  --link-hover-bg: #3498db; /* A slightly brighter blue for navigation link hover */
  --nav-active-bg: #3498db; /* Background for active navigation item */

  --button-bg: var(--link-hover-bg);
  --button-text: var(--header-footer-text);
  --button-hover-bg: #2980b9; /* Darker blue for button hover */

  --font-family-base: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  --font-size-base: 16px;
  --line-height-base: 1.6;
}

/* Dark Mode Variables */
body.dark-mode {
  --primary-color: #9cb3c9; /* Lighter blue-gray for headings/accents in dark mode */
  --text-color: #e0e6eb;    /* Light text for body in dark mode */
  --background-color: #1a202c; /* Dark background for overall page */
  --container-bg-color: #2d3748; /* Darker background for main content container */

  --header-footer-bg: #1a202c; /* Dark header/footer */
  --header-footer-text: #e0e6eb; /* Light text for header/footer */
  --link-hover-bg: #4a5568; /* Slightly lighter dark for link hover */
  --nav-active-bg: #4a5568; /* Active nav item in dark mode */

  --button-bg: var(--link-hover-bg);
  --button-text: var(--header-footer-text);
  --button-hover-bg: #616f86; /* Darker hover for buttons in dark mode */
}

/* Base HTML and Body Styles */
html {
  font-size: var(--font-size-base); /* Defines 1rem */
  background-color: var(--background-color); /* Overall page background */
  min-height: 100vh; /* Ensure html takes full viewport height for background */
}

body {
  font-family: var(--font-family-base);
  font-size: 1rem; /* Base font size for body content */
  line-height: var(--line-height-base);
  color: var(--text-color);
  background-color: var(--container-bg-color); /* White background for the content block */
  margin: 2.5rem auto; /* Center the content block with margin from top/bottom */
  padding: 0; /* Remove padding from body itself, children will add it */
  max-width: 800px; /* Max width for content */
  border-radius: 8px; /* Slightly rounded corners for a modern look */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); /* Subtle shadow for depth */
  display: flex; /* Use flexbox for header, main, footer layout */
  flex-direction: column;
  min-height: calc(100vh - 5rem); /* Adjust min-height to account for body margin */
  transition: background-color 0.3s ease, color 0.3s ease; /* Smooth transition for dark mode */
}

/* Header Styles */
header {
  background-color: var(--header-footer-bg);
  color: var(--header-footer-text);
  padding: 1.5rem 2.5rem; /* Consistent horizontal padding with body max-width */
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
  border-top-left-radius: 8px; /* Match body border-radius */
  border-top-right-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease; /* Smooth transition for dark mode */
}

header h1 {
  color: var(--header-footer-text); /* Override primary-color for header h1 */
  font-size: 2rem; /* Slightly smaller than default h1, but still prominent */
  margin: 0; /* Remove default margin for flex alignment */
  text-align: left; /* Align with flex layout */
  flex-shrink: 0; /* Prevent shrinking */
}

/* New: Wrapper for navigation and theme toggle button */
.header-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem; /* Space between nav and button */
  flex-wrap: wrap; /* Allow nav and button to wrap */
  justify-content: flex-end; /* Align to right */
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 1.5rem; /* Spacing between nav items */
  flex-wrap: wrap; /* Allow nav items to wrap */
}

nav a {
  color: var(--header-footer-text);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: background-color 0.3s ease, color 0.3s ease;
  white-space: nowrap; /* Prevent links from breaking */
}

nav a:hover,
nav a:focus {
  background-color: var(--link-hover-bg);
  color: var(--header-footer-text);
  outline: 2px solid var(--header-footer-text); /* Accessibility: visible focus */
  outline-offset: 2px;
}

/* New: Active navigation item style */
nav a.active {
  background-color: var(--nav-active-bg);
  font-weight: bold;
}

/* New: Theme Toggle Button Styles */
.theme-toggle-btn {
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.3s ease, transform 0.2s ease;
    white-space: nowrap; /* Prevent button text from breaking */
}

.theme-toggle-btn:hover,
.theme-toggle-btn:focus {
    background-color: var(--button-hover-bg);
    transform: translateY(-1px);
    outline: 2px solid var(--button-text);
    outline-offset: 2px;
}

/* Main Content Styles */
main {
  padding: 2.5rem; /* Consistent padding for main content area */
  flex-grow: 1; /* Allow main to take up available space */
  transition: background-color 0.3s ease, color 0.3s ease; /* Smooth transition for dark mode */
}

main section {
  margin-bottom: 2rem;
}

main section:last-of-type {
  margin-bottom: 0; /* No margin after the last section */
}

h2 {
  color: var(--primary-color);
  font-size: 1.8rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
  transition: color 0.3s ease; /* Smooth transition for dark mode */
}

p {
  margin-bottom: 1rem;
}

main ul {
  list-style-type: disc;
  margin-left: 1.5rem;
  padding-left: 0;
  margin-bottom: 1rem; /* Consistent spacing */
}

main li {
  margin-bottom: 0.5rem;
}

/* Footer Styles */
footer {
  background-color: var(--header-footer-bg);
  color: var(--header-footer-text);
  text-align: center;
  padding: 1.5rem 2.5rem; /* Consistent horizontal padding */
  margin-top: auto; /* Push footer to the bottom in a flex column layout */
  border-bottom-left-radius: 8px; /* Match body border-radius */
  border-bottom-right-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease; /* Smooth transition for dark mode */
}

footer p {
  margin: 0; /* Remove default paragraph margin */
}

/* Responsive Layout (Mobile-first approach) */
@media (max-width: 768px) {
  body {
    margin: 1.5rem auto; /* Smaller margin on tablets/smaller desktops */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); /* Lighter shadow */
    min-height: calc(100vh - 3rem); /* Adjust min-height for smaller body margin */
  }

  header {
    flex-direction: column;
    text-align: center;
    padding: 1.5rem; /* Adjust padding */
  }

  header h1 {
    font-size: 1.8rem; /* Adjust heading size for medium screens */
    margin-bottom: 1rem; /* Add space below title */
  }

  .header-controls {
    flex-direction: column; /* Stack nav and button */
    gap: 1rem; /* Adjust gap */
    width: 100%; /* Take full width */
    margin-top: 1rem; /* Space from h1 */
    justify-content: center; /* Center items */
  }

  nav ul {
    flex-direction: column;
    gap: 0.5rem;
    width: 100%; /* Make nav items take full width */
    margin-top: 0; /* Margin handled by .header-controls */
  }

  nav a {
    display: block; /* Make links take full width for better touch target */
    text-align: center;
    padding: 0.8rem 1rem; /* More prominent touch target */
  }

  main {
    padding: 2rem; /* Slightly less padding for main content */
  }

  h2 {
    font-size: 1.6rem; /* Adjust heading size for medium screens */
  }

  footer {
    padding: 1.5rem; /* Adjust padding */
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px; /* Slightly smaller base font for very small devices */
  }
  body {
    margin: 0; /* Remove margin entirely on very small screens to fill width */
    border-radius: 0; /* No border-radius on very small screens */
    box-shadow: none; /* No shadow on very small screens */
    min-height: 100vh; /* Full height */
  }

  header {
    border-radius: 0; /* No border-radius */
    padding: 1rem; /* Smaller padding */
  }

  header h1 {
    font-size: 1.6rem; /* Adjust heading size for mobile */
    margin-bottom: 0.8rem;
  }

  .header-controls {
    gap: 0.8rem;
    margin-top: 0.8rem;
  }

  nav ul {
    margin-top: 0;
  }

  nav a {
    padding: 0.6rem 1rem;
  }

  main {
    padding: 1.5rem; /* Even less padding */
  }

  h2 {
    font-size: 1.4rem; /* Adjust heading size for mobile */
    margin-top: 1.5rem;
  }

  footer {
    border-radius: 0; /* No border-radius */
    padding: 1rem; /* Smaller padding */
  }
}