/* --- Import Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Merriweather:wght@400;700&family=Roboto+Mono&display=swap');

/* --- CSS Variables --- */
:root {
    /* Default: Dark Theme */
    --bg-color: #1f2023;
    --container-bg: rgba(42, 45, 49, 0.7); /* Slightly more transparent */
    --text-color: #e8e8e8;
    --text-muted: #8b949e;
    --accent-color: #58a6ff;
    --accent-hover: #79bbff;
    --accent-text-dark: #1f2023;
    --heading-color: #a7c7e7; /* Lighter blue for headings */
    --input-bg: #2a2d31;
    --border-color: #44474e;
    --error-color: #f85149;
    --error-hover: #da3633;
    --button-disabled-bg: #3a5f8a;
    --button-disabled-text: #8b949e;
    --code-bg: rgba(139, 148, 158, 0.15);
    --blockquote-border: #44474e;
    --response-text-color: #c9d1d9; /* Specific for response area */

    --font-body: 'Lato', sans-serif;
    --font-heading: 'Merriweather', serif;
    --font-mono: 'Roboto Mono', monospace;

    --shadow-color-soft: rgba(0, 0, 0, 0.3);
    --shadow-color-focus: rgba(88, 166, 255, 0.25);
    --shadow-color-button-hover-accent: rgba(88, 166, 255, 0.2);
    --shadow-color-button-hover-error: rgba(218, 54, 51, 0.2);
    --shadow-color-inset: rgba(0, 0, 0, 0.2);
}

body.light-mode {
    /* Light Theme Overrides */
    --bg-color: #f8f9fa; /* Off-white background */
    --container-bg: rgba(255, 255, 255, 0.85); /* White-ish container, slightly opaque */
    --text-color: #212529; /* Dark text */
    --text-muted: #6c757d; /* Medium grey */
    --accent-color: #007bff; /* Standard blue */
    --accent-hover: #0056b3; /* Darker blue */
    --accent-text-dark: #ffffff; /* White text for blue button */
    --heading-color: #343a40; /* Dark grey for headings */
    --input-bg: #ffffff; /* White input/response bg */
    --border-color: #dee2e6; /* Light grey border */
    --error-color: #dc3545; /* Standard red */
    --error-hover: #c82333; /* Darker red */
    --button-disabled-bg: #e9ecef; /* Light grey disabled bg */
    --button-disabled-text: #6c757d; /* Medium grey disabled text */
    --code-bg: rgba(0, 0, 0, 0.05); /* Very light grey code bg */
    --blockquote-border: #ced4da; /* Light grey blockquote border */
    --response-text-color: #343a40; /* Dark text for response area */

    --shadow-color-soft: rgba(0, 0, 0, 0.1);
    --shadow-color-focus: rgba(0, 123, 255, 0.2);
    --shadow-color-button-hover-accent: rgba(0, 123, 255, 0.15);
    --shadow-color-button-hover-error: rgba(220, 53, 69, 0.15);
    --shadow-color-inset: rgba(0, 0, 0, 0.08);
}

/* --- Basic Reset & Body Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease; /* Smooth theme transition */
}

/* --- Main Content Container --- */
.container {
    width: 100%;
    max-width: 800px;
    background-color: var(--container-bg);
    padding: 2rem 2.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 25px var(--shadow-color-soft);
    border: 1px solid var(--border-color); /* Add subtle border */
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* --- Title Area --- */
.title-container {
    display: flex;
    justify-content: center; /* Center title */
    align-items: center;
    gap: 0.8rem; /* Space between title and button */
    margin-bottom: 2.5rem;
    position: relative; /* For absolute positioning if needed, but flex is good */
}

h1 {
    font-family: var(--font-heading);
    color: var(--heading-color);
    font-weight: 700;
    text-shadow: 0 1px 2px var(--shadow-color-soft); /* Use variable */
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    text-align: center; /* Ensure text is centered within its space */
    margin: 0; /* Remove default margin, handled by container */
    transition: color 0.3s ease;
}

#themeToggle {
    background: none;
    border: none;
    font-size: 1.8rem; /* Adjust emoji size */
    cursor: pointer;
    padding: 0;
    line-height: 1; /* Prevent extra spacing */
    color: var(--text-muted); /* Use muted color */
    transition: transform 0.2s ease, color 0.3s ease;
}

#themeToggle:hover {
    transform: scale(1.15) rotate(15deg); /* Fun hover effect */
    color: var(--accent-color); /* Highlight on hover */
}

h2 {
    font-family: var(--font-heading);
    color: var(--heading-color);
    margin-bottom: 1rem;
    font-weight: 700;
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    margin-top: 2.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    transition: color 0.3s ease, border-color 0.3s ease;
}

/* --- Form Elements --- */
label {
    display: block;
    margin-bottom: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.95rem;
    transition: color 0.3s ease;
}

textarea {
    width: 100%;
    margin-bottom: 1.5rem;
    padding: 0.8rem 1rem;
    font-family: var(--font-body);
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    resize: vertical;
    min-height: 120px;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
    font-style: italic;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--shadow-color-focus);
}


/* --- Buttons --- */
.button-container {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}

button {
    font-family: var(--font-body);
    font-weight: 700;
    padding: 0.75rem 1.8rem;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    transition: background-color 0.2s ease, color 0.3s ease, transform 0.1s ease, box-shadow 0.2s ease;
    /* box-shadow: 0 2px 5px var(--shadow-color-soft); */
}

button:active:not(:disabled) {
    transform: scale(0.97);
    box-shadow: none;
}

#sendButton {
    background-color: var(--accent-color);
    color: var(--accent-text-dark);
}

#sendButton:hover:not(:disabled) {
    background-color: var(--accent-hover);
    box-shadow: 0 4px 8px var(--shadow-color-button-hover-accent);
}

#sendButton:disabled {
    background-color: var(--button-disabled-bg);
    color: var(--button-disabled-text);
    cursor: not-allowed;
    box-shadow: none;
}

#stopButton {
    background-color: var(--error-color);
    /* Keep text light on red for both themes for contrast */
    color: #ffffff;
    display: none;
}

#stopButton:hover {
    background-color: var(--error-hover);
    box-shadow: 0 4px 8px var(--shadow-color-button-hover-error);
    display: none;
}

#stopButton.hidden {
    display: none;
}


/* --- Response Area --- */
div#response {
    font-family: var(--font-mono);
    background: var(--input-bg); /* Match input background */
    padding: 1.5rem;
    word-wrap: break-word;
    min-height: 180px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--response-text-color); /* Use specific variable */
    font-size: 0.95rem;
    line-height: 1.7;
    box-shadow: inset 0 1px 3px var(--shadow-color-inset);
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* --- Styling for Common Markdown Elements WITHIN #response --- */
div#response h1,
div#response h2,
div#response h3,
div#response h4,
div#response h5,
div#response h6 {
    font-family: var(--font-mono);
    color: var(--heading-color);
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 700;
    line-height: 1.3;
    transition: color 0.3s ease;
}
div#response h1 { font-size: 1.6em; }
div#response h2 { font-size: 1.4em; }
div#response h3 { font-size: 1.2em; }
div#response h4 { font-size: 1.1em; }
div#response h5 { font-size: 1.0em; }
div#response h6 { font-size: 0.9em; color: var(--text-muted); }

div#response p {
    margin-bottom: 1em;
}

div#response strong {
    font-weight: 700;
}

div#response em {
    font-style: italic;
}

div#response ul,
div#response ol {
    margin-left: 2em;
    margin-bottom: 1em;
}

div#response li {
    margin-bottom: 0.4em;
}

div#response blockquote {
    border-left: 4px solid var(--blockquote-border);
    margin: 1em 0;
    padding-left: 1em;
    color: var(--text-muted);
    font-style: italic;
    transition: color 0.3s ease, border-color 0.3s ease;
}

div#response code { /* Inline code */
    font-family: var(--font-mono);
    background-color: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

div#response pre { /* Code blocks (```) */
    background-color: var(--code-bg);
    padding: 1em;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1em;
    line-height: 1.5;
    transition: background-color 0.3s ease;
}

div#response pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 1em;
}

div#response a {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent-color);
    transition: color 0.2s ease, border-color 0.2s ease;
}

div#response a:hover {
    color: var(--accent-hover);
    border-bottom-style: solid;
}

div#response hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
    transition: border-color 0.3s ease;
}


/* --- Status Area --- */
#status {
    margin-top: 1.5rem;
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
    min-height: 1.5em;
    text-align: center;
    width: 100%;
    transition: color 0.3s ease;
}

/* --- Save Link Styling --- */
.save-link-container {
    text-align: center;
    margin-top: 0.75rem;
    min-height: 1.5em;
}

#saveLink {
    color: var(--accent-color);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent-color);
    font-size: 0.95rem;
    transition: color 0.2s ease, border-bottom-style 0.2s ease, border-color 0.2s ease;
}

#saveLink:hover {
    color: var(--accent-hover);
    border-bottom-style: solid;
}


/* --- Loading Indicator --- */
#status.loading::after {
    content: ' .';
    animation: dots 1.4s infinite steps(4, end);
    display: inline-block;
}

@keyframes dots {
    0%, 20% { content: ' .'; }
    40% { content: ' ..'; }
    60% { content: ' ...'; }
    80%, 100% { content: ' '; }
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
    body {
        padding: 1rem 0.5rem;
    }
    .container {
        padding: 1.5rem 1rem;
        border-radius: 8px;
    }
    .title-container {
        margin-bottom: 1.5rem;
        gap: 0.5rem; /* Reduce gap */
    }
    h1 {
        /* font-size adjusted via clamp already */
    }
    #themeToggle {
        font-size: 1.5rem; /* Slightly smaller button */
    }
    h2 {
        margin-top: 1.5rem;
    }
    .button-container {
        flex-direction: column;
        gap: 0.75rem;
        margin-bottom: 1.5rem; /* Adjust spacing */
    }
    button {
        /* width: 100%; */
        padding: 0.8rem 1rem;
    }
    div#response {
        padding: 1rem;
        min-height: 150px;
    }
    #status {
        margin-top: 1rem;
    }
}