:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e2e2df;
  --accent: #2f6fde;
  --prompt-bg: #e6eefc;
  --code-bg: #f2f2ef;
  --warn: #b3261e;
  --warn-bg: #fdecea;
  --busy: #1d7a3c;
  --busy-bg: #e3f3e8;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1b1c1f;
    --text: #ececee;
    --muted: #9a9aa1;
    --line: #2d2e33;
    --accent: #6c9dff;
    --prompt-bg: #1e2a42;
    --code-bg: #17181b;
    --warn: #ff8a80;
    --warn-bg: #3b1d1b;
    --busy: #7bd88f;
    --busy-bg: #17301f;
  }
}

* {
  box-sizing: border-box;
}

/* Elements styled with display: block/flex/grid would otherwise ignore the hidden attribute. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 16px calc(32px + env(safe-area-inset-bottom));
}

#bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

#back {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

#heading {
  flex: 1;
  min-width: 0;
  max-width: 820px;
}

#actions {
  flex: none;
  display: flex;
  gap: 6px;
}

.icon {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--accent);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#subtitle {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#subtitle:empty {
  display: none;
}

.mode {
  padding: 0 5px;
  border-radius: 5px;
  background: var(--busy-bg);
  color: var(--busy);
  font-size: 12px;
  font-weight: 600;
}

.mode-default,
.mode-plan {
  background: var(--code-bg);
  color: var(--text);
}

.mode-bypassPermissions {
  background: var(--warn-bg);
  color: var(--warn);
}

#error {
  margin: 8px 16px 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
}

.tier h2 {
  margin: 18px 4px 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tier-needs_answer h2 {
  color: var(--warn);
}

.sessions {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}

.sessions li + li {
  border-top: 1px solid var(--line);
}

.row {
  display: block;
  padding: 10px 14px;
  color: inherit;
  text-decoration: none;
}

.row:active {
  background: var(--code-bg);
}

.row-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}

.row-meta .branch {
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta .ago {
  margin-left: auto;
  flex: none;
}

.badge {
  flex: none;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text);
  font-size: 12px;
}

.badge-needs_answer {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-working {
  background: var(--busy-bg);
  color: var(--busy);
}

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

#older {
  display: block;
  margin: 8px auto;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.item {
  margin: 10px 0;
}

.msg.prompt {
  display: flex;
  justify-content: flex-end;
}

.bubble {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 14px 14px 4px 14px;
  background: var(--prompt-bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.attach {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.text {
  overflow-wrap: anywhere;
}

.text > :first-child {
  margin-top: 0;
}

.text > :last-child {
  margin-bottom: 0;
}

.text h1,
.text h2,
.text h3,
.text h4 {
  margin: 14px 0 6px;
  font-size: 17px;
  white-space: normal;
}

.text p,
.text ul,
.text ol,
.text blockquote,
.text table {
  margin: 6px 0;
}

.text ul,
.text ol {
  padding-left: 22px;
}

.text blockquote {
  padding-left: 10px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

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

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

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

code {
  font-family: var(--mono);
  font-size: 0.88em;
}

:not(pre) > code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--code-bg);
}

pre,
pre.hl-chroma {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre;
}

.notice {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.notice.error {
  color: var(--warn);
}

details.notice {
  text-align: left;
}

details.notice > summary {
  text-align: center;
  cursor: pointer;
}

.tool {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
}

.tool > summary {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
  overflow: hidden;
}

.tool > summary::-webkit-details-marker {
  display: none;
}

.tool-name {
  flex: none;
  font-weight: 600;
}

.tool-target {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

.tool-stat {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.tool-state {
  flex: none;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.tool.pending .tool-state {
  color: var(--busy);
}

.tool.error {
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
}

.tool.error .tool-state {
  color: var(--warn);
}

.tool-body {
  padding: 0 10px 8px;
}

.tool-body .path {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.tool-body pre.out {
  max-height: 360px;
  overflow: auto;
}

.qa .q {
  font-weight: 500;
}

.qa .a {
  color: var(--busy);
}

.todos {
  margin: 4px 0;
  padding-left: 20px;
}

.todo-completed {
  color: var(--muted);
  text-decoration: line-through;
}

.todo-in_progress {
  font-weight: 600;
}

.truncated {
  color: var(--muted);
  font-size: 12px;
}

#login {
  display: grid;
  gap: 12px;
  padding-top: 24px;
}

#login[hidden] {
  display: none;
}

.card {
  padding: 16px;
  border-radius: 12px;
  background: var(--surface);
}

.card p {
  margin: 0 0 12px;
}

#pair-form {
  display: grid;
  gap: 10px;
}

#pair-form label {
  color: var(--muted);
  font-size: 14px;
}

#pair-code {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: 20px/1.2 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#login button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#login button.primary {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.login-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
}

#chat {
  padding-bottom: 0;
}

.banner {
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
}

.banner.error {
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
  color: var(--warn);
}

.banner p {
  margin: 0;
}

.banner button {
  margin-top: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 12px -16px 0;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

#prompt,
#new-prompt {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* Below 16px iOS zooms the page when the field gets focus. */
  font-size: 16px;
  resize: none;
}

#prompt {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 160px;
  padding: 8px 14px;
  border-radius: 20px;
}

.round {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.round:disabled {
  opacity: 0.4;
  cursor: default;
}

.round.stop {
  background: var(--warn);
  font-size: 15px;
}

#newsession {
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

.picker {
  padding: 12px 12px 4px;
}

.picker-head {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

#folder-current.path {
  color: var(--text);
  font-family: var(--mono);
}

#folder-up {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 16px;
  background: var(--bg);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.picker .tier h2 {
  margin-top: 12px;
}

.picker .sessions {
  background: var(--bg);
}

.row.folder {
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#new-form {
  display: grid;
  gap: 10px;
}

#new-prompt {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  border-radius: 10px;
}

#new-form button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#new-form button:disabled {
  opacity: 0.4;
  cursor: default;
}
