:root {
  --bg: #1a1a1a;
  --text: #e8e6e3;
  --dim: #8c8a86;
  --faint: #4a4846;
  --accent: #d77757;
  --code: #b1b9f9;
  --ok: #4eba65;
  --err: #ff6b80;
  --warn: #e5c07b;
  --plan: #48968c;
  --edits: #af87ff;
  --add-bg: #1f3d26;
  --add-fg: #a6e3b0;
  --del-bg: #4a2229;
  --del-fg: #f5a3ae;
  --user-bg: #2a2a2a;
  --menu-sel: #b1b9f9;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafaf7;
    --text: #1f1e1c;
    --dim: #73706b;
    --faint: #c9c6bf;
    --accent: #c25a35;
    --code: #4b4fc2;
    --ok: #2e8b45;
    --err: #c62f4a;
    --warn: #9a6b00;
    --plan: #2f7a70;
    --edits: #7a4fd6;
    --add-bg: #dcf3e0;
    --add-fg: #185c27;
    --del-bg: #fbe0e4;
    --del-fg: #8f1d31;
    --user-bg: #efede8;
    --menu-sel: #4b4fc2;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-monospace, "SF Mono", "Cascadia Mono", Menlo, "DejaVu Sans Mono", Consolas, "Noto Sans Thai", monospace;
  -webkit-text-size-adjust: 100%;
}
b, strong { font-weight: 700; }
button, input, textarea { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
:focus-visible { outline: 1px dashed var(--accent); outline-offset: 2px; }

.accent { color: var(--accent); }
.dim { color: var(--dim); }
.error { color: var(--err); min-height: 1.5em; }
.linkish {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.linkish:hover { text-decoration: underline; }

/* ---------- welcome / login ---------- */

.welcome {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 14px;
  max-width: 640px;
  display: grid;
  gap: 2px;
}
.welcome .gap { height: .75em; }
.welcome .cwd { overflow-wrap: anywhere; }

.login {
  max-width: 640px;
  margin: 12vh auto 0;
  padding: 0 16px;
}
.login-row { display: flex; gap: 10px; align-items: center; }
.login-row input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--faint);
  padding: 4px 0;
  outline: none;
}
.login-row input:focus { border-bottom-color: var(--accent); }

/* ---------- transcript ---------- */

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 14px 16px 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }

.prompt-line {
  background: var(--user-bg);
  color: var(--dim);
  padding: 2px 8px;
  border-radius: 3px;
  display: grid;
  grid-template-columns: 2ch 1fr;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.prompt-line .body { color: var(--text); }

.row { display: grid; grid-template-columns: 2ch 1fr; min-width: 0; }
.row > .bullet { user-select: none; }
.row > .body { min-width: 0; overflow-wrap: anywhere; }
.bullet.text { color: var(--text); }
.bullet.run { color: var(--dim); animation: blink 1s steps(2, start) infinite; }
.bullet.ok { color: var(--ok); }
.bullet.err { color: var(--err); }
@keyframes blink { to { visibility: hidden; } }

.tool-head { overflow-wrap: anywhere; }
.tool-head .args { color: var(--text); }
.tool-out { display: grid; grid-template-columns: 5ch 1fr; color: var(--dim); }
.tool-out > .elbow { user-select: none; padding-left: 0; }
.tool-out > .content { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-out .content.err-text { color: var(--err); }
.tool-out .more { color: var(--dim); font-style: italic; }
.tool-out .more.linkish { font-style: italic; }

.diff { display: grid; margin-top: 2px; white-space: pre; overflow-x: auto; font-size: 13px; }
.diff > div { padding: 0 6px 0 4px; min-width: max-content; }
.diff .add { background: var(--add-bg); color: var(--add-fg); }
.diff .del { background: var(--del-bg); color: var(--del-fg); }
.diff .ctx { color: var(--dim); }
.diff .skip { color: var(--faint); }

.todos { display: grid; gap: 0; color: var(--text); }
.todos .done { color: var(--dim); text-decoration: line-through; }
.todos .active { font-weight: 700; }

.note { color: var(--dim); white-space: pre-wrap; }
.note.err { color: var(--err); }
.note.warn { color: var(--warn); }
.result-line { color: var(--dim); }

/* ---------- markdown ---------- */

.md > * { margin: 0; }
.md > * + * { margin-top: .55em; }
.md p { white-space: pre-wrap; }
.md code { color: var(--code); }
.md pre {
  white-space: pre;
  overflow-x: auto;
  padding: 6px 10px;
  border-left: 2px solid var(--faint);
}
.md pre code { color: var(--text); }
.md .h { font-weight: 700; }
.md .h1 { text-decoration: underline; }
.md .h3, .md .h4, .md .h5, .md .h6 { font-style: italic; }
.md ul, .md ol { padding-left: 3ch; }
.md li { white-space: pre-wrap; }
.md li + li { margin-top: .15em; }
.md blockquote { border-left: 2px solid var(--faint); padding-left: 1.5ch; color: var(--dim); font-style: italic; }
.md hr { border: 0; border-top: 1px solid var(--faint); }
.md a { color: var(--code); }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--faint); padding: 1px 8px; text-align: left; vertical-align: top; }
.md th { font-weight: 700; }

/* ---------- spinner ---------- */

.spinner { padding: 2px 0 10px; display: flex; flex-wrap: wrap; gap: 0 1ch; }
.spinner #spin-glyph { display: inline-block; width: 1ch; }

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

.composer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 0 0 10px;
}
.queued { color: var(--dim); padding: 0 0 4px 2ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.inputbox {
  border: 1px solid var(--faint);
  border-radius: 8px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: 2ch 1fr auto;
  align-items: start;
}
.inputbox:focus-within { border-color: var(--dim); }
.caret { color: var(--text); user-select: none; }
textarea:focus-visible { outline: none; }
textarea {
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  padding: 0;
  min-height: 1.5em;
  max-height: 40vh;
  line-height: 1.5;
  overflow-y: auto;
}
textarea::placeholder { color: var(--dim); }
.send {
  display: none;
  background: none;
  border: 1px solid var(--faint);
  border-radius: 6px;
  color: var(--dim);
  padding: 0 8px;
  margin-left: 6px;
  cursor: pointer;
}
@media (hover: none) { .send { display: block; } }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  padding: 4px 2px 0;
  font-size: 13px;
  min-height: 1.5em;
}
.mode { color: var(--dim); white-space: nowrap; flex: none; }
.mode.plan { color: var(--plan); }
.mode.acceptEdits { color: var(--edits); }
.mode.auto { color: var(--warn); }
.mode.bypassPermissions { color: var(--err); }
.mode .hint { color: var(--dim); }
.info { flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 600px) {
  .mode .hint { display: none; }
  .tool-out { grid-template-columns: 4ch 1fr; }
}

.menu { padding: 6px 2px 0; display: grid; max-height: 45vh; overflow-y: auto; }
.menu .title { color: var(--dim); padding-bottom: 4px; }
.menu .item {
  display: grid;
  grid-template-columns: minmax(12ch, max-content) 1fr;
  gap: 0 3ch;
  padding: 0 2px;
  cursor: pointer;
  color: var(--dim);
}
.menu .item .label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .item .detail { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .item.sel, .menu .item.sel .label { color: var(--menu-sel); }
.menu .item.sel .label::before { content: "❯ "; }
.menu .item:not(.sel) .label::before { content: "  "; white-space: pre; }
.menu.stack .item { grid-template-columns: 1fr; }
.menu.stack .item .detail { padding-left: 2ch; font-size: 12.5px; }
.menu .empty { color: var(--dim); }
