:root {
  --bg: #14160f;
  --bg-2: #1c2216;
  --card: #232a1c;
  --line: rgba(243, 240, 228, 0.1);
  --text: #f3f0e4;
  --muted: #a7ad9b;
  --accent: #d6f25c;
  --ink: #17200a;
  --danger: #ff8d7a;
  --ok: #b7e3a1;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --tabs: calc(92px + env(safe-area-inset-bottom));
  --kb: 0px;
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: #0e100c; color: var(--text); }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre, .mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

#app {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(20, 22, 15, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#back, #top-action, .icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
}
#back svg, #top-action svg, .icon-btn svg { width: 22px; height: 22px; }
.titles { flex: 1; min-width: 0; }
#kicker { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
#title { margin: 0; font-size: 22px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main {
  flex: 1;
  padding: 16px 16px calc(var(--tabs) + var(--kb));
}
body.no-tabs main { padding-bottom: calc(16px + env(safe-area-inset-bottom) + var(--kb)); }
body.chat-mode main { padding-bottom: calc(8px + var(--kb)); display: flex; flex-direction: column; }
body.chat-mode #main { min-height: 0; }

#tabs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: min(688px, calc(100% - 16px));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 6px;
  background: rgba(28, 34, 22, 0.94);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(16px);
}
#tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 18px;
  min-height: 54px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
}
#tabs button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.active { background: #31401c; color: var(--accent); }
body.no-tabs #tabs { display: none; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: #15190f;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #8ea84a; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.btn, button.primary, button.ghost, button.danger {
  border-radius: 14px;
  min-height: 46px;
  border: 0;
  padding: 0 14px;
}
button.primary { background: var(--accent); color: var(--ink); font-weight: 700; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: #3a221c; color: var(--danger); }
button:disabled { opacity: 0.55; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  width: 100%;
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.item strong { font-size: 16px; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: #31401c;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions button { flex: 1; min-height: 40px; border-radius: 12px; border: 1px solid var(--line); background: transparent; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chips button, .suggest button {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  min-height: 36px;
  padding: 0 12px;
}
.chips button.active { background: var(--accent); color: var(--ink); border-color: transparent; }
.suggest { display: flex; flex-direction: column; gap: 8px; }
.suggest button { text-align: left; border-radius: 14px; min-height: 44px; }

#msgs { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.bubble { max-width: 92%; padding: 10px 12px; border-radius: 16px; line-height: 1.45; word-break: break-word; }
.bubble.user { margin-left: auto; background: #31401c; border-bottom-right-radius: 6px; }
.bubble.assistant { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.tool, .note {
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
}
.bubble pre {
  overflow: auto;
  background: #10140c;
  padding: 10px;
  border-radius: 12px;
  font-size: 13px;
}
.bubble code { font-size: 0.92em; }
.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding-top: 8px;
  background: linear-gradient(transparent, var(--bg) 20%);
}
.composer textarea { min-height: 52px; max-height: 140px; flex: 1; }
.composer button.send { width: 52px; min-width: 52px; flex: 0 0 52px; display: grid; place-items: center; padding: 0; }
.composer button.send svg { width: 22px; height: 22px; }
.approval { border: 1px solid #8ea84a; }
.approval pre {
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  background: #10140c;
  padding: 10px;
  border-radius: 12px;
  font-size: 12px;
}
.status-line { min-height: 18px; font-size: 13px; color: var(--accent); }
.bar { height: 8px; background: #10140c; border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }

#sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  align-items: end;
  z-index: 20;
}
#sheet[hidden] { display: none; }
.sheet-card {
  background: var(--bg-2);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 720px;
  width: min(720px, 100%);
  margin: 0 auto;
}
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
.hide { display: none !important; }
.error { color: var(--danger); min-height: 1.2em; }
.file-row { flex-direction: row; justify-content: space-between; align-items: center; }
.crumb { color: var(--muted); font-size: 13px; word-break: break-all; }
#editor-box { min-height: 55dvh; }

.ico-wrap, .mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.ico-wrap svg, .mark svg { width: 22px; height: 22px; }
.tone-lime { background: #31401c; color: var(--accent); }
.tone-sand { background: #3a3424; color: #f0d48a; }
.tone-rose { background: #3c2420; color: #ffb4a8; }
.tone-sky { background: #243038; color: #9ad7ff; }
.tone-mint { background: #24382c; color: var(--ok); }

.menu {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.menu-row {
  width: 100%;
  min-height: 68px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
}
.menu-row:last-child { border-bottom: 0; }
.menu-row:active { background: rgba(255, 255, 255, 0.04); }
.menu-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.menu-copy strong { font-size: 16px; font-weight: 650; }
.menu-copy span, .chev { color: var(--muted); font-size: 13px; }
.chev { font-size: 22px; line-height: 1; padding-right: 2px; }
.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 8px;
}
.profile .mark { width: 52px; height: 52px; border-radius: 18px; }
.profile h2 { margin: 0; font-size: 20px; }
.hero { text-align: center; padding: 12px 8px 4px; }
.hero .mark { width: 64px; height: 64px; border-radius: 22px; margin: 0 auto 12px; }
.hero h2 { margin: 0 0 4px; }
.choice {
  width: 100%;
  text-align: left;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.choice.on { border-color: #8ea84a; background: #26321c; }
.stats { display: grid; grid-template-columns: 1fr; gap: 8px; }
.stat { background: var(--bg-2); border-radius: 16px; padding: 14px; }
.stat b { display: block; font-size: 28px; letter-spacing: -0.03em; }
.device { padding: 8px; display: flex; flex-direction: column; gap: 0; }
.device-main {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  min-height: 64px;
  padding: 6px;
}
.device-actions { display: flex; gap: 8px; padding: 0 6px 6px 60px; }
.device-actions button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
}
.device-actions svg { width: 18px; height: 18px; }
.file-row.item, button.item {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  min-height: 58px;
}
