:root,
:root[data-theme='dark'] {
  --bg: #1f1e1d;
  --surface: #2a2927;
  --raised: #34332f;
  --line: rgb(255 255 255 / 0.08);
  --text: #eeede9;
  --muted: #a19f98;
  --faint: #6f6d67;
  --accent: #d97757;
  --accent-soft: rgb(217 119 87 / 0.14);
  --on-accent: #ffffff;
  --ok: #6bbf7a;
  --danger: #e5614f;
  --danger-soft: rgb(229 97 79 / 0.14);
  --code: #191817;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --raised: #efede6;
  --line: rgb(0 0 0 / 0.08);
  --text: #1f1e1d;
  --muted: #6f6d67;
  --faint: #a19f98;
  --accent: #c96442;
  --accent-soft: rgb(201 100 66 / 0.1);
  --on-accent: #ffffff;
  --ok: #3f9a50;
  --danger: #cf4a38;
  --danger-soft: rgb(207 74 56 / 0.1);
  --code: #f1efe8;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.55 system-ui, -apple-system, 'Segoe UI Variable Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

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

svg {
  width: 20px;
  height: 20px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-icon] {
  display: inline-flex;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.round {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
}

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

.ghost:active {
  background: var(--raised);
}

/* ---------- chat list ---------- */

.top {
  padding: 18px 16px 10px;
}

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

.mark {
  color: var(--accent);
}

.mark svg {
  width: 26px;
  height: 26px;
}

h1 {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0;
  flex: 1;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 3px 10px 3px 8px;
  border-radius: 99px;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.status.online i {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgb(107 191 122 / 0.2);
}

.chips {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chip {
  flex: none;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

#chat-list {
  padding: 4px 12px 96px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}

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

.row .glyph {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--raised);
  color: var(--muted);
  display: grid;
  place-items: center;
  flex: none;
}

.row.current {
  border-color: var(--accent);
}

.row.current .glyph {
  background: var(--accent-soft);
  color: var(--accent);
}

.row .text {
  min-width: 0;
  flex: 1;
}

.row b {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 550;
  font-size: 15px;
  line-height: 1.35;
}

.row small {
  color: var(--faint);
  font-size: 12.5px;
}

.fab {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px 12px 18px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.fab:active {
  transform: translateX(-50%) scale(0.97);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 56px 24px;
  font-size: 14.5px;
}

.empty b {
  display: block;
  color: var(--text);
  font-size: 17px;
  margin-bottom: 4px;
}

/* ---------- chat ---------- */

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

.title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

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

#note {
  color: var(--muted);
  font-size: 12.5px;
}

.mode {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 8px 5px 12px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}

.mode svg {
  width: 16px;
  height: 16px;
}

.mode.danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

#log {
  padding: 16px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--raised);
  padding: 9px 14px;
  border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user .thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0 6px;
}

.user .thumbs img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  border-radius: 12px;
}

.claude {
  overflow-wrap: anywhere;
}

.claude pre {
  background: var(--code);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0;
}

.claude code,
.tool,
.perm .detail {
  font: 13px/1.5 ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
}

.claude :not(pre) > code {
  background: var(--raised);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.88em;
}

.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  min-width: 0;
}

.tool svg {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--faint);
}

.tool b {
  color: var(--text);
  font-weight: 600;
  flex: none;
}

.tool span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 12px;
  white-space: pre-wrap;
  font-size: 14px;
}

.perm {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  padding: 12px 14px;
}

.perm > b {
  display: block;
  font-weight: 600;
}

.perm .detail {
  background: var(--code);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 30vh;
  overflow-y: auto;
}

.perm .why {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.perm .buttons {
  display: flex;
  gap: 8px;
}

.perm .buttons button {
  flex: 1;
  padding: 9px;
  border-radius: 10px;
  font-weight: 600;
  background: var(--raised);
}

.perm .buttons .allow {
  background: var(--accent);
  color: var(--on-accent);
}

.perm.done {
  border-left-color: var(--line);
  opacity: 0.65;
}

.perm .answer {
  color: var(--muted);
  font-size: 13px;
}

#typing {
  display: flex;
  gap: 5px;
  padding: 6px 16px 16px;
}

#typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite ease-in-out;
}

#typing i:nth-child(2) {
  animation-delay: 0.15s;
}

#typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.composer-wrap {
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
}

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px;
  box-shadow: var(--shadow);
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 8px 4px;
  max-height: 38vh;
}

textarea::placeholder {
  color: var(--faint);
}

.send {
  background: var(--accent);
  color: var(--on-accent);
}

.send.stop {
  background: var(--text);
  color: var(--bg);
}

#attachments {
  display: flex;
  gap: 8px;
  padding: 4px 4px 8px;
  overflow-x: auto;
}

.attachment {
  position: relative;
  flex: none;
}

.attachment img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.attachment button {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
}

.attachment svg {
  width: 12px;
  height: 12px;
  stroke-width: 2.5;
}

/* ---------- mode sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  animation: fade 0.15s ease-out;
}

.sheet-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 12px max(16px, env(safe-area-inset-bottom));
  animation: rise 0.2s ease-out;
}

.grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 10px;
}

.sheet h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 4px 8px 8px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 10px;
  border-radius: 12px;
}

.option:active,
.option.on {
  background: var(--raised);
}

.option .text {
  flex: 1;
}

.option b {
  display: block;
  font-weight: 600;
}

.option small {
  color: var(--muted);
  font-size: 13px;
}

.option .check {
  color: var(--accent);
  visibility: hidden;
}

.option.on .check {
  visibility: visible;
}

.option.danger b {
  color: var(--danger);
}

@keyframes rise {
  from {
    transform: translateY(100%);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.field {
  display: block;
  margin: 0 8px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  font: 14px/1.4 ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
  outline: 0;
}

.field input:focus {
  border-color: var(--accent);
}

.field-error {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 8px 0;
}

#folder-chips {
  margin: 12px 8px 16px;
  flex-wrap: wrap;
}

.primary {
  display: block;
  width: calc(100% - 16px);
  margin: 0 8px;
  padding: 12px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
