/* --- Global & Root Variables (Defaulting to Light Theme) --- */
:root {
    /* Light Theme (Serene) - Refined Palette */
    --primary-color: #5c6bc0; /* Indigo Blue */
    --secondary-color: #7986cb; /* Lighter Indigo */
    --accent-color: #ffb300; /* Amber */
    --background-gradient-start: #e8eaf6; /* Light Lavender */
    --background-gradient-end: #c5cae9; /* Medium Lavender */
    --text-color: #212121; /* Main text color for readability on light backgrounds */
    --inverted-text-color: #ffffff; /* Text color for elements with primary/secondary backgrounds (e.g., header, buttons) */
    --card-background: #ffffff;
    --border-color: #9fa8da; /* Muted Blue-grey */
    --shadow-light: rgba(0, 0, 0, 0.07);
    --shadow-medium: rgba(0, 0, 0, 0.12);
    --input-bg: #f5f5f5; /* Very light grey */
    --meditation-timer-bg: #e0e0e0; /* Slightly darker than input-bg, but still light */
    --stats-grid-bg: #f5f5f5;
    --list-item-bg: #f5f5f5;
    --modal-content-bg: #ffffff;
    --progress-bar-bg: #e0e0e0;
    --progress-bar-fill: var(--secondary-color);
    --secondary-color-alpha: rgba(121, 134, 203, 0.2); /* Alpha version of secondary for shadows */
    --button-hover-darken: #4b5a99; /* Specific darken for light theme primary */

    /* General fixed colors (not theme-dependent) */
    --delete-color: #ef4444; /* Red */
    --delete-hover: #dc2626;
    --success-color: #22c55e; /* Green */
    --success-hover: #16a34a;
    --info-color: #3b82f6; /* Blue */
    --info-hover: #2563eb;
    --warning-color: #f59e0b; /* Orange */
    --warning-hover: #d97706;
    --warning-color-rgb: 245, 158, 11; /* For rgba shadows */

    /* Modal general styles */
    --modal-bg: rgba(0, 0, 0, 0.65);
    /* Toast notifications */
    --toast-bg: rgba(33,33,33,0.9);
    --toast-text: #fff;
}

/* --- Theme Overrides --- */

/* Light Theme (Serene) - Explicitly set for clarity, though already defaults in :root */
body.light-theme {
    --primary-color: #5c6bc0;
    --secondary-color: #7986cb;
    --accent-color: #ffb300;
    --background-gradient-start: #e8eaf6;
    --background-gradient-end: #c5cae9;
    --text-color: #212121; /* Dark grey for light backgrounds */
    --inverted-text-color: #ffffff; /* White for dark backgrounds */
    --card-background: #ffffff;
    --border-color: #9fa8da;
    --shadow-light: rgba(0, 0, 0, 0.07);
    --shadow-medium: rgba(0, 0, 0, 0.12);
    --input-bg: #f5f5f5;
    --meditation-timer-bg: #e0e0e0;
    --stats-grid-bg: #f5f5f5;
    --list-item-bg: #f5f5f5;
    --modal-content-bg: #ffffff;
    --progress-bar-bg: #e0e0e0;
    --progress-bar-fill: var(--secondary-color);
    --secondary-color-alpha: rgba(121, 134, 203, 0.2);
    --button-hover-darken: #4b5a99; /* Specific darken for light theme primary */
}

/* Dark Theme (Mystic Night) */
body.dark-theme {
    --primary-color: #b39ddb; /* Deep Lilac */
    --secondary-color: #e0b0ff; /* Light Lavender */
    --accent-color: #ffd54f; /* Yellow Amber */
    --background-gradient-start: #1c0032; /* Very Dark Purple */
    --background-gradient-end: #38006b; /* Dark Purple */
    --text-color: #e0e0e0; /* Light grey for dark backgrounds */
    --inverted-text-color: #ffffff; /* White for dark backgrounds */
    --card-background: #2a004a;
    --border-color: #5d0087;
    --shadow-light: rgba(255, 255, 255, 0.05);
    --shadow-medium: rgba(255, 255, 255, 0.1);
    --input-bg: #3d006f;
    --meditation-timer-bg: #2a004a;
    --stats-grid-bg: #2a004a;
    --list-item-bg: #2a004a;
    --modal-content-bg: #2a004a;
    --button-hover-darken: #9a76cc;
    --progress-bar-bg: #4d0087;
    --progress-bar-fill: var(--primary-color);
    --secondary-color-alpha: rgba(224, 176, 255, 0.2);
    --toast-bg: rgba(0,0,0,0.9);
}

/* Cosmic Whisper Theme */
body.cosmic-theme {
    --primary-color: #6a05ad; /* Deep Violet */
    --secondary-color: #9d52d2; /* Lighter Violet */
    --accent-color: #f7b731; /* Golden Yellow */
    --background-gradient-start: #0a011a; /* Black-Blue Space */
    --background-gradient-end: #1e0539; /* Deep Purple Space */
    --text-color: #d1c4e9; /* Light Purple-grey */
    --inverted-text-color: #ffffff; /* White for dark backgrounds */
    --card-background: #15022e;
    --border-color: #3b0a68;
    --shadow-light: rgba(255, 255, 255, 0.05);
    --shadow-medium: rgba(255, 255, 255, 0.1);
    --input-bg: #28084f;
    --meditation-timer-bg: #15022e;
    --stats-grid-bg: #15022e;
    --list-item-bg: #15022e;
    --modal-content-bg: #1e0539;
    --button-hover-darken: #570494;
    --progress-bar-bg: #3b0a68;
    --progress-bar-fill: var(--secondary-color);
    --secondary-color-alpha: rgba(157, 82, 210, 0.2);
    --toast-bg: rgba(0,0,0,0.9);
}

/* Forest Bloom Theme */
body.forest-theme {
    --primary-color: #2e7d32; /* Deep Green */
    --secondary-color: #66bb6a; /* Medium Green */
    --accent-color: #ffa000; /* Dark Orange */
    --background-gradient-start: #e8f5e9; /* Very Light Green */
    --background-gradient-end: #c8e6c9; /* Light Green */
    --text-color: #388e3c; /* Darker Green text */
    --inverted-text-color: #ffffff; /* White for dark backgrounds */
    --card-background: #ffffff;
    --border-color: #a5d6a7;
    --shadow-light: rgba(0, 0, 0, 0.07);
    --shadow-medium: rgba(0, 0, 0, 0.12);
    --input-bg: #f1f8e9; /* Off-white green tint */
    --meditation-timer-bg: #c8e6c9;
    --stats-grid-bg: #f1f8e9;
    --list-item-bg: #f1f8e9;
    --modal-content-bg: #ffffff;
    --button-hover-darken: #246328;
    --progress-bar-bg: #dcedc8;
    --progress-bar-fill: var(--secondary-color);
    --secondary-color-alpha: rgba(102, 187, 106, 0.2);
    --toast-bg: rgba(0,0,0,0.85);
}


/* --- Global Styles --- */
html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', 'Roboto', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, var(--background-gradient-start), var(--background-gradient-end));
    color: var(--text-color); /* This applies the main text color */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
    transition: background-color 0.5s ease, color 0.5s ease, background-image 0.5s ease;
    overflow-y: scroll; /* Always show scrollbar to prevent layout jump */
    -webkit-font-smoothing: antialiased; /* Smoother fonts */
    -moz-osx-font-smoothing: grayscale; /* Smoother fonts */
}

/* Custom Scrollbar */
body::-webkit-scrollbar {
    width: 12px;
}

body::-webkit-scrollbar-track {
    background: var(--background-gradient-start);
}

body::-webkit-scrollbar-thumb {
    background-color: var(--secondary-color);
    border-radius: 6px;
    border: 3px solid var(--background-gradient-start);
}

body.modal-open {
    overflow: hidden; /* Prevent scrolling when modal is open */
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5em;
}

header {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: var(--inverted-text-color); /* Uses the inverted text color */
    padding: 2.5em 0 1.5em;
    text-align: center;
    box-shadow: 0 6px 15px var(--shadow-medium);
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
}

header h1 {
    margin: 0;
    font-size: clamp(2.5em, 5vw, 3.8em); /* Responsive font size */
    letter-spacing: 2px;
    font-weight: 700;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.3);
}

header p {
    margin: 0.5em 0 0;
    font-size: clamp(1em, 2.5vw, 1.4em); /* Responsive font size */
    opacity: 0.95;
    font-weight: 300;
}

/* --- Navigation --- */
.main-nav {
    background-color: var(--card-background);
    padding: 1em 0;
    box-shadow: 0 3px 8px var(--shadow-light);
    margin-bottom: 2.5em;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    display: flex; /* For horizontal scrolling container */
    overflow-x: auto; /* Allow horizontal scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.main-nav::-webkit-scrollbar {
    height: 6px; /* Smaller scrollbar for nav */
}
.main-nav::-webkit-scrollbar-track {
    background: var(--card-background);
}
.main-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}


.main-nav .container {
    display: flex;
    justify-content: center;
    gap: 1.2em;
    flex-wrap: nowrap; /* Prevent wrapping for horizontal scroll */
    padding: 0 1.5em; /* Ensure padding on ends for scroll */
    min-width: max-content; /* Ensure container is wide enough for all buttons */
}

.nav-button {
    background-color: transparent;
    border: 1px solid transparent; /* Consistent border for smooth transition */
    color: var(--primary-color);
    padding: 1em 1.8em;
    font-size: 1.15em;
    cursor: pointer;
    border-radius: 10px;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    font-weight: 600;
    flex-shrink: 0; /* Prevent shrinking in nav scroll */
}

.nav-button i {
    font-size: 1.2em;
}

.nav-button:hover:not(:disabled) {
    background-color: var(--background-gradient-end);
    transform: translateY(-3px);
    box-shadow: 0 4px 10px var(--shadow-light);
    border-color: var(--secondary-color);
}

.nav-button.active {
    background-color: var(--secondary-color);
    color: var(--inverted-text-color); /* Uses the inverted text color */
    box-shadow: 0 4px 12px var(--shadow-medium);
    transform: translateY(-2px);
    border-color: var(--secondary-color);
}

.nav-button.active:hover {
    background-color: var(--primary-color);
    transform: none;
    box-shadow: 0 2px 8px var(--shadow-light);
}

/* --- Main Content Layout --- */
main {
    flex-grow: 1;
    padding-bottom: 3em;
}

.app-section {
    display: none;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.app-section.active-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); /* Flexible grid layout */
    gap: 2.5em;
    opacity: 1;
    transform: translateY(0);
}

/* Card Styles */
.card {
    background-color: var(--card-background);
    border-radius: 18px;
    box-shadow: 0 10px 25px var(--shadow-light);
    padding: 2.8em;
    border: 1px solid var(--border-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-7px);
    box-shadow: 0 15px 35px var(--shadow-medium);
}

.card-full-width {
    grid-column: 1 / -1; /* Make card span full width in grid */
}


h2 {
    color: var(--primary-color);
    margin-top: 0;
    font-size: clamp(1.8em, 4vw, 2.5em); /* Responsive font size */
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.8em;
    margin-bottom: 1.5em;
    display: flex;
    align-items: center;
    font-weight: 700;
}

h2 i {
    margin-right: 15px;
    color: var(--accent-color);
    font-size: 1.2em;
}

h3 {
    color: var(--secondary-color);
    margin-top: 2em;
    margin-bottom: 1.5em;
    font-size: clamp(1.4em, 3vw, 1.8em); /* Responsive font size */
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 0.6em;
    font-weight: 600;
}

.card-description {
    font-size: 1.1em;
    color: var(--text-color);
    opacity: 0.9;
    margin-bottom: 1.8em;
    line-height: 1.5;
}

/* --- Buttons --- */
button {
    background-color: var(--secondary-color);
    color: var(--inverted-text-color); /* Uses the inverted text color */
    border: none;
    padding: 1em 2em;
    border-radius: 30px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    font-weight: 500;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

button:hover:not(:disabled) {
    background-color: var(--button-hover-darken);
    transform: translateY(-3px);
    box-shadow: 0 6px 15px var(--shadow-light);
}

button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.3);
}

button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: none;
    transform: none;
}

.btn-sm {
    padding: 0.7em 1.4em;
    font-size: 0.95em;
    border-radius: 25px;
}

.btn-icon {
    padding: 0.7em 1em;
    font-size: 1.1em;
    border-radius: 50%;
    min-width: 44px; /* Larger touch target */
    min-height: 44px; /* Larger touch target */
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.btn-icon i {
    margin: 0;
}
.btn-success { background-color: var(--success-color); }
.btn-success:hover:not(:disabled) { background-color: var(--success-hover); }

.delete-button { background-color: var(--delete-color); }
.delete-button:hover:not(:disabled) { background-color: var(--delete-hover); }

.export-button { background-color: var(--success-color); }
.export-button:hover:not(:disabled) { background-color: var(--success-hover); }

.import-button { background-color: var(--info-color); }
.import-button:hover:not(:disabled) { background-color: var(--info-hover); }

.secondary-button { background-color: #9ca3af; }
.secondary-button:hover:not(:disabled) { background-color: #6b7280; }

/* --- Forms & Inputs --- */
.input-field, select {
    flex-grow: 1;
    padding: 1em 1.2em;
    border: 1px solid var(--border-color);
    border-radius: 30px;
    font-size: 1em;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    background-color: var(--input-bg);
    color: var(--text-color); /* Uses the main text color */
    min-width: 150px;
    appearance: none; /* Remove default select arrow */
    -webkit-appearance: none; /* Remove default select arrow for Safari */
}

select {
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%237986cb%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13.6-6.4H18.9c-5%200-9.6%202-13.6%206.4-4%204-6.4%209.6-6.4%2015.6%200%206%202.4%2011.6%206.4%2015.6l127.3%20127.3c4%204%209.6%206.4%2015.6%206.4s11.6-2.4%2015.6-6.4L287%20100.6c4-4%206.4-9.6%206.4-15.6-.2-6-2.5-11.6-6.4-15.6z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 1em top 50%;
    background-size: 0.8em auto;
}

.input-field:focus, select:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px var(--secondary-color-alpha); /* Use alpha for a softer glow */
}

.small-input {
    min-width: unset;
    width: 120px;
    padding: 0.8em 1em;
    border-radius: 20px;
}

/* --- Lists (ul, li) --- */
ul {
    list-style: none;
    padding: 0;
    margin: 1.5em 0 0;
    flex-grow: 1; /* Make lists take available space */
}

ul li {
    background-color: var(--list-item-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 1.2em;
    padding: 1.5em 2em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.03);
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease, border-color 0.3s ease;
    flex-wrap: wrap;
    gap: 1em;
}

ul li:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
}

ul li:last-child {
    margin-bottom: 0;
}

.info-message {
    text-align: center;
    font-style: italic;
    color: var(--text-color);
    opacity: 0.7;
    padding: 1em;
}

.mini-list li { /* For dashboard recent items */
    padding: 0.8em 1.2em;
    font-size: 0.9em;
    box-shadow: none;
    border: none;
    border-bottom: 1px dashed var(--border-color);
    border-radius: 0;
    background-color: transparent;
}
.mini-list li:hover {
    transform: none;
    background-color: var(--input-bg);
}
.mini-list li:last-child {
    border-bottom: none;
}
.mini-list li .session-date, .mini-list li .session-duration {
    font-weight: 500;
}


/* --- Meditation Specifics --- */
.meditation-timer-card {
    grid-column: span 1; /* Occupy single column */
}
.meditation-history-card {
    grid-column: span 1; /* Occupy single column */
}

.timer-display {
    font-size: clamp(3.5em, 8vw, 5.5em); /* Responsive font size */
    font-weight: bold;
    color: var(--primary-color);
    text-align: center;
    margin: 1.5em 0 2em;
    background-color: var(--meditation-timer-bg);
    padding: 0.8em 1.2em;
    border-radius: 15px;
    border: 2px solid var(--secondary-color);
    box-shadow: inset 0 3px 10px var(--shadow-light);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    letter-spacing: 1px;
}

.meditation-controls-group {
    display: flex;
    flex-direction: column;
    gap: 1.5em;
    margin-bottom: 2em;
}

.preset-buttons {
    display: flex;
    justify-content: center;
    gap: 1em;
    flex-wrap: wrap;
}

.preset-meditation-time {
    background-color: var(--primary-color);
    min-width: 80px; /* Ensure buttons don't get too small */
}
.preset-meditation-time:hover:not(:disabled) {
    background-color: var(--button-hover-darken);
}

.custom-timer-input {
    display: flex;
    gap: 0.8em;
    justify-content: center;
    align-items: center;
}
.custom-timer-input .input-field {
    max-width: 150px;
    text-align: center;
}
.custom-timer-input button {
    flex-shrink: 0;
}

.timer-controls {
    display: flex;
    justify-content: center;
    gap: 1em;
    margin-bottom: 2em;
    flex-wrap: wrap;
}
.timer-controls button {
    flex: 1 1 120px; /* Allow buttons to grow */
    max-width: 180px;
}
.timer-controls #start-meditation { background-color: var(--success-color); }
.timer-controls #start-meditation:hover:not(:disabled) { background-color: var(--success-hover); }

.sound-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1em;
    margin-top: 1em;
    flex-wrap: wrap;
}
#ambient-volume {
    width: 150px;
    accent-color: var(--secondary-color);
    cursor: pointer;
}

.session-mood-emoji {
    font-size: 1.2em;
    margin-left: 0.5em;
}

/* Dashboard Specifics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1.2em;
    background-color: var(--stats-grid-bg);
    padding: 1.8em;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: inset 0 2px 8px var(--shadow-light);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.stats-grid div {
    padding: 0.8em;
    border-bottom: 1px dashed var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.3em;
}

.stats-grid div:nth-child(odd) {
    border-right: 1px dashed var(--border-color); /* Separator for columns */
}
.stats-grid div:last-child,
.stats-grid div:nth-last-child(2):nth-child(odd) {
    border-bottom: none; /* Remove bottom border for last row */
}

@media (max-width: 600px) { /* On smaller screens, single column */
    .stats-grid div { border-right: none; border-bottom: 1px dashed var(--border-color); }
    .stats-grid div:last-child { border-bottom: none; }
}


.stats-grid strong {
    color: var(--primary-color);
    font-size: 1.05em;
    font-weight: 600;
}

/* --- Book Specifics --- */
.book-input-area, .search-input-area {
    display: flex;
    gap: 1em;
    margin-bottom: 1.8em;
    flex-wrap: wrap;
    align-items: center;
}
.book-input-area .input-field {
    flex: 1 1 180px; /* Allow fields to grow but have a base */
}
.book-input-area .small-input {
    flex: 0 0 100px; /* Fixed size for pages */
}
.book-input-area button {
    flex-shrink: 0;
}
.book-list li {
    padding: 1.2em 1.8em; /* Slightly less padding */
}
.book-item-info {
    flex: 1 1 50%;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}

.book-item-info span {
    font-size: 0.9em;
    opacity: 0.85;
}
.book-item-info strong {
    font-size: 1.15em;
    color: var(--primary-color);
}

.book-item-controls {
    display: flex;
    gap: 0.8em;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.book-item-controls button {
    padding: 0.6em 1.2em;
    font-size: 0.9em;
    border-radius: 20px;
}

.book-cover-thumbnail {
    width: 60px;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-right: 1em;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
}

/* --- Statistics Section --- */
.chart-container {
    padding: 1.5em;
    background-color: var(--list-item-bg); /* Use list-item-bg for charts too */
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin-top: 1.5em;
    margin-bottom: 2em; /* Spacing between charts */
}

/* Meditation Calendar */
.meditation-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    padding: 1em;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background-color: var(--list-item-bg);
}

.calendar-header {
    grid-column: 1 / -1;
    text-align: center;
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 10px;
    color: var(--primary-color);
}

.calendar-day-name, .calendar-day {
    padding: 8px;
    text-align: center;
    border-radius: 5px;
    font-size: 0.9em;
    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    min-height: 35px; /* Ensure consistent height */
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-day-name {
    font-weight: bold;
    background-color: var(--secondary-color);
    color: var(--inverted-text-color); /* Uses the inverted text color */
    border-color: var(--primary-color);
}

.calendar-day.empty {
    background-color: var(--background-gradient-start);
    border-color: transparent;
    opacity: 0.6;
}

.calendar-day.meditated {
    background-color: var(--success-color); /* Green for meditated days */
    color: white;
    font-weight: bold;
    border-color: var(--success-hover);
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}

.calendar-day.current-day {
    border: 2px solid var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color);
    font-weight: bold;
}

/* --- Goals Section --- */
.goal-input-area {
    display: flex;
    gap: 1em;
    margin-bottom: 2em;
    flex-wrap: wrap;
    align-items: center;
}
.goal-input-area .input-field {
    flex: 1 1 150px;
}
.goal-input-area .small-input {
    flex: 0 0 100px;
}

.goal-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1em 1.5em;
    border-radius: 10px;
    background-color: var(--list-item-bg);
    border: 1px solid var(--border-color);
    margin-bottom: 1em;
    flex-wrap: wrap;
    gap: 1em;
}

.goal-item.completed {
    opacity: 0.8;
    background-color: var(--success-color);
    color: var(--inverted-text-color); /* Uses the inverted text color */
    border-color: var(--success-hover);
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}
.goal-item.completed strong {
    color: var(--inverted-text-color); /* Uses the inverted text color */
}
.goal-item.completed span {
    color: rgba(255,255,255,0.8);
}

.goal-progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: var(--progress-bar-bg);
    border-radius: 4px;
    margin-top: 0.5em;
    overflow: hidden;
}

.goal-progress-bar {
    height: 100%;
    background-color: var(--progress-bar-fill);
    width: 0%;
    border-radius: 4px;
    transition: width 0.5s ease;
}
.goal-item.completed .goal-progress-bar {
    background-color: var(--inverted-text-color); /* White progress bar for completed goals */
}

/* --- Achievements Section --- */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5em;
    padding: 1em;
}

.achievement-card {
    background-color: var(--list-item-bg);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 1.5em;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px var(--shadow-light);
    transition: transform 0.2s ease, opacity 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
    min-height: 160px; /* Ensure consistent card height */
}

.achievement-card i {
    font-size: 3em;
    color: #a0a0a0; /* Default grey for locked */
    margin-bottom: 0.5em;
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

.achievement-card.unlocked {
    background-color: var(--background-gradient-end);
    border-color: var(--accent-color);
    box-shadow: 0 4px 15px rgba(var(--warning-color-rgb), 0.3); /* Use RGB for shadow */
}

.achievement-card.unlocked i {
    color: var(--accent-color);
    text-shadow: 0 0 12px rgba(var(--warning-color-rgb), 0.7);
}

.achievement-card h4 {
    margin: 0.5em 0;
    color: var(--primary-color);
    font-size: 1.2em;
}

.achievement-card p {
    font-size: 0.9em;
    opacity: 0.8;
}

/* --- Settings Section --- */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1em 0;
    border-bottom: 1px dashed var(--border-color);
    flex-wrap: wrap; /* Allow wrapping */
    gap: 0.8em;
}

.setting-item:last-of-type {
    border-bottom: none;
}

.setting-item span {
    font-size: 1.1em;
    color: var(--text-color); /* Uses the main text color */
    flex-shrink: 0;
}

.setting-item .input-field, .setting-item select {
    margin-left: auto; /* Push input/select to the right */
    flex-shrink: 0;
}
.setting-buttons-group {
    display: flex;
    gap: 0.8em;
    flex-wrap: wrap;
    margin-left: auto;
}
.setting-buttons-group button {
    flex-shrink: 0;
}
.data-management-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
    justify-content: center;
    margin-top: 2em;
}
.data-management-buttons button {
    flex: 1 1 140px; /* Allow buttons to grow and wrap */
}


/* Toggle Switch (reused) */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    margin-left: auto; /* Push to right */
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; -webkit-transition: .4s; transition: .4s; border-radius: 28px;
}
.slider:before {
    position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px;
    background-color: white; -webkit-transition: .4s; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--secondary-color); }
input:focus-visible + .slider { box-shadow: 0 0 0 3px var(--secondary-color-alpha); } /* Focus outline for keyboard nav */
input:checked + .slider:before { -webkit-transform: translateX(22px); -ms-transform: translateX(22px); transform: translateX(22px); }

#bell-volume {
    width: 150px;
    accent-color: var(--secondary-color);
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
}
#daily-reminder-time {
    width: 100px;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 1.8em;
    margin-top: 3em;
    background-color: var(--primary-color);
    color: var(--inverted-text-color); /* Uses the inverted text color */
    font-size: 0.9em;
    box-shadow: 0 -4px 12px var(--shadow-medium);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

/* --- Modals --- */
.modal {
    display: none;
    position: fixed;
    z-index: 200;
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto;
    background-color: var(--modal-bg);
    padding: 20px 0; /* Add some vertical padding */
    animation: fadeIn 0.3s ease-out;
    display: flex; /* Use flex to center content */
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--modal-content-bg);
    margin: auto; /* Center with flex */
    padding: 3em;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 15px 40px var(--shadow-medium);
    position: relative;
    animation: slideInTop 0.4s ease-out;
    color: var(--text-color); /* Uses the main text color */
    max-height: 95vh; /* Limit height to prevent overflow on very small screens */
    overflow-y: auto; /* Scroll content if too tall */
    display: flex; /* Make content itself a flex container for column layout */
    flex-direction: column;
}
.modal-content.modal-small {
    max-width: 450px; /* Smaller width for confirmation modal */
}

.modal-content h2 {
    color: var(--primary-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.8em;
    margin-bottom: 1.5em;
    font-size: clamp(1.6em, 3.5vw, 2.2em);
}

.modal-content h3 {
    font-size: clamp(1.2em, 2.5vw, 1.6em);
}

.modal-content p {
    margin-bottom: 1em;
    line-height: 1.6;
}

.modal-content textarea {
    width: calc(100% - 24px); /* Account for padding */
    min-height: 100px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 1em;
    line-height: 1.5;
    resize: vertical;
    margin-bottom: 1.5em;
    background-color: var(--input-bg);
    color: var(--text-color); /* Uses the main text color */
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.modal-content textarea:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px var(--secondary-color-alpha);
}

.modal-content button {
    margin-top: 1.5em;
    width: auto;
    min-width: 150px;
    align-self: flex-end; /* Push button to right */
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 40px;
    font-weight: bold;
    position: absolute;
    right: 25px;
    top: 15px;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close-button:hover {
    color: var(--primary-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1.5em;
    margin-top: 2em;
    flex-wrap: wrap;
}
.modal-actions button {
    margin-top: 0; /* Override default button margin-top */
    flex: 1 1 120px; /* Make buttons flexible */
    max-width: 180px;
}


/* Journal Modal Specifics */
.journal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2em;
    margin-bottom: 1.5em;
    width: 100%;
}
.mood-tracker, .energy-tracker {
    flex: 1 1 45%;
    min-width: 280px;
}
.mood-tracker h4, .energy-tracker h4 {
    margin-top: 0;
    margin-bottom: 0.8em;
    color: var(--secondary-color);
    font-size: 1.2em;
}
.mood-emojis {
    display: flex;
    gap: 0.8em;
    flex-wrap: wrap;
}
.mood-emojis .emoji {
    font-size: 2.2em;
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    user-select: none; /* Prevent text selection */
    min-width: 44px; /* Ensure touch target */
    text-align: center;
}
.mood-emojis .emoji:hover {
    transform: scale(1.1);
    background-color: var(--background-gradient-end);
}
.mood-emojis .emoji.selected {
    background-color: var(--accent-color);
    border-color: var(--warning-hover);
    transform: scale(1.15);
    box-shadow: 0 0 12px rgba(var(--warning-color-rgb), 0.5);
    color: white; /* Ensure visibility for darker emojis */
}
.slider-energy {
    width: calc(100% - 60px); /* Adjust width */
    vertical-align: middle;
    accent-color: var(--secondary-color);
    height: 8px;
    cursor: pointer;
    margin-right: 10px;
}
#energy-value {
    vertical-align: middle;
    font-weight: bold;
    color: var(--primary-color);
}

/* Book Modal Specifics */
.book-modal-header {
    display: flex;
    gap: 1.5em;
    align-items: flex-start;
    margin-bottom: 2em;
    flex-wrap: wrap;
}
.modal-book-cover {
    width: 120px;
    height: 180px;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    flex-shrink: 0;
    border: 1px solid var(--border-color);
}
.book-info-text {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.book-modal-header h2 {
    margin-top: 0;
    font-size: 2em;
    border: none;
    padding: 0;
    margin-bottom: 0.5em;
    color: var(--primary-color);
}
.book-modal-header p {
    margin: 0.3em 0;
    font-size: 1.05em;
}
.book-rating .fa-star {
    color: #ccc;
    font-size: 1.6em;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.1s ease;
}
.book-rating .fa-star:hover {
    transform: scale(1.1);
}
.book-rating .fa-star.active {
    color: var(--accent-color);
}
.book-modal-progress {
    margin-bottom: 2em;
    padding-top: 1em;
    border-top: 1px dashed var(--border-color);
}
.page-input-group {
    display: flex;
    align-items: center;
    gap: 0.8em;
    margin-bottom: 1em;
}
.page-input-group label strong {
    font-size: 1.05em;
    color: var(--primary-color);
}
.page-input-group input {
    max-width: 100px;
    text-align: center;
}
.progress-bar-container {
    width: 100%;
    height: 10px;
    background-color: var(--progress-bar-bg);
    border-radius: 5px;
    overflow: hidden;
    margin-top: 0.8em;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.progress-bar {
    height: 100%;
    background-color: var(--progress-bar-fill);
    width: 0%;
    border-radius: 5px;
    transition: width 0.5s ease;
}
.notes-list {
    margin-top: 1.5em;
}
.notes-list .note-item {
    background-color: var(--background-gradient-start);
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column; /* Stack content and date */
    align-items: flex-start;
    gap: 0.5em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.notes-list .note-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.notes-list .note-item .note-content {
    flex-grow: 1;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 1em;
    color: var(--text-color); /* Uses the main text color */
}
.notes-list .note-item .note-date {
    font-size: 0.8em;
    color: var(--text-color); /* Uses the main text color */
    opacity: 0.7;
    text-align: right;
    width: 100%;
}
.notes-list .note-item .delete-note-btn {
    padding: 0.4em 0.8em;
    font-size: 0.8em;
    min-width: unset;
    margin-top: 0.5em;
    align-self: flex-end; /* Align delete button to bottom right */
}

/* Interval Timer Modal Specifics */
.interval-step {
    display: flex;
    align-items: center;
    gap: 1em;
    margin-bottom: 1em;
    padding: 0.8em;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background-color: var(--input-bg);
    flex-wrap: wrap;
}
.interval-step label {
    font-weight: bold;
    color: var(--primary-color);
    flex-shrink: 0;
    font-size: 0.95em;
}
.interval-step input[type="number"], .interval-step select {
    width: 80px;
    padding: 0.6em;
    border-radius: 8px;
    flex-shrink: 0;
}
.interval-step .delete-step-btn {
    margin-left: auto; /* Push delete button to the right */
    padding: 0.5em 0.8em;
    font-size: 0.9em;
}
#interval-timer-modal button {
    margin-top: 1.5em;
}
#add-interval-step {
    background-color: var(--secondary-color);
}
#start-interval-meditation {
    background-color: var(--success-color);
    margin-left: 1em;
}

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: var(--toast-bg);
    color: var(--toast-text);
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateX(120%); /* Start further right */
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
    min-width: 280px;
    max-width: 380px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.hide {
    opacity: 0;
    transform: translateX(120%);
}

.toast i {
    font-size: 1.6em;
    color: var(--accent-color); /* Neutral color for icon */
}
.toast.success i { color: var(--success-color); }
.toast.error i { color: var(--delete-color); }
.toast.info i { color: var(--info-color); }
.toast.warning i { color: var(--warning-color); }


/* --- Keyframe Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInTop { from { transform: translateY(-50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* --- Responsive Adjustments --- */
@media (max-width: 1200px) {
    .container {
        padding: 0 1em;
    }
    .app-section.active-section {
        gap: 2em;
    }
    .card {
        padding: 2.2em;
    }
}

@media (max-width: 768px) {
    header {
        padding: 1.8em 0 1em;
        border-bottom-left-radius: 10px;
        border-bottom-right-radius: 10px;
    }
    header h1 {
        font-size: 2.2em;
    }
    header p {
        font-size: 1em;
    }
    .main-nav {
        margin-bottom: 1.5em;
        border-radius: 0; /* Full width on mobile */
    }
    .main-nav .container {
        padding: 0 0.8em; /* Reduced padding for more space */
        gap: 0.6em;
    }
    .nav-button {
        font-size: 0.95em;
        padding: 0.8em 1em;
        gap: 8px;
    }
    .nav-button i {
        font-size: 1em;
    }
    .app-section.active-section {
        grid-template-columns: 1fr; /* Stack cards vertically */
        gap: 1.5em;
    }
    .card {
        padding: 1.8em;
        border-radius: 12px;
    }
    h2 {
        font-size: 1.8em;
        margin-bottom: 1em;
        padding-bottom: 0.6em;
    }
    h3 {
        font-size: 1.4em;
        margin-top: 1.5em;
        margin-bottom: 1em;
        padding-bottom: 0.5em;
    }
    .card-description {
        font-size: 0.95em;
        margin-bottom: 1.5em;
    }
    .timer-display {
        font-size: 3.2em;
        margin: 1em 0 1.5em;
        padding: 0.6em 0.8em;
    }
    .meditation-controls-group {
        gap: 1em;
        margin-bottom: 1.5em;
    }
    .preset-buttons, .timer-controls, .sound-controls {
        flex-direction: column;
        gap: 0.8em;
    }
    button {
        width: 100%;
        padding: 0.9em 1.5em;
        font-size: 1em;
    }
    .btn-icon {
        width: auto; /* Allow auto width for icons when stacked */
        border-radius: 30px; /* Make them pill-shaped when wider */
    }
    .custom-timer-input .input-field {
        max-width: none; /* Full width */
        width: 100%;
    }
    .custom-timer-input button {
        width: 100%;
    }

    .book-input-area, .search-input-area {
        flex-direction: column;
        align-items: stretch; /* Stretch items to full width */
        gap: 0.8em;
    }
    .book-input-area .input-field, .search-input-area .input-field {
        width: 100%; /* Full width inputs */
    }
    .book-input-area .btn-icon, .search-input-area .btn-icon {
        width: 100%;
    }
    .book-list li {
        flex-direction: column;
        align-items: flex-start;
        padding: 1.2em 1.5em;
    }
    .book-cover-thumbnail {
        margin-right: 0; /* No margin on smaller screens */
        margin-bottom: 1em; /* Add space below image */
        align-self: center; /* Center image */
    }
    .book-item-info {
        width: 100%; /* Full width */
        text-align: center;
    }
    .book-item-controls {
        width: 100%;
        justify-content: center;
    }
    .stats-grid div { border-right: none; border-bottom: 1px dashed var(--border-color); }
    .stats-grid div:last-child { border-bottom: none; }

    .modal {
        padding: 0; /* No padding, modal takes full height */
    }
    .modal-content {
        width: 100%;
        min-height: 100vh; /* Make modal almost full screen */
        border-radius: 0; /* No border radius */
        padding: 1.5em;
        margin: 0;
        box-shadow: none;
        max-height: unset; /* Remove max height constraint */
    }
    .modal-content.modal-small {
        min-height: unset; /* Restore min-height for small modal */
        border-radius: 12px;
        padding: 1.5em;
        max-width: 90%;
        margin: auto;
    }

    .close-button {
        font-size: 30px;
        right: 15px;
        top: 15px;
        background-color: var(--card-background);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
    .journal-meta, .book-modal-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .mood-emojis {
        justify-content: center;
    }
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
    }
    .setting-item span {
        margin-left: 0;
        width: 100%;
        text-align: left;
    }
    .setting-item .input-field, .setting-item select, .setting-item button {
        margin-left: 0;
        width: 100%;
        text-align: left;
    }
    .setting-item .input-field.small-input {
        text-align: left;
    }
    .setting-buttons-group, .data-management-buttons {
        flex-direction: column;
        width: 100%;
    }
    #bell-volume, #ambient-volume {
        width: 100%;
        margin-left: 0;
    }
    #daily-reminder-time {
        width: 100%;
    }
    #toast-container {
        top: unset;
        bottom: 15px;
        right: 10px;
        left: 10px;
    }
    .toast {
        max-width: unset;
        transform: translateY(120%);
    }
    .toast.show {
        transform: translateY(0);
    }
    .toast.hide {
        transform: translateY(120%);
    }
    footer {
        padding: 1.5em;
        margin-top: 2em;
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
    }
}

/* Landscape orientation for mobile devices */
@media (max-width: 900px) and (orientation: landscape) {
    .main-nav .container {
        padding: 0 1em;
    }
    .modal-content {
        width: 90%;
        max-height: 90vh;
        border-radius: 12px;
        margin: auto;
        padding: 2em;
    }
    .modal-content.modal-small {
        min-height: unset;
    }
    .journal-meta, .book-modal-header {
        flex-direction: row; /* Allow side-by-side again if space permits */
        text-align: left;
    }
    .mood-emojis {
        justify-content: flex-start;
    }
    .timer-display {
        font-size: 4em;
    }
    .timer-controls {
        flex-direction: row;
    }
    .timer-controls button {
        width: auto;
    }
}