/* StairChat: 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;
  --ease  : cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
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: 14px 20px 22px; background: linear-gradient(var(--paper) 62%, rgba(255, 255, 255, 0)); }
.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; }
.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: 84px 0 190px; }

.row { position: relative; }
.row .c { min-width: 0; }

.line { display: block; padding: 3px 0 3px 46px; color: var(--mid); font-size: 14px; line-height: 1.5; cursor: pointer; border-radius: 8px; transition: color .15s, background .15s; outline: 0; }
.line .n { position: absolute; left: 0; width: 36px; letter-spacing: -.02em; text-align: right; font: 11px/21px var(--mono); color: var(--soft); }
.line .n:empty::after { content: ""; position: absolute; right: 2px; top: 10px; width: 4px; height: 1.2px; background: var(--soft); }
.line .t { display: block; overflow-wrap: anywhere; }
.line .k { font: 10.5px var(--mono); letter-spacing: .06em; color: var(--soft); text-transform: uppercase; margin-right: 1px; }
.line:hover, .line:focus-visible { color: var(--ink); }
.line:hover .n, .line:focus-visible .n { color: var(--ink); }
.line:hover .k { color: var(--ink); }
.line .wait { font-style: italic; color: var(--soft); }
.line.loading .t { animation: blink 1s infinite; }
.line + .msg, .msg + .line { margin-top: 18px; }
.line:first-child { margin-top: 8px; }

.msg { padding: 0 0 0 46px; }
.msg + .msg { margin-top: 20px; }
.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 { margin-top: 8px; }
.msg .k + p { margin-top: 0; }
.msg.note .c { font: 14px/1.5 var(--sans); color: var(--mid); }

.msg.opened { padding-top: 6px; padding-bottom: 10px; }
.msg.opened .c { font-size: 16px; }
.msg.opened.user .c { max-width: 100%; }

.mind { padding: 2px 0 2px 46px; margin: 14px 0; }
.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; }

/* opened lines: one rule per level, left of the text, that joins it back */
.inside { padding-left: calc(46px + var(--n, 1) * 14px); }
.rules { position: absolute; left: 40px; top: 0; bottom: 0; }
.rule { position: absolute; top: 0; bottom: 0; left: calc(var(--d) * 14px); width: 14px; cursor: pointer; }
.rule::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; border-left: 1px solid var(--ink); opacity: .55; transition: opacity .15s, border-width .15s; }
.rule.top::before { top: 9px; border-top-left-radius: 0; }
.rule.top::after { content: ""; position: absolute; left: 3px; top: 3px; width: 7px; height: 7px; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper); transition: background .15s; }
.rule:hover::before { opacity: 1; border-left-width: 2px; left: 5.5px; }
.rule:hover::after { background: var(--ink); }
.row.inside.line { padding-top: 3px; padding-bottom: 3px; }
.row.inside .n { left: 0; }

.merging { overflow: hidden; }
.ghost { position: absolute; inset: 0 0 auto 0; pointer-events: none; transform-origin: top; }
.ghost .row { position: static; padding-left: 46px; }

.thinking { padding: 6px 0 0 46px; margin-top: 18px; }
.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: 11px/1.4 var(--mono); letter-spacing: .04em; color: var(--soft); }

#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 18px; }
  .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; }
  .line, .msg, .mind, .thinking { padding-left: 30px; }
  .line .n { width: 22px; font-size: 10px; }
  .inside { padding-left: calc(30px + var(--n, 1) * 12px); }
  .rules { left: 24px; }
  .rule { width: 12px; left: calc(var(--d) * 12px); }
  .msg .c { font-size: 17px; }
  .msg.user .c { max-width: 88%; }
  footer { padding: 26px 10px max(10px, env(safe-area-inset-bottom)); }
  .hint { display: none; }
  #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; }
}
