@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Lora:wght@400;700&display=swap');

/* --- CSS Variables & Themes --- */
:root {
	/* Light Theme (Default) */
	--background-color: #fdfaf3;
	--background-image: url('data:image/svg+xml,%3Csvg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%23e8e4d9" fill-opacity="0.4"%3E%3Cpath d="M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z"/%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
	--text-color: #333333;
	--primary-color: #4a6b6a; /* Darkened for AA contrast with white text */
	--primary-hover-color: #3a5554;
	--secondary-color: #e0e0e0;
	--secondary-hover-color: #cccccc;
	--border-color: #dddddd;
	--card-background: #ffffff;
	--card-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
	--focus-ring-color: #3a5554;
	--sepia-filter: sepia(20%);
	--font-family-sans: 'Lato', 'Helvetica Neue', Arial, sans-serif;
	--base-font-size: 18px; /* Controlled by JS */
	--header-font-family: 'Lora', Georgia, serif;
}

body.dark-mode {
	/* Dark Theme / High Contrast */
	--background-color: #121212;
	--background-image: none;
	--text-color: #e0e0e0;
	--primary-color: #88c0d0; /* Light blue for high contrast */
	--primary-hover-color: #a0d5e5;
	--secondary-color: #444444;
	--secondary-hover-color: #555555;
	--border-color: #444444;
	--card-background: #1e1e1e;
	--card-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
	--focus-ring-color: #a0d5e5;
	--sepia-filter: none;
}

/* --- Global Styles & Accessibility --- */
html {
	box-sizing: border-box;
	scroll-behavior: smooth;
}

*,
*:before,
*:after {
	box-sizing: inherit;
}

body {
	font-family: var(--font-family-sans);
	font-size: var(--base-font-size);
	line-height: 1.6;
	color: var(--text-color);
	background-color: var(--background-color);
	background-image: var(--background-image);
	margin: 0;
	padding: 0;
	transition:
		background-color 0.3s,
		color 0.3s;
}

.container {
	width: 100%;
	max-width: 900px;
	margin: 40px auto;
	padding: 0 20px;
}

header,
footer {
	text-align: center;
}

footer {
	margin-top: 40px;
	color: #666;
	font-size: 0.9em;
}

main > section {
	padding: 30px 40px;
	background-color: var(--card-background);
	border-radius: 8px;
	box-shadow: var(--card-shadow);
	animation: fadeIn 0.5s ease-out;
}

/* --- Typography --- */
h1,
h2,
h3 {
	font-family: var(--header-font-family);
	color: var(--primary-color);
	line-height: 1.2;
}

header h1 {
	font-size: 2.5rem;
	text-align: center;
	margin-bottom: 0.5em;
}

h2 {
	font-size: 2rem;
	border-bottom: 2px solid var(--border-color);
	padding-bottom: 10px;
	margin-top: 0;
	margin-bottom: 1em;
}

h3 {
	font-size: 1.5rem;
}

p {
	margin-bottom: 1em;
}

a {
	color: var(--primary-color);
	text-decoration: underline;
	transition: color 0.2s;
}

a:hover {
	color: var(--primary-hover-color);
}

/* --- Accessibility Controls --- */
.accessibility-controls {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 20px;
	margin-bottom: 20px;
	flex-wrap: wrap;
}

.font-size-controls {
	display: flex;
	align-items: center;
	gap: 8px;
}

/* --- Form & Onboarding Wizard --- */
#profile-form {
	display: flex;
	flex-direction: column;
}

.form-step {
	border: none;
	padding: 0;
	margin: 0;
	display: none;
}

.form-step.active {
	display: block;
	animation: fadeIn 0.5s;
}

legend {
	font-family: var(--header-font-family);
	font-size: 1.2rem;
	font-weight: bold;
	color: var(--text-color);
	padding: 0;
	margin-bottom: 20px;
	width: 100%;
	border-bottom: 1px solid var(--border-color);
	padding-bottom: 10px;
}

.form-group {
	margin-bottom: 25px;
}

label {
	display: block;
	font-weight: bold;
	margin-bottom: 8px;
	font-size: 1.1em;
}

input[type='text'],
input[type='number'] {
	width: 100%;
	padding: 15px;
	font-size: 1em;
	border: 1px solid var(--border-color);
	border-radius: 5px;
	transition:
		border-color 0.3s,
		box-shadow 0.3s;
	min-height: 44px; /* Touch target size */
	background-color: var(--card-background);
	color: var(--text-color);
}

input[type='text']:focus,
input[type='number']:focus {
	outline: none;
	border-color: var(--primary-color);
	box-shadow: 0 0 5px var(--primary-color);
}

input:invalid {
	border-color: #c00;
}

.privacy-note {
	font-size: 0.9em;
	color: #666;
	text-align: center;
	margin-top: 10px;
	padding: 10px;
	background-color: rgba(0, 0, 0, 0.02);
	border-radius: 4px;
	border: 1px solid var(--border-color);
}

.form-navigation {
	display: flex;
	justify-content: space-between;
	margin-top: 30px;
	border-top: 1px solid var(--border-color);
	padding-top: 20px;
}

/* Onboarding Progress Bar */
.progress-bar {
	display: flex;
	list-style: none;
	padding: 0;
	margin: 20px 0 30px;
}

.progress-step {
	flex: 1;
	text-align: center;
	position: relative;
	padding-top: 25px;
	font-size: 0.9em;
	color: #666;
}

.progress-step::before {
	content: attr(data-step-title);
	position: absolute;
	top: 25px;
	left: 50%;
	transform: translateX(-50%);
	width: 100%;
}

.progress-step::after {
	content: '';
	position: absolute;
	top: 9px;
	left: -50%;
	width: 100%;
	height: 4px;
	background-color: var(--secondary-color);
	z-index: -1;
}

.progress-step:first-child::after {
	content: none;
}

.progress-step.active,
.progress-step.completed {
	color: var(--text-color);
	font-weight: bold;
}

.progress-step.active::before,
.progress-step.completed::before {
	/* Style for the active/completed step's circle */
}

/* --- Buttons --- */
.btn,
button {
	/* Base styles for all buttons */
	padding: 12px 24px;
	font-size: 1.05em;
	font-family: var(--font-family-sans);
	font-weight: bold;
	border-radius: 5px;
	cursor: pointer;
	transition:
		background-color 0.3s,
		transform 0.2s,
		color 0.3s,
		border-color 0.3s;
	text-align: center;
	border: 2px solid transparent;
	-webkit-appearance: none;
	min-height: 44px; /* Touch target size */
	min-width: 44px;
}

.btn:hover:not(:disabled),
button:hover:not(:disabled) {
	transform: translateY(-2px);
}

.btn:disabled,
button:disabled {
	background-color: #cccccc;
	border-color: #cccccc;
	cursor: not-allowed;
	transform: none;
	color: #666;
}

.btn:focus-visible,
button:focus-visible,
input:focus-visible {
	outline: 3px solid var(--focus-ring-color);
	outline-offset: 2px;
	box-shadow: none;
}

/* Primary buttons */
.btn-primary,
#submitBtn,
#nextBtn,
#printBtn {
	background-color: var(--primary-color);
	color: white;
	border-color: var(--primary-color);
}
body.dark-mode .btn-primary,
body.dark-mode #submitBtn,
body.dark-mode #nextBtn,
body.dark-mode #printBtn {
	color: #111; /* Dark text on light blue */
}

.btn-primary:hover:not(:disabled),
#submitBtn:hover:not(:disabled),
#nextBtn:hover:not(:disabled),
#printBtn:hover:not(:disabled) {
	background-color: var(--primary-hover-color);
	border-color: var(--primary-hover-color);
}

/* Secondary buttons */
.btn-secondary,
#prevBtn,
#editProfileBtn,
#decrease-font,
#increase-font,
#theme-toggle,
.font-size-control {
	background-color: var(--secondary-color);
	color: var(--text-color);
	border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled),
#prevBtn:hover:not(:disabled),
#editProfileBtn:hover:not(:disabled),
#decrease-font:hover:not(:disabled),
#increase-font:hover:not(:disabled),
#theme-toggle:hover:not(:disabled),
.font-size-control:hover:not(:disabled) {
	background-color: var(--secondary-hover-color);
}

/* --- Newsletter Display --- */
.newsletter-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	flex-wrap: wrap;
	gap: 20px;
	margin-bottom: 20px;
	padding-bottom: 20px;
	border-bottom: 2px solid var(--border-color);
}

#newsletter-title {
	font-size: 2rem;
	margin: 0;
	text-align: left;
	border: none;
	padding: 0;
	flex-grow: 1;
}

.button-group,
.print-button-container {
	display: flex;
	align-items: center;
	gap: 10px;
	flex-shrink: 0;
}

.button-group button,
.print-button-container button {
	padding: 10px 20px;
	font-size: 1rem;
}

#newsletter-content {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
	gap: 30px;
}

.loading-message,
.error-message {
	font-style: italic;
	color: #666;
	text-align: center;
	grid-column: 1 / -1;
	padding: 40px 0;
	font-size: 1.2em;
}

.error-message {
	color: #c00;
	font-weight: bold;
}

.newsletter-section {
	background-color: var(--card-background);
	border: 1px solid var(--border-color);
	border-radius: 8px;
	padding: 20px;
	box-shadow: var(--card-shadow);
	transition:
		transform 0.3s,
		box-shadow 0.3s;
	display: flex;
	flex-direction: column;
	animation: fadeIn 0.5s ease-out;
	position: relative;
}

.newsletter-section:hover {
	transform: translateY(-5px);
	box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.newsletter-section h3 {
	margin-top: 0;
	border-bottom: 1px solid var(--border-color);
	padding-bottom: 10px;
	margin-bottom: 15px;
	padding-right: 50px; /* Space for read aloud button */
}

.newsletter-section img {
	max-width: 100%;
	height: auto;
	border-radius: 5px;
	margin-bottom: 15px;
	object-fit: cover;
	aspect-ratio: 4 / 3;
	background-color: var(--secondary-color);
	filter: var(--sepia-filter);
	border: 1px solid var(--border-color);
}

/* Read Aloud Button */
.read-aloud-btn {
	position: absolute;
	top: 15px;
	right: 15px;
	padding: 8px 12px;
	font-size: 0.8em;
	font-weight: normal;
	background-color: var(--secondary-color);
	color: var(--text-color);
	border: 1px solid var(--border-color);
	min-height: auto;
	min-width: auto;
}
.read-aloud-btn:hover:not(:disabled) {
	background-color: var(--secondary-hover-color);
}

/* --- Utility & Animations --- */
.hidden {
	display: none !important;
}

@keyframes fadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}

	.newsletter-section:hover,
	.btn:hover:not(:disabled),
	button:hover:not(:disabled) {
		transform: none;
	}
}

/* --- Print-Friendly Styles --- */
@media print {
	body {
		padding: 0;
		margin: 1cm;
		font-size: 12pt;
		color: #000000;
		background: #ffffff;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}

	header,
	footer,
	#onboarding-container,
	.button-group,
	.print-button-container,
	.form-navigation,
	.read-aloud-btn,
	.accessibility-controls,
	.progress-bar {
		display: none;
	}

	.container,
	#newsletter-container,
	main > section {
		box-shadow: none;
		border: none;
		padding: 0;
		margin: 0;
		max-width: 100%;
		width: 100%;
	}

	.newsletter-header {
		border-bottom: 2px solid #000;
		padding-bottom: 10px;
		margin-bottom: 1em;
		justify-content: center;
	}

	#newsletter-title {
		font-size: 20pt;
		text-align: center;
		width: 100%;
		color: #000;
	}

	#newsletter-content {
		display: block; /* Switch from grid to block for printing */
	}

	h2,
	h3 {
		font-size: 18pt;
		border-bottom-color: #000000;
		padding-bottom: 5px;
		margin-top: 1.2em;
		page-break-after: avoid;
		color: #000;
	}

	.newsletter-section {
		box-shadow: none;
		border: 1px solid #ccc;
		page-break-inside: avoid;
		margin-bottom: 20px;
		padding: 15px;
	}

	.newsletter-section img {
		filter: grayscale(100%);
		max-width: 40% !important; /* Make images smaller for print */
		float: right;
		margin-left: 15px;
		margin-bottom: 10px;
	}

	p,
	h3 {
		page-break-inside: avoid;
	}

	a {
		text-decoration: none;
		color: #000000;
	}

	a[href]::after {
		content: ''; /* Don't print URLs for a cleaner look */
	}
}