:root {
	--bg: #f4f6fb;
	--card: #ffffff;
	--text: #1b2333;
	--muted: #5d6a85;
	--line: #dde3f0;
	--accent: #2b5cff;
	--accent-text: #ffffff;
	--accent-soft: #e8eeff;
	--good: #14804a;
	--good-bg: #e3f6ec;
	--bad: #c62828;
	--bad-bg: #fdeaea;
	--shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 4px 14px rgba(20, 30, 60, 0.06);
	--radius: 14px;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme='light']) {
		--bg: #0f1420;
		--card: #182033;
		--text: #e8ecf6;
		--muted: #9aa7c4;
		--line: #2a3550;
		--accent: #6b8cff;
		--accent-text: #0b1226;
		--accent-soft: #212d4d;
		--good: #5fd49a;
		--good-bg: #123a2a;
		--bad: #ff8a8a;
		--bad-bg: #44191c;
		--shadow: none;
	}
}

* {
	box-sizing: border-box;
}
html {
	-webkit-text-size-adjust: 100%;
}
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font:
		16px/1.5 system-ui,
		-apple-system,
		'Segoe UI',
		Roboto,
		sans-serif;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

.top {
	display: flex;
	align-items: baseline;
	gap: 12px;
	padding: 14px 16px;
	max-width: 1400px;
	width: 100%;
	margin: 0 auto;
}
.brand {
	font-weight: 800;
	font-size: 20px;
	color: var(--text);
	text-decoration: none;
	letter-spacing: 0.3px;
}
.brand span {
	color: var(--accent);
}
.top-sub {
	color: var(--muted);
	font-size: 14px;
}

main {
	flex: 1;
	width: 100%;
	max-width: 1400px;
	margin: 0 auto;
	padding: 8px 16px 32px;
}
.foot {
	text-align: center;
	color: var(--muted);
	font-size: 13px;
	padding: 18px 16px 28px;
	max-width: 760px;
	margin: 0 auto;
}
.foot a {
	color: var(--accent);
}

h1 {
	font-size: 26px;
	margin: 8px 0 6px;
	line-height: 1.2;
}
.lead {
	color: var(--muted);
	margin: 0 0 20px;
}

/* Home */
.grid {
	display: grid;
	gap: 14px;
	grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.chapter {
	background: var(--card);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.chapter .num {
	width: 34px;
	height: 34px;
	border-radius: 10px;
	background: var(--accent-soft);
	color: var(--accent);
	display: grid;
	place-items: center;
	font-weight: 800;
}
.chapter h2 {
	font-size: 17px;
	margin: 0;
	line-height: 1.3;
}
.chapter .meta {
	color: var(--muted);
	font-size: 14px;
}
.chapter .best {
	font-size: 14px;
	color: var(--good);
	font-weight: 600;
}
.chapter .actions {
	margin-top: auto;
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}
.head-row {
	display: flex;
	gap: 12px;
	align-items: center;
}

.btn {
	appearance: none;
	border: 1px solid var(--line);
	background: var(--card);
	color: var(--text);
	padding: 10px 16px;
	border-radius: 10px;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	text-decoration: none;
	display: inline-block;
}
.btn:hover {
	border-color: var(--accent);
}
.btn:focus-visible,
.opt:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}
.btn.primary {
	background: var(--accent);
	color: var(--accent-text);
	border-color: var(--accent);
}
.btn.small {
	padding: 7px 12px;
	font-size: 14px;
}
.btn.warn {
	color: var(--bad);
}

/* Setup */
.panel {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 20px;
	max-width: 760px;
}
.field {
	margin: 18px 0;
}
.field > label,
.field > .lbl {
	display: block;
	font-weight: 700;
	margin-bottom: 8px;
}
.seg {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}
.seg input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}
.seg label {
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 8px 14px;
	cursor: pointer;
	font-weight: 600;
	background: var(--card);
}
.seg input:checked + label {
	background: var(--accent);
	color: var(--accent-text);
	border-color: var(--accent);
}
.seg input:focus-visible + label {
	outline: 3px solid var(--accent);
	outline-offset: 2px;
}

/* Quiz */
.qhead {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 10px;
}
.qhead .title {
	font-weight: 700;
	flex: 1;
	min-width: 160px;
}
.stat {
	color: var(--muted);
	font-size: 14px;
	white-space: nowrap;
}
.stat b {
	color: var(--text);
}
.bar {
	height: 8px;
	background: var(--line);
	border-radius: 99px;
	overflow: hidden;
	margin-bottom: 18px;
}
.bar > i {
	display: block;
	height: 100%;
	background: var(--accent);
	width: 0;
	transition: width 0.25s;
}

.qcard {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 20px;
}
.qno {
	color: var(--muted);
	font-size: 13px;
	font-weight: 600;
	margin-bottom: 6px;
}
.qtext {
	font-size: 19px;
	font-weight: 650;
	line-height: 1.45;
	margin: 0 0 16px;
}
.opts {
	display: grid;
	gap: 10px;
}
.opt {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	text-align: left;
	width: 100%;
	background: var(--card);
	color: var(--text);
	border: 2px solid var(--line);
	border-radius: 12px;
	padding: 12px 14px;
	font: inherit;
	cursor: pointer;
}
.opt:hover:not(:disabled) {
	border-color: var(--accent);
	background: var(--accent-soft);
}
.opt .badge {
	flex: none;
	width: 28px;
	height: 28px;
	border-radius: 8px;
	background: var(--accent-soft);
	color: var(--accent);
	display: grid;
	place-items: center;
	font-weight: 800;
	font-size: 14px;
}
.opt:disabled {
	cursor: default;
}
.opt.correct {
	border-color: var(--good);
	background: var(--good-bg);
}
.opt.correct .badge {
	background: var(--good);
	color: #fff;
}
.opt.wrong {
	border-color: var(--bad);
	background: var(--bad-bg);
}
.opt.wrong .badge {
	background: var(--bad);
	color: #fff;
}
.opt.dim {
	opacity: 0.6;
}
.feedback {
	margin-top: 14px;
	font-weight: 700;
	min-height: 24px;
}
.feedback.good {
	color: var(--good);
}
.feedback.bad {
	color: var(--bad);
}
.nextrow {
	margin-top: 12px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 10px;
	flex-wrap: wrap;
}
.hint {
	color: var(--muted);
	font-size: 13px;
}

/* Results */
.score {
	text-align: center;
	padding: 26px 16px;
}
.score .big {
	font-size: 56px;
	font-weight: 800;
	line-height: 1;
	color: var(--accent);
}
.score .sub {
	color: var(--muted);
	margin-top: 6px;
}
.row-actions {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: center;
	margin: 14px 0 6px;
}
.mistakes {
	margin-top: 22px;
	display: grid;
	gap: 12px;
}
.mistake {
	background: var(--card);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 14px 16px;
}
.mistake .q {
	font-weight: 650;
	margin-bottom: 8px;
}
.mistake .a {
	font-size: 15px;
	padding: 3px 0;
}
.mistake .a.you {
	color: var(--bad);
}
.mistake .a.ok {
	color: var(--good);
}

@media (max-width: 520px) {
	h1 {
		font-size: 22px;
	}
	.qtext {
		font-size: 17px;
	}
	.qcard,
	.panel {
		padding: 16px;
	}
}
@media (prefers-reduced-motion: reduce) {
	.bar > i {
		transition: none;
	}
}
