@font-face {
  font-family: "Instrument Sans";
  src: url("/static/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/*
  nudgethis marks up a live app. Its controls are stickers on that app:
  solid paper, a thick ink outline, a hard shadow, and one marker red. They
  read the same over any app, light or dark. Pressed, a sticker moves into
  its shadow: a nudge. The panel and the home page follow the system theme.
*/
:root {
  --paper: oklch(0.985 0.012 95);
  --ink: oklch(0.2 0.015 60);
  --dim: oklch(0.43 0.012 60);
  --hairline: oklch(0.2 0.015 60 / 0.16);
  --tint: oklch(0.945 0.018 90);
  --field: oklch(0.955 0.016 90);
  --accent: oklch(0.6 0.22 32);
  --on-accent: oklch(1 0 0);

  /* The sticker layer over the app: the same in light and dark. */
  --st-paper: oklch(0.985 0.012 95);
  --st-ink: oklch(0.2 0.015 60);
  --st-dim: oklch(0.43 0.012 60);
  --st-field: oklch(0.945 0.018 90);

  --line: 2px;
  --lift: 3px;
  --radius: 16px;
  --spring: cubic-bezier(0.2, 1.25, 0.35, 1);
  --ease: cubic-bezier(0.2, 0.9, 0.2, 1);
  --edge: max(12px, env(safe-area-inset-top));
  --edge-bottom: max(14px, env(safe-area-inset-bottom));
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(0.2 0.012 60);
    --ink: oklch(0.95 0.012 90);
    --dim: oklch(0.74 0.01 80);
    --hairline: oklch(0.95 0.012 90 / 0.18);
    --tint: oklch(0.25 0.014 60);
    --field: oklch(0.27 0.014 60);
    --accent: oklch(0.66 0.21 34);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: inherit; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  padding: 4px 14px;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 16px or more: iOS Safari zooms the page into a smaller field. */
input, textarea { font-size: max(16px, 1em); }
::placeholder { color: var(--dim); opacity: 1; }

/* A sticker: solid, outlined, with a hard shadow. Inside it the theme tokens
   take the sticker's values, so its children read well over any app. */
.sticker {
  --paper: var(--st-paper);
  --ink: var(--st-ink);
  --dim: var(--st-dim);
  --field: var(--st-field);
  --tint: var(--st-field);
  --hairline: oklch(0.2 0.015 60 / 0.16);
  background: var(--st-paper);
  color: var(--st-ink);
  border: var(--line) solid var(--st-ink);
  box-shadow: var(--lift) var(--lift) 0 var(--st-ink);
}

.chip { font-size: 0.82rem; padding: 4px 14px; }
.dim { color: var(--dim); }

/* ---------- home: one prompt, then the apps ---------- */

#home { max-width: 36rem; margin: 0 auto; padding: max(2.5rem, env(safe-area-inset-top)) 1rem 4rem; }
.homehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.homehead .chip { color: var(--dim); border-color: var(--hairline); font-weight: 600; text-decoration: none; }
.homehead .chip:hover { color: var(--ink); border-color: var(--ink); }
#home h1 {
  isolation: isolate;
  margin: 0;
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: -0.03em;
}
/* The name gets the mark it is about: a red marker stroke under "this". */
#home h1 .this {
  position: relative;
  display: inline-block;
}
#home h1 .this::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -4px;
  bottom: 1px;
  height: 6px;
  border-radius: 3px;
  background: var(--accent);
  rotate: -2.5deg;
  z-index: -1;
}

.newapp { margin-top: 2.25rem; padding: 6px 6px 6px 6px; border-radius: 22px; }
.newapp .prompt {
  display: block;
  width: 100%;
  min-height: 5.5em;
  max-height: 40vh;
  field-sizing: content;
  font-family: inherit;
  font-size: 1.12rem;
  line-height: 1.45;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 14px 14px 8px;
  resize: none;
  outline: none;
}
.newfoot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin: 0;
  padding: 8px 6px 4px 14px;
  border-top: 1px solid var(--hairline);
  font-size: 0.88rem;
}
.newfoot .where { display: inline-flex; align-items: baseline; gap: 8px; min-width: 0; }
.newfoot .what { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.newfoot .addr { display: inline-flex; align-items: baseline; min-width: 0; padding: 3px 8px; border-radius: 8px; background: var(--field); }
/* The name fits its text: no gap before it, and it grows as it is typed. */
.newfoot .addr input {
  field-sizing: content;
  min-width: 3ch;
  max-width: 18ch;
  font-family: inherit;
  font-size: inherit;
  font-weight: 700;
  color: inherit;
  background: transparent;
  border: 0;
  outline: none;
  padding: 0;
  text-align: left;
}
.newfoot .addr:focus-within { box-shadow: inset 0 0 0 1.5px var(--ink); }
.newfoot .addr input::placeholder { color: var(--dim); font-weight: 600; }
.newfoot .from { flex: 1 1 100%; order: 3; font-size: 0.78rem; }
.newfoot .make { margin-left: auto; padding: 8px 18px; background: var(--accent); color: var(--on-accent); border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.newfoot .make:disabled { opacity: 1; background: var(--field); color: var(--dim); border-color: var(--hairline); box-shadow: none; }

/* Ideas: whole prompts, to start from. */
.ideas { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 8px; }
.ideas button {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 14px;
  border: 1.5px solid var(--hairline);
  border-radius: 14px;
  text-align: left;
  font-weight: 400;
}
.ideas button:hover { border-color: var(--ink); background: var(--tint); }
/* A phone: one row to swipe through, not a long column. */
@media (max-width: 640px) {
  .ideas {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 78%;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    margin: 1rem -1rem 0;
    padding: 0 1rem 4px;
    scrollbar-width: none;
  }
  .ideas li { scroll-snap-align: start; }
}
.ideas strong { font-size: 0.88rem; }
.ideas span { font-size: 0.8rem; color: var(--dim); line-height: 1.35; }

#home h2 { margin: 2.75rem 0 0.5rem; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
#home .apps { list-style: none; margin: 0; padding: 0; }
#home .apps li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--hairline);
}
/* Each app in its own colour: a dot before its name. */
#home .apps li::before {
  content: "";
  width: 11px;
  height: 11px;
  flex: none;
  border-radius: 50%;
  background: var(--dot, var(--accent));
  border: var(--line) solid var(--ink);
}
#home .apps a { font-weight: 650; text-decoration: none; }
#home .apps a:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
#home .apps .name { font-weight: 650; color: var(--dim); }
#home .appurl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; color: var(--dim); }
#home .apps .state { flex: 1; min-width: 0; }
#home .remove {
  width: 28px;
  height: 28px;
  margin-left: auto;
  padding: 0;
  border-color: transparent;
  color: var(--dim);
  font-size: 1.1rem;
  line-height: 1;
}
#home .remove:hover { color: var(--ink); border-color: var(--hairline); }
.state { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--dim); }
.state .inkloop { width: 30px; }
.state.failed { color: var(--accent); font-weight: 600; }

.confirm { width: min(22rem, calc(100% - 2rem)); padding: 18px 18px 14px; border-radius: 18px; }
.confirm::backdrop { background: oklch(0 0 0 / 0.3); }
.confirm p { margin: 0 0 8px; }
.confirm .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.chip.danger { background: var(--accent); color: var(--on-accent); }

.homehead nav { display: flex; align-items: center; gap: 6px; }
.homehead a.chip { border: var(--line) solid var(--hairline); border-radius: 999px; }

/* ---------- settings: what the builder runs on ---------- */

#settings { max-width: 40rem; margin: 0 auto; padding: max(2rem, env(safe-area-inset-top)) 1rem 4rem; }
#settings .homehead { justify-content: flex-start; gap: 16px; }
#settings h1 { margin: 0; font-size: 1.6rem; font-weight: 750; letter-spacing: -0.02em; }
#settings .back { color: var(--dim); text-decoration: none; font-weight: 600; }
#settings .section {
  margin-top: 1.5rem;
  padding: 18px 18px 16px;
  border: var(--line) solid var(--ink);
  border-radius: 18px;
}
#settings h2 { margin: 0; font-size: 1.05rem; font-weight: 750; }
#settings .lead { margin: 2px 0 0; font-size: 0.86rem; }
#settings .state { margin: 10px 0 4px; font-size: 0.82rem; font-weight: 600; color: var(--accent); }
#settings .state.ok { color: var(--ink); }
#settings .state.ok::before { content: "● "; color: oklch(0.62 0.15 150); }
.field { display: grid; gap: 4px; margin-top: 14px; }
.field .label { display: flex; align-items: baseline; gap: 8px; font-size: 0.82rem; font-weight: 700; }
.field .src { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--dim); }
.field .src.saved { color: var(--accent); }
.field input, .field select {
  width: 100%;
  font-family: inherit;
  color: inherit;
  background: var(--field);
  border: var(--line) solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--ink); }
.field .help { font-size: 0.76rem; color: var(--dim); }
.linkish { justify-self: start; padding: 0; border: 0; font-size: 0.76rem; font-weight: 600; color: var(--dim); text-decoration: underline; }
#settings .save { margin-top: 16px; background: var(--ink); color: var(--paper); }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: 10px; margin: 12px 0 6px; }
.totals div { display: grid; padding: 10px 12px; border: 1px solid var(--hairline); border-radius: 12px; }
.totals strong { font-size: 1.3rem; font-weight: 750; }
.totals span { font-size: 0.76rem; }
.usage table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 0.84rem; }
.usage th, .usage td { padding: 7px 6px; text-align: left; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.usage thead th { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.usage tbody th { font-weight: 650; }
.usage { overflow-x: auto; }

/* ---------- stage: the app, full screen ---------- */

#frame { position: fixed; inset: 0; overflow: hidden; overflow: clip; background: var(--tint); }
html:has(#frame), html:has(#frame) body { overflow: hidden; overscroll-behavior: none; }

.stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--paper);
  transition: transform 0.55s var(--ease), border-radius 0.55s var(--ease);
}
.stage iframe {
  /* Element Capture (the snap) needs the iframe to be its own stacking context. */
  isolation: isolate;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--paper);
}
/* A phone: the sheet comes up over the app; the strip above it closes it. */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 20;
  border: 0;
  border-radius: 0;
  background: oklch(0 0 0 / 0.18);
}

/* ---------- the pill ---------- */

/* The pill sits at the bottom, under the thumb. */
#nudge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--edge-bottom) + var(--kb, 0px));
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  pointer-events: none;
}
#nudge > * { pointer-events: auto; }
.snapping #nudge,
#frame:has(.ink.on) #nudge { visibility: hidden; }

.pill {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 18px 0 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.5s var(--spring), translate 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
/* The nudge: pressed, the sticker moves into its shadow. */
.pill.pressed { translate: 2px 2px; box-shadow: 1px 1px 0 var(--st-ink); }
.pill.dragging { cursor: grabbing; transition: translate 0.12s var(--ease), box-shadow 0.12s var(--ease); }
.pill.bounce { animation: bounce 0.45s var(--spring); }
@keyframes bounce {
  30% { scale: 1.08 0.92; }
  60% { scale: 0.97 1.03; }
}

.pill .label { white-space: nowrap; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; }
.pill .inkloop { width: 30px; height: 10px; }

/* The status: grey at rest, red when a reply or a change waits. */
.orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: color-mix(in oklch, var(--st-ink) 28%, transparent);
  transition: background 0.3s, scale 0.3s var(--spring);
}
.orb.unread,
.pill[data-state="busy"] .orb { background: var(--accent); scale: 1.25; }
.pill[data-state="busy"] .orb { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { scale: 0.8; opacity: 0.7; } }

.shipmark {
  position: absolute;
  left: 9px;
  top: 50%;
  translate: 0 -50%;
  opacity: 0;
  pointer-events: none;
}
.shipmark svg { width: 20px; height: 20px; display: block; }
.shipmark path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
}
.shipmark.play { animation: shipmark 1.8s var(--ease) forwards; }
.shipmark.play path { animation: drawcheck 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards; }
.pill:has(.shipmark.play) .orb { animation: hide 1.8s forwards; }
@keyframes shipmark { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
@keyframes hide { 0%, 80% { opacity: 0; } 100% { opacity: 1; } }
@keyframes drawcheck { to { stroke-dashoffset: 0; } }

.pill:not(.bounce) { animation: pop 0.3s var(--spring); }
@keyframes pop { from { scale: 0.85; opacity: 0; } }

.card {
  width: min(560px, 100%);
  border-radius: var(--radius);
  padding: 10px;
}

/* ---------- composer ---------- */

.composer .hint { margin: 2px 6px 8px; font-size: 0.82rem; color: var(--dim); }

.pend { display: flex; gap: 8px; margin: 2px 4px 10px; }
.pendshot { position: relative; display: inline-block; }
.pendshot img {
  width: 84px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: var(--line) solid var(--ink);
  display: block;
}
.pendshot .unshot {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  padding: 0;
  background: var(--paper);
  font-size: 0.75rem;
  line-height: 1;
}

.composerow { display: flex; gap: 8px; align-items: flex-end; }
.composerow textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 30vh;
  field-sizing: content;
  font-family: inherit;
  line-height: 22px;
  color: var(--ink);
  background: var(--field);
  border: var(--line) solid transparent;
  border-radius: 12px;
  padding: 7px 12px;
  resize: none;
  outline: none;
}
.composerow textarea:focus { border-color: var(--ink); }

.round {
  width: 40px;
  height: 40px;
  padding: 0;
  flex: none;
  display: grid;
  place-items: center;
  border: var(--line) solid transparent;
  transition: translate 0.1s var(--ease), box-shadow 0.1s var(--ease);
}
.round.snap { border-color: var(--ink); background: var(--paper); }
.round.close { color: var(--ink); }
.round.send { background: var(--accent); color: var(--on-accent); border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.round.send:active:not(:disabled) { translate: 2px 2px; box-shadow: none; }
.round.send:disabled { opacity: 1; background: var(--field); color: var(--dim); border-color: var(--hairline); box-shadow: none; }
.icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- the sheet: everything about the app, in one place ---------- */

/* A phone: a bottom sheet over most of the screen; the app shows above it. */
#sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: min(88dvh, calc(100% - 56px));
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-top: var(--line) solid var(--ink);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px -20px oklch(0 0 0 / 0.5);
  overflow: hidden;
  overscroll-behavior: contain;
  transform: translateY(105%);
  transition: transform 0.45s var(--ease);
}
#sheet.open { transform: none; }
/* Held by its header, the sheet follows the finger (app.swipe). */
#sheet.held { transition: none; }
#frame:has(.ink.on) #sheet,
#frame:has(.ink.on) .scrim { visibility: hidden; }

.sheethead {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 18px 10px 8px 14px;
  touch-action: none;
}
.sheethead .home { color: var(--dim); }
.sheethead .home:hover { color: var(--ink); }
.sheethead .grab {
  position: absolute;
  top: 7px;
  left: 50%;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: var(--hairline);
}
.appswitch {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 6px 8px;
  border-radius: 12px;
  font-size: 1.02rem;
  font-weight: 700;
  text-align: left;
}
.appswitch:hover, .appswitch[aria-expanded="true"] { background: var(--tint); }
.appswitch .dot { width: 14px; height: 14px; flex: none; border-radius: 50%; background: var(--accent); border: var(--line) solid var(--ink); }
.appswitch .appname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appswitch .chev { width: 16px; height: 16px; flex: none; transition: rotate 0.2s var(--ease); }
.appswitch[aria-expanded="true"] .chev { rotate: 180deg; }

/* The app list and the menu drop over the chat, under the header. */
#sheet .drop { overscroll-behavior: contain; }
#sheet .drop {
  position: absolute;
  top: 62px;
  left: 10px;
  right: 10px;
  z-index: 2;
  max-height: calc(100% - 80px);
  overflow-y: auto;
  padding: 8px 0;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--lift) var(--lift) 0 var(--ink);
}
.newlink {
  display: block;
  margin: 6px 12px 2px;
  padding: 10px;
  border-top: 1px solid var(--hairline);
  font-weight: 650;
  text-decoration: none;
  color: var(--dim);
}
.newlink:hover { color: var(--ink); }

/* A large screen: the sheet sits beside the app, and the app stays in use. */
@media (min-width: 900px) {
  :root { --panel: 400px; }
  #sheet {
    top: 0;
    left: auto;
    height: auto;
    width: var(--panel);
    border-top: 0;
    border-left: var(--line) solid var(--ink);
    border-radius: 0;
    box-shadow: none;
    transform: translateX(105%);
    padding-top: var(--edge);
  }
  .sheethead { padding-top: 8px; }
  .sheethead .grab { display: none; }
  .stage { transition: right 0.45s var(--ease); }
  .stage.away { right: var(--panel); }
  .scrim { display: none !important; }
}

.applist { list-style: none; margin: 0; padding: 0 8px; }
.appitem a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 650;
}
.appitem a:hover { background: var(--tint); }
.appitem.here a { background: var(--tint); box-shadow: inset 0 0 0 var(--line) var(--ink); }
.appitem .dot { width: 14px; height: 14px; flex: none; border-radius: 50%; background: var(--dot); border: var(--line) solid var(--ink); }
.appitem .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appitem .state { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 600; color: var(--dim); }
.appitem .state .inkloop { width: 24px; height: 10px; }
.appitem .state .inkloop path { stroke: var(--dot); }
.appitem .new { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--dot); }

.swatches { padding: 10px 16px 14px; }
.swatches .name { display: block; margin-bottom: 8px; font-size: 0.72rem; font-weight: 700; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.swatches .row { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--sw);
  border: var(--line) solid var(--ink);
  transition: translate 0.1s var(--ease), box-shadow 0.1s var(--ease);
}
.swatch.on { box-shadow: 2px 2px 0 var(--ink), 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); }
.swatch:active { translate: 1px 1px; }



.tabs, .seg {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
}
.tabs { align-self: center; margin-bottom: 12px; }
.tabs button, .seg button { border: 0; padding: 4px 16px; font-size: 0.85rem; color: var(--dim); }
.tabs button.on, .seg button.on { background: var(--ink); color: var(--paper); }
.seg { flex-wrap: wrap; border-radius: 14px; align-self: flex-start; }
.seg button { border-radius: 10px; }


.coder {
  padding: 12px 16px 8px;
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.coder .lead { margin: 0; color: var(--dim); font-size: 0.85rem; }
.setting { display: flex; flex-direction: column; gap: 6px; }
.setting .name { font-size: 0.72rem; font-weight: 700; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.picker {
  font: inherit;
  font-weight: 650;
  color: inherit;
  padding: 10px 14px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background-color: var(--paper);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.maxmode { margin: 0; font-size: 0.8rem; color: var(--accent); font-weight: 600; }

#sheet .composer {
  padding: 8px 12px calc(var(--edge-bottom) + var(--kb, 0px));
  border-top: 1px solid var(--hairline);
}
.round.mic { color: var(--dim); }
.round.mic.on { color: var(--on-accent); background: var(--accent); border-color: var(--ink); animation: breathe 1.6s ease-in-out infinite; }

.timeline {
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
  margin: 0;
  padding: 6px 18px var(--edge-bottom);
  list-style: none;
  overflow-y: auto;
}
.step {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 3px 12px;
  padding: 14px 10px;
  margin: 0 -10px;
  border-bottom: 1px solid var(--hairline);
  border-radius: 10px;
  scroll-margin: 40px;
}
.step .status { grid-column: 1; display: flex; gap: 8px; align-items: baseline; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.step .when { font-weight: 500; letter-spacing: 0; text-transform: none; }
.step .brief { grid-column: 1; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.step .result { grid-column: 1; margin: 0; font-size: 0.9rem; color: var(--dim); overflow-wrap: anywhere; }
.step .took { grid-column: 1; font-size: 0.75rem; color: var(--dim); }
.step .undo { grid-column: 2; grid-row: 1 / span 4; align-self: center; }
.step.live .status { color: var(--accent); }
.step.undone .brief, .step.dropped .brief { color: var(--dim); }
.step.flash { animation: flash 1.6s var(--ease); }
@keyframes flash { 0%, 40% { background: color-mix(in oklch, var(--accent) 16%, transparent); } }

.inflight {
  list-style: none;
  margin: 0 18px 4px;
  padding: 8px 12px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.86rem;
}
.inflight li { display: flex; align-items: baseline; gap: 8px; }
.inflight li::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: none;
  align-self: center;
  border-radius: 50%;
  background: var(--accent);
  animation: breathe 1.6s ease-in-out infinite;
}
.inflight .what { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inflight .phase { flex: none; font-size: 0.76rem; color: var(--dim); }

/* A flex child shrinks below its content only with min-height: 0; then it
   scrolls itself, and its end does not pull the page (no pull-to-refresh). */
#msgs {
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
  margin: 0;
  padding: 14px 18px;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.msg { max-width: 88%; }
.msg .tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--dim);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 0 4px;
  margin-bottom: 2px;
}
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.msg.you { align-self: flex-end; text-align: right; }
.msg.you p, .msg.you .thumbs {
  background: var(--tint);
  border: var(--line) solid var(--ink);
  border-radius: 14px 14px 4px 14px;
  padding: 7px 12px;
  display: inline-block;
  text-align: left;
}
.msg.you .thumbs { display: inline-flex; gap: 6px; margin-top: 4px; padding: 6px; }
.msg.you .thumbs img {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  display: block;
}
.msg.nudge { align-self: flex-start; padding-left: 12px; border-left: 3px solid var(--accent); }
.msg.nudge p { white-space: normal; }

/* Nudge's and the coder's markdown, drawn small and calm. */
.md { overflow-wrap: break-word; }
.md > * { margin: 0; }
.md > * + * { margin-top: 0.55em; }
.md h4 {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}
.md > * + h4 { margin-top: 0.9em; }
.md ul, .md ol { padding-left: 1.2em; }
.md li + li { margin-top: 0.3em; }
.md ul li::marker { color: var(--accent); }
.md ol li::marker { color: var(--dim); font-weight: 600; font-size: 0.9em; }
.md strong { font-weight: 700; }
.md code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86em;
  padding: 0.05em 0.35em;
  border-radius: 5px;
  background: var(--tint);
  border: 1px solid var(--hairline);
}
.md pre {
  overflow-x: auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--tint);
  border: 1px solid var(--hairline);
}
.md pre code { padding: 0; border: 0; background: none; font-size: 0.82rem; }
.md a { text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

.act.undo { margin-top: 8px; font-size: 0.82rem; }
.step .act.undo { margin-top: 0; }

.empty { color: var(--dim); font-size: 0.88rem; }

/* While Nudge or the coder works: one dim line that updates in place. */
.doing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--dim);
}
.doing .inkloop { width: 30px; height: 10px; }
.doing .clock { font-variant-numeric: tabular-nums; opacity: 0.8; }
.msg .details {
  margin-top: 4px;
  padding: 0;
  border: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--dim);
  text-decoration: underline;
  text-decoration-color: var(--hairline);
  text-underline-offset: 3px;
}
.msg .details:hover { color: var(--ink); text-decoration-color: var(--accent); }

.inkloop { width: 46px; height: 12px; display: block; }
.inkloop path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-dasharray: 12 42;
  animation: inkloop 1.6s linear infinite;
}
@keyframes inkloop { to { stroke-dashoffset: -54; } }

/* ---------- a chat picture, large ---------- */

.lightbox {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  border: 0;
  background: transparent;
  display: none;
  place-items: center;
  cursor: zoom-out;
}
.lightbox[open] { display: grid; }
.lightbox::backdrop { background: oklch(0.12 0.01 60 / 0.88); }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 12px;
  border: var(--line) solid var(--st-paper);
  box-shadow: 0 20px 60px -20px oklch(0 0 0 / 0.8);
}
.lightbox .close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  color: var(--st-ink);
  background: var(--st-paper);
}
.msg.you .thumbs a { cursor: zoom-in; }

/* ---------- ink editor ---------- */

.ink {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  z-index: 30;
  background: var(--tint);
}
.ink.on { display: flex; }
/* Drawing on the live app: a red frame says the screen is being marked. */
.ink.live { background: transparent; }
/* Over the live app the canvas covers the whole frame and the bar floats on
   it, so the marks and the app's picture share one size. */
.ink.live .inkbar { position: absolute; left: 0; right: 0; bottom: 0; }
.ink.live .inkstage { box-shadow: inset 0 0 0 3px var(--accent); }
.inkstage { position: relative; flex: 1; min-height: 0; }
.inkcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
.inktext {
  position: absolute;
  min-width: 8ch;
  font: 600 18px/24px "Instrument Sans", sans-serif;
  padding: 0 3px;
  background: var(--st-paper);
  border: 2px solid currentColor;
  border-radius: 4px;
  outline: none;
}
.inkbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 10px 12px calc(var(--edge-bottom) + var(--kb, 0px));
  padding: 8px;
  border-radius: 20px;
}
.inktools { display: flex; gap: 2px; justify-content: space-between; flex: 1 1 100%; }
@media (min-width: 640px) { .inktools { flex: none; } }
.inktools .round { color: var(--ink); }
.inktools .round.on { color: var(--on-accent); background: var(--accent); border-color: var(--ink); }
.inkmsg { flex: 1 1 260px; display: flex; align-items: flex-end; gap: 8px; min-width: 0; }
.inkmsg textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 24vh;
  field-sizing: content;
  font-family: inherit;
  line-height: 22px;
  color: var(--ink);
  background: var(--field);
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  padding: 7px 12px;
  resize: none;
  outline: none;
}
.inkmsg textarea:focus { border-color: var(--accent); }

/* ---------- misc ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 40;
}

@media (prefers-reduced-motion: reduce) {
  .stage, .pill, #sheet { transition: none; }
  .pill, .pill.bounce, .card, #composer, .pill[data-state="busy"] .orb { animation: none; }
  .inkloop path { animation: none; stroke-dasharray: none; }
  .shipmark.play path { animation: none; stroke-dashoffset: 0; }
}
