/* -------------------------------------------------------------------------- */
/* Base Styles & Color Scheme Support                                         */
/* -------------------------------------------------------------------------- */
:root {
    /* Define color variables for easier switching */
    --background-light: #f8f9fa;
    --background-dark: #1a202c;
    --text-light: #333;
    --text-dark: #e2e8f0;
    --heading-light: #1a202c;
    --heading-dark: #a0aec0;
    --subheading-light: #000000;
    --subheading-dark: #a0aec0;
    --card-background-light: #ffffff;
    --card-background-dark: #2d3748;
    --toggle-track-light: #ccc;
    --toggle-track-dark: #4a5568;
    --toggle-thumb-light: white;
    --toggle-thumb-dark: #cbd5e0;
    --toggle-accent-dark: #3182ce;
    --icon-color-light: #333;
    --icon-color-dark: #f8f9fa;
}

/* Apply color scheme support to the HTML tag */
html {
    color-scheme: light dark;
    supported-color-schemes: light dark;
}

/* General body styling */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
    line-height: 1.7;
    color: var(--text-light);
    background-color: var(--background-light);
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Main container for the letter content */
.letter-body {
    width: 100%;
    max-width: 750px;
    background-color: var(--card-background-light);
    padding: 40px 50px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    text-align: left;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Typography and Headings */
h1 {
    font-size: 2.8em; 
    font-weight: 700; 
    color: var(--heading-light); 
    text-align: center; 
    margin-bottom: 30px; 
    line-height: 1.2; 
    transition: color 0.3s ease;
}

h2 {
    font-size: 1.8em; 
    font-weight: 600; 
    color: var(--subheading-light); 
    margin-top: 35px; 
    margin-bottom: 15px; 
    padding-bottom: 8px; 
    transition: color 0.3s ease, border-color 0.3s ease;
}

p { margin-bottom: 20px; }
ul { list-style-type: disc; margin-left: 28px; margin-bottom: 20px; padding-left: 20px; }
li { margin-bottom: 10px; }

.signature {
    text-align: right;
    margin-top: 40px;
    font-style: italic;
    color: #555;
    font-size: 1.1em;
}

/* --- Theme Switcher Styling --- */
.theme-switcher-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    display: flex;
    align-items: center;
}

.theme-toggle-checkbox { 
    opacity: 0; 
    position: absolute; 
    cursor: pointer; 
    height: 0; 
    width: 0; 
}

.theme-toggle-label {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--toggle-track-light);
    cursor: pointer;
    transition: background-color 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.icon-container {
    position: relative;
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Base icon styling */
.theme-icon {
    width: 24px;
    height: 24px;
    stroke: var(--icon-color-light);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Default state: Sun visible, Moon hidden */
.sun-icon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

.moon-icon {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(180deg) scale(0.8);
}

/* --- Dark Mode Styles --- */
/* When checkbox is checked, apply dark mode */
.theme-toggle-checkbox:checked + .theme-toggle-label {
    background-color: var(--toggle-accent-dark);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Icon transitions for dark mode */
.theme-toggle-checkbox:checked + .theme-toggle-label .sun-icon {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-180deg) scale(0.8);
}

.theme-toggle-checkbox:checked + .theme-toggle-label .moon-icon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

.theme-toggle-checkbox:checked + .theme-toggle-label .theme-icon {
    stroke: var(--icon-color-dark);
}

/* --- Apply Dark Mode Theme Variables --- */
.theme-toggle-checkbox:checked ~ * {
    /* This approach doesn't work well, let's use a different method */
}

/* Dark mode styles using :has() */
body:has(.theme-toggle-checkbox:checked) {
    --background-light: var(--background-dark);
    --text-light: var(--text-dark);
    --heading-light: var(--heading-dark);
    --subheading-light: var(--subheading-dark);
    --card-background-light: var(--card-background-dark);
    --toggle-track-light: var(--toggle-track-dark);
    --toggle-thumb-light: var(--toggle-thumb-dark);
    --icon-color-light: var(--icon-color-dark);
}

body:has(.theme-toggle-checkbox:checked) .letter-body {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

body:has(.theme-toggle-checkbox:checked) .signature {
    color: #a0aec0;
}

/* --- Image Styling --- */
.image-container {
    margin-top: 30px;
    width: 100%;
    flex-shrink: 0;
}

.image-container img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
    max-height: 500px;
    object-fit: cover;
}

/* -------------------------------------------------------------------------- */
/* Responsive Design Adjustments                                              */
/* -------------------------------------------------------------------------- */

/* For tablets and smaller desktops */
@media (max-width: 768px) {
    .letter-body {
        padding: 30px 30px;
        margin: 10px;
    }
    h1 { font-size: 2.2em; }
    h2 { font-size: 1.6em; }
    ul { margin-left: 20px; padding-left: 15px; }
}

/* For mobile phones */
@media (max-width: 480px) {
    body { padding: 10px; }
    .letter-body {
        padding: 25px 20px;
        border-radius: 8px;
    }
    h1 {
        font-size: 1.8em;
        margin-bottom: 25px;
    }
    h2 {
        font-size: 1.4em;
        margin-top: 30px;
        border-bottom-width: 2px;
    }
    p, li { font-size: 0.95em; }
    .signature { margin-top: 30px; font-size: 1em; }

    /* Responsive adjustments for the toggle button on small screens */
    .theme-switcher-container {
        top: 15px;
        left: 15px;
    }
    .theme-toggle-label {
        width: 40px;
        height: 40px;
    }
    .icon-container {
        width: 20px;
        height: 20px;
    }
    .theme-icon {
        width: 20px;
        height: 20px;
    }
}