:root {
  /* Icons drawn with CSS masks, for symbols phone fonts may lack (see js/icons.js). */
  --ico-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5l5 5L19.5 7'/%3E%3C/svg%3E");
  --ico-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E");
  --ico-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 5l7 7-7 7'/%3E%3C/svg%3E");
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #6e7681;
  --accent: #7ee787;
  --accent-ink: #0d1117;
  --cyan: #79c0ff;
  --yellow: #d29922;
  --red: #ff7b72;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--cyan); }

/* Pinned to the visible screen: --app-h / --app-top follow the visual viewport (ui.js
   fitViewport), so a keyboard or a browser bar that comes and goes never leaves the page
   taller than the screen. */
.app {
  display: flex; flex-direction: column; position: fixed; left: 0; right: 0; top: var(--app-top, 0px);
  height: var(--app-h, 100dvh); max-width: 820px; margin: 0 auto;
}

header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
header h1 { font-size: 16px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header h1 small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: none; border: 0; padding: 6px 8px; border-radius: 8px; color: var(--muted);
  font-size: 20px; line-height: 1; min-width: 36px; min-height: 36px;
}
.icon-btn:active { background: var(--panel-2); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.ok { background: var(--accent); }
.dot.busy { background: var(--yellow); animation: pulse 1.2s infinite; }
.dot.err { background: var(--red); }
@keyframes pulse { 50% { opacity: .35; } }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; /* >=16px stops iOS zoom-on-focus */
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--cyan); }
input[type=search] { -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; min-height: 96px; }
.row { display: flex; gap: 10px; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--dim); margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px;
  padding: 11px 16px; font-weight: 600; min-height: 44px;
}
.btn:active { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; margin-top: 18px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 8px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }

.cs-list { display: flex; flex-direction: column; gap: 8px; }
.cs {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border);
}
.cs .meta { flex: 1; min-width: 0; }
.cs .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs .sub { font-size: 12.5px; color: var(--muted); }
.empty { color: var(--dim); font-size: 14px; padding: 12px 0; }

/* Terminal */
#term {
  font: 13px/1.5 var(--mono); padding: 12px 14px 20px; white-space: pre-wrap; word-break: break-word;
}
.ev { margin: 0 0 6px; }
.ev.prompt { color: var(--accent); font-weight: 700; margin-top: 14px; }
.ev.prompt::before { content: ""; display: inline-block; width: .9em; height: .9em; margin-right: .45em; vertical-align: -0.1em; background: currentColor; -webkit-mask: var(--ico-chevron) center / contain no-repeat; mask: var(--ico-chevron) center / contain no-repeat; }
.ev.system, .ev.local { color: var(--dim); }
.ev.local::before { content: "· "; }
.ev.text { color: var(--text); font-family: var(--sans); font-size: 14.5px; }
.ev.tool { color: var(--cyan); }
.ev.tool b { font-weight: 700; }
.ev.tool .detail { color: var(--muted); display: block; padding-left: 14px; }
.ev.result {
  color: var(--dim); border-left: 2px solid var(--border); padding-left: 10px; margin-left: 4px;
  max-height: 7.5em; overflow: hidden; position: relative;
}
.ev.result.open { max-height: none; }
.ev.result.long:not(.open)::after {
  content: "tap to expand"; position: absolute; right: 0; bottom: 0; padding: 0 6px;
  background: var(--bg); color: var(--muted); font-size: 11px;
}
.ev.result.err { color: var(--red); border-color: var(--red); }
.ev.stderr { color: var(--yellow); }
.ev.error { color: var(--red); }
.ev.done { color: var(--accent); font-weight: 600; margin-top: 8px; }
.ev.done.fail { color: var(--red); }
.ev.ask { border: 1px solid var(--yellow, #e3b341); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.ev.ask.answered { border-color: var(--border); }
.ev.ask .ask-cmd { display: block; white-space: pre-wrap; word-break: break-word; font-size: 12px; color: var(--muted); margin: 6px 0; max-height: 7.5em; overflow: auto; }
.ev.ask .ask-state:empty { display: none; }
.ev.ask.yes .ask-state { color: var(--accent); }
.ev.ask.no .ask-state { color: var(--red); }
.ev.ask .ask-when { display: block; color: var(--dim); }
.ev.ask .ask-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ev.ask .ask-btns .btn { flex: 1 1 auto; min-height: 40px; padding: 6px 12px; }
.ev.apk { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.ev.apk.ok { border-color: var(--accent); }
.ev.apk.fail { border-color: var(--red); }
.ev.apk .apk-err { white-space: pre-wrap; font-size: 12px; color: var(--dim); max-height: 7.5em; overflow: hidden; margin: 6px 0 0; cursor: pointer; }
.ev.apk .apk-err.open { max-height: none; }
.ev.site { border: 1px solid var(--accent); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.ev.site a.btn { display: inline-block; margin-top: 6px; text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; }
.ev.divider { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; margin: 14px 0 6px; }
.ev.divider::before, .ev.divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.ev.divider.archived { text-align: center; }
.ev.divider.archived::before, .ev.divider.archived::after { flex: 0 0 16px; }
.ev.divider.archived { cursor: pointer; color: var(--accent, inherit); }

.composer {
  border-top: 1px solid var(--border); background: var(--bg);
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
}
.composer .row { align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 40vh; resize: none; padding: 10px 12px; }
.send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 700;
}
.send.stop { background: var(--red); color: #fff; font-size: 16px; }
.completed-bar { display: none; margin-bottom: 10px; }
.completed-bar.show { display: block; }
.completed-bar .btn { width: 100%; }

/* Sheets */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; z-index: 10;
  align-items: flex-end; justify-content: center;
}
.sheet-bg.show { display: flex; }
.sheet {
  width: 100%; max-width: 820px; max-height: 88dvh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0; border: 1px solid var(--border); border-bottom: 0;
  padding: 18px 16px calc(var(--safe-bottom) + 18px);
}
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .opts { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.opt { text-align: left; display: block; width: 100%; padding: 14px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--border); }
a.opt { text-decoration: none; color: inherit; }
a.opt b { color: var(--cyan); }
.opt b { display: block; }
.opt span { color: var(--muted); font-size: 13px; }
.opt.danger b { color: var(--red); }
.opt-row { display: flex; gap: 8px; align-items: stretch; }
.opt-row .opt { flex: 1; min-width: 0; }
.opt-side { flex: none; padding: 0 14px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid var(--border); font-weight: 600; color: var(--cyan); white-space: nowrap; }
.opt-side.danger { color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); padding: 10px 14px; border-radius: 10px;
  font-size: 14px; max-width: calc(100% - 32px); z-index: 20; display: none;
}
.toast.show { display: block; }
/* Model picker + usage meters */
.composer-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.model-select { flex: none; width: auto; max-width: 46%; padding: 6px 8px; font-size: 14px !important; min-height: 34px; border-radius: 8px; }
.usage { display: flex; gap: 10px; flex: 1; min-width: 0; }
.meter { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); }
.meter-top { display: flex; justify-content: space-between; gap: 6px; }
.meter-top b { color: var(--text); }
.meter-track { height: 5px; margin: 3px 0 2px; border-radius: 3px; background: var(--bg); overflow: hidden; border: 1px solid var(--border); }
.meter-fill { height: 100%; background: var(--accent); }
.meter.mid .meter-fill { background: var(--yellow); }
.meter.hi .meter-fill { background: var(--red); }
.meter small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.usage-mini .meter small { display: none; }
.usage-card { margin-top: 22px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.usage-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 600; font-size: 14px; }
.usage-head small { color: var(--muted); font-weight: 400; }
.usage-card .meter { font-size: 13px; }

/* Image viewer */
.viewer { position: fixed; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .72); }
.viewer-box { width: 100%; max-width: 560px; max-height: 88dvh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 14px; border-bottom: 1px solid var(--border); }
.viewer-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 14px; }
.viewer-title small { color: var(--muted); font-size: 12px; }
.viewer-img {
  position: relative; flex: 1; min-height: 180px; display: flex; align-items: center; justify-content: center; padding: 12px;
  background-color: #1c2128;
  background-image: linear-gradient(45deg, #262c34 25%, transparent 25%), linear-gradient(-45deg, #262c34 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #262c34 75%), linear-gradient(-45deg, transparent 75%, #262c34 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  touch-action: pan-y;
}
.viewer-img img { max-width: 100%; max-height: 62dvh; object-fit: contain; image-rendering: auto; }
.viewer-img img.pixel { image-rendering: pixelated; min-width: 96px; }
.viewer-img .spinner { position: absolute; }
.viewer-err { position: absolute; padding: 0 16px; text-align: center; color: var(--text); }
.viewer-nav { display: flex; align-items: center; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border); }
.viewer-nav .hint { flex: 1; text-align: center; margin: 0; }
.viewer-nav .btn { min-height: 40px; padding: 6px 14px; }
.view-btn { flex: none; background: none; border: 1px solid var(--border); border-radius: 8px; min-width: 40px; min-height: 36px; margin-right: 4px; font-size: 16px; }

/* File editor */
.editor {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--bg);
  padding: var(--safe-top) 0 var(--safe-bottom);
}
.editor-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.editor-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.editor-title b, .editor-title small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-title small { color: var(--muted); font: 12px var(--mono); }
.editor-head .btn { min-height: 38px; padding: 6px 16px; }
.editor-tools { display: flex; align-items: center; gap: 12px; padding: 4px 14px; border-bottom: 1px solid var(--border); }
.editor-tools .check { margin: 0; }
.editor-tools .hint { margin: 0; flex: 1; text-align: right; }
.editor-body { position: relative; flex: 1; min-height: 0; display: flex; }
#editorText, .editor-mirror, .gutter, .editor-hl { font: 13.5px/1.55 var(--mono); tab-size: 2; }
#editorText {
  flex: 1; min-width: 0; height: 100%; border: 0; border-radius: 0; resize: none; background: var(--bg); color: var(--text);
  padding: 12px 14px 12px 10px; white-space: pre-wrap; overflow-wrap: anywhere;
}
#editorText.nowrap { white-space: pre; overflow-wrap: normal; overflow-x: auto; }
/* Syntax colours: the text you type is see-through over a coloured copy (files.js paintColours). */
#editorText.hl { position: relative; z-index: 1; background: transparent; color: transparent; caret-color: var(--text); -webkit-text-fill-color: transparent; }
#editorText.hl::selection { background: rgba(56, 139, 253, .35); }
.editor-hl {
  position: absolute; margin: 0; overflow: hidden; pointer-events: none; background: var(--bg); color: var(--text);
  padding: 12px 14px 12px 10px; white-space: pre-wrap; overflow-wrap: anywhere; border: 0;
}
.editor-hl.nowrap { white-space: pre; overflow-wrap: normal; }
.gutter {
  flex: none; overflow: hidden; padding: 12px 8px 60vh 10px; text-align: right; color: var(--dim);
  background: var(--panel); border-right: 1px solid var(--border); user-select: none; -webkit-user-select: none;
  font-variant-numeric: tabular-nums;
}
.gutter div { white-space: nowrap; }
.gutter div.cur { color: var(--text); font-weight: 700; }
/* Invisible copy of the text, used to measure how tall each (wrapped) line is. */
.editor-mirror {
  position: absolute; top: 0; left: -99999px; visibility: hidden; pointer-events: none;
  white-space: pre-wrap; overflow-wrap: anywhere; padding: 0;
}
.editor-mirror div { min-height: 1lh; }
.editor-pos { flex: none !important; text-align: left !important; font-family: var(--mono); }
.editor-note { padding: 8px 14px; margin: 0; border-top: 1px solid var(--border); }
.edit-btn { flex: none; background: none; border: 1px solid var(--border); border-radius: 8px; min-width: 40px; min-height: 36px; margin-right: 4px; color: var(--cyan); font-size: 16px; }

/* Home banners (install, notifications) */
.banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding: 10px 6px 10px 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px;
}
.banner span { flex: 1; min-width: 0; }
.banner .btn { min-height: 38px; padding: 8px 14px; }

/* Home: recent repos, running codespaces, repo search */
.section-title.first { margin-top: 0; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.cs.recent { width: 100%; text-align: left; color: inherit; font: inherit; }
.cs.recent .go { color: var(--muted); font-size: 20px; }
.new-repo { margin-bottom: 12px; padding: 4px 12px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.home-links { justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.repo-list { margin-top: 8px; max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.repo-list:empty { display: none; }
.repo {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0;
  border-bottom: 1px solid var(--border); padding: 10px 12px; min-height: 44px;
}
.repo:last-child { border-bottom: 0; }
.repo:active { background: var(--panel-2); }
.repo .rn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.repo small { color: var(--muted); flex: none; }
.repo-list .empty { padding: 12px; }
.picked { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; font-weight: 600; }
.picked span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.picked .btn.link { min-height: 32px; padding: 0 4px; }

/* Progress */
.progress { padding: 10px 16px 12px; border-bottom: 1px solid var(--border); background: var(--panel); }
.progress-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.progress-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-time { font: 12px var(--mono); color: var(--muted); }
.spinner {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track { height: 6px; margin-top: 8px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .25s linear; }
.progress.ok .spinner, .progress.fail .spinner { animation: none; border-color: transparent; }
.progress.ok .spinner::before, .progress.fail .spinner::before { content: ""; display: block; width: 14px; height: 14px; -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat; }
.progress.ok .spinner::before { --ico: var(--ico-check); background: var(--accent); }
.progress.fail .spinner::before { --ico: var(--ico-x); background: var(--red); }
.progress.fail .progress-fill { background: var(--red); }
.progress.fail .progress-label { white-space: normal; color: var(--red); }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .progress-fill { transition: none; } }

/* Files */
.sheet.files-sheet { padding: 0; }
.files-head { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 18px 16px 8px; border-bottom: 1px solid var(--border); }
.files-title { display: flex; align-items: center; gap: 8px; }
.files-title h3 { flex: 1; margin: 0; }
.files-title .btn.link { min-height: 36px; padding: 0 4px; }
.files-head input[type=search] { margin-top: 10px; }
.pills {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font-size: 13.5px; min-height: 34px; white-space: nowrap;
}
.pill small { color: var(--muted); margin-left: 5px; }
.pill[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.pill[aria-pressed="true"] small { color: var(--accent-ink); }
.file-tree { padding: 4px 8px 8px; }
.file-tree .empty { padding: 16px 8px; }
.node { display: flex; align-items: center; min-height: 46px; padding-left: calc(var(--d, 0) * 18px); border-bottom: 1px solid var(--border); }
.node input { width: 20px; height: 20px; margin: 0 10px 0 6px; flex: none; accent-color: var(--accent); }
.node .nm { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: none; border: 0; text-align: left; padding: 10px 4px; min-height: 44px; }
.nm .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 14px var(--mono); }
.nm small { flex: none; color: var(--muted); font-size: 12px; }
.caret { flex: none; width: 12px; color: var(--muted); transition: transform .15s; }
.node.open .caret { transform: rotate(90deg); }
.node.folder .t { font-weight: 600; font-family: var(--sans); }
.node.sel { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.gh-zip { display: block; margin: 12px 16px 18px; color: var(--cyan); }
.dl-bar {
  position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border-top: 1px solid var(--border); padding: 10px 12px calc(var(--safe-bottom) + 10px);
}
.dl-info { flex: 1; min-width: 0; font-size: 14px; }
.dl-bar .btn { min-height: 42px; padding: 8px 14px; }

/* Setup steps */
.step { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.step.disabled { opacity: .45; pointer-events: none; }
.step-head { display: flex; gap: 12px; align-items: center; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--border); font-weight: 700; font-size: 14px;
}
.step.done .step-num { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.step h2 { font-size: 16px; margin: 0; }
.step-state { font-size: 13px; color: var(--muted); }
.step-body { margin-top: 12px; }
.step-body:empty { display: none; }
.step-body .btn { width: 100%; margin-top: 8px; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--accent-ink); }
.btn.link { background: none; border: 0; color: var(--cyan); font-weight: 500; min-height: 36px; }
.devcode {
  font: 700 30px/1.2 var(--mono); letter-spacing: .12em; text-align: center; padding: 12px;
  background: var(--bg); border-radius: 10px; margin: 8px 0; user-select: all; -webkit-user-select: all;
}
.step-log { font: 12.5px/1.5 var(--mono); color: var(--dim); margin-top: 8px; max-height: 10em; overflow-y: auto; }
.step-log .error { color: var(--red); }
.step-log .stderr { color: var(--yellow); }
.step-error { color: var(--red); font-size: 13.5px; margin-top: 8px; }
.step-error:empty { display: none; }
ol.howto { padding-left: 20px; margin: 4px 0 8px; color: var(--muted); font-size: 14px; }
ol.howto li { margin: 4px 0; }
.hidden { display: none !important; }

/* Repo view */
.repo-head { display: flex; gap: 10px; align-items: center; }
.repo-head select { flex: 1; min-width: 0; }
.repo-head .btn { flex: none; }
.rv-tree { margin-top: 10px; padding: 0; }
.rv-tree .node { padding-left: calc(var(--d, 0) * 18px + 4px); }
.attach-btn { flex: none; background: none; border: 1px solid var(--border); border-radius: 8px; min-width: 44px; min-height: 40px; margin-right: 4px; color: var(--accent); font-size: 18px; }
.node.attached .attach-btn { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
/* File viewer (fileview.js): nearly full height, the file scrolls under a fixed head */
#previewSheet { z-index: 26; }
.preview-sheet { height: 94dvh; max-height: 94dvh; max-width: 980px; display: flex; flex-direction: column; overflow: hidden; padding: 10px 12px calc(var(--safe-bottom) + 10px); }
.preview-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.preview-head .btn { min-height: 38px; padding: 6px 14px; }
.pv-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.pv-tools .check { margin: 0; font-size: 13px; }
.pv-as { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.pv-as select { min-height: 32px; padding: 4px 6px; max-width: 46vw; font-size: 13px; }
.pv-tools .btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.pv-status { margin: 0 0 0 auto; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 6px 12px; color: var(--muted); font-size: 13px; min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); font-weight: 600; }
.pv-body { flex: 1; min-height: 0; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; overscroll-behavior: contain; }
.pv-body > .hint { padding: 14px; margin: 0; }
.preview-img { display: block; max-width: 100%; max-height: 100%; margin: 12px auto; border-radius: 8px; background: #1c2128; }

/* Code: one row per line, numbered by a CSS counter; the numbers stay put when
   long lines scroll sideways. */
.code-view { counter-reset: ln; font: 12.5px/1.55 var(--mono); tab-size: 4; padding: 8px 0; width: max-content; min-width: 100%; }
.code-view.wrap { width: auto; }
.code-view .ln { display: flex; }
.code-view .ln::before {
  counter-increment: ln; content: counter(ln); flex: none; position: sticky; left: 0; width: calc(var(--gw, 2ch) + 18px);
  padding: 0 10px 0 6px; text-align: right; color: var(--dim); background: var(--bg); user-select: none; -webkit-user-select: none;
}
.code-view .lc { white-space: pre; padding-right: 14px; }
.code-view.wrap .lc { white-space: pre-wrap; word-break: break-word; min-width: 0; }
.code-view.plain { font-size: 13px; }
.code-view.plain .ln::before { display: none; }
.code-view.plain .lc { padding-left: 12px; }
.tk-kw { color: #ff7b72; }
.tk-str { color: #a5d6ff; }
.tk-cm { color: #8b949e; font-style: italic; }
.tk-num, .tk-lit { color: #79c0ff; }
.tk-fn { color: #d2a8ff; }
.tk-type { color: #ffa657; }
.tk-tag { color: #7ee787; }
.tk-attr, .tk-key { color: #79c0ff; }
.tk-var { color: #ffa657; }
.tk-meta { color: #d2a8ff; }
.tk-b { font-weight: 700; }
.tk-ins { color: #aff5b4; background: rgba(46, 160, 67, .15); }
.tk-del { color: #ffdcd7; background: rgba(248, 81, 73, .15); }

/* Markdown, close to how GitHub shows it */
.md { padding: 14px 16px 28px; font-size: 15px; line-height: 1.6; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.3em 0 .55em; line-height: 1.25; font-weight: 600; scroll-margin-top: 8px; }
.md h1 { font-size: 1.75em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.4em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.2em; }
.md h4 { font-size: 1em; }
.md h5, .md h6 { font-size: .9em; color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .md-table, .md details, .md .md-alert { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li + li { margin-top: .25em; }
.md li > ul, .md li > ol { margin: .25em 0 0; }
.md a { color: var(--cyan); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code { font: .86em var(--mono); background: rgba(110, 118, 129, .4); padding: .15em .4em; border-radius: 6px; }
.md pre { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow: auto; font: 12.5px/1.5 var(--mono); }
.md pre code { background: none; padding: 0; font: inherit; white-space: pre; }
.md pre[data-lang]::before { content: attr(data-lang); position: absolute; top: 4px; right: 8px; color: var(--dim); font: 11px var(--sans); }
.md blockquote { padding: 0 1em; color: var(--muted); border-left: .25em solid var(--border); }
.md hr { height: 2px; border: 0; background: var(--border); margin: 1.5em 0; }
.md img { max-width: 100%; vertical-align: middle; }
.md .md-table { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 12px; }
.md th { background: var(--panel); font-weight: 600; }
.md tr:nth-child(2n) td { background: rgba(110, 118, 129, .08); }
.md kbd { font: 12px var(--mono); padding: 2px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; background: var(--panel); }
.md mark { background: rgba(210, 153, 34, .4); color: inherit; }
.md details summary { cursor: pointer; font-weight: 600; }
.md ul.md-tasks { list-style: none; padding-left: .4em; }
.md ul.md-tasks ul.md-tasks { padding-left: 0; }
.md li.md-task-item { position: relative; padding-left: 30px; min-height: 26px; }
.md ul.md-tasks > li:not(.md-task-item) { list-style: disc; margin-left: 1.2em; }
.md li.md-done { color: var(--muted); }
.md input.md-task { position: absolute; left: 0; top: .1em; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.md input.md-task:disabled { cursor: default; opacity: .7; }
.md-alert { padding: 8px 14px; border-left: .25em solid var(--cyan); border-radius: 0 6px 6px 0; background: rgba(56, 139, 253, .06); }
.md-alert > :last-child { margin-bottom: 0; }
.md-alert-title { font-weight: 600; margin-bottom: .3em !important; color: var(--cyan); }
.md-alert-tip { border-color: #3fb950; } .md-alert-tip .md-alert-title { color: #3fb950; }
.md-alert-important { border-color: #a371f7; } .md-alert-important .md-alert-title { color: #a371f7; }
.md-alert-warning { border-color: var(--yellow); } .md-alert-warning .md-alert-title { color: var(--yellow); }
.md-alert-caution { border-color: #f85149; } .md-alert-caution .md-alert-title { color: #f85149; }

/* Composer chips: mode, Android tools, attached files */
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 4px 12px;
  border-radius: 17px; border: 1px solid var(--border); background: var(--panel-2); font-size: 13.5px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip[disabled] { opacity: .75; pointer-events: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { font: 12.5px var(--mono); font-weight: 400; max-width: 70vw; }
.chips .chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips .chip b { color: var(--muted); font-size: 16px; line-height: 1; }
.composer-top { flex-wrap: wrap; }
/* Chips stay on one line and scroll sideways; the model picker and meters go on the line below. */
.composer-chips { display: flex; gap: 8px; flex: 1 0 100%; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.composer-chips::-webkit-scrollbar { display: none; }
.composer-chips .chip { flex: none; white-space: nowrap; }
/* Usage meters need room: on a narrow screen they take their own line under the chips. */
.composer-top .usage-mini { min-width: 220px; }

/* Session status strip (Phase 2): mode, state, run link or Start/Standby */
.status-strip { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 4px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--muted); }
.ss-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.status-strip[data-state="running"] .ss-dot, .status-strip[data-state="starting"] .ss-dot { background: var(--yellow); animation: pulse 1.2s infinite; }
.status-strip[data-state="done"] .ss-dot { background: var(--accent); }
.status-strip[data-state="failed"] .ss-dot { background: var(--red); }
.ss-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-link { flex: none; font-weight: 600; text-decoration: none; padding: 8px 4px; }
.status-strip .btn.small { flex: none; min-height: 32px; padding: 4px 12px; }

/* Shared context (Phase 2b): + Context sheet, @mention suggestions, prompt extras */
.ctx-list { margin-top: 10px; }
.ctx-row { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.ctx-row .meta { flex: 1; min-width: 0; }
.ctx-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-row .sub { font-size: 12.5px; color: var(--muted); }
.ctx-row .sub.err { color: var(--red); }
.ctx-row input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.ctx-row .btn.small { flex: none; }
.ctx-build-bar { position: sticky; bottom: 0; padding-top: 8px; background: var(--panel); }
.mention-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.mention { min-height: 36px; padding: 4px 12px; border-radius: 17px; border: 1px solid var(--border); background: var(--panel-2); font: 13.5px var(--mono); color: var(--cyan); }
.ev.prompt .with { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

/* Phase 3: summary card and folded run log */
.summary-card { margin: 12px 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); font-family: var(--sans); white-space: normal; }
.sc-head { font-weight: 700; color: var(--accent); display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.sc-head small { font: 12px var(--mono); color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-text { margin-top: 8px; white-space: pre-wrap; font-size: 14.5px; }
.sc-text.long:not(.open) { max-height: 9em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.sc-ask { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); font-weight: 600; font-size: 14px; }
.sc-files { margin-top: 10px; font-size: 13.5px; color: var(--muted); }
.sc-files b { color: var(--text); font-weight: 600; }
.sc-files ul { margin: 6px 0 0; padding-left: 4px; list-style: none; font: 12.5px/1.6 var(--mono); }
.sc-links { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.sc-links a { text-decoration: none; font-weight: 600; }
.sc-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.sc-actions .btn.small { min-height: 40px; }
details.ev.group { margin: 10px 0; border-left: 2px solid var(--border); padding-left: 10px; }
details.ev.group > summary { cursor: pointer; color: var(--muted); font-family: var(--sans); font-size: 13.5px; padding: 8px 0; }

/* Phase 4: queued message bar */
.queued { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 6px 6px 6px 12px; border: 1px dashed var(--border); border-radius: 10px; background: var(--panel); font-size: 13.5px; color: var(--muted); }
.queued span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queued .icon-btn { min-width: 40px; min-height: 40px; }

/* File browsers: search, sort and upload row (repo view and codespace Files sheet) */
.rv-tools { margin-top: 10px; }
.rv-tools .pills { margin-top: 8px; }
/* Sort and buttons: one row that scrolls sideways (like .pills) when it doesn't fit the screen. */
.tool-row {
  display: flex; gap: 8px; align-items: center; margin: 8px -16px 0; padding: 0 16px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
}
.tool-row::-webkit-scrollbar { display: none; }
.tool-row select { flex: 1 0 140px; min-width: 140px; padding: 8px 10px; font-size: 14px; min-height: 40px; }
.tool-row .btn.small { flex: none; min-height: 40px; }
.rv-tree .node input { margin-left: 2px; }
.rv-dl-bar { position: sticky; bottom: 0; margin-top: 10px; }
.rv-dl-bar .btn { padding: 8px 11px; }
.hub-row { flex-direction: column; align-items: flex-start; gap: 2px; margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.rv-tree .node { -webkit-touch-callout: none; }
.rv-tree .more-btn { margin: 0 -4px 0 -4px; min-width: 36px; min-height: 40px; }
#rvZipLink { display: block; margin-top: 12px; }

/* Inbox: files attached to a message */
.inbox-btn { flex: none; min-width: 44px; min-height: 44px; font-size: 20px; border: 1px solid var(--border); border-radius: 50%; background: var(--panel); }
#inboxChips .chip { font-family: var(--sans); }

/* Row menus: ⋯ button, tap and hold, options sheet */
.cs { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.more-btn { flex: none; min-width: 44px; min-height: 44px; margin: -6px -8px -6px -6px; font-size: 22px; }
.cs.recent { cursor: pointer; }
.cs.recent .more-btn { margin-right: -2px; }
.row-menu-sub { white-space: pre-line; overflow-wrap: anywhere; }
.row-menu-sub.warn { color: var(--yellow); }
#rowMenuSheet { z-index: 12; }

/* Dialogs (confirm / question), replacing the browser's own */
.dialog-bg { z-index: 40; }
.dialog h3 { font-size: 18px; margin-bottom: 8px; }
.dlg-body { white-space: pre-line; overflow-wrap: anywhere; color: var(--text); font-size: 15px; }
.dlg-items { margin: 10px 0 0; padding-left: 20px; font: 13px/1.6 var(--mono); color: var(--muted); max-height: 32dvh; overflow-y: auto; overflow-wrap: anywhere; }
.dlg-warn { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--yellow); border-radius: 10px; color: var(--yellow); font-size: 14px; }
.dlg-warn::before { content: "⚠ "; }
.dialog input { margin-top: 12px; }
.dialog .pills { margin-top: 8px; }
.dialog .hint { margin-top: 10px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 18px; }
.dlg-actions .btn { flex: 1; min-height: 48px; }
.btn.danger-solid { background: var(--red); color: #1b0b09; border-color: transparent; }

/* My machines (machines.js) */
pre.cmd { margin: 6px 0; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-all; user-select: all; }
.store-meter { height: 8px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; }
.store-fill { height: 100%; width: 0; background: var(--cyan); }
.store-fill.full { background: var(--red); }
.hint.warn { color: var(--yellow); }

/* Adding a machine: steps, and the QR scanner */
.add-steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 12px; }
.add-steps .hint { display: block; margin-top: 4px; }
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.scan-frame { position: absolute; left: 50%; top: 42%; width: min(64vw, 280px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); pointer-events: none; }
.scan-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 16px; color: #fff; background: #000; font-size: 15px; }

/* Terminal on a machine (terminal.js) */
.term-screen { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: #0b0d10; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.term-screen.hidden { display: none; }
body.term-open { overflow: hidden; }
.term-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line, #222); }
.term-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 13px var(--mono, monospace); color: #ccc; }
.term-note { margin: 6px 8px 0; }
.term-view { flex: 1; min-height: 0; padding: 4px; overflow: hidden; }
.term-line { display: flex; gap: 6px; padding: 6px 8px; }
.term-line input { flex: 1; min-width: 0; font: 14px var(--mono, monospace); }
.term-keys { display: flex; gap: 4px; overflow-x: auto; padding: 6px 8px; border-top: 1px solid var(--line, #222); scrollbar-width: none; }
.term-keys button { flex: 0 0 auto; min-width: 42px; padding: 8px 10px; border-radius: 8px; border: 1px solid #333; background: #1a1d22; color: #eee; font: 13px var(--mono, monospace); }
.term-keys button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* 🛠 Actions: command output and diffs */
.act-out { margin: 8px 0 0; padding: 10px; min-height: 80px; max-height: 55vh; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--text); }
.act-out .add { color: var(--accent); }
.act-out .del { color: var(--red); }
.act-out .hunk { color: var(--cyan); }

/* 💬 Chat (chat.js) */
.chat-row { border-color: var(--accent); }
.past-chats { margin: -6px 0 10px; padding-left: 0; }
.chat-docs { position: sticky; top: 0; z-index: 2; display: flex; gap: 6px; align-items: center; overflow-x: auto; padding: 8px 14px; background: var(--bg); border-bottom: 1px solid var(--border); }
.chat-docs .docs-label { color: var(--dim); font-size: 12px; flex: none; }
.chat-docs .doc-chip, .chat-docs .folder-chip { flex: none; }
.ev.text.md { padding: 0; font-size: 14.5px; white-space: normal; }
.ev.text.md > :last-child { margin-bottom: 0; }
.ev pre.md-code { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 6px 0; overflow: auto; font: 12.5px/1.5 var(--mono); white-space: pre; }
.ev pre.md-code code { background: none; padding: 0; font: inherit; }
pre.md-code.md-has-copy { padding-top: 30px; }
pre.md-code[data-lang].md-has-copy::before { content: attr(data-lang); position: absolute; top: 6px; left: 12px; right: auto; color: var(--dim); font: 11px var(--sans); }
.md-copy { position: absolute; top: 4px; right: 6px; min-height: 24px; padding: 2px 10px; font: 12px var(--sans); color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.chat-project { border: 1px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-family: var(--sans); white-space: normal; }
.chat-project .cp-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.chat-project .cp-head span { color: var(--muted); font-size: 13.5px; }
.chat-project .cp-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-project .cp-done { color: var(--muted); font-size: 13.5px; margin-bottom: 6px; }
.composer.chat-off #followInput { opacity: .6; }
