/* unkernel · kelir — design system.
   Tokens first, then layout, then components. Dark by default, light by system preference. */

/* Theme: wayang kulit. The page is the kelir, the lit cloth screen; the agent is
   the shadow play on it. Dark = the theatre at night with the blencong (oil lamp)
   behind the screen; light = the cloth by day. Gold is lamplight, sogan brown is batik. */
:root {
	color-scheme: dark;
	--bg: #0f0a07;
	--bg-glow: rgba(240, 160, 60, .08);
	--lamp: rgba(255, 176, 72, .3);
	--weave: transparent;
	--puppet: #060302;
	--rim: rgba(255, 190, 100, .55);
	--surface: #19120d;
	--surface-2: #211810;
	--surface-3: #2b1f15;
	--code-bg: #0c0805;
	--line: rgba(255, 220, 170, .085);
	--line-strong: rgba(255, 220, 170, .17);
	--text: #f4eadb;
	--text-2: #d0c2ab;
	--dim: #9b8c75;
	--accent: #e8b04f;
	--accent-2: #e09a45;
	--accent-ink: #2a1706;
	--accent-soft: rgba(232, 176, 79, .12);
	--accent-line: rgba(232, 176, 79, .36);
	--user-bg: linear-gradient(180deg, rgba(190, 105, 40, .26), rgba(150, 80, 30, .16));
	--user-line: rgba(232, 150, 70, .3);
	--ok: #8bc47a;
	--warn: #f0b441;
	--err: #ec7060;
	--err-soft: rgba(236, 112, 96, .12);
	--shadow: 0 1px 0 rgba(255, 220, 170, .05) inset, 0 10px 32px -12px rgba(0, 0, 0, .75);
	--shadow-pop: 0 24px 64px -16px rgba(0, 0, 0, .85), 0 0 0 1px var(--line-strong);
	--hl-kw: #f0a06a;
	--hl-str: #a8d08d;
	--hl-num: #e8c26a;
	--hl-cmt: #86775f;
	--hl-var: #7fc4d6;
	--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Noto Serif", Georgia, serif;
	--mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
	--r-sm: 8px;
	--r-md: 12px;
	--r-lg: 18px;
	--r-xl: 24px;
	--col: 760px;
	--gutter: 38px;
	--app-h: 100dvh;
	--safe-t: env(safe-area-inset-top, 0px);
	--safe-b: env(safe-area-inset-bottom, 0px);
	--ease: cubic-bezier(.22, .8, .24, 1);
}

@media (prefers-color-scheme: light) {
	:root {
		color-scheme: light;
		--bg: #f6eedd;
		--bg-glow: rgba(255, 190, 90, .22);
		--lamp: rgba(255, 190, 80, .3);
		--weave: rgba(110, 70, 20, .03);
		--puppet: #24140a;
		--rim: rgba(150, 80, 20, .5);
		--surface: #fbf4e4;
		--surface-2: #f4ead4;
		--surface-3: #ecdfc4;
		--code-bg: #f8f0de;
		--line: rgba(80, 45, 10, .12);
		--line-strong: rgba(80, 45, 10, .22);
		--text: #2a1a0d;
		--text-2: #52391f;
		--dim: #84694a;
		--accent: #a8641a;
		--accent-2: #b8651c;
		--accent-ink: #fff8ea;
		--accent-soft: rgba(168, 100, 26, .12);
		--accent-line: rgba(168, 100, 26, .4);
		--user-bg: linear-gradient(180deg, rgba(168, 100, 26, .17), rgba(168, 100, 26, .1));
		--user-line: rgba(168, 100, 26, .28);
		--ok: #4d7a2a;
		--warn: #a8641a;
		--err: #b4402f;
		--err-soft: rgba(180, 64, 47, .09);
		--shadow: 0 1px 2px rgba(80, 45, 10, .08), 0 10px 28px -14px rgba(80, 45, 10, .3);
		--shadow-pop: 0 24px 64px -20px rgba(60, 30, 5, .45), 0 0 0 1px var(--line-strong);
		--hl-kw: #9a3d1c;
		--hl-str: #4d7a2a;
		--hl-num: #a06a10;
		--hl-cmt: #9a8466;
		--hl-var: #1f6f86;
	}
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	height: var(--app-h);
	overflow: hidden;
	background:
		radial-gradient(1100px 520px at 50% -140px, var(--bg-glow), transparent 70%),
		var(--bg);
	color: var(--text);
	font: 15px/1.6 var(--font);
	font-feature-settings: "cv11", "ss01";
	-webkit-font-smoothing: antialiased;
	display: flex;
	flex-direction: column;
	overscroll-behavior: none;
}
::selection { background: var(--accent-soft); color: var(--text); }
a { color: var(--accent); }
code, pre, kbd, samp { font-family: var(--mono); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- header ---------- */
header {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: calc(10px + var(--safe-t)) 18px 10px;
	background: color-mix(in srgb, var(--bg) 72%, transparent);
	backdrop-filter: saturate(1.4) blur(14px);
	-webkit-backdrop-filter: saturate(1.4) blur(14px);
	border-bottom: 1px solid var(--line);
	position: relative;
	z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 28px; height: 28px; flex: 0 0 auto; display: block; filter: drop-shadow(0 4px 12px rgba(240, 150, 50, .3)); }
.brand h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand h1 span { color: var(--dim); font-weight: 500; }
.spacer { flex: 1 1 auto; }

#status {
	display: inline-flex; align-items: center; gap: 8px;
	max-width: 44vw; padding: 5px 11px 5px 9px;
	border: 1px solid var(--line); border-radius: 999px;
	background: var(--surface);
	font-size: 12px; font-family: var(--mono); color: var(--dim);
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
	transition: color .2s, border-color .2s;
}
#status::before {
	content: ""; width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
	background: var(--warn); box-shadow: 0 0 0 0 transparent;
	animation: pulse 1.6s ease-in-out infinite;
}
#status.ok { color: var(--text-2); }
#status.ok::before { background: var(--ok); box-shadow: 0 0 10px color-mix(in srgb, var(--ok) 70%, transparent); animation: none; }
#status.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
#status.err::before { background: var(--err); animation: none; }
body.busy #status::before { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.icon-btn {
	width: 36px; height: 36px; display: grid; place-items: center;
	border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--dim);
	transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.icon-btn:active:not(:disabled) { transform: scale(.96); }
.icon-btn.danger:hover:not(:disabled) { color: var(--err); }

/* ---------- transcript ---------- */
main {
	flex: 1 1 auto; min-height: 0; overflow-y: auto; position: relative;
	padding: 26px 18px 18px;
	scroll-behavior: smooth; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.wrap { max-width: var(--col); margin: 0 auto; display: flex; flex-direction: column; gap: 22px; min-height: 100%; padding-bottom: 30px; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg, .call, .turn-note, .typing { animation: rise .32s var(--ease) both; }

.msg { display: flex; min-width: 0; }
.msg .body { min-width: 0; overflow-wrap: anywhere; }

/* you */
.msg.user { justify-content: flex-end; }
.msg.user .body {
	max-width: min(86%, 560px);
	padding: 10px 15px;
	background: var(--user-bg);
	border: 1px solid var(--user-line);
	border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
	white-space: pre-wrap;
	box-shadow: var(--shadow);
}
.msg.user .who { display: none; }

/* kelir */
.flow { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.msg.agent { position: relative; padding-left: var(--gutter); }
.msg.agent .who {
	position: absolute; left: 0; top: 1px; width: 28px; height: 28px;
	display: grid; place-items: center; font-size: 0; /* label text is for assistive tech only */
	border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
	color: var(--accent-ink); box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}
.msg.agent .who::before {
	content: ""; width: 14px; height: 14px; background: currentColor;
	-webkit-mask: var(--glyph) center / contain no-repeat; mask: var(--glyph) center / contain no-repeat;
	--glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 6l7 6-7 6'/%3E%3Cpath d='M14 18h6'/%3E%3C/svg%3E");
}
.msg.agent .body { flex: 1 1 auto; padding-top: 2px; color: var(--text); }
.msg.agent .body > :first-child { margin-top: 0; }
.msg.agent .body > :last-child { margin-bottom: 0; }
.flow > .call, .flow > .turn-note, .flow > .typing { margin-left: var(--gutter); }

.msg .body p { margin: 0 0 .85em; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body strong { color: var(--text); font-weight: 650; }
.msg .body a { text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 3px; transition: text-decoration-color .15s; }
.msg .body a:hover { text-decoration-color: var(--accent); }
.msg .body :not(pre) > code {
	-webkit-box-decoration-break: clone; box-decoration-break: clone;
	font-size: .86em; padding: .16em .42em; border-radius: 6px;
	background: var(--surface-3); border: 1px solid var(--line); color: var(--text);
}
.msg .body h1, .msg .body h2, .msg .body h3, .msg .body h4, .msg .body h5, .msg .body h6 {
	margin: 1.25em 0 .45em; line-height: 1.3; font-weight: 650; letter-spacing: -.012em; color: var(--text);
}
.msg .body h1 { font-size: 1.28em; }
.msg .body h2 { font-size: 1.14em; }
.msg .body h3 { font-size: 1.04em; }
.msg .body h4, .msg .body h5, .msg .body h6 { font-size: .95em; color: var(--text-2); }
.msg .body ul, .msg .body ol { margin: .3em 0 .9em; padding-left: 1.4em; }
.msg .body li { margin: .22em 0; padding-left: .1em; }
.msg .body li::marker { color: var(--dim); }
.msg .body blockquote { margin: .8em 0; padding: .1em 0 .1em 14px; border-left: 3px solid var(--accent-line); color: var(--text-2); }
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.msg .body .tbl { overflow-x: auto; max-width: 100%; margin: .8em 0; border: 1px solid var(--line); border-radius: var(--r-md); }
.msg .body table { border-collapse: collapse; width: 100%; font-size: .9em; }
.msg .body th, .msg .body td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.msg .body tbody tr:last-child td { border-bottom: 0; }
.msg .body th { background: var(--surface-2); font-weight: 600; color: var(--text-2); font-size: .86em; letter-spacing: .02em; }
.msg .body tbody tr:hover td { background: var(--surface-2); }

/* code blocks */
.code { margin: .85em 0; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--code-bg); overflow: hidden; max-width: 100%; }
.code-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); font: 11.5px var(--mono); color: var(--dim); }
.code-head .copy {
	display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; min-height: 0;
	background: transparent; border: 1px solid transparent; border-radius: 7px; color: var(--dim); font: inherit;
	transition: background .15s, color .15s;
}
.code-head .copy:hover { background: var(--surface-3); color: var(--text); }
.code-head .copy .icon { width: 13px; height: 13px; }
.msg .body .code pre { margin: 0; padding: 13px 15px; overflow-x: auto; font-size: 12.8px; line-height: 1.6; white-space: pre; border: 0; background: transparent; color: var(--text); -webkit-overflow-scrolling: touch; }
.tok-k { color: var(--hl-kw); }
.tok-s { color: var(--hl-str); }
.tok-n { color: var(--hl-num); }
.tok-c { color: var(--hl-cmt); font-style: italic; }
.tok-v { color: var(--hl-var); }

/* ---------- tool calls ---------- */
.call {
	border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface);
	min-width: 0; overflow: hidden; transition: border-color .2s, box-shadow .2s;
}
.call:hover { border-color: var(--line-strong); }
.call.open { box-shadow: var(--shadow); }
.call .head {
	display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px;
	padding: 9px 12px; background: none; border: 0; text-align: left; color: var(--text-2); font-size: 13.5px;
}
.call .head:hover { color: var(--text); }
.call .ico { width: 18px; height: 18px; flex: 0 0 auto; display: grid; place-items: center; }
.call .ico .icon { width: 16px; height: 16px; stroke-width: 2.2; }
.call .ico .ok, .call .ico .bad { display: none; }
.call:not(.running):not(.failed) .ico .ok { display: block; color: var(--ok); }
.call.failed .ico .bad { display: block; color: var(--err); }
.call.running .ico::before {
	content: ""; width: 14px; height: 14px; border-radius: 50%;
	border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.call .title { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; line-height: 1.4; }
.call .state { flex: 0 0 auto; font: 11.5px var(--mono); color: var(--dim); padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.call.running .state { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.call.running .state::after { content: "…"; }
.call.failed .state { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); background: var(--err-soft); }
.call .chev { width: 16px; height: 16px; color: var(--dim); transition: transform .22s var(--ease); }
.call.open .chev { transform: rotate(90deg); }
.call .out-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .26s var(--ease); }
.call.open .out-wrap { grid-template-rows: 1fr; }
.call .out { overflow: hidden; min-height: 0; min-width: 0; }
.call .out-in { margin: 0 12px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--code-bg); overflow: hidden; }
.call .out pre { margin: 0; padding: 10px 13px; font-size: 12.3px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; overflow: auto; max-height: 340px; }
.call .out pre.output { white-space: pre; overflow-wrap: normal; }
.call .out pre.cmd { color: var(--text); border-bottom: 1px solid var(--line); background: var(--surface-2); max-height: 150px; }
.call .out pre.cmd::before { content: "$ "; color: var(--accent); user-select: none; }
.call .out pre.output { color: var(--text-2); }
.call.failed .out pre.output { color: color-mix(in srgb, var(--err) 80%, var(--text)); }
.call .out pre.output:empty { display: none; }

.turn-note { font: 12px var(--mono); color: var(--dim); padding: 8px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px dashed var(--line-strong); overflow-wrap: anywhere; }
.turn-note.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); background: var(--err-soft); border-style: solid; }

.typing { display: inline-flex; gap: 5px; align-items: center; padding: 10px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); animation: bob 1.1s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 70%, 100% { transform: translateY(0); opacity: .4; } 35% { transform: translateY(-4px); opacity: 1; } }

/* ---------- empty state ---------- */
#empty { margin: auto; padding: 4vh 4px 2vh; text-align: center; max-width: 640px; animation: rise .5s var(--ease) both; }
#empty .hero-mark { width: 96px; height: 128px; display: block; position: relative; ; }
#empty h2 { margin: 0 0 10px; text-wrap: balance; font-size: clamp(24px, 4.4vw, 32px); line-height: 1.15; letter-spacing: -.025em; font-weight: 700; }
#empty h2 em { font-style: normal; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
#empty p { margin: 0 auto 18px; color: var(--dim); max-width: 46ch; font-size: 15px; text-wrap: balance; }
.specs { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin: 0 0 26px; }
.specs span { font: 12px var(--mono); color: var(--text-2); padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.specs b { color: var(--accent); font-weight: 600; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.suggest button {
	text-align: left; color: inherit;
	display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px;
	background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
	transition: transform .18s var(--ease), border-color .18s, background .18s, box-shadow .18s;
}
.suggest button:hover { border-color: var(--accent-line); background: var(--surface-2); transform: translateY(-1px); box-shadow: var(--shadow); }
.suggest button:active { transform: translateY(0) scale(.99); }
.suggest .s-ico { width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.suggest .s-ico .icon { width: 16px; height: 16px; }
.suggest .s-t { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; color: var(--text); }
.suggest .s-d { display: block; margin-top: 2px; font-size: 12.5px; color: var(--dim); line-height: 1.4; }

/* ---------- composer ---------- */
footer {
	flex: 0 0 auto; position: relative; z-index: 4;
	margin-top: -40px; padding: 40px 18px calc(14px + var(--safe-b));
	background: linear-gradient(180deg, transparent, var(--bg) 46px);
	pointer-events: none;
}
.composer { max-width: var(--col); margin: 0 auto; position: relative; pointer-events: auto; }
.box {
	background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-xl);
	box-shadow: var(--shadow); padding: 6px 8px 8px 8px;
	transition: border-color .18s, box-shadow .18s;
}
.box:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 7%, transparent); }
textarea#prompt {
	display: block; width: 100%; resize: none; min-height: 46px; max-height: min(220px, 34dvh);
	padding: 11px 12px 6px; background: transparent; border: 0; outline: none; line-height: 1.5; font-size: 15px;
}
textarea#prompt::placeholder { color: var(--dim); }
textarea#prompt:disabled { opacity: .55; }
.tools { display: flex; align-items: center; gap: 6px; padding: 2px 2px 0 6px; }
.pill {
	display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0;
	height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px;
	background: var(--surface-2); color: var(--text-2); font-size: 12.5px;
	transition: border-color .15s, color .15s, background .15s;
}
.pill:hover:not(:disabled) { border-color: var(--line-strong); color: var(--text); background: var(--surface-3); }
.pill .icon { width: 14px; height: 14px; color: var(--dim); }
.model-wrap { position: relative; display: inline-flex; min-width: 0; }
.model-wrap select {
	appearance: none; -webkit-appearance: none; height: 32px; max-width: 100%; min-width: 0;
	padding: 0 26px 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2);
	color: var(--text-2); font-size: 12.5px; text-overflow: ellipsis; cursor: pointer;
	transition: border-color .15s, color .15s;
}
.model-wrap select:hover:not(:disabled) { border-color: var(--line-strong); color: var(--text); }
.model-wrap select:disabled { opacity: .6; cursor: default; }
.model-wrap .icon { position: absolute; right: 9px; top: 9px; width: 14px; height: 14px; color: var(--dim); pointer-events: none; }
.model-wrap select option { background: var(--surface); color: var(--text); }
.send-btn {
	width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center;
	border-radius: 50%; border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
	box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--accent) 70%, transparent);
	transition: transform .15s var(--ease), opacity .15s, box-shadow .15s, filter .15s;
}
.send-btn .icon { width: 18px; height: 18px; stroke-width: 2.4; }
.send-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { background: var(--surface-3); color: var(--dim); box-shadow: none; opacity: .75; }
#stop.send-btn { background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong); box-shadow: none; }
#stop.send-btn .icon { fill: currentColor; stroke-width: 0; width: 13px; height: 13px; }
.tools .send-wrap { margin-left: auto; display: flex; }

.to-bottom {
	position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
	width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
	background: var(--surface); border: 1px solid var(--line-strong); color: var(--text-2); box-shadow: var(--shadow);
	transition: opacity .2s, transform .2s var(--ease);
}
.to-bottom.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.to-bottom:hover { color: var(--text); }

/* ---------- boot overlay ---------- */
#boot {
	position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
	padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
	background:
		radial-gradient(900px 480px at 50% 28%, var(--bg-glow), transparent 70%),
		color-mix(in srgb, var(--bg) 99%, transparent);
	transition: opacity .45s var(--ease), visibility .45s;
}
#boot.done { opacity: 0; visibility: hidden; pointer-events: none; }
#boot .card { width: min(440px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
#boot .boot-mark { width: 54px; height: 72px; display: block; position: relative; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
#boot h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; font-weight: 650; }
#boot .bar { width: 100%; height: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
#boot .bar::after { content: ""; display: block; width: 38%; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); animation: slide 1.3s var(--ease) infinite; }
@keyframes slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(300%); } }
#boot.failed .bar::after { animation: none; width: 100%; background: var(--err); }
#bootlog { width: 100%; max-height: 38vh; overflow: auto; text-align: left; font: 12.5px/1.65 var(--mono); color: var(--dim); display: flex; flex-direction: column; gap: 2px; }
#bootlog div { display: flex; gap: 9px; align-items: baseline; overflow-wrap: anywhere; animation: rise .25s var(--ease) both; }
#bootlog div::before { content: "✓"; color: var(--ok); flex: 0 0 auto; font-weight: 700; }
#bootlog div:last-child { color: var(--text-2); }
#bootlog div:last-child::before { content: "›"; color: var(--accent); }
#bootlog div.err { color: var(--err); }
#bootlog div.err::before { content: "✕"; color: var(--err); }

/* ---------- settings ---------- */
dialog#settings {
	padding: 0; width: min(540px, calc(100vw - 24px)); max-height: calc(var(--app-h) - 24px); overflow: auto;
	background: var(--surface); color: var(--text); border: 0; border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
}
dialog#settings[open] { animation: pop .28s var(--ease) both; }
dialog#settings::backdrop { background: rgba(14, 7, 2, .68); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .25s both; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#settings-form { padding: 22px; }
.dlg-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.dlg-head .mark { width: 34px; height: 34px; }
.dlg-head h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.dlg-head p { margin: 0; font-size: 12.5px; color: var(--dim); }
.field { display: block; border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
.field > .lbl, .field > legend { display: block; margin: 0 0 8px; padding: 0; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
.key-row { position: relative; }
.key-row input {
	width: 100%; height: 46px; padding: 0 46px 0 14px; background: var(--code-bg); border: 1px solid var(--line-strong);
	border-radius: var(--r-md); font: 13.5px var(--mono); outline: none; transition: border-color .15s, box-shadow .15s;
}
.key-row input:focus, #set-wisp:focus { border-color: var(--accent-line); box-shadow: 0 0 0 4px var(--accent-soft); }
.key-row .icon-btn { position: absolute; right: 5px; top: 5px; width: 36px; height: 36px; }
.field small { display: block; margin-top: 8px; font-size: 12.5px; line-height: 1.5; color: var(--dim); }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
	position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 0 12px; padding: 13px 14px;
	border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); cursor: pointer;
	transition: border-color .15s, background .15s, box-shadow .15s;
}
.opt:hover { border-color: var(--line-strong); }
.opt input { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; margin: 3px 0 0; border-radius: 50%; border: 2px solid var(--line-strong); background: transparent; display: grid; place-items: center; transition: border-color .15s, background .15s; }
.opt input::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-ink); transform: scale(0); transition: transform .15s var(--ease); }
.opt input:checked { border-color: var(--accent); background: var(--accent); }
.opt input:checked::after { transform: scale(1); }
.opt:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt .t { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.opt .t em { font-style: normal; font: 600 10.5px var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); }
.opt .d { grid-column: 2; margin-top: 3px; font-size: 12.5px; line-height: 1.5; color: var(--dim); }
.opt .d code { font-size: .92em; color: var(--text-2); }
#set-wisp { width: 100%; height: 42px; margin-top: 8px; padding: 0 14px; background: var(--code-bg); border: 1px solid var(--line-strong); border-radius: var(--r-md); font: 13px var(--mono); outline: none; transition: border-color .15s, box-shadow .15s, opacity .15s; }
#set-wisp:disabled { opacity: .4; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin: 4px -22px -22px; padding: 14px 22px 22px; position: sticky; bottom: 0; background: linear-gradient(180deg, transparent, var(--surface) 28%); }
.btn { height: 42px; padding: 0 18px; border-radius: 12px; font-weight: 600; font-size: 14px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text); transition: background .15s, transform .15s, filter .15s; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.98); }
.btn.primary { border: 0; color: var(--accent-ink); background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn.primary:hover { filter: brightness(1.07); }
#settings .err { margin: 0 0 14px; padding: 9px 12px; font-size: 13px; color: var(--err); background: var(--err-soft); border-radius: var(--r-sm); }

/* ---------- toast ---------- */
#toast {
	position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translate(-50%, 10px); z-index: 30;
	padding: 9px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 550;
	box-shadow: var(--shadow-pop); opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
	:root { --gutter: 34px; }
	header { padding: calc(8px + var(--safe-t)) 12px 8px; gap: 6px; }
	.brand h1 span { display: none; }
	#status { max-width: 46vw; }
	.spacer { display: none; }
	#status { margin-left: auto; }
	#settings-btn { margin-left: auto; }
	#status.err + #settings-btn { margin-left: 0; }
	main { padding: 18px 12px 12px; }
	.wrap { gap: 18px; }
	.msg.user .body { max-width: 92%; }
	.msg.agent .who { width: 24px; height: 24px; border-radius: 8px; }
	.msg.agent .who::before { width: 12px; height: 12px; }
	footer { padding: 4px 10px calc(10px + var(--safe-b)); }
	textarea#prompt { font-size: 16px; }
	.model-wrap select { font-size: 16px; max-width: 58vw; }
	.model-wrap { flex: 0 1 auto; }
	.suggest { grid-template-columns: 1fr; gap: 8px; }
	.suggest button { padding: 10px 12px; align-items: center; }
	.suggest .s-d { display: none; }
	.suggest .s-ico { width: 28px; height: 28px; }
	#empty { padding-top: 0; }
	#empty .hero-mark { width: 48px; height: 48px; margin-bottom: 12px; }
	#empty h2 { font-size: 24px; margin-bottom: 16px; }
	#empty p { display: none; }
	.specs { margin-bottom: 18px; gap: 6px; }
	.specs span:nth-child(n+4) { display: none; }
	textarea#prompt { min-height: 40px; padding-top: 9px; }
	#settings-form { padding: 18px; }
	.actions { margin: 4px -18px -18px; padding: 14px 18px 18px; }
	.call .head { padding: 9px 10px; }
	.call .out-in { margin: 0 8px 8px; }
}
@media (max-width: 380px) { .specs span:nth-child(n+4) { display: none; } }
@media (hover: none) {
	.suggest button:hover { transform: none; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
	#boot .bar::after { width: 100%; }
}

/* state hooks set by app.mjs */
body[data-net="fetch"] .needs-net { display: none; }
body:not(.ready) .suggest button { opacity: .55; pointer-events: none; }
body.busy #send { display: none; }
body.busy .box { border-color: var(--accent-line); }
.specs:empty { display: none; }

/* settings: danger zone */
.dz { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.dz > div { flex: 1 1 auto; min-width: 0; }
.dz b { font-size: 14px; }
.dz small { margin-top: 2px; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 35%, transparent); background: var(--err-soft); flex: 0 0 auto; }
.btn.danger:hover { background: color-mix(in srgb, var(--err) 18%, transparent); }
.btn.danger.armed { color: #fff; background: var(--err); border-color: var(--err); }

/* The status pill only appears when something needs attention; otherwise it is
   kept for assistive tech and tests but not shown. */
#status:not(.err) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap; }


/* ================= wayang accents (kept quiet) ================= */
/* The only motifs: the gunungan puppet as the mark, a warm lamp-lit palette,
   and a faint glow behind the hero. No ornament, no texture, no flicker. */
.brand h1 { font-size: 15px; }
.stage { position: relative; display: grid; place-items: center; margin: 0 auto; }
#empty .stage { width: 120px; height: 84px; margin-bottom: 14px; }
#boot .stage { width: 96px; height: 76px; }
#empty .hero-mark { width: 40px; height: 54px; display: block; position: relative; opacity: .92; }
#boot .boot-mark { width: 32px; height: 43px; display: block; position: relative; opacity: .92; }
.lamp {
	position: absolute; left: 50%; top: 50%; width: 150px; height: 150px; margin: -75px 0 0 -75px; border-radius: 50%;
	background: radial-gradient(circle, var(--lamp) 0%, transparent 68%);
	pointer-events: none;
}
.kicker { display: none !important; }

/* agent avatar: flat gunungan on the accent, no glow */
.msg.agent .who::before {
	width: 13px; height: 16px;
	--glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 64'%3E%3Cpath fill-rule='evenodd' d='M24 2C26 10 36 14 41 26 45 38 45 54 41 62L7 62C3 54 3 38 7 26 12 14 22 10 24 2ZM17 62V47C17 41 20 38 24 38 28 38 31 41 31 47V62Z'/%3E%3C/svg%3E");
}
.msg.agent .who { background: var(--accent); box-shadow: none; }

#boot { background: radial-gradient(700px 420px at 50% 30%, var(--bg-glow), transparent 70%), var(--bg); }
#boot h2 { font-size: 18px; }
@media (max-width: 640px) {
	#empty .stage { width: 110px; height: 72px; }
	.msg.agent .who::before { width: 11px; height: 14px; }
}

/* one mark everywhere: header, hero, boot, dialog, and the agent avatar all use the same tile */
.msg.agent .who { background: url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%2032%2032%27%3E%3Cdefs%3E%3ClinearGradient%20id=%27g%27%20x1=%270%27%20y1=%270%27%20x2=%271%27%20y2=%271%27%3E%3Cstop%20offset=%270%27%20stop-color=%27%23f6cc72%27/%3E%3Cstop%20offset=%271%27%20stop-color=%27%23ea8a38%27/%3E%3C/linearGradient%3E%3Cmask%20id=%27m%27%20maskUnits=%27userSpaceOnUse%27%20x=%270%27%20y=%270%27%20width=%2748%27%20height=%2764%27%3E%3Crect%20width=%2748%27%20height=%2764%27%20fill=%27%23000%27/%3E%3Cpath%20d=%27M24%202%20C26%2010%2036%2014%2041%2026%20C45%2038%2045%2054%2041%2062%20L7%2062%20C3%2054%203%2038%207%2026%20C12%2014%2022%2010%2024%202%20Z%27%20fill=%27%23fff%27/%3E%3Cpath%20d=%27M24%2036V14M24%2029q-6-1-8-7M24%2029q6-1%208-7%27%20fill=%27none%27%20stroke=%27%23000%27%20stroke-width=%273%27%20stroke-linecap=%27round%27/%3E%3Cpath%20d=%27M17%2062%20V47%20C17%2041%2020%2038%2024%2038%20C28%2038%2031%2041%2031%2047%20V62%20Z%27%20fill=%27%23000%27/%3E%3C/mask%3E%3C/defs%3E%3Crect%20width=%2732%27%20height=%2732%27%20rx=%279%27%20fill=%27url%28%23g%29%27/%3E%3Cg%20transform=%27translate%287.4%204.2%29%20scale%28.36%29%27%3E%3Cpath%20d=%27M24%202%20C26%2010%2036%2014%2041%2026%20C45%2038%2045%2054%2041%2062%20L7%2062%20C3%2054%203%2038%207%2026%20C12%2014%2022%2010%2024%202%20Z%27%20fill=%27%232a1706%27%20mask=%27url%28%23m%29%27/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat; border-radius: 8px; box-shadow: none; }
.msg.agent .who::before { display: none; }
#empty .hero-mark { width: 56px; height: 56px; opacity: 1; filter: drop-shadow(0 6px 18px rgba(240, 150, 50, .25)); }
#boot .boot-mark { width: 48px; height: 48px; opacity: 1; filter: drop-shadow(0 6px 18px rgba(240, 150, 50, .25)); }
#empty .stage { height: 90px; }
@media (max-width: 640px) { #empty .hero-mark { width: 48px; height: 48px; } #empty .stage { height: 76px; } }
