/* Kelp's window, folded into a phone. The list is the sidebar (window material, a card of rows, the pill, the
   "Asks:" line, the needs-you capsule); an agent is the editor card (a terminal that glows while it asks).
   Colour only where an agent calls you (orange) or failed (red). Values: the Kelp Design System's tokens.json. */
:root {
  color-scheme: light dark;
  --window: #f2f2f7;         /* iOS grouped ground */
  --card: #fff;              /* editor-bg */
  --sheet: #fff;
  --label: #000000e0;
  --quiet: #00000094;        /* label-secondary, lifted to 4.5:1 on the window */
  --on-pill: #00000094;
  --separator: #0000001a;
  --rest: #fff;              /* the group of rows */
  --hover: #00000014;        /* fill-hover */
  --pill: #f2f2f7;           /* the row that asks */
  --pill-shadow: none;
  --button: #fff;
  --button-shadow: 0 0 0 0.5px #0000002e, 0 0.5px 1px #0000001f;
  --glass: #ffffff8c;
  --glass-solid: #f6f6f6;
  --glass-shadow: inset 0 0 0 0.5px #ffffff99, inset 0 1px 0 #ffffffd9, inset 0 -1px 0 #0000000d,
    0 0 0 0.5px #00000014, 0 0.5px 1px #0000001a, 0 6px 20px #00000017;
  --scrim: #00000026;
  --banner: #f6f6f6f0;
  --banner-shadow: 0 2px 6px #00000033, inset 0 0 0 0.5px #0000001a;
  --accent: #0064e1;
  --accent-fill: #0064e1;
  --waiting: #ff9500;        /* status-waiting, glyphs */
  --waiting-text: #9a5000;   /* text-orange */
  --call: #ff950029;         /* the tab's call fill */
  --glow: 0 0 0 1px #ff9500f2, 0 0 14px #ff950066, inset 0 0 22px #ff950024;
  --failed: #ff3b30;
  --failed-text: #cc0014;
  --text: #000;              /* editor-text */
  --comment: #5d6c79;        /* syntax-comment */
  --type: #0b4f79;           /* syntax-type */
  --line: #ecf5ff;           /* editor-line */
  --tile: #0058b824;
  --tile-text: #0058b8;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --tap: 2.75rem;            /* 44 pt */
  --fast: 120ms;
  --base: 180ms;
  --appear: 240ms;
  --push: 420ms cubic-bezier(0.32, 0.72, 0, 1);   /* iOS's push and sheet curve */
  --seen: 100dvh;            /* app.js keeps it at the height above the keyboard */
}
@media (prefers-color-scheme: dark) {
  :root {
    --window: #000;
    --card: #1e1e22;
    --sheet: #2c2c2e;
    --label: #ffffffe0;
    --quiet: #ffffff94;
    --on-pill: #ffffffc7;
    --separator: #ffffff1a;
    --rest: #1c1c1e;
    --hover: #ffffff14;
    --pill: #2c2c2e;
    --pill-shadow: none;
    --button: #ffffff29;
    --button-shadow: inset 0 0 0 0.5px #ffffff14;
    --glass: #6e6e7647;
    --glass-solid: #3a3f43;
    --glass-shadow: inset 0 0 0 0.5px #ffffff24, inset 0 1px 0 #ffffff38, inset 0 -1px 0 #0000002e,
      0 0.5px 1px #00000033, 0 8px 24px #0000004d;
    --scrim: #00000059;
    --banner: #323234f0;
    --banner-shadow: 0 2px 6px #00000033, inset 0 0 0 0.5px #ffffff1f;
    --accent: #0a84ff;
    --accent-fill: #0a6fe0;
    --waiting: #ff9f0a;
    --waiting-text: #ff9f0a;
    --glow: 0 0 0 1px #ff9f0ae6, 0 0 14px #ff9f0a73, inset 0 0 22px #ff9f0a33;
    --failed: #ff453a;
    --failed-text: #ff6961;
    --text: #e5e5ea;
    --comment: #7f8c98;
    --type: #5dd8ff;
    --line: #23252b;
    --tile: #6cb4ff2e;
    --tile-text: #6cb4ff;
  }
}

html { font: 100%/1.3 system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
/* iOS only: the body text style, so every rem follows the phone's text size. */
@supports (-webkit-touch-callout: none) { html { font: -apple-system-body; } }

*, ::before, ::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; height: var(--seen); overflow: hidden;
  background: var(--window); color: var(--label);
  -webkit-tap-highlight-color: transparent; overflow-wrap: anywhere;
}
h1, h2, h3, p, ul { margin: 0; padding: 0; }
.quiet { color: var(--quiet); }
/* The icons come from icons/marks.svg by <use>, and take their paint from here. */
svg {
  display: block; width: 1rem; height: 1rem; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

/* Kelp's buttons: capsules; the accent for the one that matters. */
button {
  min-height: 2.5rem; min-width: var(--tap); padding: 0 1.125rem;
  border: 0; border-radius: 1.375rem;
  background: var(--button); box-shadow: var(--button-shadow); color: var(--label);
  font: inherit; font-weight: 500; touch-action: manipulation;
  transition: opacity var(--fast), transform var(--fast);
}
button.primary { background: var(--accent-fill); box-shadow: none; color: #fff; font-weight: 600; }
button.danger { color: var(--failed-text); }
button.icon {
  display: grid; place-items: center; width: var(--tap); height: var(--tap); padding: 0;
  background: none; box-shadow: none; color: var(--quiet);
}
button.icon svg { width: 1.25rem; height: 1.25rem; }
button.icon.glass { color: var(--label); border-radius: 50%; }
button.glass:active:not(:disabled) { opacity: 1; transform: scale(1.08); }
button:active:not(:disabled) { opacity: 0.6; transform: scale(0.97); }
button:disabled { opacity: 0.4; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- screens */

.screen {
  display: none; position: fixed; inset: 0 0 auto; height: var(--seen); flex-direction: column;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--window);
}
[data-screen="pair"] #pair, [data-screen="list"] #list,
[data-screen="agent"] #list, [data-screen="agent"] #agent { display: flex; }
#agent { animation: arrive var(--push); }
@keyframes arrive { from { transform: translateX(100%); } }

/* The window's title band floats: the rows scroll under it and blur out at the edge. */
.bar {
  position: sticky; top: 0; z-index: 2; flex: none;
  display: flex; align-items: center; justify-content: flex-end; gap: 0.5625rem; min-height: 3.5rem;
  padding: calc(env(safe-area-inset-top) + 0.25rem) 1rem 0.375rem;
}
.bar::before {
  content: ""; position: absolute; inset: 0 0 -1rem; z-index: -1; pointer-events: none;
  background: linear-gradient(color-mix(in srgb, var(--window) 75%, transparent), transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent);
}
.bar h1 { font-size: 1.0625rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The large title: the Mac's name, scrolling away under the band as iOS's does. */
#mac { margin-top: -0.375rem; padding: 0 1.25rem 0.625rem; font-size: 2.125rem; font-weight: 700; letter-spacing: 0.011em; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Liquid Glass: the layer of controls that floats over what scrolls. Never the content itself.
   The blur and the lit rim stand in for the lens: Safari takes no SVG filter in backdrop-filter. */
.glass, button.glass, #quick button {
  background: linear-gradient(#ffffff24, #ffffff00 55%) var(--glass); box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(18px) saturate(180%); backdrop-filter: blur(18px) saturate(180%);
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .glass, button.glass, #quick button, .sheet.glass { background: var(--glass-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .bar::before { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
/* A pane with a lens (app.js): the copy of what lies under it, bent by the filter, then the tint and the lit rim. */
.lensed { isolation: isolate; overflow: hidden; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.lens { position: absolute; inset: 0; z-index: -1; overflow: hidden; border-radius: inherit; background: var(--under, var(--window)); pointer-events: none; }
.lens > div { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
/* Safari drops an SVG filter over anything it composites: nothing in the copy may spin or scroll by itself. */
.lens * { animation: none !important; transition: none !important; }
.lens > div > *, .lens pre { overflow: hidden !important; }
.lensed::after {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  background: linear-gradient(#ffffff24, #ffffff00 55%) var(--glass); box-shadow: var(--glass-shadow);
}
#a-card { --under: var(--card); }
.calls #a-ask::after { box-shadow: var(--glass-shadow), inset 0 0 0 1px var(--waiting); }
#a-ask, #send-form { position: relative; }
/* The needs-you capsule. */
.capsule {
  display: flex; align-items: center; gap: 0.5rem; height: 3rem; padding: 0 1.25rem 0 1rem;
  border-radius: 1.5rem; font-size: 0.9375rem; white-space: nowrap; min-width: 0; overflow: hidden;
}
.capsule b { font-weight: 600; }
.capsule span { color: var(--quiet); }
.capsule svg { width: 1rem; height: 1rem; }
/* It floats at the foot of the list, where a thumb and iOS's own toolbars are. */
#needs { position: fixed; z-index: 2; left: 50%; bottom: max(env(safe-area-inset-bottom), 1rem); max-width: calc(100% - 2rem); translate: -50%; }

/* A banner floats over the window. */
.strip {
  display: flex; align-items: flex-start; gap: 0.5625rem;
  margin: 0 1rem 0.5rem; padding: 0.6875rem 0.875rem 0.6875rem 0.75rem;
  border-radius: 1.25rem; background: var(--banner); box-shadow: var(--banner-shadow); font-size: 0.875rem;
}
.strip > svg { margin-top: 0.125rem; color: var(--quiet); }
.strip.warn > svg { color: var(--waiting); }
.strip span { flex: 1; }
.strip .icon { margin: -0.75rem -0.75rem -0.75rem -0.25rem; }
.strip .icon svg { width: 0.875rem; height: 0.875rem; }
.note { color: var(--failed-text); font-size: 0.8125rem; }
.note:empty { display: none; }

#pair { padding-top: env(safe-area-inset-top); }
#pair { align-items: center; justify-content: center; gap: 0.625rem; padding: 2.75rem; text-align: center; }
#pair h1 { margin-top: 0.625rem; font-size: 1.25rem; font-weight: 600; }
#pair p { color: var(--quiet); line-height: 1.4; }

/* ---- status marks: colour only for waiting and error, the rest said by shape and motion */

.mark { color: var(--quiet); }
[data-mark="waiting"] .mark { color: var(--waiting); }
[data-mark="error"] .mark { color: var(--failed); }
[data-mark=""] .mark { visibility: hidden; }
[data-mark="working"] .mark { animation: turn 1s linear infinite; }
@keyframes turn { to { transform: rotate(1turn); } }

/* ---- the sidebar */

#list { overflow-y: auto; overscroll-behavior: contain; }
#list > * { flex: none; }
#scroll {
  padding: 0.25rem 1rem calc(env(safe-area-inset-bottom) + 5.5rem);
  transition: opacity var(--base);
}
.stale #scroll { opacity: 0.45; }
#rows { list-style: none; padding: 0.25rem 0; border-radius: 1.625rem; background: var(--rest); }
.row { position: relative; }
.row + .row::before { content: ""; position: absolute; inset: 0 0 auto 2.25rem; height: 1px; background: var(--separator); transform: scaleY(0.5); }
.row[data-status="waiting"]::before, .row[data-status="waiting"] + .row::before { content: none; }
#rows:empty { display: none; }
#empty { padding: 3rem 2rem; text-align: center; }

.open {
  display: grid; grid-template-columns: 0.9375rem 1fr auto auto; column-gap: 0.5625rem; row-gap: 0.1875rem; align-items: baseline;
  min-height: var(--tap); padding: 0.75rem 1rem 0.75rem 0.75rem; color: inherit; text-decoration: none;
}
.open .mark { grid-row: span 3; align-self: start; width: 0.9375rem; height: 0.9375rem; margin-top: 0.1875rem; }
.title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread .title { font-weight: 600; }
:is([data-status="hibernated"], [data-status="exited"]) .title { color: var(--quiet); }
.dot { align-self: center; width: 0.4375rem; height: 0.4375rem; margin-right: -0.125rem; border-radius: 50%; background: var(--accent); }
.time { grid-column: 4; color: var(--quiet); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }

/* Where the agent works: the project's tile and name, the branch. */
.place { grid-column: 2 / -1; display: flex; align-items: center; gap: 0.375rem; min-width: 0; color: var(--quiet); font-size: 0.8125rem; white-space: nowrap; overflow: hidden; }
.place svg { width: 0.75rem; height: 0.75rem; margin-right: -0.1875rem; }
.tile {
  display: grid; place-items: center; flex: none; width: 0.9375rem; height: 0.9375rem; border-radius: 22%;
  background: var(--tile); color: var(--tile-text); font-size: 0.5rem; font-weight: 700; line-height: 1;
}
/* What it says: "Asks: …", "Failed: …", or the command it runs, as a chip. */
.says { grid-column: 2 / -1; color: var(--quiet); font-size: 0.875rem; line-height: 1.35; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.lead.asks { color: var(--waiting-text); }
.lead.failed { color: var(--failed-text); }
.chip {
  grid-column: 2 / -1; justify-self: start; display: flex; align-items: center; gap: 0.3125rem; max-width: 100%;
  height: 1.375rem; padding: 0 0.4375rem; border-radius: 0.3125rem; background: var(--hover); color: var(--quiet);
  font: 0.75rem/1 var(--mono); white-space: nowrap; overflow: hidden;
}
.chip svg { width: 0.6875rem; height: 0.6875rem; stroke-width: 1.7; }
.row .note { padding: 0 0.75rem 0.625rem 2.25rem; }

/* An agent that needs you sits on the selection pill, its question in full. */
.row[data-status="waiting"] { margin: 0 0.25rem 0.25rem; border-radius: 1.375rem; background: var(--pill); box-shadow: var(--pill-shadow); }
[data-status="waiting"] .title { font-weight: 600; }
[data-status="waiting"] :is(.time, .place) { color: var(--on-pill); }
[data-status="waiting"] .says { color: var(--label); -webkit-line-clamp: 4; }

/* Allow and Deny: far enough apart for a thumb, Allow the one that stands out. */
.answer { display: grid; grid-template-columns: 1fr 1fr; gap: 0.625rem; }
.answer button { min-height: 3rem; font-weight: 600; }
.row .answer { padding: 0.125rem 0.75rem 0.75rem 2.25rem; }

/* ---- the agent: the editor card */

#agent .bar { position: static; padding-left: 0.75rem; gap: 0.75rem; }
#agent .bar::before { content: none; }
.who { flex: 1; min-width: 0; display: grid; gap: 0.0625rem; justify-items: center; margin-right: 3.5rem; text-align: center; }
.who > * { max-width: 100%; }
.who h1 { font-size: 1.0625rem; }

/* Its tab: a capsule that takes the call fill while the agent asks. */
#a-status { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem 0.5rem; font-size: 0.875rem; color: var(--quiet); }
.tab {
  display: flex; align-items: center; gap: 0.4375rem; height: 2rem; padding: 0 0.8125rem 0 0.5625rem;
  border-radius: 1rem; background: var(--pill); box-shadow: var(--pill-shadow); color: var(--label); font-weight: 500;
}
.tab .mark { width: 0.9375rem; height: 0.9375rem; }
.calls .tab { background: var(--call); box-shadow: inset 0 0 0 1px var(--waiting); color: var(--waiting-text); }
.calls #a-word { color: var(--waiting-text); }
[data-mark="error"] ~ #a-word { color: var(--failed-text); }

#a-card {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  margin: 0 0.5rem max(env(safe-area-inset-bottom), 0.5rem);
  border-radius: 2rem; background: var(--card); box-shadow: 0 0 0 1px var(--separator);
  color: var(--text); transition: box-shadow var(--appear);
}
.calls #a-card { box-shadow: var(--glow); }   /* the attention glow */

/* The agent's last reply, as its terminal shows it. */
#a-body { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 1rem 1rem calc(var(--dock, 4rem) + 0.5rem); scroll-padding-bottom: var(--dock, 4rem); font: 0.8125rem/1.55 var(--mono); }
#a-body > * + * { margin-top: 0.625rem; }
.dim { color: var(--comment); }
#a-reply { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 0.5rem; row-gap: 0.625rem; }
#a-reply::before { content: "●"; }
#a-reply:empty { display: none; }
#a-reply > * { grid-column: 2; margin: 0; }
#a-reply :is(h2, h3, h4, h5, h6) { margin-top: 0.375rem; font: inherit; font-weight: 700; }
#a-reply :is(ul, ol) { padding-left: 1.5rem; }
#a-reply li::marker { color: var(--comment); }
#a-reply a { color: var(--accent); }
#a-reply code { font: inherit; color: var(--type); }
#a-reply pre { overflow-x: auto; margin: 0 -1rem 0 -2.125rem; padding: 0.5rem 1rem; background: var(--line); font-size: 0.75rem; overflow-wrap: normal; }
#a-reply pre code { color: inherit; white-space: pre; }

/* The dock: the question and the prompt, glass over the terminal. Its corners follow the card's. */
#dock { position: absolute; inset: auto 0.625rem 0.625rem; display: grid; gap: 0.5rem; }
#a-ask { display: grid; gap: 0.75rem; padding: 0.875rem; border-radius: 1.375rem; }
.calls #a-ask { box-shadow: var(--glass-shadow), inset 0 0 0 1px var(--waiting); }
#a-ask-text { font: 700 0.8125rem/1.55 var(--mono); white-space: pre-wrap; max-height: 9rem; overflow-y: auto; }
#a-ask .answer button { min-height: var(--tap); }

/* The prompt. */
#quick { display: flex; flex-wrap: wrap; gap: 0.5rem; padding-bottom: 0.5rem; }
#quick button { min-height: 2.25rem; padding: 0 0.875rem; font-size: 0.875rem; font-weight: 400; }
#send-form { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.375rem 0.375rem 0.375rem 1rem; border-radius: 1.5rem; }
#send-form:focus-within { box-shadow: var(--glass-shadow), 0 0 0 2px var(--accent); }
.prompt { align-self: center; color: var(--type); font: 700 0.9375rem/1 var(--mono); }
#text {
  flex: 1; min-height: 2.25rem; max-height: 8rem; resize: none; padding: 0.4375rem 0;
  border: 0; outline: 0; background: none; color: inherit;
  font: max(1rem, 16px)/1.35 var(--mono);   /* under 16 px iOS zooms the page on focus */
}
#text::placeholder { color: var(--comment); }
#send { display: grid; place-items: center; width: 2.25rem; min-width: 2.25rem; min-height: 2.25rem; padding: 0; border-radius: 50%; }
#send-error { padding: 0.375rem 1rem 0; }

/* ---- menu: a sheet over the window */

.sheet {
  width: calc(100% - 1rem); max-width: 30rem; margin: auto auto max(env(safe-area-inset-bottom), 0.5rem);
  padding: 1.5rem; border: 0; border-radius: 2.25rem; color: inherit;
}
/* A sheet holds text: mostly solid, so it reads where the top layer gets no blur (WebKit). */
.sheet.glass {
  background: color-mix(in srgb, var(--glass-solid) 94%, transparent);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
}
.sheet[open] { display: grid; gap: 1rem; animation: rise var(--push); }
.sheet::before { content: ""; justify-self: center; width: 2.25rem; height: 0.3125rem; margin: -0.875rem 0 -0.25rem; border-radius: 1rem; background: var(--quiet); opacity: 0.5; }
.sheet::backdrop { background: var(--scrim); }
@keyframes rise { from { transform: translateY(100%); } }
.sheet h2 { font-size: 1.0625rem; font-weight: 600; }
.sheet h3 { font-size: 1rem; font-weight: 400; }
.setting { display: flex; align-items: flex-start; gap: 0.625rem; padding-bottom: 1rem; border-bottom: 1px solid var(--separator); }
.setting > svg { width: 1.125rem; height: 1.125rem; margin-top: 0.125rem; color: var(--quiet); stroke-width: 1.3; }
.setting div { flex: 1; display: grid; gap: 0.125rem; }
.setting p { font-size: 0.8125rem; }
.ends { display: grid; gap: 0.625rem; }
.ends button { min-height: 3rem; }

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation: none !important; transition: none !important; }
}
