:root {
	--bg: #faf8f4;
	--surface: #ffffff;
	--surface-2: #f1eee7;
	--text: #1f1d1a;
	--muted: #6b665d;
	--border: #e2ddd2;
	--accent: #2f5d8a;
	--accent-soft: #e4edf6;
	--again: #b3261e;
	--hard: #8a5a00;
	--good: #1d6b3a;
	--easy: #2f5d8a;
	--note-bg: #fff6e0;
	--note-border: #e8c76a;
	--code-bg: #f3f1ec;
	--shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
	--serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Charter, Georgia, serif;
	--sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	--mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
	--radius: 12px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #161513;
		--surface: #1f1e1b;
		--surface-2: #2a2825;
		--text: #ece8e1;
		--muted: #a39d92;
		--border: #3a3733;
		--accent: #8fb8e0;
		--accent-soft: #233243;
		--again: #f08a80;
		--hard: #e0b45c;
		--good: #7cc995;
		--easy: #8fb8e0;
		--note-bg: #2d2717;
		--note-border: #7a6526;
		--code-bg: #262421;
		--shadow: 0 1px 2px rgb(0 0 0 / 40%);
		color-scheme: dark;
	}
	/* imagens dos slides têm fundo branco: um leve escurecimento evita o "clarão" */
	.fig img { filter: brightness(0.92); }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: var(--sans);
	font-size: 16px;
	line-height: 1.5;
	-webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }

/* ---------- topo ---------- */
.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	background: color-mix(in srgb, var(--bg) 92%, transparent);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	border-bottom: 1px solid var(--border);
	padding-top: env(safe-area-inset-top);
}
.topbar-inner {
	max-width: 760px;
	margin: 0 auto;
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
	height: 52px;
}
.brand {
	font-weight: 700;
	text-decoration: none;
	color: var(--text);
	margin-right: auto;
	font-size: 15px;
	white-space: nowrap;
}
.navlink {
	text-decoration: none;
	color: var(--muted);
	padding: 8px 9px;
	border-radius: 8px;
	font-size: 15px;
	min-height: 40px;
	display: inline-flex;
	align-items: center;
}
.topbar-inner { gap: 2px; }
@media (max-width: 360px) { .navlink { padding: 8px 6px; font-size: 14px; } .brand { font-size: 14px; } }
.navlink[aria-current='page'] { color: var(--text); background: var(--surface-2); font-weight: 600; }

main {
	max-width: 760px;
	margin: 0 auto;
	padding: 20px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h1 { font-size: 1.75rem; line-height: 1.2; margin: 8px 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; line-height: 1.3; margin: 40px 0 10px; }
h3 { font-size: 1.08rem; margin: 28px 0 8px; }
.lede { color: var(--muted); margin-top: 0; }

/* ---------- cartões de navegação (início) ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid { grid-template-columns: 1fr 1fr; } }
.tile {
	display: block;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	text-decoration: none;
	color: var(--text);
	box-shadow: var(--shadow);
}
.tile strong { display: block; font-size: 1.05rem; margin-bottom: 4px; }
.tile span { color: var(--muted); font-size: 0.93rem; }

.panel {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 16px;
	box-shadow: var(--shadow);
	margin: 16px 0;
}

/* ---------- formulários e botões ---------- */
label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type='email'], select {
	width: 100%;
	font: inherit;
	font-size: 16px; /* evita o zoom automático do iPhone */
	padding: 12px;
	border-radius: 10px;
	border: 1px solid var(--border);
	background: var(--bg);
	color: var(--text);
}
.btn {
	font: inherit;
	font-weight: 600;
	border: 1px solid transparent;
	border-radius: 10px;
	padding: 12px 18px;
	min-height: 48px;
	background: var(--accent);
	color: #fff;
	cursor: pointer;
	touch-action: manipulation;
}
@media (prefers-color-scheme: dark) { .btn { color: #10202f; } }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.link { background: none; color: var(--accent); padding: 8px; min-height: 40px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.error { color: var(--again); }

/* ---------- texto de livro (teoria) ---------- */
.book {
	font-family: var(--serif);
	font-size: 1.1rem;
	line-height: 1.68;
	hyphens: auto;
	-webkit-hyphens: auto;
}
.book p { margin: 0 0 1.05em; text-align: justify; text-justify: inter-word; }
@media (max-width: 420px) { .book p { text-align: left; } }
.book h1, .book h2, .book h3 { hyphens: manual; -webkit-hyphens: manual; }
.book h2, .book h3 { font-family: var(--sans); }
.book em { font-style: italic; }
.book code, .card code {
	font-family: var(--mono);
	font-size: 0.86em;
	background: var(--code-bg);
	padding: 0.1em 0.35em;
	border-radius: 5px;
	word-break: break-word;
}
.book pre {
	font-family: var(--mono);
	font-size: 0.82rem;
	line-height: 1.5;
	background: var(--code-bg);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 12px 14px;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	margin: 0 0 1.2em;
	hyphens: none;
}
.book pre code { background: none; padding: 0; font-size: inherit; }
.eq {
	font-family: var(--serif);
	text-align: center;
	margin: 0.4em 0 1.2em;
	font-size: 1.05rem;
	overflow-x: auto;
	padding: 6px 0;
}
.eq var, .book var { font-style: italic; }

.fig { margin: 1.4em 0 1.6em; text-align: center; }
.fig img, .fig svg {
	max-width: 100%;
	height: auto;
	border-radius: 8px;
	background: #fff;
}
.fig svg { background: var(--surface); border: 1px solid var(--border); }
/* diagramas largos: no celular, rolam de lado dentro da figura em vez de encolher o texto */
.fig.wide .scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.fig.wide svg { min-width: 600px; }
.fig.wide figcaption::before { content: ''; }
@media (max-width: 620px) { .fig.wide figcaption::before { content: '↔ arraste para os lados · '; } }
.fig .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.fig .trio { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; align-items: end; }
.fig figcaption {
	font-family: var(--sans);
	font-size: 0.85rem;
	color: var(--muted);
	margin-top: 8px;
	line-height: 1.45;
	text-align: left;
}

.exam {
	background: var(--note-bg);
	border-left: 4px solid var(--note-border);
	border-radius: 0 10px 10px 0;
	padding: 14px 16px 4px;
	margin: 1.6em 0;
}
.exam > strong:first-child {
	font-family: var(--sans);
	font-size: 0.8rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	display: block;
	margin-bottom: 6px;
}
.exam p { text-align: left; }

.toc { font-family: var(--sans); font-size: 0.95rem; }
.toc ol { padding-left: 1.2em; margin: 6px 0; }
.toc li { margin: 4px 0; }

.chapter-nav {
	display: flex;
	justify-content: space-between;
	gap: 12px;
	margin-top: 48px;
	font-family: var(--sans);
}
.chapter-nav a { text-decoration: none; padding: 10px 0; }

/* ---------- flash cards ---------- */
.study { display: flex; flex-direction: column; min-height: calc(100dvh - 52px - 60px - env(safe-area-inset-top)); }
.counts { display: flex; gap: 14px; font-weight: 700; font-variant-numeric: tabular-nums; justify-content: center; margin: 4px 0 12px; }
.counts .c-new { color: var(--easy); }
.counts .c-learn { color: var(--again); }
.counts .c-review { color: var(--good); }
.counts span small { font-weight: 500; color: var(--muted); margin-left: 3px; }

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 16px;
	box-shadow: var(--shadow);
	padding: 22px 18px;
	flex: 1;
	min-height: 260px;
	display: flex;
	flex-direction: column;
	cursor: pointer;
	user-select: text;
}
.card .tag {
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
	margin-bottom: 10px;
}
.card .front { font-size: 1.18rem; line-height: 1.5; font-weight: 600; }
.card hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; width: 100%; }
.card .back { font-family: var(--serif); font-size: 1.08rem; line-height: 1.6; }
.card .back p { margin: 0 0 0.8em; }
.card .hint { margin-top: auto; padding-top: 16px; color: var(--muted); font-size: 0.85rem; text-align: center; }

.answers {
	position: sticky;
	bottom: 0;
	background: var(--bg);
	padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 8px;
}
.answers.show-only { grid-template-columns: 1fr; }
.answers button {
	font: inherit;
	font-weight: 700;
	font-size: 0.95rem;
	border-radius: 12px;
	min-height: 60px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	cursor: pointer;
	touch-action: manipulation;
}
.answers button small { font-weight: 500; font-size: 0.78rem; color: var(--muted); }
.answers .a1 { color: var(--again); }
.answers .a2 { color: var(--hard); }
.answers .a3 { color: var(--good); }
.answers .a4 { color: var(--easy); }
.answers .show { background: var(--accent); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) { .answers .show { color: #10202f; } }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chip {
	font: inherit;
	font-size: 0.88rem;
	white-space: nowrap;
	padding: 8px 12px;
	min-height: 38px;
	border-radius: 999px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--accent); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) { .chip[aria-pressed='true'] { color: #10202f; } }

.sync { font-size: 0.8rem; color: var(--muted); text-align: center; min-height: 1.2em; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin: 12px 0; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 10px 4px; }
.stats b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: 0.8rem; color: var(--muted); }

.done { text-align: center; padding: 32px 8px; }
.done h2 { margin-top: 8px; }

details.howto { font-size: 0.92rem; color: var(--muted); margin-top: 16px; }
details.howto summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }
details.howto p { margin: 6px 0; }

[hidden] { display: none !important; }

/* links para seções (#q2 etc.) não escondem o título sob o menu fixo */
[id] { scroll-margin-top: calc(64px + env(safe-area-inset-top)); }
