:root {
  --bg: #0e0e11;
  --panel: #16161b;
  --panel-2: #1c1c23;
  --line: #2a2a33;
  --text: #e8e6e3;
  --muted: #9a97a3;
  --accent: #d8935a;
  --accent-dim: #6b4a2e;
  --user: #22222b;
  --ok: #6fbf8b;
  --err: #d97a7a;
  --call: #d8b45a;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf9f7;
    --panel: #ffffff;
    --panel-2: #f3f1ee;
    --line: #e2ded8;
    --text: #1c1a18;
    --muted: #6d6862;
    --accent: #a85c22;
    --accent-dim: #e6d3c0;
    --user: #efece7;
    --ok: #2f7d4f;
    --err: #b03b3b;
    --call: #8a6a12;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

body { display: flex; flex-direction: column; }

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

/* ---------- header ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* A CD, because the shop sells them. */
.disc {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex: none;
  background:
    radial-gradient(circle at 50% 50%, var(--bg) 0 5px, transparent 5px),
    conic-gradient(from 0deg, #7a5cff, #2ec5c1, #d8935a, #d95f8a, #7a5cff);
  box-shadow: inset 0 0 0 1px var(--line);
}

.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

select, input, textarea, button { font-family: inherit; font-size: 13px; color: var(--text); }

select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 190px;
}

button {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 7px 12px;
  background: var(--accent);
  color: #14100c;
  font-weight: 600;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
  font-weight: 500;
}

.ghost[aria-pressed="false"] { opacity: 0.55; }

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

/* ---------- layout ---------- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
}

main.no-trace { grid-template-columns: minmax(0, 1fr); }
main.no-trace .trace { display: none; }

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- messages ---------- */

.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto; }

.msg .who {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.msg.user .who { background: var(--user); }
.msg.assistant .who { color: var(--accent); border-color: var(--accent-dim); }

.msg .body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-width: 0;
}

.msg.user .body { background: var(--user); }
.msg.error .body { border-color: var(--err); color: var(--err); }

.msg .body strong { font-weight: 650; }

.welcome {
  max-width: 760px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.welcome h2 { margin: 0 0 6px; font-size: 15px; color: var(--text); }
.welcome ul { margin: 10px 0 0; padding-left: 18px; }
.welcome li { margin: 3px 0; }
.welcome code { font-family: var(--mono); font-size: 12px; color: var(--accent); }

/* thinking indicator */
.dots span {
  display: inline-block; width: 6px; height: 6px; margin-right: 3px;
  border-radius: 50%; background: var(--muted);
  animation: blink 1.3s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- token gate ---------- */

.gate {
  max-width: 620px;
  margin: 8px auto 20px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.gate h2 { margin: 0 0 8px; font-size: 15px; }
.gate p { margin: 0 0 10px; font-size: 13px; }
.gate .muted { color: var(--muted); }
.gate code { font-family: var(--mono); font-size: 12px; }

#token-form { display: flex; gap: 8px; margin-top: 14px; }

#token {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: var(--mono);
}

/* ---------- composer ---------- */

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px 20px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

#input {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  line-height: 1.5;
  font-size: 14px;
}

#input:focus, #token:focus, select:focus { outline: 2px solid var(--accent-dim); outline-offset: 1px; }

#send { height: 40px; width: 42px; display: grid; place-items: center; padding: 0; }

.statusline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px 12px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  font-size: 12px;
  color: var(--muted);
}

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

/* ---------- trace ---------- */

.trace {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.trace-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px;
}

.trace-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.trace-hint {
  margin: 0 16px 10px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}

.trace-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
  font-family: var(--mono);
  font-size: 11.5px;
}

.entry { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }

.entry .head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 9px;
  background: var(--panel-2);
  cursor: pointer;
  user-select: none;
}

.entry .arrow { color: var(--call); font-weight: 700; }
.entry.ok .arrow { color: var(--ok); }
.entry.fail .arrow { color: var(--err); }
.entry .name { font-weight: 700; }
.entry .args { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.entry pre {
  margin: 0;
  padding: 8px 9px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-top: 1px solid var(--line);
  max-height: 320px;
  overflow-y: auto;
  color: var(--muted);
}

.entry.fail pre { color: var(--err); }
.entry[data-open="false"] pre { display: none; }

.turnmark {
  color: var(--muted);
  margin: 12px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.trace-empty { color: var(--muted); padding: 8px 4px; font-family: var(--font); font-size: 12.5px; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .trace { border-left: none; border-top: 1px solid var(--line); max-height: 45vh; }
  .brand p { display: none; }
}
