/* --- Global Settings & Variables --- */
:root {
    /* Light Mode Colors (Default) */
    --bg-color: #ffffff;
    --text-color: #333333;
    --heading-color: #1a1a1a;
    --link-color: #0056b3;
    --link-hover-color: #003d80;
    --border-color: #dddddd;
    --card-bg-color: #f9f9f9;
    --card-border-color: #eeeeee;
    --header-bg-color: #f8f9fa;
    --header-border-color: #e7e7e7;
    --button-bg-color: #007bff;
    --button-text-color: #ffffff;
    --button-hover-bg-color: #0056b3;
    --input-bg-color: #ffffff;
    --input-border-color: #cccccc;
    --input-text-color: #333333;
    --result-bg-color: #eef7ff; /* Light blue background for results */
    --result-border-color: #cce5ff;

    /* Typography */
    --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --base-font-size: 1rem; /* Approx 16px */
    --line-height: 1.6;

    /* Layout */
    --content-max-width: 80ch; /* Optimal line length for readability */
    --grid-min-item-width: 280px; /* Min width for category cards */
    --grid-gap: 1.5rem;
    --container-padding: 1rem;
    --wide-container-padding: 2rem;
}

/* --- Dark Mode Overrides --- */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #cccccc;
        --heading-color: #ffffff;
        --link-color: #66bfff;
        --link-hover-color: #aaddff;
        --border-color: #555555;
        --card-bg-color: #2c2c2c;
        --card-border-color: #444444;
        --header-bg-color: #252525;
        --header-border-color: #3a3a3a;
        --button-bg-color: #0056b3; /* Keep button noticeable */
        --button-text-color: #ffffff;
        --button-hover-bg-color: #007bff;
        --input-bg-color: #333333;
        --input-border-color: #666666;
        --input-text-color: #cccccc;
        --result-bg-color: #2a3a4a; /* Dark blue background for results */
        --result-border-color: #3a5a7a;
    }
}

/* --- Base Styles --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--base-font-size);
    scroll-behavior: smooth;
    /* Basic responsive font size adjustment */
    font-size: clamp(0.9rem, 0.8rem + 0.5vw, 1.1rem);
}

body {
    font-family: var(--font-family-sans);
    line-height: var(--line-height);
    color: var(--text-color);
    background-color: var(--bg-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex-grow: 1; /* Ensures main content pushes footer down */
    padding-top: 2rem;
    padding-bottom: 3rem;
}

/* --- Container --- */
.container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--container-padding);
    padding-right: var(--container-padding);
}

/* Apply max-width constraints for readability */
main > .container,
.tool-container {
    max-width: var(--content-max-width);
}
/* Allow grid to use more space on wider screens */
main > .container:has(.category-grid) {
    max-width: 1600px; /* Allow grid to expand */
}


@media (min-width: 768px) {
    .container {
        padding-left: var(--wide-container-padding);
        padding-right: var(--wide-container-padding);
    }
}


/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
    color: var(--heading-color);
    margin-bottom: 0.75em;
    line-height: 1.3;
    font-weight: 600;
}

h1 { font-size: clamp(2rem, 1.5rem + 2vw, 3rem); }
h2 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); } /* Category titles */
h3 { font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem); }

p {
    margin-bottom: 1em;
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover, a:focus {
    color: var(--link-hover-color);
    text-decoration: underline;
}

ul {
    list-style: none;
    padding-left: 0;
}

/* --- Header & Navigation --- */
.site-header {
    background-color: var(--header-bg-color);
    border-bottom: 1px solid var(--header-border-color);
    padding: 0.8rem 0;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%; /* Header spans full width */
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--heading-color);
}
.logo a {
    color: inherit;
    text-decoration: none;
}
.logo a:hover {
    color: var(--link-color);
}

.main-nav ul {
    display: flex;
    gap: 1.5rem;
}

.main-nav a {
    font-weight: 500;
    text-decoration: none;
}

/* --- Footer --- */
.site-footer {
    background-color: var(--header-bg-color); /* Reuse header style */
    border-top: 1px solid var(--header-border-color);
    padding: 1.5rem 0;
    text-align: center;
    font-size: 0.9rem;
    margin-top: auto; /* Pushes footer to bottom */
    color: var(--text-color);
}

.site-footer .container {
     max-width: 100%; /* Footer spans full width */
}

/* --- Homepage Grid --- */
.intro {
    font-size: 1.1rem;
    max-width: 70ch; /* Slightly wider intro */
    margin-bottom: 2rem;
}

.category-grid {
    display: grid;
    /* Responsive Columns: Fit as many columns as possible with a minimum width */
    grid-template-columns: repeat(auto-fit, minmax(var(--grid-min-item-width), 1fr));
    gap: var(--grid-gap);
}

.category-card {
    background-color: var(--card-bg-color);
    border: 1px solid var(--card-border-color);
    border-radius: 8px;
    padding: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.category-card:hover {
    /* Subtle hover effect */
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
@media (prefers-color-scheme: dark) {
    .category-card:hover {
         box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
    }
}


.category-card h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.3rem; /* Slightly smaller heading for cards */
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.category-card ul li {
    margin-bottom: 0.6rem;
}

.category-card ul li a {
    display: block; /* Make link area larger */
    padding: 0.2rem 0;
    font-size: 0.95rem;
}

/* --- Tool Page Template --- */
.tool-container {
    /* Already centered and max-width applied by .container rules */
    padding-top: 1rem;
}

.tool-description {
    font-size: 1.1rem;
    color: var(--text-color); /* Use main text color, slightly faded maybe */
    margin-bottom: 2rem;
    opacity: 0.9;
}

.tool-form {
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--heading-color);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--input-border-color);
    border-radius: 4px;
    background-color: var(--input-bg-color);
    color: var(--input-text-color);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--link-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25); /* Adjust focus color */
}

button,
input[type="submit"] {
    background-color: var(--button-bg-color);
    color: var(--button-text-color);
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: inline-block; /* Ensure button doesn't stretch full width unless intended */
}

button:hover,
input[type="submit"]:hover {
    background-color: var(--button-hover-bg-color);
}

.result-area {
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: var(--result-bg-color);
    border: 1px solid var(--result-border-color);
    border-radius: 4px;
    /* display: none; /* Initially hidden, shown by JS */
}

.result-area h2 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.4rem;
}

.result-area p {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.result-area strong {
    color: var(--heading-color);
}


/* --- Accessibility --- */
/* Add visible focus styles for keyboard navigation */
a:focus, button:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}
/* Remove default outline when custom focus is applied */
*:focus:not(:focus-visible) {
  outline: none;
}
*:focus-visible {
   outline: 2px solid var(--link-color);
   outline-offset: 2px;
}


/* --- Responsiveness Adjustments --- */
@media (max-width: 768px) {
    .site-header .container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .main-nav ul {
        gap: 1rem;
        padding-top: 0.5rem;
    }

    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.4rem; }
    .category-card h2 { font-size: 1.2rem; }

    :root {
       --grid-min-item-width: 240px; /* Slightly smaller min width on mobile */
    }
}

@media (max-width: 480px) {
    html {
        font-size: 0.95rem; /* Slightly smaller base on very small screens */
    }
     :root {
       --grid-min-item-width: 90%; /* Force single column on very small screens */
       --grid-gap: 1rem;
       --container-padding: 0.8rem;
    }
    .tool-form button {
        width: 100%; /* Make button full width on small screens */
        text-align: center;
    }
}