/* ==========================================================================
   Base Styles & CSS Custom Properties (Variables)
   ========================================================================== */

/* 1. Modern CSS Reset (A more comprehensive reset)
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove list styles on ul, ol elements with a list role, which suggests they're not purely decorative */
ul[role="list"],
ol[role="list"] {
  list-style: none;
}

/* Set core root defaults */
html {
  scroll-behavior: smooth;
  font-size: 100%; /* Usually 16px by default */
}

html:focus-within {
  scroll-behavior: smooth; /* Re-enable smooth scroll for keyboard navigation */
}

/* Set core body defaults */
body {
  min-height: 100vh;
  text-rendering: optimizeSpeed;
  line-height: 1.5; /* Default line height */
  font-family: var(--font-family-base);
  background-color: var(--color-background);
  color: var(--color-text-primary);
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* Make images easier to work with */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit; /* Ensure form elements inherit text color */
}

/* Remove all animations, transitions and smooth scroll for people that prefer not to see them */
@media (prefers-reduced-motion: reduce) {
  html:focus-within {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/*
   Focus states:
   Remove the ugly default blue glow from Chrome and use our own.
   Provide a consistent focus style for interactive elements.
*/
*:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--color-focus-shadow);
}

/* For elements that should not have a focus ring but are focusable (use with caution) */
.focus-invisible:focus-visible {
  outline: none;
  box-shadow: none;
}


/* 2. CSS Custom Properties (Variables)
   -------------------------------------------------------------------------- */
:root {
  /* Transitions */
  --transition-speed: 0.3s;
  --transition-speed-fast: 0.15s;
  --transition-timing: ease-in-out;

  /* Typography */
  --font-family-base: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  --font-family-heading: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

  /* Font Weights */
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Font Sizes (using a basic type scale, can be expanded) */
  --font-size-xs: 0.75rem;  /* 12px */
  --font-size-sm: 0.875rem; /* 14px */
  --font-size-base: 1rem;    /* 16px */
  --font-size-md: 1.125rem; /* 18px */
  --font-size-lg: 1.25rem;  /* 20px */
  --font-size-xl: 1.5rem;   /* 24px */
  --font-size-2xl: 1.875rem; /* 30px */
  --font-size-3xl: 2.25rem;  /* 36px */
  --font-size-4xl: 3rem;     /* 48px */

  /* Spacing (can be used for margins, paddings, gaps) */
  --space-xxs: 0.25rem; /* 4px */
  --space-xs: 0.5rem;   /* 8px */
  --space-sm: 0.75rem;  /* 12px */
  --space-md: 1rem;     /* 16px */
  --space-lg: 1.5rem;   /* 24px */
  --space-xl: 2rem;     /* 32px */
  --space-2xl: 2.5rem;  /* 40px */
  --space-3xl: 3rem;    /* 48px */

  /* Borders */
  --border-radius-sm: 0.25rem; /* 4px */
  --border-radius-md: 0.5rem;  /* 8px */
  --border-radius-lg: 0.75rem; /* 12px */
  --border-radius-xl: 1rem;    /* 16px */
  --border-radius-pill: 9999px;
  --border-width: 1px;
  --border-width-thick: 2px;

  /* Shadows (example setup, can be refined) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Default Theme: Mint (Light) */
  --color-primary-hue: 160; /* Approximate hue for mint */
  --color-primary-saturation: 80%;
  --color-primary-lightness: 50%;

  --color-primary: hsl(var(--color-primary-hue), var(--color-primary-saturation), var(--color-primary-lightness)); /* #15E2AA */
  --color-primary-light: hsl(var(--color-primary-hue), var(--color-primary-saturation), calc(var(--color-primary-lightness) + 20%));
  --color-primary-dark: hsl(var(--color-primary-hue), var(--color-primary-saturation), calc(var(--color-primary-lightness) - 10%)); /* #00A896 (approx) */
  --color-primary-rgb: 21, 226, 170; /* For rgba() glows etc. */

  --color-secondary-hue: 175; /* Secondary color, can be adjusted or be a different color */
  --color-secondary-saturation: 70%;
  --color-secondary-lightness: 35%;
  --color-secondary: hsl(var(--color-secondary-hue), var(--color-secondary-saturation), var(--color-secondary-lightness));

  --color-background: hsl(210, 30%, 97%); /* #f4f7f9 - Very light cool gray */
  --color-surface: hsl(0, 0%, 100%); /* White for cards, modals etc. */
  --color-surface-alt: hsl(210, 30%, 94%); /* Slightly darker surface */

  --color-text-primary: hsl(210, 25%, 25%);    /* #333e4d - Dark desaturated blue */
  --color-text-secondary: hsl(210, 15%, 45%);  /* #657180 - Medium gray */
  --color-text-muted: hsl(210, 15%, 65%);      /* #98a2af - Lighter gray */
  --color-text-on-primary: hsl(0, 0%, 100%);   /* White text on primary backgrounds */

  --color-border: hsl(210, 20%, 88%);       /* #dae0e6 - Light gray border */
  --color-border-hover: hsl(210, 20%, 75%);

  --color-success: hsl(145, 63%, 42%);
  --color-warning: hsl(45, 100%, 51%);
  --color-error: hsl(0, 72%, 51%);
  --color-info: hsl(200, 82%, 52%);

  --color-focus-ring: hsl(var(--color-primary-hue), var(--color-primary-saturation), calc(var(--color-primary-lightness) + 10%));
  --color-focus-shadow: hsla(var(--color-primary-hue), var(--color-primary-saturation), var(--color-primary-lightness), 0.25);

  /* Gradient variables (can be overridden by theme.js) */
  --gradient-start: var(--color-primary-dark);
  --gradient-middle: var(--color-primary);
  --gradient-end: var(--color-primary-light);
  --banner-color: var(--color-primary-light); /* Example for free-banner, can be specific */
}

/* Dark Mode Theme */
.dark-mode {
  --color-primary-lightness: 55%; /* Make primary slightly brighter in dark mode if needed */

  --color-background: hsl(220, 18%, 12%); /* #1a1c22 - Very dark cool gray */
  --color-surface: hsl(220, 15%, 18%);    /* #252830 - Darker surface for cards */
  --color-surface-alt: hsl(220, 15%, 15%); /* Even darker surface */

  --color-text-primary: hsl(210, 25%, 90%);   /* #e0e4e8 - Light gray for text */
  --color-text-secondary: hsl(210, 15%, 70%); /* #a7b0bb - Medium light gray */
  --color-text-muted: hsl(210, 15%, 55%);     /* #7f8a99 - Darker light gray */

  --color-border: hsl(220, 12%, 28%);      /* #3e424d - Darker border */
  --color-border-hover: hsl(220, 12%, 40%);

  --color-success: hsl(145, 58%, 52%);
  --color-warning: hsl(45, 100%, 61%);
  --color-error: hsl(0, 72%, 61%);
  --color-info: hsl(200, 82%, 62%);

  --color-focus-shadow: hsla(var(--color-primary-hue), var(--color-primary-saturation), calc(var(--color-primary-lightness) + 10%), 0.35);
  --banner-color: var(--color-surface);
}


/* 3. Basic Typography
   -------------------------------------------------------------------------- */
body {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-heading);
  font-weight: var(--font-weight-bold);
  line-height: 1.3;
  color: var(--color-text-primary);
  margin-bottom: var(--space-md); /* Default bottom margin for headings */
}
h1:last-child, h2:last-child, h3:last-child, h4:last-child, h5:last-child, h6:last-child {
  margin-bottom: 0;
}

h1 { font-size: var(--font-size-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--font-size-2xl); letter-spacing: -0.015em; }
h3 { font-size: var(--font-size-xl); font-weight: var(--font-weight-semibold); }
h4 { font-size: var(--font-size-lg); font-weight: var(--font-weight-semibold); }
h5 { font-size: var(--font-size-md); font-weight: var(--font-weight-medium); }
h6 { font-size: var(--font-size-base); font-weight: var(--font-weight-medium); text-transform: uppercase; letter-spacing: 0.05em; }

p {
  margin-bottom: var(--space-md);
  line-height: 1.65;
}
p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-speed-fast) ease;
}
a:hover,
a:focus {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

strong, b {
  font-weight: var(--font-weight-bold);
}

em, i {
  font-style: italic;
}

small {
  font-size: var(--font-size-sm);
}

hr {
  display: block;
  height: var(--border-width);
  border: 0;
  border-top: var(--border-width) solid var(--color-border);
  margin: var(--space-lg) 0;
  padding: 0;
}

/* Quotes */
blockquote {
  margin: var(--space-lg) 0;
  padding-left: var(--space-lg);
  border-left: 4px solid var(--color-border);
  font-style: italic;
  color: var(--color-text-secondary);
}
blockquote p {
  margin-bottom: var(--space-xs);
}
blockquote cite {
  display: block;
  margin-top: var(--space-sm);
  font-style: normal;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Code blocks and inline code */
pre,
code,
kbd,
samp {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
  font-size: 0.9em; /* Slightly smaller for monospace */
}
pre {
  background-color: var(--color-surface-alt);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-md);
  overflow-x: auto;
  white-space: pre-wrap; /* Or pre for no wrap */
  word-wrap: break-word;
}
code {
  background-color: hsla(var(--color-primary-hue), 20%, 90%, 0.5);
  padding: 0.15em 0.3em;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-primary);
}
.dark-mode code {
  background-color: hsla(var(--color-primary-hue), 20%, 20%, 0.7);
}
pre code {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit; /* Inherit pre's font size */
}

/* 4. Custom Scrollbar (WebKit-based browsers)
   -------------------------------------------------------------------------- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--color-surface-alt);
  border-radius: var(--border-radius-pill);
}
::-webkit-scrollbar-thumb {
  background-color: var(--color-text-muted);
  border-radius: var(--border-radius-pill);
  border: 2px solid var(--color-surface-alt); /* Creates padding around thumb */
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-secondary);
}
.dark-mode ::-webkit-scrollbar-thumb {
  background-color: var(--color-border-hover);
}
.dark-mode ::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-primary-dark);
}


/* 5. Utility Classes (very basic examples)
   -------------------------------------------------------------------------- */
.visually-hidden { /* For screen reader only content */
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.text-center { text-align: center !important; }
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }

.block { display: block !important; }
.inline-block { display: inline-block !important; }
.inline { display: inline !important; }
.flex { display: flex !important; }
.inline-flex { display: inline-flex !important; }
.grid { display: grid !important; }
.hidden { display: none !important; }

.img-responsive { /* Basic responsive image */
  max-width: 100%;
  height: auto;
}

/* Margins - example, can be expanded or use a more systematic approach like Tailwind */
.mt-1 { margin-top: var(--space-xs) !important; }
.mb-1 { margin-bottom: var(--space-xs) !important; }
.mt-2 { margin-top: var(--space-sm) !important; }
.mb-2 { margin-bottom: var(--space-sm) !important; }
.mt-3 { margin-top: var(--space-md) !important; }
.mb-3 { margin-bottom: var(--space-md) !important; }
.mt-4 { margin-top: var(--space-lg) !important; }
.mb-4 { margin-bottom: var(--space-lg) !important; }
.mt-5 { margin-top: var(--space-xl) !important; }
.mb-5 { margin-bottom: var(--space-xl) !important; }

/* Basic container (can be refined in layout.css) */
.container {
  width: 100%;
  max-width: 1200px; /* Example max-width */
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}

@media (min-width: 768px) {
  .container {
    padding-left: var(--space-lg);
    padding-right: var(--space-lg);
  }
}