:root {
  color-scheme: dark;
  /* VSCode's Dark Modern theme, with Claude's orange for Claude Code. */
  --bg: #181818;
  --panel: #1f1f1f;
  --panel-2: #2a2a2a;
  --input: #313131;
  --line: #2b2b2b;
  --line-strong: #3c3c3c;
  --text: #cccccc;
  --bright: #e7e7e7;
  --muted: #9d9d9d;
  --accent: #0078d4;
  --claude: #d97757;
  --green: #2ea043;
  --yellow: #cca700;
  --red: #f85149;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --radius: 6px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", system-ui, Ubuntu, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login-icon { width: 48px; height: 48px; margin: 0 auto; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }
.login input, .login button { padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }
.login button { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.login-error { color: var(--red) !important; min-height: 1.4em; }
code { font-family: var(--mono); font-size: 0.9em; }

/* Layout */
.app { max-width: 820px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.logo { width: 28px; height: 28px; flex: none; }
.project { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.project-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.on::before { background: var(--green); }
.pill.wait::before { background: var(--yellow); }
.pill.off::before { background: var(--red); }

.icon-btn, .stage-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
}

/* Stream */
.stage { position: relative; background: #000; line-height: 0; min-height: 180px; }
.screen { width: 100%; height: auto; display: block; user-select: none; -webkit-user-drag: none; }
.stage.control .screen { touch-action: none; cursor: crosshair; }
.stage.control { outline: 2px solid var(--accent); outline-offset: -2px; }
.stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); font-size: 14px; line-height: 1.4; padding: 16px; text-align: center;
}
.stage-action {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-weight: 600; line-height: 1.2;
}
.stage-action:disabled { opacity: 0.5; }
.stage-quality {
  position: absolute; left: 8px; bottom: 8px; padding: 2px 7px; border-radius: 4px;
  background: rgba(24, 24, 24, 0.75); color: var(--muted); font: 11px/1.6 var(--mono);
}
.stage-btn { position: absolute; right: 8px; bottom: 8px; background: rgba(24, 24, 24, 0.75); }
.stage:fullscreen { display: grid; place-items: center; }
.stage:fullscreen .screen { width: 100%; height: 100%; object-fit: contain; }

/* Controls */
.controls { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.ctl {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 7px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); font-size: 13px;
}
.ctl[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }

/* Keyboard */
.keyboard { padding: 8px 12px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); }
.key-row { display: flex; gap: 6px; }
.key {
  flex: 1; min-width: 0; padding: 11px 0; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2);
  font-size: 13px; touch-action: none; user-select: none;
}
.key.wide { flex: 3; }
.key.down { background: var(--accent); border-color: var(--accent); }
.type-form { display: flex; gap: 6px; }
.type-form input { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.type-form button { padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }

/* Claude Code -- laid out like its VSCode panel: one conversation at a
   time, your messages boxed, Claude's steps as a dotted timeline. */
.chat { flex: 1; display: flex; flex-direction: column; background: var(--panel); }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.session-button {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; background: none; border: none; text-align: left; color: var(--bright);
}
.session-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chevron { flex: none; color: var(--muted); }
.spark { color: var(--claude); font-size: 15px; line-height: 1; flex: none; }
.session-summary { flex: none; font-size: 12px; color: var(--muted); }
.session-summary.working { color: var(--claude); }
.icon-btn.small { width: 28px; height: 28px; border: none; background: none; color: var(--muted); }
.icon-btn.small:hover { background: var(--panel-2); color: var(--text); }

.session-list {
  display: grid; padding: 4px; border-bottom: 1px solid var(--line);
  background: var(--bg); max-height: 50vh; overflow-y: auto;
}
.session-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: none; border-radius: var(--radius); background: none; text-align: left;
}
.session-row:hover, .session-row.current { background: var(--panel-2); }
.session-row-icon { width: 8px; text-align: center; color: var(--muted); }
.session-row-text { min-width: 0; display: grid; }
.session-row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--bright); }
.session-row-meta { font-size: 12px; color: var(--muted); }

.transcript { flex: 1; padding: 14px 12px 20px; display: grid; gap: 10px; align-content: start; }

.msg-user {
  justify-self: stretch; padding: 8px 12px; border-radius: var(--radius);
  background: var(--input); border: 1px solid var(--line-strong);
  color: var(--bright); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* Each step hangs off a dot; a hairline joins consecutive steps. */
.step { position: relative; display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 8px; align-items: start; }
.step + .step::before {
  content: ""; position: absolute; left: 3.5px; top: -10px; height: 12px;
  border-left: 1px solid var(--line-strong);
}
.dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.reply { background: var(--bright); }
.dot.ok { background: var(--green); }
.dot.error { background: var(--red); }
.dot.running { background: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
.dot.idle { background: var(--line-strong); }
.reply-text { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

.tool-line { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.tool-name { font-weight: 600; color: var(--bright); flex: none; }
.tool-args {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono); font-size: 12.5px; color: var(--muted);
}
.tool-time { margin-left: auto; flex: none; font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-left: 6px; }
.step.error .tool-name, .step.error .tool-time { color: var(--red); }
.step.expandable { cursor: pointer; }
.tool-detail {
  margin: 6px 0 0; padding: 8px 10px; border-radius: var(--radius); background: var(--bg);
  border: 1px solid var(--line); font: 12px/1.45 var(--mono); color: var(--muted);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.subagent { margin-left: 22px; border-left: 1px solid var(--line-strong); padding-left: 10px; display: grid; gap: 8px; }
.subagent-head {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 2px 0; background: none; border: none; text-align: left;
}
.subagent-head .dot { margin-top: 0; }
.subagent-label { flex: none; font-weight: 600; color: var(--bright); }
.subagent-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.subagent-failed { flex: none; margin-left: auto; font-size: 12px; color: var(--red); }
.subagent-steps { display: grid; gap: 8px; font-size: 13px; }

.working-line { display: flex; align-items: center; gap: 8px; color: var(--claude); }
.working-line .tool-time { color: var(--muted); }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.link-button { justify-self: start; padding: 0; background: none; border: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; }

.empty-chat { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty-chat p { margin: 8px 0 0; }
.empty-spark { font-size: 28px; color: var(--claude); }

/* Composer -- Claude Code's input box: the field and its controls in one frame. */
.composer {
  position: sticky; bottom: 0; z-index: 5;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.composer-box {
  display: grid; gap: 4px; padding: 8px 8px 6px 12px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--input);
}
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea {
  width: 100%; resize: none; max-height: 160px; padding: 2px 0;
  border: none; outline: none; background: none; color: var(--bright);
}
.composer-foot { display: flex; align-items: center; gap: 4px; }
.composer-foot .icon-btn.small { margin-left: -6px; margin-right: 2px; }
.icon-btn.small[aria-pressed="true"] { color: var(--claude); }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 4px 2px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line-strong); font-size: 12.5px;
}
.chip.studio { border-color: var(--claude); }
.chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove {
  width: 22px; height: 22px; flex: none; border: none; border-radius: 50%;
  background: none; color: var(--muted); font-size: 15px; line-height: 1;
}
.chip-remove:hover { background: var(--input); color: var(--text); }

/* Permission requests -- Claude Code is blocked until one is answered. */
.permissions { display: grid; gap: 8px; }
.permissions:not(:empty) { margin-bottom: 8px; max-height: 45vh; overflow-y: auto; }
.permission {
  display: grid; gap: 8px; padding: 10px 12px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--claude);
}
.permission-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.permission-title { font-weight: 600; color: var(--bright); }
.permission-session { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.permission-summary {
  display: block; padding: 6px 8px; border-radius: var(--radius); background: var(--panel);
  font: 12.5px/1.45 var(--mono); color: var(--bright); white-space: pre-wrap; overflow-wrap: anywhere;
}
.permission-detail summary { font-size: 12.5px; color: var(--muted); cursor: pointer; }
.permission-detail .tool-detail { max-height: 30vh; overflow-y: auto; }
.permission-actions { display: flex; gap: 8px; }
.permission-actions button {
  flex: 1; padding: 9px; border-radius: 8px; font-weight: 600;
  border: 1px solid var(--line-strong); background: var(--panel-2);
}
.permission-actions .allow { background: var(--accent); border-color: var(--accent); color: #fff; }
.permission-actions button:disabled { opacity: 0.5; }
.composer-target { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.send {
  width: 28px; height: 28px; flex: none; border-radius: 50%; border: none;
  background: var(--claude); color: #fff; display: grid; place-items: center;
}
.send:disabled { opacity: 0.4; }

/* Toasts */
.toasts { position: fixed; left: 12px; right: 12px; top: 12px; z-index: 20; display: grid; gap: 8px; pointer-events: none; }
.toast {
  justify-self: center; max-width: 520px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--line); font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-color: var(--red); }
