/* Lesson Page - Minimal CSS with Tailwind */

/* Table of Contents - Desktop Sidebar */
.toc-sidebar {
	scrollbar-width: thin;
	scrollbar-color: #d1d5db #f3f4f6;
}

.toc-sidebar::-webkit-scrollbar {
	width: 6px;
}

.toc-sidebar::-webkit-scrollbar-track {
	background: #f3f4f6;
}

.toc-sidebar::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 3px;
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
	background: #9ca3af;
}

.toc-link {
	transition: all 0.2s ease;
}

.toc-link:hover {
	transform: translateX(4px);
}

/* Adjust main content to accommodate desktop sidebar */
@media (min-width: 1024px) {
	.lesson-content-wrapper {
		margin-left: 16rem; /* 256px = w-64 */
	}
}

/* Progress Status - Custom styles that need specific functionality */
.progress-status {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.5rem 1rem;
	border-radius: 0.5rem;
	font-size: 0.875rem;
	font-weight: 500;
}

.progress-status.saving {
	background-color: #dbeafe;
	color: #1d4ed8;
}

.progress-status.saved {
	background-color: #d1fae5;
	color: #065f46;
}

.progress-status.error {
	background-color: #fee2e2;
	color: #dc2626;
}

.progress-status.not-logged-in {
	background-color: #fef3c7;
	color: #92400e;
}

.btn-retry {
	background-color: #f97316;
	color: white;
	padding: 0.25rem 0.75rem;
	border-radius: 0.25rem;
	border: none;
	font-size: 0.75rem;
	cursor: pointer;
	margin-left: 0.5rem;
	transition: background-color 0.2s;
}

.btn-retry:hover {
	background-color: #ea580c;
}

/* Lesson Content — spacing + blue/indigo theme (see design.md) */
.lesson-content { color: #1f2937; font-size: calc(1rem * var(--reading-scale, 1)); }
.lesson-content > *:first-child { margin-top: 0; }

.lesson-content h1,
.lesson-content h2,
.lesson-content h3,
.lesson-content h4 {
	color: #111827;
	font-weight: 800;
	line-height: 1.3;
	scroll-margin-top: 4rem;
}

.lesson-content h1 { font-size: calc(1.875rem * var(--reading-scale, 1)); margin: 0 0 1rem; }

/* each numbered section gets a clear gap + a soft divider so it breathes */
.lesson-content h2 {
	font-size: calc(1.4rem * var(--reading-scale, 1));
	margin: 2.75rem 0 1rem;
	padding-top: 1.5rem;
	border-top: 1px solid #eef2ff;
}
.lesson-content h2:first-of-type { border-top: 0; padding-top: 0; margin-top: 1.5rem; }

.lesson-content h3 { font-size: calc(1.15rem * var(--reading-scale, 1)); margin: 1.9rem 0 0.7rem; color: #4338ca; }
.lesson-content h4 { font-size: calc(1.05rem * var(--reading-scale, 1)); margin: 1.4rem 0 0.5rem; }

.lesson-content p { margin: 0.95rem 0; line-height: 1.8; }
.lesson-content ul,
.lesson-content ol { margin: 0.95rem 0; padding-left: 1.6rem; list-style: revert; }
.lesson-content li { margin: 0.45rem 0; line-height: 1.75; }
.lesson-content strong { color: #4338ca; font-weight: 700; }
.lesson-content em { color: #b45309; font-style: normal; font-weight: 600; }

.lesson-content blockquote {
	border-left: 4px solid #6366f1;
	background: #eef2ff;
	color: #3730a3;
	padding: 0.95rem 1.15rem;
	margin: 1.6rem 0;
	border-radius: 0 0.7rem 0.7rem 0;
}
.lesson-content blockquote strong { color: #312e81; }

.lesson-explainer {
	margin: 1.25rem 0;
	padding: 1rem 1.1rem;
	border: 1px solid #c7d2fe;
	border-radius: 0.85rem;
	background: #f8faff;
	color: #334155;
}

.lesson-explainer__label {
	display: inline-flex;
	align-items: center;
	gap: 0.45rem;
	margin-bottom: 0.45rem;
	color: #4338ca;
	font-size: 0.9rem;
	font-weight: 800;
}

.lesson-explainer__label i {
	color: #6366f1;
}

.lesson-explainer p {
	margin: 0;
	line-height: 1.75;
}

.lesson-explainer em {
	color: #92400e;
	font-weight: 700;
}

/* embedded summary cards (figures) — give them real breathing room */
.lesson-content figure { margin: 2rem 0; text-align: center; }
.lesson-content figure img { max-width: 100%; border-radius: 0.75rem; border: 1px solid #e5e7eb; }
.lesson-content figcaption { font-size: 0.85rem; color: #6b7280; margin-top: 0.45rem; }

.lesson-content figure.lesson-figure-zoomable {
	position: relative;
}

.lesson-zoomable-image {
	cursor: zoom-in;
	transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.lesson-zoomable-image:hover {
	border-color: #c7d2fe !important;
	box-shadow: 0 0 0 4px #eef2ff;
	transform: translateY(-1px);
}

.lesson-zoomable-image:focus-visible {
	outline: 3px solid #c7d2fe;
	outline-offset: 4px;
}

.lesson-image-zoom-badge {
	position: absolute;
	right: 0.75rem;
	bottom: 0.75rem;
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.45rem 0.65rem;
	border-radius: 999px;
	background: rgba(49, 46, 129, 0.92);
	color: #fff;
	font-size: 0.78rem;
	font-weight: 800;
	line-height: 1;
	box-shadow: 0 8px 18px -12px rgba(15, 23, 42, 0.8);
	pointer-events: none;
}

.lesson-content table {
	width: 100%;
	border-collapse: collapse;
	margin: 1.4rem 0;
	background: #fff;
	border-radius: 0.7rem;
	overflow: hidden;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
	font-size: calc(0.95rem * var(--reading-scale, 1));
}
.lesson-content th,
.lesson-content td {
	padding: 0.6rem 0.95rem;
	text-align: left;
	border-bottom: 1px solid #eef2ff;
	vertical-align: top;
}
.lesson-content th { background: #eef2ff; font-weight: 700; color: #3730a3; }
.lesson-content tr:last-child td { border-bottom: 0; }

/* Lesson image viewer */
.lesson-image-viewer {
	position: fixed;
	inset: 0;
	z-index: 70;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	background: rgba(15, 23, 42, 0.72);
}

.lesson-image-viewer__dialog {
	display: grid;
	grid-template-rows: auto minmax(0, 1fr) auto;
	width: min(1120px, 100%);
	height: min(92vh, 900px);
	overflow: hidden;
	border-radius: 1.25rem;
	background: #fff;
	box-shadow: 0 20px 48px -24px rgba(0, 0, 0, 0.45);
}

.lesson-image-viewer__header,
.lesson-image-viewer__footer {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.85rem 1rem;
	background: #fff;
	border-color: #e5e7eb;
}

.lesson-image-viewer__header {
	justify-content: space-between;
	border-bottom: 1px solid #e5e7eb;
}

.lesson-image-viewer__footer {
	justify-content: flex-end;
	border-top: 1px solid #e5e7eb;
}

.lesson-image-viewer__title {
	min-width: 0;
}

.lesson-image-viewer__badge {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	margin-bottom: 0.2rem;
	color: #4f46e5;
	font-size: 0.78rem;
	font-weight: 800;
}

.lesson-image-viewer__title h3 {
	margin: 0;
	overflow: hidden;
	color: #111827;
	font-size: 1rem;
	font-weight: 800;
	line-height: 1.35;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.lesson-image-viewer__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 2.5rem;
	height: 2.5rem;
	border: 1px solid #e5e7eb;
	border-radius: 999px;
	background: #fff;
	color: #475569;
	transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.lesson-image-viewer__close:hover {
	border-color: #c7d2fe;
	background: #eef2ff;
	color: #4338ca;
}

.lesson-image-viewer__body {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	min-height: 0;
	overflow: auto;
	padding: 1rem;
	background: #f8fafc;
}

.lesson-image-viewer__body img {
	max-width: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 0.75rem;
	background: #fff;
	box-shadow: 0 8px 24px -18px rgba(15, 23, 42, 0.55);
}

.lesson-image-viewer__primary,
.lesson-image-viewer__secondary {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
	min-height: 2.75rem;
	padding: 0.65rem 1rem;
	border-radius: 0.75rem;
	font-size: 0.9rem;
	font-weight: 800;
	text-decoration: none;
	transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.lesson-image-viewer__primary {
	background: #4f46e5;
	color: #fff;
}

.lesson-image-viewer__primary:hover {
	background: #4338ca;
}

.lesson-image-viewer__secondary {
	border: 1px solid #c7d2fe;
	background: #fff;
	color: #4f46e5;
}

.lesson-image-viewer__secondary:hover {
	background: #eef2ff;
	color: #4338ca;
}

@media (prefers-reduced-motion: reduce) {
	.lesson-zoomable-image,
	.lesson-image-viewer__close,
	.lesson-image-viewer__primary,
	.lesson-image-viewer__secondary {
		transition: none;
	}
	.lesson-zoomable-image:hover {
		transform: none;
	}
}

@media (max-width: 768px) {
	.lesson-content { font-size: calc(1rem * var(--reading-scale, 1)); }
	.lesson-content h2 { font-size: calc(1.25rem * var(--reading-scale, 1)); margin-top: 2.25rem; }
	.lesson-image-zoom-badge {
		right: 0.5rem;
		bottom: 0.5rem;
		font-size: 0.72rem;
	}
	.lesson-image-viewer {
		align-items: stretch;
		padding: 0;
	}
	.lesson-image-viewer__dialog {
		width: 100%;
		height: 100dvh;
		border-radius: 0;
	}
	.lesson-image-viewer__header,
	.lesson-image-viewer__footer {
		padding: 0.8rem;
	}
	.lesson-image-viewer__footer {
		display: grid;
		grid-template-columns: 1fr 1fr;
	}
	.lesson-image-viewer__body {
		justify-content: flex-start;
	}
	.lesson-image-viewer__body img {
		max-width: none;
		width: min(920px, 180vw);
	}
	.lesson-image-viewer__primary,
	.lesson-image-viewer__secondary {
		width: 100%;
		padding-inline: 0.75rem;
	}
}

/* standalone นิคคหิต (ํ) — bare combining mark needs its own box so it doesn't collide with the next char on mobile */
.lesson-content .nik { display: inline-block; min-width: 1.62em; text-align: center; }

/* Games Sidebar - Desktop Scrollbar customization */
.games-sidebar {
	scrollbar-width: thin;
	scrollbar-color: #d1d5db #f3f4f6;
}

.games-sidebar::-webkit-scrollbar {
	width: 6px;
}

.games-sidebar::-webkit-scrollbar-track {
	background: #f3f4f6;
}

.games-sidebar::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 3px;
}

.games-sidebar::-webkit-scrollbar-thumb:hover {
	background: #9ca3af;
}

/* ── Inline roadmap checklist (แทรกในบทเรียน) ─────────────────────────────
   Hydrated by lesson.js from <div class="rm-check" data-topics="…">.
   Shares state with the side panel + /roadmap via localStorage. */
.lesson-content .rm-check { margin: 1.75rem 0; }
.rm-check__card {
	border: 1px solid #c7d2fe;
	background: linear-gradient(180deg, #f5f7ff 0%, #ffffff 60%);
	border-radius: 1rem;
	padding: 1rem 1.1rem 0.9rem;
	box-shadow: 0 14px 30px -24px rgba(49, 46, 129, 0.9);
}
.rm-check__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.rm-check__title {
	display: inline-flex; align-items: center; gap: 0.45rem;
	font-weight: 800; color: #3730a3;
	font-size: calc(1.02rem * var(--reading-scale, 1));
}
.rm-check__title i { color: #6366f1; }
.rm-check__count {
	flex: none; font-weight: 800; font-size: 0.72rem;
	color: #4338ca; background: #e0e7ff;
	padding: 0.15rem 0.55rem; border-radius: 999px;
}
.rm-check__bar { height: 6px; border-radius: 999px; background: #e5e7eb; overflow: hidden; margin: 0.7rem 0 0.85rem; }
.rm-check__bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #6366f1, #10b981); transition: width 0.25s ease; }
.rm-check__grp {
	margin: 0.7rem 0 0.3rem; font-weight: 700;
	font-size: calc(0.82rem * var(--reading-scale, 1)); color: #6b7280;
}
.rm-check__grp:first-child { margin-top: 0.15rem; }
.rm-check__item {
	display: flex; align-items: flex-start; gap: 0.65rem;
	padding: 0.5rem 0.55rem; border-radius: 0.6rem; cursor: pointer;
	transition: background 0.14s;
}
.rm-check__item:hover { background: rgba(99, 102, 241, 0.08); }
.rm-check__item input {
	margin-top: 0.15rem; flex: none;
	width: 1.1rem; height: 1.1rem; accent-color: #4f46e5; cursor: pointer;
}
.rm-check__item span {
	font-size: calc(0.95rem * var(--reading-scale, 1));
	line-height: 1.5; color: #374151;
}
.rm-check__item.is-done span { text-decoration: line-through; color: #9ca3af; }

/* Full-page game CTA — links out to the standalone /kitaka & /kiriya games.
   Sibling to the popup .drill-cta (styled in drill-modal.js) but navigates
   to the game page instead of opening a popup. */
.lesson-game-cta {
	position: relative; display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 1rem;
	margin: 2rem 0; padding: 1rem; text-decoration: none;
	border: 2px solid #a5b4fc; border-radius: 1rem;
	background: linear-gradient(135deg, #4338ca 0%, #6d28d9 55%, #7c3aed 100%);
	color: #fff; box-shadow: 0 18px 38px -22px rgba(49, 46, 129, 0.9);
	transition: transform 0.14s, box-shadow 0.14s, border-color 0.14s, filter 0.14s;
}
.lesson-game-cta::after {
	content: ""; position: absolute; inset: 2px; border-radius: 0.85rem;
	background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 44%, rgba(255, 255, 255, 0.16));
	pointer-events: none;
}
.lesson-game-cta:hover {
	transform: translateY(-2px); border-color: #c7d2fe;
	box-shadow: 0 22px 44px -22px rgba(49, 46, 129, 0.95); filter: saturate(1.06);
}
.lesson-game-cta:focus-visible { outline: 3px solid #c7d2fe; outline-offset: 3px; }
.lesson-game-cta--kiriya {
	border-color: #6ee7b7;
	background: linear-gradient(135deg, #065f46 0%, #0f766e 50%, #0d9488 100%);
	box-shadow: 0 18px 38px -22px rgba(6, 78, 59, 0.9);
}
.lesson-game-cta--kiriya:hover { border-color: #a7f3d0; }
.lesson-game-cta__ic {
	position: relative; z-index: 1; display: grid; place-items: center;
	width: 3.35rem; height: 3.35rem; border-radius: 1rem; flex: none;
	background: #fff; color: #4f46e5; font-size: 1.35rem; line-height: 1;
	box-shadow: 0 12px 22px -14px rgba(15, 23, 42, 0.8);
}
.lesson-game-cta--kiriya .lesson-game-cta__ic { color: #0d9488; }
.lesson-game-cta__tx { position: relative; z-index: 1; flex: 1; min-width: 0; }
.lesson-game-cta__badge {
	display: inline-flex; align-items: center; gap: 0.35rem; margin-bottom: 0.35rem;
	padding: 0.25rem 0.55rem; border-radius: 999px;
	background: rgba(255, 255, 255, 0.18); color: #fff;
	font-size: 0.75rem; font-weight: 900; line-height: 1;
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.lesson-game-cta__tx b {
	display: block; font-weight: 900;
	font-size: calc(1.05rem * var(--reading-scale, 1)); line-height: 1.35; color: #fff;
	text-shadow: 0 1px 8px rgba(15, 23, 42, 0.28);
}
.lesson-game-cta__meta {
	display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem;
	margin-top: 0.35rem; font-size: 0.82rem; color: #e0e7ff;
}
.lesson-game-cta--kiriya .lesson-game-cta__meta { color: #d1fae5; }
.lesson-game-cta__go {
	position: relative; z-index: 1; display: inline-flex; align-items: center;
	justify-content: center; gap: 0.4rem; flex: none; white-space: nowrap;
	font-size: 0.9rem; font-weight: 900; padding: 0.65rem 0.95rem;
	border-radius: 0.85rem; background: #fff; color: #4338ca;
	box-shadow: 0 12px 22px -16px rgba(15, 23, 42, 0.8);
}
.lesson-game-cta--kiriya .lesson-game-cta__go { color: #0f766e; }
.lesson-game-cta:hover .lesson-game-cta__go { background: #f8fafc; }
@media (max-width: 640px) {
	.lesson-game-cta { grid-template-columns: auto 1fr; padding: 0.95rem; }
	.lesson-game-cta__go { grid-column: 1 / -1; width: 100%; margin-top: 0.15rem; }
	.lesson-game-cta__ic { width: 3rem; height: 3rem; border-radius: 0.85rem; }
}
