:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181f;
  --ink: #e8edf5;
  --muted: #8b95a7;
  --line: #2a3140;
  --accent: #3dd68c;
  --accent-ink: #062315;
  --danger: #ff6b6b;
  --focus: #7aa2ff;
  --warn: #f0c674;
  font-family: "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

html.theme-home,
body.theme-home {
  --bg: #0a2416;
  --panel: #123322;
  --line: #1e4a34;
  --accent: #4adf8a;
  --accent-ink: #062315;
}

body.theme-home .app,
body.theme-home .stage,
body.theme-home .transcript {
  background: var(--bg);
}

body.theme-home .top,
body.theme-home .composer {
  background: #000;
}

body.theme-home .think-live {
  background: transparent;
}

body.theme-home .composer #stop {
  background: rgba(184, 245, 212, 0.7);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  opacity: 1;
}

body.theme-home .composer #stop:disabled {
  opacity: 0.7;
}

html.theme-studio,
body.theme-studio {
  --bg: #09070d;
  --panel: #120e18;
  --ink: #e7e2ee;
  --muted: #8b8296;
  --line: #2c2436;
  --accent: #8d7aa3;
  --accent-ink: #140f1c;
}

body.theme-studio .app,
body.theme-studio .stage {
  background: #09070d;
}

body.theme-studio .transcript {
  background: transparent;
}

body.theme-studio .top,
body.theme-studio .composer,
body.theme-studio .terms {
  background: #07060a;
}

body.theme-studio .think-live {
  background: transparent;
}

body.theme-studio .composer #stop {
  background: #bda6dc;
  color: #140f1c;
  border: 0;
  opacity: 1;
}

body.theme-studio .composer #stop:disabled {
  opacity: 0.72;
}

body.theme-studio .stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background-repeat: no-repeat;
  background-image:
    radial-gradient(circle at 7% 11%, rgba(216, 180, 102, 0.62) 1.4px, transparent 2.2px),
    radial-gradient(circle at 19% 38%, rgba(204, 168, 90, 0.4) 1.3px, transparent 2.1px),
    radial-gradient(circle at 31% 72%, rgba(220, 184, 104, 0.5) 1.4px, transparent 2.2px),
    radial-gradient(circle at 44% 22%, rgba(198, 164, 86, 0.36) 1.3px, transparent 2px),
    radial-gradient(circle at 58% 61%, rgba(214, 176, 96, 0.46) 1.4px, transparent 2.2px),
    radial-gradient(circle at 73% 16%, rgba(208, 170, 92, 0.38) 1.3px, transparent 2.1px),
    radial-gradient(circle at 81% 47%, rgba(224, 186, 108, 0.55) 1.45px, transparent 2.3px),
    radial-gradient(circle at 88% 79%, rgba(200, 164, 84, 0.34) 1.3px, transparent 2px),
    radial-gradient(circle at 14% 86%, rgba(216, 178, 98, 0.44) 1.4px, transparent 2.2px),
    radial-gradient(circle at 63% 88%, rgba(196, 160, 80, 0.32) 1.25px, transparent 2px),
    radial-gradient(circle at 92% 33%, rgba(212, 174, 94, 0.4) 1.3px, transparent 2.1px),
    radial-gradient(circle at 37% 49%, rgba(206, 168, 88, 0.3) 1.25px, transparent 2px),
    radial-gradient(circle at 12% 54%, rgba(218, 180, 100, 0.42) 1.35px, transparent 2.15px),
    radial-gradient(circle at 26% 18%, rgba(210, 172, 92, 0.34) 1.25px, transparent 2px),
    radial-gradient(circle at 49% 78%, rgba(222, 184, 106, 0.48) 1.4px, transparent 2.2px),
    radial-gradient(circle at 67% 34%, rgba(200, 164, 86, 0.36) 1.3px, transparent 2.1px),
    radial-gradient(circle at 76% 70%, rgba(216, 178, 98, 0.44) 1.35px, transparent 2.15px),
    radial-gradient(circle at 5% 28%, rgba(208, 170, 90, 0.32) 1.2px, transparent 1.95px),
    radial-gradient(circle at 53% 8%, rgba(220, 182, 102, 0.4) 1.3px, transparent 2.1px),
    radial-gradient(circle at 84% 58%, rgba(198, 162, 84, 0.34) 1.25px, transparent 2px);
}

body.theme-studio .transcript,
body.theme-studio .think-live {
  position: relative;
  z-index: 2;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

body.in-app {
  height: 100%;
  overflow: hidden;
}

.shell {
  width: 100%;
  max-width: 420px;
  padding: max(24px, env(safe-area-inset-top)) 20px 32px;
}

.mark {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  font-weight: 620;
  margin: 0 0 8px;
}

h2 {
  font-size: 18px;
  margin: 0 0 8px;
  font-weight: 620;
}

.lede {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 16px;
  line-height: 1.45;
}

.login-or, .login-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin: 12px 0;
}

.pw-fallback {
  margin: 8px 0 12px;
}
.pw-fallback summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.webauthn-autofill {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lock-gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(11, 13, 16, 0.94);
}
.lock-gate.hidden {
  display: none !important;
}
.lock-gate .card {
  width: min(420px, 100%);
}

form, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

input[type="password"],
input[type="text"],
textarea {
  width: 100%;
  font-size: 16px;
  padding: 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0e1218;
  color: var(--ink);
  outline: none;
  font-family: inherit;
}

textarea {
  resize: none;
  line-height: 1.4;
  min-height: 72px;
}

#prompt {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

.attachments {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 8px;
  padding-top: 6px;
}

.attach {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
}

.attach img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}

.attach button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  background: #1b1f27;
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1;
}

input:focus, textarea:focus {
  border-color: var(--focus);
}

.row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.row.compact {
  flex-direction: row;
  margin-top: 10px;
}

.row.compact .primary { flex: 1; }
.row.compact .ghost { flex: 0 0 auto; min-width: 56px; }

button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 16px;
  color: inherit;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.small {
  min-height: 36px;
  font-size: 13px;
  padding: 6px 12px;
}

button:disabled {
  opacity: 0.5;
}

.status {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.status.err { color: var(--danger); }
.status.ok { color: var(--accent); }

.who {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--ink);
}

.hidden { display: none !important; }

.session dt {
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
}
.session dd {
  margin: 4px 0 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
}

.foot {
  margin-top: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.app {
  width: 100%;
  max-width: 560px;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  background: var(--bg);
}

@media (min-width: 800px) {
  .app { max-width: 960px; }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  z-index: 8;
  background: var(--bg);
  padding:
    max(14px, env(safe-area-inset-top))
    16px
    12px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 16px rgba(11, 13, 16, 0.55);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.conn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.conn #conn-label {
  font-size: 15px;
  font-weight: 620;
}

.sid {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.terms {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.term-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.term-strip::-webkit-scrollbar { display: none; }

.term-side {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.term-count,
.term-keys {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.term-keys { display: none; }

button.term-nav {
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  font-size: 26px;
  line-height: 1;
}

button#term-new {
  font-size: 28px;
  font-weight: 500;
}

.term-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  min-height: 44px;
  max-width: 250px;
  background: #0e1218;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  touch-action: manipulation;
}

.term-chip.current {
  border-color: var(--accent);
  background: #123322;
}

.term-chip.arm-close {
  border-color: var(--danger);
}

.term-chip.closing {
  opacity: 0.45;
}

button.term-chip-open {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 176px;
  min-height: 44px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 6px 8px 6px 10px;
  font-size: 13px;
  font-weight: 600;
  touch-action: manipulation;
}

button.term-x {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  touch-action: manipulation;
}

button.term-x:hover,
button.term-x:focus-visible {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
}

.term-chip.arm-close button.term-x {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.term-chip .term-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.term-chip .term-where {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.term-chip .hot-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: middle;
}

body.theme-home .term-chip.current {
  background: #0c2a1c;
}

body.theme-studio .term-chip.current {
  background: #140f1c;
  border-color: #3a2e48;
}

button.computer-pick.studio-mac {
  background: #120e18;
  border-color: #2c2436;
}

.transcript.pending-sync {
  visibility: hidden;
}

@media (min-width: 800px) {
  .term-keys { display: inline; }
  .term-chip { max-width: 320px; }
  button.term-chip-open { max-width: 250px; }
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot.ok { background: var(--accent); }
.dot.busy { background: var(--warn); }
.dot.err { background: var(--danger); }
.dot.reauth { background: var(--focus); }

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

.banner.err {
  color: var(--danger);
  border-color: #4a2428;
}

.computer-picker {
  margin-top: 8px;
}
.computer-pick-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
button.computer-pick {
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 16px;
  padding: 16px;
  font: inherit;
}
button.computer-pick .meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}
button.computer-pick.home-mac {
  background: #123322;
  border-color: #1e4a34;
}

button.computer-pick.offline {
  opacity: 0.55;
}

.picker {
  margin: 12px 14px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

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

.picker ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button.pick {
  width: 100%;
  text-align: left;
  background: #0e1218;
  border: 1px solid var(--line);
}

.pick-title { font-size: 15px; }
.pick-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  word-break: break-all;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scroll-pin {
  height: 1px;
  flex: 0 0 auto;
  pointer-events: none;
}

.stage.thinking .transcript {
  padding-bottom: 8px;
}

.card-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.card-row.copied {
  outline: 1px solid var(--accent);
}

.card-row.user {
  border-color: #2a3a2f;
}

.card-row .head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-row .label,
.card-row summary {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
}

.card-row summary { cursor: pointer; }

.card-row .meta {
  font-size: 12px;
  color: var(--muted);
}

.card-row .meta.ok { color: var(--accent); }
.card-row .meta.err { color: var(--danger); }
.card-row .meta.busy { color: var(--warn); }

.card-row .body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.5;
}

.card-row.assistant .body,
.card-row.user .body {
  font-family: inherit;
  font-size: 16px;
}

.inline-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  color: #e6c07b;
  background: rgba(230, 192, 123, 0.1);
  border-radius: 5px;
  padding: 0.08em 0.35em;
}

.code-block {
  position: relative;
  margin: 10px 0;
  padding: 12px 12px 10px;
  background: #0d1117;
  border: 1px solid #2a3140;
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #d6deeb;
}

.code-block code {
  font: inherit;
}

.code-lang {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7aa2ff;
  margin-bottom: 8px;
}

.code-block.streaming {
  outline: 1px dashed rgba(122, 162, 255, 0.35);
}

.tok-kw { color: #c792ea; }
.tok-str { color: #ecc48d; }
.tok-cmt { color: #637777; font-style: italic; }
.tok-num { color: #f78c6c; }
.tok-fn { color: #82aaff; }
.tok-type { color: #ffcb6b; }
.tok-prop { color: #7fdbca; }
.tok-ink { color: #d6deeb; }
.tok-ansi-red { color: #ff6b6b; }
.tok-ansi-green { color: #3dd68c; }
.tok-ansi-yellow { color: #f0c674; }
.tok-ansi-blue { color: #7aa2ff; }
.tok-ansi-magenta { color: #c792ea; }
.tok-ansi-cyan { color: #7fdbca; }
.tok-ansi-white { color: #e8edf5; }
.tok-ansi-black { color: #5c6773; }

.card-row.thought .body {
  color: var(--muted);
  font-size: 13px;
}

.think-live {
  position: relative;
  flex: 0 0 128px;
  height: 128px;
  width: 100%;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: transparent;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.think-live.driving {
  border-top-color: var(--accent);
  box-shadow: inset 0 3px 0 var(--accent);
}

.think-live canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.plan-item {
  display: flex;
  gap: 8px;
  font-size: 14px;
  margin: 4px 0;
  font-family: inherit;
}

.plan-mark { color: var(--muted); width: 1.2em; }
.plan-item.ok .plan-mark { color: var(--accent); }
.plan-item.err .plan-mark { color: var(--danger); }
.plan-item.busy .plan-mark { color: var(--warn); }

.composer {
  flex: 0 0 auto;
  z-index: 8;
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.composer #stop {
  width: 100%;
  margin-bottom: 8px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.mac-status {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.mac-status.panel {
  margin: 10px 14px 0;
}

.mac-status h2 {
  font-size: 15px;
  margin: 0 0 8px;
}

.mac-status p {
  margin: 0 0 10px;
}

.mac-status p:last-child {
  margin-bottom: 0;
}

.mac-status summary {
  cursor: pointer;
  font-weight: 620;
  color: var(--ink);
}

.mac-status .power-line {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}

.install {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 0 0 20px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.stepup {
  margin: 12px 14px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.stepup p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 0 0 14px;
}

.stepup .primary {
  width: 100%;
}

.wake-hint {
  color: var(--warn);
  font-size: 13px;
  line-height: 1.45;
  margin: 10px 0 0;
}

.composer .wake-hint {
  margin: 0 0 8px;
}

.perm-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.perm-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  color: var(--ink);
}

.perm-val {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  flex: 0 1 auto;
}

.perm-val.ok { color: var(--accent); }
.perm-val.err { color: var(--danger); }
