/* Terminal UI, dark unless the viewer picks light: one monospace font, panels titled in their top border, bracketed controls, inverse-video selection. */

:root {
	/* BoweIQ brand: yellow surface with dark blue-grey foreground, and the logo's grey. */
	--brand-yellow: #f1b434;
	--brand-dark: #2e434e;
	--brand-grey: #cccccc;

	--bg: #172128;
	--panel: #1c2830;
	--text: #d3dce1;
	--bright: #ffffff;
	--muted: #8899a4;
	--line: #3a505c;
	--accent: var(--brand-yellow);
	--accent-text: var(--brand-dark);
	--green: #7ee787;
	--red: #ff7b72;
	--yellow: var(--brand-yellow);
	--magenta: #9fc3d6;
	--bar: var(--brand-yellow);
	--bar-text: var(--brand-dark);
	--code-bg: #11191e;
	--selection: #2e434e;
	--font: "JetBrains Mono", ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
	color-scheme: dark;
}

:root[data-theme="light"] {
	--bg: #f4f5f6;
	--panel: #ffffff;
	--text: #2e434e;
	--bright: #17252d;
	--muted: #6b7b85;
	--line: var(--brand-grey);
	--accent: var(--brand-dark);
	--accent-text: #ffffff;
	--green: #2f8a2f;
	--red: #c0392b;
	--yellow: #9a6a00;
	--magenta: #4f6d7d;
	--code-bg: #f7f8f9;
	--selection: #fdf0d2;
	color-scheme: light;
}


* { box-sizing: border-box; }
::selection { background: var(--accent); color: var(--accent-text); }

body {
	margin: 0;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.7 var(--font);
	font-variant-ligatures: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { background: var(--accent); color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1680px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 40px); }
main.wrap { flex: 1; padding-bottom: 48px; }

/* Status bars, top and bottom, like tmux. */
.site-header, .site-footer { background: var(--bar); color: var(--bar-text); border-color: var(--brand-dark); border-style: solid; border-width: 0; font-size: 0.85rem; }
.site-header { border-bottom-width: 1px; margin-bottom: 28px; }
.site-footer { border-top-width: 1px; }
.header-row, .footer-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; min-height: 40px; }
.brand { color: var(--bar-text); font-weight: 700; }
.brand::before { content: "▌"; color: var(--bar-text); }
/* The BoweIQ hexagon, drawn one CSS pixel per cell so it stays sharp. */
.brand-icon { color: var(--bar-text); margin: 0 6px 0 4px; vertical-align: middle; }
.header-nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.header-nav a, .header-nav .link-button { color: var(--bar-text); }
.header-nav a:hover, .header-nav .link-button:hover, .brand:hover { background: var(--bar-text); color: var(--bar); }
.who { color: var(--bar-text); font-weight: 700; }
.who::before { content: "● "; }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-button::before, .link-button::after { content: none; }
.hotkeys { display: flex; gap: 18px; flex-wrap: wrap; }
.hotkeys kbd { font: inherit; color: var(--bar); background: var(--bar-text); padding: 0 5px; margin-right: 6px; }

/* Headings. */
h1, h2, h3 { color: var(--bright); font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.6rem; margin: 0 0 10px; }
h1::before { content: "# "; color: var(--accent); }
.lesson-head h1::after { content: "▋"; color: var(--accent); margin-left: 6px; animation: blink 1.1s steps(1) infinite; }
h2 { font-size: 1.2rem; margin: 30px 0 10px; }
h2::before { content: "## "; color: var(--accent); }
h3 { font-size: 1rem; margin: 22px 0 6px; }
h3::before { content: "### "; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.empty { color: var(--muted); }
.empty::before { content: "-- "; }
.ok { color: var(--green); }
.bad { color: var(--red); }

/* Panels: a box with its title cut into the top border. */
.card {
	position: relative;
	background: var(--panel);
	border: 1px solid var(--line);
	padding: 24px 22px 18px;
	margin: 30px 0;
}
.card > h2:first-child, .card > .course-head:first-child {
	position: absolute;
	top: 0;
	left: 14px;
	right: 14px;
	transform: translateY(-50%);
	margin: 0;
	pointer-events: none;
}
.card > h2:first-child { font-size: 0.95rem; width: fit-content; background: var(--panel); padding: 0 8px; }
.card > h2:first-child::before { content: "┤ "; color: var(--line); }
.card > h2:first-child::after { content: " ├"; color: var(--line); }
.card:focus-within { border-color: var(--accent); }

.intro p { color: var(--muted); max-width: 72ch; }
.intro p::before { content: "> "; color: var(--green); }

.course-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.course-head h2 { font-size: 0.95rem; background: var(--panel); padding: 0 8px; margin: 0; }
.course-head h2::before { content: "┤ "; color: var(--line); }
.course-head h2::after { content: " ├"; color: var(--line); }
.course-count { background: var(--panel); padding: 0 8px; color: var(--muted); font-size: 0.8rem; }

.meter { display: block; margin: 0 0 10px; color: var(--muted); white-space: pre; overflow: hidden; }
.meter-fill { color: var(--green); }

/* Lesson list: a directory listing with a moving cursor. */
.lesson-list { margin: 0; padding: 0; list-style: none; counter-reset: lesson; }
.lesson-list li {
	counter-increment: lesson;
	display: grid;
	grid-template-columns: 3ch 1.6em 1fr auto;
	align-items: baseline;
	column-gap: 8px;
	padding: 3px 6px;
}
.lesson-list li::before { content: counter(lesson, decimal-leading-zero); color: var(--muted); }
.lesson-list li:hover, .lesson-list li:focus-within { background: var(--selection); }
.lesson-list li:hover a, .lesson-list li:focus-within a { color: var(--bright); background: none; }
.lesson-list a { color: var(--text); font-weight: 700; }
.lesson-list .lesson-meta { grid-column: 3; font-size: 0.8rem; }
.lesson-list .badge { grid-column: 4; grid-row: 1; }
.lesson-kind { color: var(--magenta); }
.lesson-meta { color: var(--muted); display: inline-flex; gap: 16px; flex-wrap: wrap; align-items: baseline; }
.stage { white-space: nowrap; color: var(--yellow); }

/* Badges: [ DONE ] */
.badge { font-size: 0.75rem; font-weight: 700; white-space: nowrap; text-transform: uppercase; }
.badge::before { content: "[ "; color: var(--muted); }
.badge::after { content: " ]"; color: var(--muted); }
.badge-done { color: var(--green); }
.badge-outdated, .badge-attempted { color: var(--yellow); }
.badge-new { color: var(--accent); }

.breadcrumb { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.breadcrumb::before { content: "~/"; color: var(--green); }
.lesson-head { margin-bottom: 22px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.title-icon { color: var(--magenta); margin-right: 4px; }

.notice { border: 1px solid var(--yellow); color: var(--text); padding: 8px 14px; margin: 16px 0; }
.notice::before { content: "! "; color: var(--yellow); font-weight: 700; }

/* Lesson text. */
.lesson-body { overflow-wrap: break-word; max-width: 100ch; }
.lesson-body strong { color: var(--bright); }
.lesson-body table { border-collapse: collapse; width: 100%; margin: 16px 0; font-size: 0.85rem; display: block; overflow-x: auto; }
.lesson-body th, .lesson-body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.lesson-body th { color: var(--bar-text); background: var(--bar); }
.lesson-body blockquote { margin: 18px 0; padding: 4px 16px; border-left: 3px solid var(--magenta); background: var(--panel); }
.lesson-body ul { padding-left: 0; list-style: none; }
.lesson-body ul li { padding-left: 2ch; text-indent: -2ch; }
.lesson-body ul li::before { content: "- "; color: var(--accent); }
.lesson-body ol { padding-left: 3ch; }
.lesson-body ol li::marker { color: var(--accent); }

code { font-family: var(--font); color: var(--yellow); }
pre { background: var(--code-bg); border: 1px solid var(--line); padding: 12px 16px; overflow-x: auto; line-height: 1.55; tab-size: 4; }
pre code { color: var(--text); font-size: 0.85rem; }

/* Buttons: [ Label ], inverted when active. */
button {
	font: inherit; font-weight: 700; color: var(--accent);
	background: none; border: 0; padding: 4px 2px; cursor: pointer;
}
button::before { content: "[ "; color: var(--muted); }
button::after { content: " ]"; color: var(--muted); }
button:hover, button:focus-visible { background: var(--accent); color: var(--accent-text); outline: none; }
button:hover::before, button:hover::after, button:focus-visible::before, button:focus-visible::after { color: var(--accent-text); }
button.primary { background: var(--brand-yellow); color: var(--brand-dark); padding: 4px 8px; }
button.primary::before, button.primary::after { color: var(--brand-dark); }
button.primary:hover { background: var(--brand-dark); color: var(--brand-yellow); }
button.primary:hover::before, button.primary:hover::after { color: var(--brand-yellow); }
button:disabled { cursor: progress; opacity: 0.8; }

/* Quiz: radio buttons drawn as (X). */
.quiz fieldset { border: 1px dashed var(--line); padding: 10px 16px 6px; margin: 0 0 18px; }
.quiz fieldset.correct { border: 1px solid var(--green); }
.quiz fieldset.incorrect { border: 1px solid var(--red); }
.quiz legend { color: var(--bright); font-weight: 700; padding: 0 6px; }
.question-number { color: var(--accent); }
.choice { display: flex; gap: 10px; align-items: baseline; padding: 2px 6px; }
.choice:hover { background: var(--selection); }
.choice label { cursor: pointer; }
.choice.is-answer { background: color-mix(in srgb, var(--green) 18%, transparent); }
.choice.is-wrong { background: color-mix(in srgb, var(--red) 18%, transparent); }
.choice input[type="radio"] { appearance: none; margin: 0; font: inherit; cursor: pointer; color: var(--muted); }
.choice input[type="radio"]::before { content: "( )"; white-space: pre; }
.choice input[type="radio"]:checked { color: var(--accent); }
.choice input[type="radio"]:checked::before { content: "(X)"; }
.explain { color: var(--muted); margin: 6px 0 4px; }
.explain::before { content: "// "; color: var(--green); }

.quiz-result { padding: 6px 12px; margin: 0 0 16px; border: 1px solid currentColor; }
.quiz-result.passed { color: var(--green); }
.quiz-result.failed { color: var(--red); }
.quiz-result.failed span { color: var(--text); }

.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 28px; flex-wrap: wrap; }

/* Challenge. */
.editor { height: clamp(320px, 55vh, 900px); border: 1px solid var(--line); }
.code-input { width: 100%; font: 0.85rem/1.55 var(--font); tab-size: 4; padding: 12px; border: 1px solid var(--line); background: var(--code-bg); color: var(--text); resize: vertical; }
.challenge-actions { display: flex; gap: 18px; margin: 14px 0 6px; flex-wrap: wrap; }

.checks { list-style: none; padding: 0; margin: 0; }
.check { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.check:last-child { border-bottom: 0; }
.check-icon { width: 1.6em; flex: none; text-align: center; }
.check > div { flex: 1; min-width: 0; }
.check-pass .check-icon { color: var(--green); }
.check-fail .check-icon { color: var(--red); }
.check-pending .check-icon { color: var(--line); }
.check-name { font-weight: 700; color: var(--bright); }
.check-summary { color: var(--muted); font-size: 0.9rem; }
.compiler-output { margin: 8px 0 0; font-size: 0.78rem; white-space: pre-wrap; overflow-wrap: anywhere; border-color: var(--red); }
.compiler-output code { color: var(--red); }
.solution { margin-top: 18px; }
.solution summary { cursor: pointer; font-weight: 700; color: var(--accent); }

/* Admin report. */
.table-scroll { overflow-x: auto; }
.report { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.report th, .report td { border-bottom: 1px dashed var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.report thead th { color: var(--accent); font-size: 0.75rem; }
.errors li { margin-bottom: 6px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
	.lesson-head h1::after { animation: none; }
}

/* The sieve: green at the top, red at the bottom, and the last stage drawn as a failure. */
:root {
	--stage-1: #7ee787;
	--stage-2: #a5e05f;
	--stage-3: #d4d64a;
	--stage-4: #e3b341;
	--stage-5: #f0883e;
	--stage-6: #ff4d4d;
}

:root[data-theme="light"] {
	--stage-1: #2f8a2f;
	--stage-2: #5f8a1a;
	--stage-3: #8a7f00;
	--stage-4: #a06a00;
	--stage-5: #c2570c;
	--stage-6: #c41e1e;
}

.sieve-1 { --stage: var(--stage-1); }
.sieve-2 { --stage: var(--stage-2); }
.sieve-3 { --stage: var(--stage-3); }
.sieve-4 { --stage: var(--stage-4); }
.sieve-5 { --stage: var(--stage-5); }
.sieve-6 { --stage: var(--stage-6); }

.sieve-ladder { list-style: none; margin: 0; padding: 0; }
.sieve-row {
	display: grid;
	grid-template-columns: 2ch minmax(14ch, 28ch) 13ch minmax(10ch, 1fr);
	gap: 12px;
	align-items: baseline;
	padding: 2px 8px;
	color: var(--text);
}
.sieve-number { color: var(--stage); font-weight: 700; }
.sieve-cost { color: var(--stage); letter-spacing: -1px; white-space: pre; }
.sieve-time { color: var(--muted); font-size: 0.85rem; }
.sieve-current { background: var(--selection); outline: 1px solid var(--stage); }
.sieve-current .sieve-name { color: var(--bright); font-weight: 700; }
.sieve-current .sieve-name::after { content: "  ◀ this lesson"; color: var(--stage); font-weight: 400; font-size: 0.8rem; }
.sieve-failure {
	margin-top: 6px;
	background: var(--stage-6);
	color: #fff;
	font-weight: 700;
	animation: alarm 1.6s steps(1) infinite;
}
.sieve-failure .sieve-number, .sieve-failure .sieve-cost, .sieve-failure .sieve-time { color: #fff; }
.sieve-failure .sieve-time strong { letter-spacing: 0.15em; }
@keyframes alarm { 50% { background: color-mix(in srgb, var(--stage-6) 70%, #000); } }
.sieve-caption { margin: 12px 0 0; color: var(--muted); font-size: 0.85rem; }
.sieve-caption::before { content: "// "; color: var(--stage-6); }
@media (max-width: 640px) {
	.sieve-row { grid-template-columns: 2ch 1fr auto; }
	.sieve-time { display: none; }
}
@media (prefers-reduced-motion: reduce) {
	.sieve-failure { animation: none; }
}

.given { margin: 0 0 14px; }
.given summary { cursor: pointer; color: var(--muted); }
.given pre { margin: 6px 0 0; border-style: dashed; }

/* Wide screens: a challenge's brief on the left, kept in view, and the editor and checks on the right. */
.intro p, .notice, .quiz { max-width: 100ch; }
@media (min-width: 1200px) {
	.has-challenge {
		display: grid;
		grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
		gap: 32px;
		align-items: start;
	}
	.has-challenge > .lesson-body {
		position: sticky;
		top: 16px;
		max-height: calc(100vh - 32px);
		overflow-y: auto;
	}
	.has-challenge > .challenge { margin-top: 14px; }
	.has-challenge > .notice { grid-column: 1 / -1; }
	.has-challenge .editor { height: clamp(320px, calc(100vh - 360px), 900px); }
}

.admin-add { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.admin-add input { font: inherit; padding: 4px 8px; background: var(--code-bg); color: var(--text); border: 1px solid var(--line); min-width: 28ch; }
