:root {
	--bg: #16181d;
	--panel: #1d2026;
	--raised: #252932;
	--line: #323744;
	--text: #e3e6ed;
	--dim: #8b93a5;
	--accent: #7aa2f7;
	--green: #9ece6a;
	--red: #f7768e;
	--yellow: #e0af68;
	--purple: #bb9af7;
	--radius: 10px;
	--mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
	--sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 15px/1.5 var(--sans);
	-webkit-text-size-adjust: 100%;
	overscroll-behavior: none;
}

body {
	display: flex;
	flex-direction: column;
	height: 100dvh;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

[hidden] {
	display: none !important;
}

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

code,
pre {
	font-family: var(--mono);
	font-size: 0.86em;
}

pre {
	white-space: pre-wrap;
	word-break: break-word;
	margin: 0;
}

.dim {
	color: var(--dim);
}

.spacer {
	flex: 1;
}

/* ─── Controls ───────────────────────────────────────────────────────────── */

button {
	font: inherit;
	font-size: 14px;
	color: var(--text);
	background: var(--raised);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 7px 12px;
	cursor: pointer;
	white-space: nowrap;
	touch-action: manipulation;
}

button:disabled {
	opacity: 0.5;
	cursor: default;
}

button.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: #10131a;
	font-weight: 600;
}

button.danger {
	background: var(--red);
	border-color: var(--red);
	color: #10131a;
	font-weight: 600;
}

button.ghost {
	background: transparent;
}

button.small {
	padding: 4px 9px;
	font-size: 13px;
}

button.icon {
	background: transparent;
	border: none;
	font-size: 20px;
	padding: 4px 8px;
}

.danger-text {
	color: var(--red);
}

select,
input.text,
textarea {
	font: inherit;
	font-size: 16px; /* iOS zooms into anything smaller */
	color: var(--text);
	background: var(--raised);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 7px 10px;
	min-width: 0;
}

select {
	font-size: 14px;
}

@supports (-webkit-touch-callout: none) {
	select {
		font-size: 16px;
	}
}

.chip {
	border-radius: 999px;
	font-size: 13px;
}

.badge {
	font-size: 12px;
	color: var(--yellow);
}

.pill {
	font-size: 12px;
	color: var(--dim);
	background: var(--raised);
	border-radius: 999px;
	padding: 3px 9px;
	white-space: nowrap;
	cursor: default;
}

.pill.error,
.pill.moved {
	color: var(--red);
}

.pill.busy,
.pill.loading {
	color: var(--yellow);
}

.pill.idle,
.pill.ready {
	color: var(--green);
}

/* ─── Shell ──────────────────────────────────────────────────────────────── */

.splash {
	margin: auto;
	font-size: 28px;
	text-align: center;
}

.splash.error {
	font-size: 15px;
	max-width: 640px;
	padding: 24px;
}

.topbar {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}

.brand {
	white-space: nowrap;
	font-size: 15px;
}

.brand b {
	color: var(--accent);
}

.lesson-picker {
	max-width: min(52vw, 420px);
	text-overflow: ellipsis;
}

.banner {
	display: flex;
	gap: 10px;
	align-items: center;
	justify-content: space-between;
	padding: 8px 12px;
	background: #3b2f1a;
	color: var(--yellow);
	font-size: 14px;
}

.layout {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.pane-left,
.pane-right {
	display: contents;
}

.side-tabs {
	display: none;
}

.tabbar {
	display: flex;
	border-top: 1px solid var(--line);
	background: var(--panel);
	padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1px;
	border: none;
	background: transparent;
	border-radius: 0;
	padding: 6px 0 7px;
	font-size: 11px;
	color: var(--dim);
}

.tabbar button.active {
	color: var(--accent);
}

.tab-icon {
	font-size: 19px;
	line-height: 1.2;
}

body.wide .layout {
	flex-direction: row;
}

body.wide .pane-left {
	display: flex;
	flex: 1.15;
	min-width: 0;
	border-right: 1px solid var(--line);
}

body.wide .pane-right {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

body.wide .side-tabs {
	display: flex;
	gap: 2px;
	padding: 6px 8px 0;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}

body.wide .side-tabs button {
	border: none;
	border-radius: 8px 8px 0 0;
	background: transparent;
	color: var(--dim);
}

body.wide .side-tabs button.active {
	background: var(--bg);
	color: var(--text);
}

body.wide .tabbar {
	display: none;
}

.panel {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.toolbar {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 7px 10px;
	border-bottom: 1px solid var(--line);
	flex-wrap: wrap;
}

.scroll {
	flex: 1;
	overflow: auto;
	padding: 12px 14px 28px;
	-webkit-overflow-scrolling: touch;
}

.actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	margin: 12px 0;
}

.hint {
	color: var(--dim);
	font-size: 13px;
	margin-top: 0;
}

/* ─── Learn ──────────────────────────────────────────────────────────────── */

.lesson {
	max-width: 760px;
}

.lesson h1 {
	font-size: 22px;
	margin: 6px 0 10px;
}

.lesson h2 {
	font-size: 17px;
	margin-top: 22px;
	color: var(--accent);
}

.lesson table {
	border-collapse: collapse;
	font-size: 13px;
	display: block;
	overflow-x: auto;
}

.lesson td,
.lesson th {
	border: 1px solid var(--line);
	padding: 4px 8px;
	text-align: left;
}

.lesson code {
	background: var(--raised);
	padding: 1px 4px;
	border-radius: 4px;
}

.lesson pre {
	background: var(--panel);
	padding: 10px;
	border-radius: 8px;
	overflow-x: auto;
}

.lesson pre code {
	background: none;
	padding: 0;
}

.lesson-progress {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 13px;
	color: var(--dim);
}

.bar {
	flex: 1;
	max-width: 240px;
	height: 6px;
	border-radius: 3px;
	background: var(--raised);
	overflow: hidden;
}

.fill {
	height: 100%;
	background: var(--green);
	transition: width 0.3s;
}

.next {
	margin: 18px 0;
}

/* ─── Tests ──────────────────────────────────────────────────────────────── */

ul.tests {
	list-style: none;
	padding: 0;
	margin: 0;
}

ul.tests li {
	display: flex;
	gap: 8px;
	align-items: baseline;
	padding: 7px 0;
	border-bottom: 1px solid var(--line);
	flex-wrap: wrap;
}

ul.tests .icon {
	width: 16px;
	flex: none;
	text-align: center;
	font-weight: 700;
}

ul.tests .name {
	font-size: 14px;
}

ul.tests details {
	flex: 1;
	min-width: 0;
}

ul.tests summary {
	cursor: pointer;
	list-style: none;
}

ul.tests .why {
	width: 100%;
	font-family: var(--mono);
	font-size: 12px;
	color: var(--red);
	padding-left: 24px;
}

ul.tests details .why {
	padding-left: 0;
}

li.pass .icon {
	color: var(--green);
}

li.fail .icon {
	color: var(--red);
}

li.running .icon,
li.none .icon {
	color: var(--dim);
}

.failure {
	margin-top: 8px;
}

.failure .message {
	background: #2a1d24;
	color: #ffc0cb;
	padding: 8px;
	border-radius: 8px;
	font-size: 12px;
}

.traceback {
	margin-top: 6px;
	background: var(--panel);
	padding: 8px;
	border-radius: 8px;
	font-size: 11.5px;
	color: var(--dim);
	max-height: 260px;
	overflow: auto;
}

.traceback a {
	color: var(--yellow);
}

/* ─── Code ───────────────────────────────────────────────────────────────── */

.code-panel {
	position: relative;
}

.file-picker {
	max-width: min(60vw, 360px);
}

.readonly-tag {
	font-size: 12px;
	color: var(--dim);
}

.cm-host {
	flex: 1;
	min-height: 0;
}

.cm-editor {
	height: 100%;
	font-size: 13.5px;
}

.cm-scroller {
	font-family: var(--mono) !important;
}

.console {
	display: none;
	flex-direction: column;
	max-height: 40%;
	border-top: 1px solid var(--line);
	background: #111317;
}

.console.open {
	display: flex;
}

.console-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 2px 10px;
	font-size: 12px;
	color: var(--dim);
}

.console-body {
	overflow: auto;
	padding: 6px 10px 12px;
	font-size: 12.5px;
}

.console .err {
	color: var(--red);
}

/* ─── Viz ────────────────────────────────────────────────────────────────── */

.viz-panel .toolbar select {
	flex: 1;
	min-width: 0;
}

.empty {
	text-align: center;
	color: var(--dim);
	padding-top: 40px;
}

.tables {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
}

.table {
	background: var(--panel);
	border-radius: 8px;
	padding: 8px;
	overflow-x: auto;
	max-width: 100%;
}

.table-title {
	font-size: 12px;
	color: var(--accent);
	margin-bottom: 4px;
}

.table table {
	border-collapse: collapse;
	font: 12px var(--mono);
}

.table th,
.table td {
	padding: 2px 8px;
	text-align: left;
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
}

.table th {
	color: var(--dim);
	font-weight: 400;
}

ol.calls {
	list-style: none;
	padding: 0;
	margin: 0;
	font: 12px/1.45 var(--mono);
}

li.call {
	border-left: 2px solid var(--line);
	padding: 3px 0 3px 8px;
	margin-bottom: 2px;
}

li.call.commit {
	border-left-color: var(--accent);
}

li.call.failed {
	border-left-color: var(--red);
}

li.call summary {
	cursor: pointer;
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	list-style: none;
}

li.call .index {
	color: var(--dim);
	min-width: 20px;
}

li.call .method {
	color: var(--purple);
}

li.call .args {
	color: var(--dim);
	word-break: break-all;
}

li.call .result {
	color: var(--green);
	word-break: break-all;
}

li.call .err {
	color: var(--red);
}

li.call pre {
	margin: 4px 0 6px 26px;
	color: var(--dim);
	max-height: 260px;
	overflow: auto;
}

li.call.assertion {
	border-left-color: var(--red);
	color: var(--red);
}

li.call.assertion pre {
	color: #ffc0cb;
	margin-left: 0;
}

.writes {
	margin: 3px 0 3px 26px;
}

.write {
	word-break: break-all;
}

.wtype {
	padding: 0 5px;
	border-radius: 4px;
	background: var(--raised);
	color: var(--yellow);
}

.wtype.conversation {
	color: var(--accent);
}

.wtype.entry {
	color: var(--green);
}

.wtype.task {
	color: var(--purple);
}

/* ─── Tutor ──────────────────────────────────────────────────────────────── */

.segmented {
	display: inline-flex;
	background: var(--raised);
	border-radius: 9px;
	padding: 2px;
}

.segmented button {
	border: none;
	background: transparent;
	padding: 4px 12px;
	font-size: 13px;
	color: var(--dim);
	border-radius: 7px;
}

.segmented button.active {
	background: var(--accent);
	color: #10131a;
	font-weight: 600;
}

.task-strip {
	display: flex;
	gap: 6px;
	padding: 5px 10px;
	overflow-x: auto;
	font: 11.5px var(--mono);
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
	min-height: 28px;
	align-items: center;
}

.task {
	padding: 1px 7px;
	border-radius: 999px;
	background: var(--raised);
	color: var(--dim);
}

.task b {
	color: var(--text);
	font-weight: 500;
}

.task.running {
	color: var(--green);
	box-shadow: 0 0 0 1px var(--green) inset;
}

.task.waiting,
.task.sleeping {
	color: var(--yellow);
}

.notice:not(:empty) {
	padding: 6px 12px;
	font-size: 13px;
	color: var(--yellow);
	background: #2b2619;
}

.chat-log {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	-webkit-overflow-scrolling: touch;
}

.msg {
	max-width: 92%;
	padding: 8px 12px;
	border-radius: 14px;
	overflow-wrap: anywhere;
}

.msg.user {
	align-self: flex-end;
	background: #2d3a5c;
	white-space: pre-wrap;
	border-bottom-right-radius: 4px;
}

.msg.assistant {
	align-self: flex-start;
	background: var(--panel);
	border-bottom-left-radius: 4px;
}

.msg.assistant p {
	margin: 0.4em 0;
}

.msg.assistant pre {
	background: #111317;
	padding: 8px;
	border-radius: 6px;
	overflow-x: auto;
	white-space: pre;
}

.msg.assistant :first-child {
	margin-top: 0;
}

.msg.assistant :last-child {
	margin-bottom: 0;
}

.msg.error {
	background: #2a1d24;
	color: #ffc0cb;
	font-size: 13px;
}

.msg.pending .dots::after {
	content: "…";
	animation: blink 1s infinite;
}

@keyframes blink {
	50% {
		opacity: 0.2;
	}
}

.note {
	align-self: center;
	font-size: 12px;
	color: var(--dim);
}

details.thinking {
	align-self: flex-start;
	max-width: 92%;
	font-size: 13px;
	color: var(--dim);
}

details.tool {
	align-self: flex-start;
	max-width: 92%;
	font-size: 12.5px;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 4px 8px;
}

details.tool summary {
	cursor: pointer;
	display: flex;
	gap: 6px;
	align-items: baseline;
	flex-wrap: wrap;
	list-style: none;
}

details.tool .tool-status {
	color: var(--dim);
	font-size: 11px;
}

details.tool.running .tool-status,
details.tool.pending .tool-status {
	color: var(--yellow);
}

details.tool.error .tool-status {
	color: var(--red);
}

details.tool .tool-result {
	color: var(--green);
}

details.tool pre {
	margin-top: 6px;
	max-height: 280px;
	overflow: auto;
	color: var(--dim);
	font-size: 11.5px;
}

.proposal {
	align-self: stretch;
	background: var(--panel);
	border: 1px solid var(--accent);
	border-radius: 10px;
	padding: 8px 10px;
	font-size: 13px;
}

.proposal p {
	margin: 4px 0 8px;
}

.proposal-head {
	display: flex;
	gap: 4px;
	align-items: baseline;
	flex-wrap: wrap;
}

.decision {
	margin-left: auto;
	font-size: 12px;
}

.decision.accepted {
	color: var(--green);
}

.decision.rejected {
	color: var(--dim);
}

.proposal-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 8px;
}

.diff {
	font: 11.5px/1.45 var(--mono);
	background: #111317;
	border-radius: 6px;
	padding: 4px 0;
	overflow-x: auto;
	max-height: 360px;
}

.diff div {
	white-space: pre;
	padding: 0 8px;
}

.diff .add {
	background: #1d2f1f;
	color: #b8e994;
}

.diff .add::before {
	content: "+ ";
}

.diff .del {
	background: #2f1d22;
	color: #ffb3c1;
}

.diff .del::before {
	content: "- ";
}

.diff .same::before {
	content: "  ";
}

.diff .gap {
	color: var(--dim);
	font-style: italic;
}

.welcome {
	color: var(--dim);
	font-size: 14px;
	margin: auto 0 0;
}

.suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.composer {
	display: flex;
	gap: 8px;
	padding: 8px 10px;
	border-top: 1px solid var(--line);
	align-items: flex-end;
}

.chat-input {
	flex: 1;
	resize: none;
	max-height: 160px;
	line-height: 1.35;
}

/* ─── Dialogs ────────────────────────────────────────────────────────────── */

dialog {
	background: var(--panel);
	color: var(--text);
	border: 1px solid var(--line);
	border-radius: 14px;
	padding: 0;
	width: min(560px, 94vw);
	max-height: 90dvh;
}

dialog.wide {
	width: min(1100px, 96vw);
	height: 90dvh;
}

dialog::backdrop {
	background: rgba(0, 0, 0, 0.6);
}

dialog[open] {
	display: flex;
	flex-direction: column;
}

.dialog-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px 14px;
	border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
	font-size: 17px;
	margin: 0;
}

.dialog-body {
	overflow: auto;
	padding: 12px 16px 16px;
	flex: 1;
	min-height: 0;
}

.settings label,
.commit label {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 13px;
	color: var(--dim);
	margin: 8px 0;
	flex: 1;
}

.settings .row {
	display: flex;
	gap: 10px;
}

.settings h3 {
	margin: 18px 0 2px;
	font-size: 15px;
}

.settings .intro p {
	margin-top: 0;
}

.commit-file summary {
	display: flex;
	gap: 8px;
	align-items: center;
	padding: 6px 0;
	cursor: pointer;
}

.spec {
	display: flex;
	gap: 14px;
	height: 100%;
}

.spec-toc {
	width: 240px;
	flex: none;
	overflow: auto;
	font-size: 13px;
	display: flex;
	flex-direction: column;
}

.spec-toc a {
	text-decoration: none;
	padding: 2px 0;
}

.spec-toc a.level3 {
	padding-left: 12px;
	color: var(--dim);
}

.spec-body {
	flex: 1;
	overflow: auto;
	min-width: 0;
}

@media (max-width: 700px) {
	.spec {
		flex-direction: column;
	}
	.spec-toc {
		width: auto;
		max-height: 28%;
		border-bottom: 1px solid var(--line);
	}
	.brand {
		display: none;
	}
	.lesson-picker {
		max-width: 58vw;
	}
}

/* ─── Toasts ─────────────────────────────────────────────────────────────── */

.toasts {
	position: fixed;
	left: 50%;
	transform: translateX(-50%);
	bottom: calc(76px + env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column;
	gap: 6px;
	z-index: 10;
	width: min(560px, 92vw);
	pointer-events: none;
}

.toast {
	pointer-events: auto;
	background: var(--raised);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 8px 12px;
	font-size: 14px;
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.toast.error {
	border-color: var(--red);
	color: #ffc0cb;
}

.mode-tag {
	display: inline-block;
	font-size: 10.5px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--accent);
	background: rgba(122, 162, 247, 0.15);
	border-radius: 4px;
	padding: 0 5px;
	margin-right: 6px;
	vertical-align: 1px;
}
