:root {
	color-scheme: light;
	--navy: #0f2a52;
	--navy-2: #1d4280;
	--soft: #eef3fb;
	--bg: #ffffff;
	--fg: #0b0d12;
	--muted: #5b6472;
	--accent: #2f6df6;
	--border: #e4e7ec;
	--danger: #b42318;
	--radius: 10px;
	--space: 1rem;
	--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: never) {
	:root {
		--bg: #0b0d12;
		--fg: #f4f6fa;
		--muted: #9aa4b2;
		--accent: #6f9bff;
		--border: #232833;
		--danger: #ff9a8f;
	}
}

* {
	box-sizing: border-box;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font-family: var(--font);
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
}

.shell {
	max-width: 42rem;
	margin: 0 auto;
	padding: calc(var(--space) * 3) var(--space);
}

h1 {
	margin: 0 0 0.5rem;
	font-size: clamp(1.6rem, 4vw, 2.25rem);
	letter-spacing: -0.02em;
}

.lede {
	margin: 0 0 0.75rem;
	font-size: 1.05rem;
}

.hint {
	margin: 0;
	color: var(--muted);
}

.btn {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.55rem 0.9rem;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: var(--accent);
	color: #fff;
	font: inherit;
	font-weight: 500;
	cursor: pointer;
}

.btn:hover {
	filter: brightness(1.05);
}

.btn-secondary {
	background: transparent;
	color: var(--fg);
	border-color: var(--border);
}

.card {
	padding: var(--space);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
}

.input,
.select,
.textarea {
	width: 100%;
	padding: 0.55rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--fg);
	font: inherit;
}

.field {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.35rem;
	margin-bottom: var(--space);
}

.field > label {
	font-size: 0.875rem;
	color: var(--muted);
}

/*
 * 390px-safe, like .grid below. A grid with no column list gets one implicit
 * auto column, and an auto column is never narrower than its widest item's
 * min-content width. One nowrap scrolling strip (days, time slots) anywhere
 * inside an item therefore widened the whole column past the screen: the page
 * scrolled sideways instead of the strip scrolling on its own. minmax(0, 1fr)
 * caps the column at the container; the min-width rule keeps a child from
 * bringing the same floor back if an app redefines the columns. :where() adds
 * no specificity, so a min-width the app sets on a child still wins.
 */
.stack {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--space);
}

:where(.field, .stack, .list) > * {
	min-width: 0;
}

.row {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	flex-wrap: wrap;
}

/*
 * 390px-safe. An unclamped minmax track overflows a 390px viewport once the
 * shell padding is subtracted, and nothing in the pipeline ever looked at a
 * phone-width layout, so every generated app inherited the horizontal scroll.
 * min() clamps the track to the container instead.
 */
.grid {
	display: grid;
	gap: var(--space);
	grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
}

.list {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.list-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	padding: 0.7rem 0.85rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.table {
	width: 100%;
	border-collapse: collapse;
}

.table th,
.table td {
	padding: 0.6rem 0.5rem;
	text-align: left;
	border-bottom: 1px solid var(--border);
}

.table th {
	font-size: 0.8125rem;
	color: var(--muted);
	font-weight: 600;
}

.empty {
	padding: calc(var(--space) * 2);
	text-align: center;
	color: var(--muted);
}

.empty-title {
	margin: 0 0 0.25rem;
	color: var(--fg);
	font-weight: 600;
}

/* Loading. Every fetch has one; without a primitive each app invented its own. */
.loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.6rem;
	padding: calc(var(--space) * 1.5);
	color: var(--muted);
}

.spinner {
	flex: none;
	width: 1.15rem;
	height: 1.15rem;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: fab-spin 0.7s linear infinite;
}

@keyframes fab-spin {
	to {
		transform: rotate(360deg);
	}
}

/* Placeholder for content whose shape is known before its data arrives. */
.skeleton {
	display: block;
	height: 1rem;
	border-radius: calc(var(--radius) / 2);
	background: linear-gradient(90deg, var(--border), transparent, var(--border));
	background-size: 200% 100%;
	animation: fab-shimmer 1.2s linear infinite;
}

@keyframes fab-shimmer {
	to {
		background-position: -200% 0;
	}
}

/* Error strip: a failure the user can see and retry, never a silent no-op. */
.alert {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	padding: 0.7rem 0.85rem;
	border: 1px solid var(--border);
	border-left: 3px solid var(--muted);
	border-radius: var(--radius);
}

.alert-error {
	border-left-color: var(--danger);
	color: var(--danger);
}

.badge {
	display: inline-block;
	padding: 0.1rem 0.5rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	font-size: 0.8125rem;
	color: var(--muted);
}

/*
 * The scaffold had exactly one @media rule (prefers-color-scheme) and no width
 * breakpoint at all, so the shell was a 42rem column at every size.
 * Mobile-first stays the default; these only widen it.
 */
@media (min-width: 48rem) {
	.shell {
		max-width: 52rem;
		padding: calc(var(--space) * 3) calc(var(--space) * 1.5);
	}
}

@media (min-width: 64rem) {
	.shell {
		max-width: 64rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.spinner,
	.skeleton {
		animation: none;
	}
}

body { background: #f4f7fc; }
.app { min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
	padding: 0.9rem 1.25rem; background: var(--navy); color: #fff; }
.brand { display: flex; gap: 0.7rem; align-items: center; }
.brand small { display: block; opacity: 0.75; font-size: 0.8rem; }
.brand strong { font-size: 1.15rem; letter-spacing: -0.01em; }
.logo { width: 2.3rem; height: 2.3rem; display: grid; place-items: center; border-radius: 10px;
	background: #fff; color: var(--navy); font-weight: 800; font-size: 1.3rem; }
.pick { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.pick .select { width: auto; max-width: 16rem; }
.panels { display: grid; gap: 1rem; padding: 1rem; grid-template-columns: minmax(0, 1fr); max-width: 90rem; margin: 0 auto; }
@media (min-width: 64rem) { .panels { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; } }
.panel { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem;
	box-shadow: 0 1px 3px rgba(15, 42, 82, 0.06); display: grid; gap: 0.9rem; }
.panel h2 { margin: 0; font-size: 1.05rem; color: var(--navy); display: flex; align-items: center; gap: 0.5rem; }
.num { width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--soft); color: var(--navy-2);
	display: grid; place-items: center; font-size: 0.85rem; }
.problem { background: var(--soft); border-left: 4px solid var(--navy-2); border-radius: 10px; padding: 0.9rem; }
.problem p { margin: 0.5rem 0 0; font-size: 1.05rem; font-weight: 600; color: var(--navy); }
.btn { background: var(--navy-2); justify-content: center; }
.btn-primary { background: var(--navy); width: 100%; padding: 0.8rem 1rem; font-weight: 600; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.steps li { display: grid; gap: 0.2rem; padding: 0.65rem 0.8rem; border: 1px solid var(--border); border-radius: 10px;
	font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; animation: fadein 0.3s ease; }
.stepn { font-family: var(--font); font-size: 0.75rem; font-weight: 700; color: var(--navy-2); text-transform: uppercase; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; margin: 0.4rem 0 0; }
.chat { height: 22rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; padding: 0.6rem;
	background: #f8fafd; border-radius: 10px; border: 1px solid var(--border); }
.bubble { max-width: 85%; padding: 0.55rem 0.8rem; border-radius: 12px; font-size: 0.92rem; animation: fadein 0.25s ease; }
.bubble.bot { background: #fff; border: 1px solid var(--border); align-self: flex-start; }
.bubble.user { background: var(--navy-2); color: #fff; align-self: flex-end; }
.quick { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { border: 1px solid #c9d6ec; background: var(--soft); color: var(--navy); border-radius: 999px;
	padding: 0.35rem 0.75rem; font: inherit; font-size: 0.82rem; cursor: pointer; }
.chip:hover { background: #dfe8f7; }
.chat-input { display: flex; gap: 0.5rem; }
.chat-input .input { flex: 1; min-width: 0; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; }
.textarea { resize: vertical; }
.result { margin-top: 0.5rem; padding: 0.9rem; border-radius: 10px; border: 1px solid; }
.result.ok { background: #ecfdf3; border-color: #a6e9c0; color: #05603a; }
.result.ko { background: #fff6ed; border-color: #f9d3a8; color: #93370d; }
.result h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.result ul { margin: 0 0 0.6rem; padding-left: 1rem; font-size: 0.9rem; }
.exercise-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 0.75rem; }
.ex-btn {
	min-width: 2.5rem; min-height: 2.5rem; border-radius: 999px; border: 1px solid var(--border);
	background: var(--bg); color: var(--navy); font-weight: 600; cursor: pointer;
}
.ex-btn:hover { border-color: var(--accent); }
.ex-btn.on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* DUA supports */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0.5rem; background: var(--navy); color: #fff; padding: 0.5rem 0.8rem; border-radius: 8px; z-index: 10; }
.skip:focus { left: 0.5rem; }
.topbar { flex-wrap: wrap; gap: 0.6rem; }
.prefs { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; align-items: center; margin: 0.75rem 1rem 0; padding: 0.9rem 1rem;
	background: var(--soft); border: 1px solid var(--border); border-radius: var(--radius); }
.pref-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.pref-check { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; }
.pref-check input { width: 1.1rem; height: 1.1rem; }
.seg { display: inline-flex; border: 1px solid var(--navy); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; color: var(--navy); padding: 0.35rem 0.7rem; font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--navy); color: #fff; }
.mission { display: grid; gap: 0.75rem; margin: 0.75rem 1rem 0; padding: 1rem; background: #fff; border: 1px solid var(--border);
	border-left: 4px solid var(--navy); border-radius: var(--radius); }
.mission h2 { margin: 0 0 0.25rem; font-size: 1rem; color: var(--navy); }
.mission p { margin: 0; }
.progress { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.progress li { font-size: 0.85rem; padding: 0.3rem 0.65rem; border-radius: 999px; background: var(--soft); color: var(--muted); }
.progress li.done { background: #ecfdf3; color: #05603a; font-weight: 600; }
@media (min-width: 900px) { .mission { grid-template-columns: 1fr auto; align-items: center; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.grow { flex: 1; min-width: 0; }
.listen { border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 0.1rem 0.35rem; font-size: 0.85rem;
	cursor: pointer; line-height: 1.4; flex: none; margin-left: 0.35rem; vertical-align: middle; }
.listen:hover { background: var(--soft); }
.steps li { align-items: flex-start; }
.glossary { margin-top: 0.9rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.8rem; background: var(--soft); }
.glossary summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.glossary dl { margin: 0.6rem 0 0; display: grid; gap: 0.5rem; }
.glossary dt { font-weight: 600; font-size: 0.9rem; }
.glossary dd { margin: 0; font-size: 0.88rem; color: var(--muted); }
.help { margin: 0 0 0.35rem; font-size: 0.82rem; color: var(--muted); }
.symbols { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }
.sym { min-width: 2.2rem; min-height: 2.2rem; border: 1px solid var(--border); background: #fff; border-radius: 6px; font: inherit;
	font-weight: 600; color: var(--navy); cursor: pointer; }
.sym:hover { background: var(--soft); }

.app.legible { font-family: Verdana, Tahoma, "Trebuchet MS", sans-serif; letter-spacing: 0.03em; word-spacing: 0.12em; line-height: 1.75; }
.app.legible p, .app.legible li, .app.legible .bubble { line-height: 1.75; }
.app.calm *, .app.calm *::before, .app.calm *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
.app.hc { --fg: #000; --muted: #1a1a1a; --border: #000; --soft: #fff; --navy: #001a40; --accent: #0033cc; background: #fff; color: #000; }
.app.hc .panel, .app.hc .mission, .app.hc .problem, .app.hc .input, .app.hc .select, .app.hc .textarea, .app.hc .chip, .app.hc .bubble {
	border: 2px solid #000 !important; }
.app.hc .bubble.bot { background: #fff; color: #000; }
.app.hc .bubble.user { background: #001a40; color: #fff; }
.app.hc :focus-visible { outline: 3px solid #ff8c00 !important; outline-offset: 3px; }

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