/* Unii-Chat: black ink on white paper, drawn with lines. */

:root {
  --ink   : #111;
  --mid   : #5f5f5f;
  --soft  : #9a9a9a;
  --hair  : #e6e6e6;
  --paper : #fff;
  --line  : 1.25px;
  --serif : "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans  : -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono  : ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --col   : 740px;
  --gut   : 46px;
  --step  : 14px;
  --pill  : 34px;
  --ease  : cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: var(--ink); color: var(--paper); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* Solo pages: sign-in, notes ------------------------------------------- */

body.solo { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.center { width: min(420px, 100% - 48px); text-align: center; padding: 48px 0; }
.center .mark { width: 76px; height: 76px; margin-bottom: 18px; }
.center h1 { margin: 0; font: 400 46px/1.05 var(--serif); letter-spacing: -.015em; }
.center .tag { margin: 14px 0 44px; font: 12px/1.4 var(--mono); letter-spacing: .22em; color: var(--mid); }
.center .sub { margin: 22px 0 0; color: var(--mid); font-size: 14.5px; }
.center .sub b { color: var(--ink); font-weight: 500; }
.bad { color: var(--ink) !important; }
.bad::before { content: "! "; font-family: var(--mono); }
.rise { animation: rise .7s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.login { display: flex; align-items: center; gap: 10px; border: var(--line) solid var(--ink); border-radius: 999px; padding: 5px 5px 5px 20px; transition: box-shadow .2s; }
.login:focus-within { box-shadow: 0 0 0 4px #ececec; }
.login input { flex: 1; min-width: 0; border: 0; outline: 0; font: 16px var(--sans); background: none; color: var(--ink); padding: 8px 0; }
.login input::placeholder { color: var(--soft); }
.login button, .go { display: inline-flex; align-items: center; gap: 8px; background: var(--ink); color: var(--paper); border-radius: 999px; padding: 10px 16px 10px 18px; font-size: 14.5px; font-weight: 500; white-space: nowrap; transition: transform .15s var(--ease), opacity .2s; }
.login button:hover, .go:hover { transform: translateX(2px); }
.login button:disabled, .go:disabled { opacity: .5; }
.arr { width: 16px; height: 16px; stroke-width: 1.8; }
.link { margin-top: 26px; font-size: 14px; color: var(--mid); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* Header ----------------------------------------------------------------- */

header { position: fixed; inset: 0 0 auto; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--paper); border-bottom: 1px solid var(--hair); }
.brand { display: flex; align-items: center; gap: 10px; font: 400 21px/1 var(--serif); letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; margin: -4px -2px 0 0; }
.tools { display: flex; align-items: center; gap: 8px; }
.pill { height: 34px; display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; border: var(--line) solid var(--ink); border-radius: 999px; font-size: 13.5px; background: var(--paper); transition: background .15s, color .15s; }
@media (hover: hover) {
  .pill:hover { background: var(--ink); color: var(--paper); }
  .pill:hover .dim { color: #bdbdbd; }
}
.pill b { font-weight: 500; }
.pill svg { width: 15px; height: 15px; margin: 0 -4px 0 -2px; }
.pill.root svg { margin: 0 0 0 -3px; }
.pill.root.on { background: var(--ink); color: var(--paper); }
html, #log { overflow-anchor: none; }
.credits { font-family: var(--mono); font-size: 12.5px; letter-spacing: .02em; }
.credits.low { border-style: dashed; }
.more { width: 34px; padding: 0; justify-content: center; gap: 3px; }
.more i { width: 3.5px; height: 3.5px; border-radius: 50%; background: currentColor; }
.dim { color: var(--mid); font-weight: 400; }
.net { width: 8px; height: 8px; border-radius: 50%; border: var(--line) solid var(--ink); opacity: 0; transition: opacity .3s; }
.net.on { opacity: 1; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* The log --------------------------------------------------------------- */

#log { width: min(var(--col), 100% - 40px); margin: 0 auto; padding: 86px 0 190px; }

/* a row: its gutter (its level, in one column, then the rails of the
   cuts it lies in), then its content. The gap above a row is its own padding, so rails run
   unbroken from row to row. */
.row { --depth: 0; --gap: 22px; --in: calc(var(--depth) * var(--step)); position: relative; padding: var(--gap) 0 0 calc(var(--in) + var(--gut)); }
#log > .row:first-child { --gap: 0px; }
.row .c { min-width: 0; }

/* the level: 0x a message, whole; kx a fold of 2^k messages */
.z { position: absolute; left: 0; top: calc(var(--gap) + 3px); width: var(--pill); text-align: center; font: 600 11px/18px var(--sans); font-variant-numeric: tabular-nums; border: var(--line) solid var(--ink); border-radius: 999px; color: var(--ink); background: var(--paper); transition: background .15s, color .15s; }
.z0 { border-color: #c2c2c2; color: #8a8a8a; font-weight: 500; }
.msg.user .z0 { top: calc(var(--gap) + 11px); }

/* a rail: the bracket of a cut, along both its halves */
.rail { position: absolute; left: calc(var(--pill) + 6px + var(--d) * var(--step)); top: 0; bottom: 0; width: 7px; border-left: var(--line) solid var(--ink); opacity: .28; pointer-events: none; transition: opacity .15s; }
.rail.top { top: calc(var(--gap) + 10px); border-top: var(--line) solid var(--ink); border-top-left-radius: 7px; }
.rail.end { bottom: 2px; border-bottom: var(--line) solid var(--ink); border-bottom-left-radius: 7px; }
.rail.lit { opacity: .9; }

/* a fold: a card of many messages, k times compressed: how many and
   when, then their summary, in the chat's own forms; a click cuts it in
   two */
.fold { cursor: pointer; outline: 0; }
.fold + .fold, .fold + .steps, .steps + .fold, .steps + .steps { --gap: 14px; }
.fold .c { display: flex; flex-direction: column; gap: 6px; padding: 9px 16px 12px; background: #f4f4f4; border: 1px solid #ececec; border-radius: 14px; color: #555; overflow-wrap: anywhere; transition: background .15s, color .15s; }
.fold .meta { margin: 0; font: 500 11.5px/1.4 var(--sans); color: #9a9a9a; }
.fold .say { margin: 0; font: 16px/1.6 var(--serif); }
.fold .ask { align-self: flex-end; max-width: min(82%, 560px); font: 15px/1.5 var(--sans); background: var(--paper); border: 1px solid #d8d8d8; border-radius: 18px 18px 5px 18px; padding: 7px 14px; }
.fold .act { display: flex; gap: 10px; font: 12px/1.5 var(--mono); color: #8a8a8a; }
.fold .act .k { flex: none; width: 38px; text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; padding-top: 1px; }
.fold .wait { font-style: italic; color: var(--soft); }
.fold:hover .c, .fold:focus-visible .c, .fold.lit .c { background: #ebebeb; color: var(--ink); }
.fold:hover .z, .fold:focus-visible .z { background: var(--ink); color: var(--paper); }
.fold.loading .c { animation: blink 1s infinite; }

/* a seam: where a fold was cut; its round button, on the cut's rail,
   joins it */
.seam { --gap: 10px; height: calc(var(--gap) + 20px); }
.seam + .row { --gap: 10px; }
.seam .cut { position: absolute; left: calc(var(--in) + var(--gut)); right: 0; top: calc(var(--gap) + 10px); border-top: 1px dashed #b8b8b8; transform-origin: left; transition: border-color .15s; }
.join { position: absolute; left: calc(var(--pill) - 4px + var(--in)); top: var(--gap); z-index: 1; width: 21px; height: 21px; display: grid; place-items: center; border: var(--line) solid var(--ink); border-radius: 50%; background: var(--paper); transition: background .15s, color .15s; }
.join svg { width: 12px; height: 12px; stroke-width: 2.2; }
.seam.lit .join, .join:focus-visible { background: var(--ink); color: var(--paper); outline: 0; }
.seam.lit .cut { border-top-color: var(--ink); }

/* a run of tool rows, without verbose: a click shows them */
.steps { --gap: 12px; cursor: pointer; }
.steps .c { display: flex; align-items: center; gap: 8px; font: 12px/18px var(--sans); color: var(--soft); }
.steps .c::before { content: ""; width: 16px; border-top: 1px dashed #c8c8c8; }
.steps .show { opacity: 0; text-decoration: underline; text-underline-offset: 3px; transition: opacity .15s; }
.steps:hover .c { color: var(--ink); }
.steps:hover .show { opacity: 1; }

/* at Root, the caption over the tops */
.cap .c p { margin: 0; font: italic 16px/1.5 var(--serif); color: var(--mid); }

.msg .c { font: 17.5px/1.68 var(--serif); }
.msg .c > :first-child { margin-top: 0; }
.msg .c > :last-child { margin-bottom: 0; }
.msg p, .msg ul, .msg ol, .msg blockquote, .msg pre, .msg .table { margin: 0 0 .85em; }
.msg ul, .msg ol { padding-left: 1.3em; }
.msg li { margin: .2em 0; }
.msg li::marker { color: var(--mid); }
.msg h2, .msg h3, .msg h4 { font-family: var(--serif); font-weight: 600; margin: 1.2em 0 .45em; line-height: 1.3; }
.msg h2 { font-size: 1.3em; } .msg h3 { font-size: 1.12em; } .msg h4 { font-size: 1em; }
.msg hr { border: 0; border-top: var(--line) solid var(--ink); margin: 1.4em 0; width: 48px; }
.msg blockquote { border-left: var(--line) solid var(--ink); padding-left: 1em; color: var(--mid); font-style: italic; }
.msg code { font: .82em var(--mono); border: 1px solid #d4d4d4; border-radius: 5px; padding: .08em .35em; }
.msg pre { position: relative; font: 13.5px/1.55 var(--mono); border: var(--line) solid var(--ink); border-radius: 12px; padding: 14px 16px; overflow-x: auto; }
.msg pre code { font: inherit; border: 0; padding: 0; }
.msg pre .lang { position: absolute; top: 9px; right: 14px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); }
.msg .table { overflow-x: auto; }
.msg table { border-collapse: collapse; font: 15px/1.45 var(--sans); }
.msg th, .msg td { text-align: left; padding: 6px 14px 6px 0; border-bottom: 1px solid var(--hair); }
.msg th { font-weight: 600; border-bottom: var(--line) solid var(--ink); }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .c { font: 16px/1.55 var(--sans); max-width: min(82%, 560px); }
.bubble { border: var(--line) solid var(--ink); border-radius: 20px 20px 6px 20px; padding: 10px 17px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble code { font: .88em var(--mono); }

.msg.tool .c, .msg.echo .c { font: 12.5px/1.5 var(--mono); color: var(--mid); display: flex; gap: 10px; }
.msg.tool .k, .msg.echo .k { flex: none; width: 38px; text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; padding-top: 1px; color: var(--soft); }
.msg.tool pre, .msg.echo pre { margin: 0; border: 0; padding: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; max-height: 9em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.msg.tool, .msg.echo { cursor: pointer; }
.msg.wide pre { max-height: none; -webkit-mask-image: none; mask-image: none; }
.msg.tool:hover .c, .msg.echo:hover .c { color: var(--ink); }
.msg.tool + .msg.echo, .msg.echo + .msg.tool, .msg.tool + .msg.tool { --gap: 8px; }
.msg.tool .z0, .msg.echo .z0 { top: var(--gap); }
.msg .k + p { margin-top: 0; }
.msg.note .c { font: 14px/1.5 var(--sans); color: var(--mid); }


.mind { --gap: 14px; }
.mind .c { font: italic 14.5px/1.6 var(--serif); color: var(--mid); border-left: 1px dashed var(--soft); padding-left: 14px; max-height: 18em; overflow: auto; }
.mind .c p { margin: 0 0 .6em; }
.mind .c > :last-child { margin-bottom: 0; }
.live.mind { display: block; }
.msg.live.mind .c { font: italic 14.5px/1.6 var(--serif); color: var(--mid); border-left: 1px dashed var(--soft); padding-left: 14px; }

.merging { overflow: hidden; }
.ghost { position: absolute; left: calc(var(--in) + var(--gut)); right: 0; top: var(--gap); pointer-events: none; transform-origin: top; color: var(--mid); }
.ghost .c + .c { margin-top: 12px; }

.thinking { --gap: 24px; }
.thinking span { font: 14.5px var(--serif); font-style: italic; letter-spacing: .01em; background: linear-gradient(90deg, #a8a8a8 0 35%, var(--ink) 50%, #a8a8a8 65% 100%); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shine 1.8s linear infinite; }
.thinking span::after { content: "…"; }
@keyframes shine { from { background-position: 100% 0; } to { background-position: 0 0; } }

.empty { position: fixed; inset: 0; display: none; place-content: center; text-align: center; pointer-events: none; }
.empty.on { display: grid; animation: rise .8s var(--ease) both; }
.empty .mark { width: 64px; height: 64px; margin: 0 auto 16px; }
.empty p { margin: 0; font: italic 19px/1.5 var(--serif); color: var(--mid); }

/* Composer -------------------------------------------------------------- */

footer { position: fixed; inset: auto 0 0; z-index: 10; padding: 34px 20px max(14px, env(safe-area-inset-bottom)); background: linear-gradient(rgba(255, 255, 255, 0), var(--paper) 38%); }
.composer { width: min(var(--col), 100%); margin: 0 auto; display: flex; align-items: flex-end; gap: 10px; border: var(--line) solid var(--ink); border-radius: 26px; padding: 7px 7px 7px 20px; background: var(--paper); transition: box-shadow .2s; }
.composer:focus-within { box-shadow: 0 0 0 4px #efefef; }
.composer textarea { flex: 1; resize: none; border: 0; outline: 0; background: none; color: var(--ink); font: 16px/1.5 var(--sans); padding: 7px 0; max-height: 40vh; }
.composer textarea::placeholder { color: var(--soft); }
.send { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--paper); transition: transform .15s var(--ease); }
.send:hover { transform: translateY(-1px); }
.send svg { width: 20px; height: 20px; stroke-width: 2; }
.send.stop { background: var(--paper); color: var(--ink); border: var(--line) solid var(--ink); }
.send.stop svg { fill: currentColor; stroke-width: 0; width: 16px; height: 16px; }
.hint { margin: 9px 0 0; text-align: center; font: 12px/1.4 var(--sans); color: var(--soft); }
.hint svg { width: 12px; height: 12px; stroke-width: 2.2; vertical-align: -2px; color: var(--mid); }

#toast { position: absolute; left: 50%; bottom: calc(100% - 22px); transform: translate(-50%, 8px); max-width: min(560px, 100% - 40px); padding: 8px 16px; border: var(--line) solid var(--ink); border-radius: 999px; background: var(--paper); font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .3s var(--ease); cursor: pointer; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.bad { border-style: dashed; }

/* Popovers -------------------------------------------------------------- */

#pop { position: fixed; z-index: 20; width: 320px; max-width: calc(100vw - 24px); padding: 10px; border: var(--line) solid var(--ink); border-radius: 18px; background: var(--paper); opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity .18s, transform .22s var(--ease); }
#pop.on { opacity: 1; transform: none; pointer-events: auto; }
#pop .label { margin: 10px 8px 6px; font: 10.5px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--soft); }
#pop .label:first-child { margin-top: 4px; }
.opt { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; text-align: left; font-size: 14.5px; transition: background .12s; }
.opt:hover { background: #f3f3f3; }
.opt .dim { margin-left: auto; font-size: 12.5px; }
.dot { flex: none; width: 13px; height: 13px; border: var(--line) solid var(--ink); border-radius: 50%; position: relative; }
.opt.on .dot::after { content: ""; position: absolute; inset: 2.5px; border-radius: 50%; background: var(--ink); }
.segs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 6px 6px; }
.seg { flex: 1 1 auto; min-width: 0; padding: 6px 7px; border: var(--line) solid var(--ink); border-radius: 999px; font-size: 12.5px; transition: background .12s, color .12s; }
.seg:hover { background: #f3f3f3; }
.seg.on { background: var(--ink); color: var(--paper); }
.seg:disabled { opacity: .28; cursor: default; background: none; border-style: dashed; }
#pop .big { margin: 0 8px 6px; font: 400 34px/1.1 var(--serif); }
#pop .go { width: calc(100% - 12px); margin: 10px 6px 4px; justify-content: center; }
#pop .note { margin: 10px 8px 4px; font-size: 12.5px; color: var(--mid); line-height: 1.45; }
#pop .who { margin: 6px 10px 8px; font-size: 13px; color: var(--mid); overflow-wrap: anywhere; }
.switch { margin-left: 4px; flex: none; width: 30px; height: 18px; border: var(--line) solid var(--ink); border-radius: 999px; position: relative; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; border: var(--line) solid var(--ink); background: var(--paper); transition: transform .2s var(--ease); box-sizing: border-box; }
.toggle.on .switch { background: var(--ink); }
.toggle.on .switch::after { transform: translateX(12px); }
.toggle .dim { font-size: 12px; }

/* Small screens --------------------------------------------------------- */

@media (max-width: 600px) {
  header { padding: 10px 12px; }
  .brand span { display: none; }
  .brand img { width: 32px; height: 32px; }
  .tools { gap: 6px; }
  .pill { height: 32px; padding: 0 11px; font-size: 13px; }
  .model .dim { display: none; }
  #log { width: calc(100% - 28px); padding-top: 70px; }
  :root { --gut: 32px; --step: 9px; --pill: 26px; }
  .z { font-size: 10px; }
  .rail { left: calc(var(--pill) + 4px + var(--d) * var(--step)); width: 5px; }
  .join { left: calc(var(--pill) - 6px + var(--in)); }
  .fold .c { padding: 8px 12px 10px; }
  .msg .c { font-size: 17px; }
  .msg.user .c { max-width: 88%; }
  footer { padding: 26px 10px max(10px, env(safe-area-inset-bottom)); }
  .hint { margin-top: 6px; font-size: 11px; }
  #pop { left: 12px; right: 12px !important; width: auto; max-width: none; }
  .center h1 { font-size: 40px; }
}

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