:root {
	--a4-w: 210mm;
	--a4-h: 297mm;
	--m: 10mm;
	--focus-color: #0066cc;
	--focus-width: 2px;
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* Skip link for accessibility */
.skip-link {
	position: absolute;
	top: -40px;
	left: 0;
	background: #000;
	color: #fff;
	padding: 8px;
	text-decoration: none;
	z-index: 1000;
}

.skip-link:focus {
	top: 0;
}

@page {
	size: A4;
	margin: 0;
}

@media screen {
	html {
		width: 100%;
		min-height: 100%;
		overflow-x: hidden;
		overflow-y: auto;
	}

	body {
		width: 100%;
		min-height: 100%;
		overflow-x: hidden;
		overflow-y: auto;
		background: #f5f5f5;
		margin: 0;
	}

	.sheet-viewport {
		width: 100%;
		overflow-x: auto;
		overflow-y: visible;
		-webkit-overflow-scrolling: touch;
	}

	.sheet-root {
		min-width: calc(var(--a4-w) + 32px);
		width: fit-content;
		margin: 0 auto;
	}

	.preview-stage {
		padding: 16px;
	}

	.page {
		width: var(--a4-w);
		min-height: var(--a4-h);
		box-sizing: border-box;
		background: #fff;
		border: 1px solid #ccc;
		box-shadow: 0 2mm 6mm rgba(0, 0, 0, 0.15);
		margin: 0 auto;
		overflow: hidden;
	}
}

@media screen and (max-width: 768px) {
	.navbar-content {
		flex-wrap: wrap;
	}

	.navbar-brand {
		font-size: 14pt;
	}

	.navbar-print-btn {
		font-size: 10pt;
		padding: 4px 8px;
	}

	.worksheet-grid {
		grid-template-columns: repeat(auto-fit, minmax(110pt, 1fr));
		gap: 6pt;
	}

	.worksheet-card {
		padding: 8pt;
	}

	.worksheet-icon {
		font-size: 22pt;
	}

	.worksheet-name {
		font-size: 11pt;
	}

	.worksheet-desc {
		font-size: 8pt;
	}

	.home-header h1 {
		font-size: 22pt;
	}

	.home-subtitle {
		font-size: 11pt;
	}

	.worksheet-actions {
		flex-wrap: wrap;
		gap: 3mm;
	}

	.worksheet-action-btn {
		font-size: 10pt;
		padding: 2mm 3mm;
	}

	.answer-key-grid {
		grid-template-columns: repeat(3, 1fr);
	}

	.category-title {
		font-size: 12pt;
	}
}

@media screen and (max-width: 480px) {
	.worksheet-grid {
		grid-template-columns: 1fr;
	}

	.worksheet-card {
		flex-direction: row;
		text-align: left;
		padding: 8pt 10pt;
	}

	.worksheet-icon {
		font-size: 20pt;
		margin-bottom: 0;
		margin-right: 8pt;
	}

	.answer-key-grid {
		grid-template-columns: repeat(2, 1fr);
	}
}

@media print {
	body {
		margin: 0;
	}

	.preview-stage {
		padding: 0;
		background: transparent;
	}

	.page {
		margin: 0;
		border: none;
		box-shadow: none;
	}

	.navbar {
		display: none !important;
	}

	.coloring-form {
		display: none !important;
	}

	.coloring-vote-form {
		display: none !important;
	}

	.coloring-history {
		display: none !important;
	}

	.regular-ui-section {
		display: none !important;
	}

	.answer-key-section {
		page-break-before: always;
	}
}

/* Number Bonds worksheet styles */
.number-bonds-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 6mm;
	margin-top: 6mm;
}

.number-bond {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 2mm;
}

.number-bond-svg {
	width: 90px;
	height: 99px;
}

.number-bond-circle {
	fill: #fff;
	stroke: #000;
	stroke-width: 2;
}

.number-bond-line {
	stroke: #000;
	stroke-width: 2;
}

.number-bond-text {
	fill: #000;
	font-size: 14px;
	font-weight: 600;
}

.number-bonds-answers {
	grid-template-columns: repeat(5, 1fr) !important;
}

/* Themed worksheet decorations */
.themed-worksheet {
	position: relative;
}

.themed-content {
	position: relative;
	z-index: 1;
}

.watermark-decoration {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
	pointer-events: none;
}

.corner-decoration {
	position: absolute;
	z-index: 2;
	pointer-events: none;
}

.corner-top-left {
	top: 5mm;
	left: 5mm;
}

.corner-top-right {
	top: 5mm;
	right: 5mm;
}

.corner-bottom-left {
	bottom: 5mm;
	left: 5mm;
}

.corner-bottom-right {
	bottom: 5mm;
	right: 5mm;
}

/* Hide themed decorations in navbar area (don't print them) */
@media print {
	.corner-decoration {
		/* Keep decorations in print but ensure they're positioned correctly */
	}
}

/* Color by Number worksheet styles */
.cbn-layout {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8mm;
	margin: 6mm auto;
	width: min(100%, 160mm);
}

.cbn-svg {
	border: 1px solid #000;
	background: #fff;
}

.cbn-region {
	stroke-linejoin: round;
	stroke-linecap: round;
	cursor: pointer;
}

.cbn-number {
	fill: #000;
	pointer-events: none;
	user-select: none;
}

.cbn-color-key {
	text-align: center;
	width: 100%;
}

.cbn-color-key-title {
	font-size: 11pt;
	font-weight: 600;
	margin-bottom: 3mm;
}

.cbn-color-key-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 3mm;
	justify-content: center;
}

.cbn-color-key-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1mm;
}

.cbn-color-swatch {
	width: 10mm;
	height: 10mm;
	border: 1px solid #000;
}

.cbn-color-label {
	font-size: 11pt;
	font-weight: 600;
}

.cbn-problems {
	display: flex;
	flex-wrap: wrap;
	gap: 4mm;
	justify-content: center;
	margin-bottom: 4mm;
}

.cbn-problem {
	display: flex;
	align-items: center;
	gap: 2mm;
	font-size: 12pt;
}

.cbn-problem-number {
	font-weight: 600;
	color: #666;
}

.cbn-problem-equals {
	color: #666;
}

.cbn-problem-blank {
	border-bottom: 1px solid #000;
	min-width: 25px;
	text-align: center;
}

.cbn-color-key-full {
	display: flex;
	flex-wrap: wrap;
	gap: 3mm;
	justify-content: center;
}

.cbn-answer-item {
	display: flex;
	align-items: center;
	gap: 2mm;
	font-size: 11pt;
}

.navbar {
	position: sticky;
	top: 0;
	background: #fff;
	border-bottom: 1px solid #ccc;
	padding: 12px 16px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
	z-index: 100;
}

.navbar-content {
	width: 100%;
	margin: 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.navbar-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

.navbar-print-btn {
	font-size: 12pt;
	padding: 6px 12px;
	border: 1px solid #333;
	background: #fff;
	color: #333;
	cursor: pointer;
	text-decoration: none;
}

.navbar-print-btn:hover {
	background: #f5f5f5;
}

.navbar-print-btn:focus,
.navbar-brand:focus {
	outline: 2px solid var(--focus-color);
	outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
select:focus-visible {
	outline: 2px solid var(--focus-color);
	outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
	outline: none;
}

.regular-ui-section {
	width: min(100%, calc(var(--a4-w) + 32px));
	margin: 12px auto 0 auto;
	padding: 0 16px;
}

.regular-ui-panel {
	background: #fff;
	border: 1px solid #ccc;
	box-shadow: 0 1mm 3mm rgba(0, 0, 0, 0.08);
	padding: 12px;
}

/* Home page specific styling - wider max width */
.regular-ui-section.home-page {
	width: 100%;
	max-width: 900px;
	margin: 0 auto;
	padding: 24px 32px 32px 32px;
}

.regular-ui-section.home-page .regular-ui-panel {
	background: #fff;
	border: none;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	padding: 0;
}

.navbar-brand {
	font-size: 16pt;
	font-weight: 600;
	color: #333;
}

.navbar-brand:hover {
	text-decoration: none;
}

.sheet {
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	padding: var(--m);
	font-family:
		system-ui,
		-apple-system,
		'Segoe UI',
		Roboto,
		'Noto Sans',
		Arial,
		sans-serif;
	font-size: 11pt;
	line-height: 1.2;
}

.worksheet-title {
	font-size: 24pt;
	margin-bottom: 1cm;
	text-align: center;
}

.worksheet-instructions {
	text-align: center;
	margin-bottom: 1cm;
	font-size: 12pt;
}

.worksheet {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 8mm;
	margin-top: 8mm;
}

.problem {
	font-size: 16pt;
	text-align: center;
	padding: 4mm;
	border: 1px solid #000;
	min-height: 15mm;
	display: flex;
	align-items: center;
	justify-content: center;
}

.worksheet-footer {
	text-align: center;
	margin-top: 8mm;
	font-size: 11pt;
}

.maze-seed {
	text-align: center;
	margin-bottom: 4mm;
	font-size: 10pt;
	color: #444;
}

.maze-wrapper {
	margin: 0 auto;
	width: min(100%, 178mm);
}

.maze-svg {
	width: 100%;
	height: auto;
	display: block;
}

.maze-svg line {
	stroke: #000;
	stroke-width: 2;
	vector-effect: non-scaling-stroke;
	shape-rendering: crispEdges;
}

.maze-svg text {
	fill: #000;
	font-size: 16px;
	font-weight: 700;
}

.coloring-form {
	display: grid;
	gap: 8px;
	margin: 0 auto 8mm auto;
	width: min(100%, 170mm);
}

.coloring-label {
	font-size: 11pt;
	font-weight: 600;
}

.coloring-form textarea {
	font-size: 11pt;
	padding: 3mm;
	border: 1px solid #000;
	min-height: 24mm;
	resize: vertical;
}

.coloring-select {
	font-size: 11pt;
	padding: 3mm;
	border: 1px solid #000;
	background: #fff;
}

.coloring-form button {
	font-size: 11pt;
	padding: 3mm 4mm;
	border: 1px solid #000;
	background: #fff;
	cursor: pointer;
}

.coloring-error {
	color: #b00020;
	text-align: center;
	margin: 4mm 0;
}

.coloring-prompt {
	margin-bottom: 3mm;
	font-size: 10pt;
}

.coloring-model {
	text-align: center;
	margin-top: 3mm;
	font-size: 9pt;
	color: #444;
}

.coloring-svg-wrapper {
	width: min(100%, 180mm);
	margin: 0 auto;
	border: 1px solid #000;
	padding: 4mm;
	min-height: 140mm;
	display: grid;
	place-items: center;
}

.coloring-svg-wrapper svg {
	width: 100%;
	height: auto;
	display: block;
}

.coloring-loading-wrapper {
	width: min(100%, 180mm);
	margin: 0 auto;
	border: 1px solid #000;
	padding: 4mm;
	min-height: 140mm;
	display: grid;
	place-items: center;
}

.coloring-loading {
	font-size: 12pt;
	color: #444;
	animation: coloring-pulse 1.2s ease-in-out infinite;
}

.coloring-loading-note {
	margin-top: 3mm;
	font-size: 10pt;
	color: #666;
}

.coloring-vote-form {
	margin-top: 4mm;
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
}

.coloring-vote-form button {
	font-size: 10pt;
	padding: 2mm 3mm;
	border: 1px solid #000;
	background: #fff;
	cursor: pointer;
}

.coloring-score {
	font-size: 10pt;
	color: #333;
}

.coloring-history {
	margin: 7mm auto 0 auto;
	width: min(100%, 180mm);
	border-top: 1px solid #ccc;
	padding-top: 4mm;
}

.coloring-history-title {
	font-size: 13pt;
	margin-bottom: 3mm;
}

.coloring-history-empty {
	font-size: 10pt;
	color: #666;
}

.coloring-history-list {
	display: grid;
	grid-template-columns: 1fr;
	gap: 3mm;
	list-style: none;
	margin: 0;
	padding: 0;
}

.coloring-history-item {
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: 2mm;
}

.coloring-history-vote-form {
	margin: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	flex-wrap: wrap;
}

.coloring-history-vote-form button {
	font-size: 9pt;
	padding: 1.5mm 2.5mm;
	border: 1px solid #000;
	background: #fff;
	cursor: pointer;
}

.coloring-history-link {
	display: grid;
	grid-template-columns: 36mm 1fr;
	gap: 3mm;
	border: 1px solid #d0d0d0;
	padding: 2.5mm;
	color: inherit;
	text-decoration: none;
}

.coloring-history-thumbnail {
	width: 36mm;
	height: 28mm;
	border: 1px solid #000;
	overflow: hidden;
	display: grid;
	place-items: center;
}

.coloring-history-thumbnail svg {
	width: 100%;
	height: 100%;
	display: block;
}

.coloring-history-details {
	min-width: 0;
}

.coloring-history-prompt {
	font-size: 10pt;
	font-weight: 600;
	margin-bottom: 1mm;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.coloring-history-model {
	font-size: 9pt;
	color: #555;
	margin-bottom: 1mm;
}

.coloring-history-score {
	font-size: 9pt;
	color: #333;
}

@keyframes coloring-pulse {
	0% {
		opacity: 0.35;
	}
	50% {
		opacity: 1;
	}
	100% {
		opacity: 0.35;
	}
}

/* Safety margin to ensure single-page output */
.safety-margin {
	height: 10mm;
}

a {
	color: #0066cc;
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

ul {
	list-style: none;
	padding: 0;
}

li {
	margin: 0.5cm 0;
	font-size: 14pt;
}

/* Home page styles */
.home-header {
	text-align: center;
	padding: 2cm 0 1.5cm 0;
}

.home-header h1,
.home-header-title {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8pt;
	font-size: 28pt;
	margin-bottom: 6pt;
	color: #222;
}

.home-logo-icon {
	width: 1em;
	height: 1em;
	flex-shrink: 0;
}

.home-subtitle {
	font-size: 13pt;
	color: #555;
	margin: 0;
}

.category-section {
	margin-bottom: 1.5cm;
	padding: 12pt 10pt;
	background: #fafafa;
	border-radius: 6pt;
}

.category-title {
	font-size: 14pt;
	font-weight: 600;
	color: #333;
	margin-bottom: 12pt;
	padding-bottom: 4pt;
	border-bottom: 2px solid #e0e0e0;
}

.worksheet-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(140pt, 1fr));
	gap: 10pt;
}

.worksheet-card {
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	padding: 12pt;
	background: #f8f8f8;
	border: 1px solid #d0d0d0;
	border-radius: 8pt;
	text-decoration: none;
	color: inherit;
	transition: all 0.15s ease;
}

.worksheet-card:hover {
	background: #fff;
	border-color: #999;
	box-shadow: 0 2pt 6pt rgba(0, 0, 0, 0.1);
	transform: translateY(-1pt);
}

.worksheet-card:focus {
	outline: 2px solid #0066cc;
	outline-offset: 2px;
}

.worksheet-icon {
	font-size: 28pt;
	margin-bottom: 6pt;
}

.worksheet-name {
	font-size: 12pt;
	font-weight: 600;
	margin: 0 0 4pt 0;
	color: #222;
}

.worksheet-badge {
	display: inline-block;
	border-radius: 999px;
	padding: 2pt 7pt;
	font-size: 7.5pt;
	font-weight: 700;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	margin-bottom: 4pt;
}

.worksheet-badge-ai {
	background: #fff3bf;
	border: 1px solid #e0b100;
	color: #5c4300;
}

.worksheet-desc {
	font-size: 9pt;
	color: #555;
	margin: 0;
	line-height: 1.3;
}

.worksheet-capability-note {
	text-align: center;
	margin-top: -6mm;
	margin-bottom: 5mm;
	font-size: 9pt;
	color: #665100;
	font-weight: 600;
}

.cbn-shape-form {
	display: inline-flex;
	align-items: center;
	gap: 2mm;
}

.cbn-shape-label {
	font-size: 10pt;
	color: #333;
	font-weight: 600;
}

.cbn-shape-select {
	font-size: 10pt;
	padding: 1.5mm 2.5mm;
	border: 1px solid #000;
	background: #fff;
}

.home-footer {
	margin-top: 2cm;
	text-align: center;
}

.home-tip {
	font-size: 11pt;
	color: #555;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6pt;
	margin: 0;
}

.tip-icon {
	font-size: 14pt;
}

/* Worksheet action buttons */
.worksheet-actions {
	display: flex;
	justify-content: center;
	gap: 6mm;
	margin-top: 4mm;
}

.worksheet-action-btn {
	font-size: 11pt;
	padding: 3mm 5mm;
	border: 1px solid #333;
	background: #fff;
	color: #333;
	cursor: pointer;
	border-radius: 3pt;
	transition: background 0.1s ease;
}

.worksheet-action-btn:hover {
	background: #f0f0f0;
}

.worksheet-action-btn:focus {
	outline: 2px solid #0066cc;
	outline-offset: 2px;
}

/* Answer key section */
.answer-key-section {
	margin-top: 5mm;
	padding: 3mm;
	border: 1px dashed #999;
	background: #f5f5f5;
}

.answer-key-title {
	font-size: 11pt;
	font-weight: 600;
	margin-bottom: 2mm;
	text-align: center;
}

.answer-key-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 4mm;
}

.answer-key-item {
	font-size: 11pt;
	text-align: center;
	padding: 2mm;
	background: #fff;
	border: 1px solid #ccc;
}

/* Word problems worksheet */
.word-problems-worksheet {
	display: flex;
	flex-direction: column;
	gap: 6mm;
	margin-top: 5mm;
}

.word-problem-item {
	display: flex;
	flex-direction: column;
	padding: 3mm;
	border: 1px solid #ccc;
	border-radius: 3pt;
	background: #fafafa;
	page-break-inside: avoid;
}

.problem-number {
	font-size: 10pt;
	font-weight: 600;
	color: #333;
	margin-bottom: 2mm;
}

.problem-text {
	font-size: 11pt;
	line-height: 1.5;
	margin-bottom: 3mm;
	flex: 1;
}

.answer-line {
	font-size: 11pt;
	padding-top: 2mm;
	border-top: 1px dotted #999;
}

.word-problems-answer-key {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 3mm;
}

.answer-key-problem {
	display: flex;
	align-items: center;
	gap: 2mm;
	padding: 2mm;
	background: #fff;
	border: 1px solid #ccc;
}

.answer-key-number {
	font-size: 10pt;
	font-weight: 600;
	min-width: 20pt;
}

.answer-key-value {
	font-size: 11pt;
	font-weight: 600;
}

.loading-spinner {
	display: flex;
	justify-content: center;
	align-items: center;
	min-height: 100mm;
}

.spinner {
	width: 50px;
	height: 50px;
	border: 4px solid #f3f3f3;
	border-top: 4px solid #0066cc;
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

@keyframes spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

.error-message {
	padding: 4mm;
	background: #fee;
	border: 1px solid #fcc;
	border-radius: 4pt;
	text-align: center;
}

.form-row {
	display: flex;
	flex-direction: column;
	gap: 3pt;
	margin-bottom: 6pt;
}

.form-label {
	font-size: 10pt;
	font-weight: 600;
	color: #333;
}

.form-input {
	padding: 3mm;
	border: 1px solid #999;
	border-radius: 3pt;
	font-size: 11pt;
}

.form-help {
	font-size: 8pt;
	color: #666;
	margin: 0;
}

.form-submit {
	padding: 4mm 8mm;
	background: #0066cc;
	color: #fff;
	border: none;
	border-radius: 4pt;
	font-size: 11pt;
	font-weight: 600;
	cursor: pointer;
	margin-top: 4pt;
}

.form-submit:hover {
	background: #0052a3;
}

.hidden {
	display: none !important;
}
