/* Relay: Apple design language (iOS 26: Liquid Glass bars, large titles,
   inset grouped lists, sheets). Colours are iOS system colours. */

:root {
  --bg: #ffffff;
  --bg-grouped: #f2f2f7;
  --bg-cell: #ffffff;
  --bg-elev: #ffffff;
  --label: #000000;
  --label-2: rgba(60, 60, 67, .6);
  --label-3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .2);
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(118, 118, 128, .2);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --purple: #af52de;
  --indigo: #5856d6;
  --teal: #30b0c7;
  --bubble-me: #007aff;
  --code-bg: #f5f5f7;
  --glass: rgba(255, 255, 255, .62);
  --glass-strong: rgba(255, 255, 255, .82);
  --glass-rim: rgba(0, 0, 0, .06);
  --glass-hi: rgba(255, 255, 255, .9);
  --glass-shadow: 0 6px 24px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .06);
  --scrim: rgba(0, 0, 0, .32);
  --spring: cubic-bezier(.32, .72, 0, 1);
  --bounce: cubic-bezier(.34, 1.36, .64, 1);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --nav-h: calc(var(--st) + 60px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", "Helvetica Neue", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-grouped: #000000;
    --bg-cell: #1c1c1e;
    --bg-elev: #1c1c1e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, .6);
    --label-3: rgba(235, 235, 245, .3);
    --sep: rgba(84, 84, 88, .6);
    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(118, 118, 128, .32);
    --blue: #0a84ff;
    --red: #ff453a;
    --green: #30d158;
    --orange: #ff9f0a;
    --purple: #bf5af2;
    --indigo: #5e5ce6;
    --teal: #40c8e0;
    --bubble-me: #0a84ff;
    --code-bg: #1c1c1e;
    --glass: rgba(44, 44, 48, .58);
    --glass-strong: rgba(44, 44, 48, .86);
    --glass-rim: rgba(255, 255, 255, .1);
    --glass-hi: rgba(255, 255, 255, .14);
    --glass-shadow: 0 6px 24px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
    --scrim: rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 17px/1.35 var(--font);
  letter-spacing: -.01em;
  color: var(--label);
  background: #000;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ico { width: 22px; height: 22px; flex: none; display: block; }

/* ------------------------------------------------------------- frame */
#app {
  position: fixed; top: 0; left: 0; right: 0; height: var(--vvh, 100%);
  background: var(--bg);
  overflow: hidden;
  transform-origin: 50% 0;
  transition: transform .5s var(--spring), border-radius .5s var(--spring), filter .5s var(--spring);
}
.view {
  position: absolute; inset: 0;
  background: var(--bg);
  transition: transform .5s var(--spring);
  will-change: transform;
}
#listView { z-index: 1; }
#chatView { z-index: 2; transform: translateX(100%); box-shadow: -10px 0 40px rgba(0, 0, 0, .12); }
body.in-chat #chatView { transform: translateX(0); }
body.in-chat #listView { transform: translateX(-28%); }
#listView::after {
  content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, .12);
  opacity: 0; pointer-events: none; transition: opacity .5s var(--spring);
}
body.in-chat #listView::after { opacity: 1; }
body.dragging .view, body.dragging #listView::after,
body.no-trans .view, body.no-trans #listView::after { transition: none !important; }

@media (min-width: 860px) {
  #listView { width: 360px; right: auto; background: var(--bg-grouped); transform: none !important; border-right: .5px solid var(--sep); }
  #listView::after { display: none; }
  #chatView { left: 360px; transform: none !important; box-shadow: none; }
  #backBtn { visibility: hidden; }
}

/* ------------------------------------------------------- glass + bars */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: var(--glass-shadow), inset 0 .5px 0 var(--glass-hi), inset 0 0 0 .5px var(--glass-rim);
}
.circle {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  transition: transform .25s var(--bounce), opacity .2s;
}
.circle:active, .pill:active { transform: scale(.9); }
.pill {
  height: 44px; border-radius: 22px; padding: 0 12px 0 16px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .25s var(--bounce);
}

.nav {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  height: var(--nav-h);
  padding: var(--st) max(16px, var(--sr)) 0 max(16px, var(--sl));
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  pointer-events: none;
}
.nav > * { pointer-events: auto; }
/* scroll-edge effect: content softly blurs and fades under the bar */
.nav::before {
  content: ""; position: absolute; inset: 0 0 -24px; z-index: -1; pointer-events: none;
  background: linear-gradient(var(--bg) calc(var(--st) + 10px), color-mix(in srgb, var(--bg) 70%, transparent) 60%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
  opacity: 0; transition: opacity .2s;
}
.nav.scrolled::before { opacity: 1; }
#listView .nav::before { background: linear-gradient(var(--bg) calc(var(--st) + 10px), color-mix(in srgb, var(--bg) 70%, transparent) 60%, transparent); }
@media (min-width: 860px) {
  #listView .nav::before { background: linear-gradient(var(--bg-grouped) calc(var(--st) + 10px), color-mix(in srgb, var(--bg-grouped) 70%, transparent) 60%, transparent); }
}
.nav-title {
  text-align: center; font-weight: 600; font-size: 17px;
  opacity: 0; transform: translateY(4px); transition: opacity .2s, transform .2s;
}
.nav.titled .nav-title { opacity: 1; transform: none; }

.scroll {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--nav-h) 0 calc(var(--sb) + 96px);
}

/* ------------------------------------------------------------- list */
.large-title {
  font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .01em;
  margin: 4px 0 10px; padding: 0 max(20px, var(--sl));
}
.search {
  display: flex; align-items: center; gap: 6px;
  margin: 0 max(16px, var(--sl)) 14px; height: 40px; padding: 0 12px;
  border-radius: 20px; background: var(--fill);
  color: var(--label-2);
}
.search .ico { width: 18px; height: 18px; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 17px; color: var(--label);
}
.search input::placeholder { color: var(--label-2); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.chat-list { list-style: none; margin: 0; padding: 0 0 0 max(0px, var(--sl)); }
.chat-row { position: relative; overflow: hidden; }
.row-del {
  position: absolute; top: 0; bottom: 0; right: 0; width: 100%;
  display: flex; align-items: center; justify-content: flex-end; padding-right: 24px;
  background: var(--red); color: #fff; font-weight: 500;
  visibility: hidden;
}
.chat-row.open .row-del, .chat-row.swiping .row-del { visibility: visible; }
.row-main {
  position: relative; display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 16px 11px 20px; background: var(--bg);
  transition: transform .4s var(--spring), background-color .15s;
  touch-action: pan-y;
}
@media (min-width: 860px) {
  .chat-list { padding: 0 10px; }
  .chat-row { border-radius: 14px; }
  .row-main { background: var(--bg-grouped); padding: 10px 12px; border-radius: 14px; }
  .chat-row.active .row-main { background: var(--fill-2); }
}
.chat-row:active .row-main { background: var(--fill); }
.row-main::after {
  content: ""; position: absolute; left: 20px; right: 0; bottom: 0; height: .5px; background: var(--sep);
}
.chat-row:last-child .row-main::after, .chat-row.active .row-main::after { display: none; }
@media (min-width: 860px) { .row-main::after { left: 12px; right: 12px; } }
.row-text { flex: 1; min-width: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: 15px; color: var(--label-2); flex: none; }
.row-preview {
  font-size: 15px; line-height: 20px; color: var(--label-2); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row-meta { font-size: 12px; color: var(--label-3); margin-top: 3px; }

.empty { text-align: center; padding: 56px 32px; color: var(--label-2); }
.empty-title { font-size: 20px; font-weight: 600; color: var(--label); margin-bottom: 6px; }

/* ------------------------------------------------------------- chat */
#chatView .nav { grid-template-columns: 44px 1fr auto; }
/* iOS 26 groups neighbouring bar buttons in one glass capsule */
.bar-group { display: flex; height: 44px; border-radius: 22px; padding: 0 2px; }
.bar-group button { width: 42px; height: 44px; display: grid; place-items: center; border-radius: 22px; transition: transform .25s var(--bounce); }
.bar-group button:active { transform: scale(.86); }
.model-btn { justify-self: center; max-width: min(64vw, 380px); min-width: 0; }
.model-text { display: flex; flex-direction: column; align-items: center; min-width: 0; line-height: 1.1; }
#modelName { font-size: 15px; font-weight: 600; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#providerName { font-size: 11px; color: var(--label-2); font-weight: 500; }
.chev-down .ico { width: 14px; height: 14px; stroke-width: 2.6; color: var(--label-2); }

.welcome {
  position: absolute; left: 0; right: 0; top: 34%;
  display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 32px;
  transition: opacity .3s;
}
.welcome-icon { width: 68px; height: 68px; border-radius: 16px; margin-bottom: 14px; box-shadow: 0 6px 20px rgba(80, 60, 220, .25); }
.welcome-title { font-size: 22px; font-weight: 700; }
.welcome-sub { font-size: 15px; color: var(--label-2); margin-top: 4px; }
.has-msgs .welcome { opacity: 0; pointer-events: none; }

.messages { max-width: 780px; margin: 0 auto; padding: 4px max(16px, var(--sr)) 0 max(16px, var(--sl)); }
.msg { margin: 0 0 18px; animation: rise .45s var(--spring) both; }
.msg.no-anim { animation: none; }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  max-width: min(82%, 560px);
  background: var(--bubble-me); color: #fff;
  padding: 8px 14px 9px; border-radius: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  user-select: text; -webkit-user-select: text;
  transition: transform .2s var(--bounce);
}
.msg.user.pressed .bubble, .msg.assistant.pressed .md { transform: scale(.97); }

.msg.assistant .md { line-height: 1.5; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; transition: transform .2s var(--bounce); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.25; margin: 1.1em 0 .45em; }
.md h1 { font-size: 24px; } .md h2 { font-size: 21px; } .md h3 { font-size: 19px; } .md h4 { font-size: 17px; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md li::marker { color: var(--label-2); }
.md a { color: var(--blue); text-decoration: none; }
.md blockquote { margin: 0 0 .7em; padding: 2px 0 2px 12px; border-left: 3px solid var(--fill-2); color: var(--label-2); }
.md hr { border: 0; height: .5px; background: var(--sep); margin: 1.2em 0; }
.md code { font: .88em/1.4 var(--mono); background: var(--fill); padding: .12em .38em; border-radius: 6px; }
.md table { border-collapse: collapse; margin: 0 0 .8em; font-size: 15px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border-bottom: .5px solid var(--sep); padding: 6px 12px 6px 0; text-align: left; }
.md th { font-weight: 600; }
.md img { max-width: 100%; border-radius: 12px; }
.code {
  margin: 0 0 .8em; border-radius: 16px; background: var(--code-bg); overflow: hidden;
  box-shadow: inset 0 0 0 .5px var(--sep);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px 0 14px; font-size: 12px; color: var(--label-2); font-weight: 500;
}
.code-copy { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 10px; color: var(--label-2); font-size: 12px; }
.code-copy .ico { width: 14px; height: 14px; }
.code-copy:active { background: var(--fill); }
.code pre { margin: 0; padding: 8px 14px 13px; overflow-x: auto; }
.code pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; white-space: pre; }

.cursor::after {
  content: ""; display: inline-block; width: .55em; height: .55em; margin-left: 3px; vertical-align: .05em;
  border-radius: 50%; background: var(--label); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

.typing { display: inline-flex; gap: 5px; padding: 12px 16px; border-radius: 20px; background: var(--fill); }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--label-2); animation: dot 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

.think { margin: 0 0 10px; }
.think summary {
  list-style: none; display: inline-flex; align-items: center; gap: 4px;
  font-size: 15px; color: var(--label-2); cursor: pointer; user-select: none; -webkit-user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary .ico { width: 14px; height: 14px; stroke-width: 2.4; transition: transform .3s var(--spring); }
.think[open] summary .ico { transform: rotate(90deg); }
.think.live summary span {
  background: linear-gradient(90deg, var(--label-2) 30%, var(--label) 50%, var(--label-2) 70%);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.think-body {
  margin-top: 6px; padding-left: 12px; border-left: 2px solid var(--fill-2);
  font-size: 15px; line-height: 1.45; color: var(--label-2); white-space: pre-wrap;
  max-height: 320px; overflow-y: auto;
}

.meta { display: flex; align-items: center; gap: 2px; margin-top: 6px; color: var(--label-2); min-height: 30px; }
.meta button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; transition: transform .2s var(--bounce), background-color .15s; }
.meta button:active { background: var(--fill); transform: scale(.88); }
/* Copy buttons flip to a tick for a moment: it pops in and draws itself. */
.meta button.copied, .code-copy.copied { color: var(--green); }
.copied .ico { animation: tick-pop .5s var(--bounce) both; }
.copied .ico path { stroke-dasharray: 22; stroke-dashoffset: 22; animation: tick-draw .32s .06s ease-out forwards; }
@keyframes tick-pop { from { transform: scale(.4); opacity: 0; } }
@keyframes tick-draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .copied .ico, .copied .ico path { animation: none; stroke-dashoffset: 0; } }
.meta .ico { width: 18px; height: 18px; }
.meta-model { font-size: 12px; margin-left: 6px; color: var(--label-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 18px; background: var(--fill); font-size: 15px;
}
.notice .ico { width: 20px; height: 20px; color: var(--orange); margin-top: 1px; }
.notice.err .ico { color: var(--red); }
.notice-act { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.notice-act button { padding: 6px 14px; border-radius: 16px; background: var(--fill-2); font-size: 15px; font-weight: 600; color: var(--blue); }

.to-bottom { position: absolute; left: 50%; bottom: calc(var(--sb) + 84px); margin-left: -20px; width: 40px; height: 40px; z-index: 4; }
.to-bottom .ico { width: 18px; height: 18px; }

/* --------------------------------------------------------- composer */
.composer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px max(12px, var(--sr)) calc(var(--sb) + 10px) max(12px, var(--sl));
  pointer-events: none;
}
.composer::before {
  content: ""; position: absolute; inset: -20px 0 0; z-index: -1;
  background: linear-gradient(transparent, color-mix(in srgb, var(--bg) 85%, transparent) 45%);
}
body.kb .composer { padding-bottom: 8px; }
body.kb .scroll { padding-bottom: 80px; }
body.kb .to-bottom { bottom: 74px; }
@media (pointer: coarse) {
  .bubble, .msg.assistant .md { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}
.field {
  pointer-events: auto;
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  min-height: 50px; padding: 7px; border-radius: 25px;
  background: var(--glass-strong);
}
.field-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.field textarea {
  width: 100%; min-width: 0; border: 0; outline: 0; background: none; resize: none;
  font-size: 17px; line-height: 22px; padding: 7px 0; max-height: 160px;
}
.attach {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--fill); color: var(--label-2);
  transition: transform .25s var(--bounce), background-color .2s;
}
.attach .ico { width: 20px; height: 20px; stroke-width: 2.4; }
.attach:active { transform: scale(.86); background: var(--fill-2); }
/* photos waiting to be sent */
.tray { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 0 6px; }
.tray::-webkit-scrollbar { display: none; }
.thumb { position: relative; flex: none; width: 64px; height: 64px; animation: rise .35s var(--spring) both; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; box-shadow: inset 0 0 0 .5px var(--sep); }
.thumb-x {
  position: absolute; top: -5px; right: -5px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--label); color: var(--bg);
  box-shadow: 0 0 0 2px var(--bg-cell);
}
.thumb-x .ico { width: 12px; height: 12px; stroke-width: 3; }
/* photos in a sent message */
.user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; max-width: min(82%, 560px); }
.user-col .bubble { max-width: 100%; }
.shots { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.shots img {
  display: block; max-width: min(240px, 100%); max-height: 300px; border-radius: 18px; object-fit: cover; cursor: zoom-in;
  background: var(--fill); transition: transform .2s var(--bounce);
}
.shots img:only-child { max-width: min(280px, 100%); }
.msg.user.pressed .shots img { transform: scale(.97); }
.lightbox {
  position: absolute; inset: 0; display: grid; place-items: center; padding: calc(var(--st) + 20px) 12px calc(var(--sb) + 20px);
  background: rgba(0, 0, 0, .92); opacity: 0; transition: opacity .3s; pointer-events: auto; cursor: zoom-out;
}
.lightbox.show { opacity: 1; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; transform: scale(.94); transition: transform .4s var(--spring); }
.lightbox.show img { transform: none; }
.field textarea::placeholder { color: var(--label-2); }
.send {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--blue); color: #fff;
  transition: transform .25s var(--bounce), background-color .2s, opacity .2s;
}
.send .ico { width: 20px; height: 20px; stroke-width: 2.6; }
.send:active { transform: scale(.86); }
.send:disabled { background: var(--fill-2); color: var(--label-3); cursor: default; }
.send.stop { background: var(--label); color: var(--bg); }

/* group chats: member faces above the message box (tap = speak now) */
.members {
  pointer-events: auto; max-width: 780px; margin: 0 auto 8px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px;
}
.members::-webkit-scrollbar { display: none; }
.member {
  flex: none; display: flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 13px 0 4px; border-radius: 18px;
  font-size: 14px; font-weight: 500; color: var(--label);
  transition: transform .25s var(--bounce), opacity .2s;
}
.member img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--fill); }
.member:active { transform: scale(.92); }
.member:disabled { opacity: .45; }
/* room for the composer, measured in app.js (--composer-h) */
#msgScroll { padding-bottom: calc(var(--composer-h, 96px) + 14px); }
#toBottom { bottom: calc(var(--composer-h, 96px) + 6px); }
.cell.pickable .check { opacity: 0; transition: opacity .15s; }
.cell.pickable.picked .check { opacity: 1; }
.cell-av { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; margin-right: 12px; background: var(--fill); }

/* context meter: a ring beside Send, and its sheet */
.ctx {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--blue);
  transition: transform .25s var(--bounce), color .2s;
}
.ctx:active { transform: scale(.86); }
.ctx.high, .ctx-hero.high { color: var(--orange); }
.ctx.full, .ctx-hero.full { color: var(--red); }
.ring .track { fill: none; stroke: var(--fill-2); }
.ring .bar { fill: none; stroke: currentColor; stroke-linecap: round; }
.ctx-hero { display: grid; justify-items: center; gap: 12px; padding: 6px 0 24px; color: var(--blue); }
.ctx-dial { display: grid; place-items: center; }
.ctx-dial > * { grid-area: 1 / 1; }
.ctx-pct { font-size: 30px; font-weight: 700; letter-spacing: -.02em; color: var(--label); font-variant-numeric: tabular-nums; }
.ctx-cap { font-size: 15px; color: var(--label-2); }

/* ----------------------------------------------------------- sheets */
#layer { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .45s var(--spring); pointer-events: auto; }
.scrim.show { opacity: 1; }
body.sheet-open #app { transform: translateY(calc(var(--st) + 10px)) scale(.92); border-radius: 22px; }
@media (min-width: 700px) { body.sheet-open #app { transform: none; border-radius: 0; } }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(100% - var(--st) - 18px);
  background: var(--bg-grouped); color: var(--label);
  border-radius: 28px 28px 0 0; overflow: hidden;
  transform: translateY(100%); transition: transform .5s var(--spring);
  pointer-events: auto; display: flex; flex-direction: column;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) { .sheet { background: #1c1c1e; } .sheet .cells { background: #2c2c2e; } .sheet .search, .sheet .seg { background: rgba(118, 118, 128, .24); } }
.sheet.show { transform: translateY(0); }
.sheet.drag { transition: none; }
@media (min-width: 700px) {
  .sheet {
    left: 50%; top: 50%; bottom: auto; width: 560px; height: min(700px, 86vh); margin-left: -280px;
    border-radius: 28px; transform: translateY(calc(-50% + 40px)) scale(.96); opacity: 0;
    transition: transform .45s var(--spring), opacity .3s;
  }
  .sheet.show { transform: translateY(-50%); opacity: 1; }
}
.grabber { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--label-3); z-index: 3; }
@media (min-width: 700px) { .grabber { display: none; } }

.pages { position: relative; flex: 1; overflow: hidden; }
.page {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  background: inherit; transition: transform .45s var(--spring), opacity .45s var(--spring);
}
.pages > .page { background: var(--bg-grouped); }
@media (prefers-color-scheme: dark) { .pages > .page { background: #1c1c1e; } }
.page.under { transform: translateX(-30%); opacity: .6; }
.page.right { transform: translateX(100%); }
.page-head {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 16px 14px 6px; min-height: 66px;
}
.page-head h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-head .l { justify-self: start; } .page-head .r { justify-self: end; }
.page-head .circle { width: 40px; height: 40px; }
.page-head .circle .ico { width: 20px; height: 20px; }
.page-head .done { background: var(--blue); color: #fff; }
.page-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 calc(var(--sb) + 30px); }

.group { margin: 0 16px 26px; }
.group-h { font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: .02em; margin: 0 16px 7px; }
.group-f { font-size: 13px; line-height: 1.4; color: var(--label-2); margin: 7px 16px 0; }
.group-f a { color: var(--blue); text-decoration: none; }
.cells { background: var(--bg-cell); border-radius: 22px; overflow: hidden; }
.cell {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 52px; padding: 8px 16px; text-align: left; font-size: 17px;
}
button.cell:active, a.cell:active, .cell.tap:active { background: var(--fill); }
.cell.tap { cursor: pointer; }
.cell .star { flex: none; width: 34px; height: 34px; margin-right: -8px; border-radius: 50%; display: grid; place-items: center; color: var(--label-3); transition: transform .25s var(--bounce), color .2s; }
.cell .star .ico { width: 20px; height: 20px; }
.cell .star.on { color: var(--orange); }
.cell .star:active { transform: scale(.8); }
.cell.total { font-weight: 600; }
.group-f.pad { margin: -12px 32px 26px; }
.row-meta .row-ico { display: inline-block; width: 11px; height: 11px; vertical-align: -1px; margin-right: 3px; stroke-width: 2.4; }
.cell + .cell::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; height: .5px; background: var(--sep); }
.cell.has-tile + .cell::before, .cell + .cell.has-tile::before { left: 58px; }
.tile { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; flex: none; font-weight: 700; font-size: 14px; }
.tile .ico { width: 18px; height: 18px; }
.cell-label { flex: 1; min-width: 0; }
.cell-label small { display: block; font-size: 13px; color: var(--label-2); margin-top: 1px; }
/* Model picker: the sort menu in the list header, and each model's numbers. */
.models-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sort-btn { display: inline-flex; align-items: center; gap: 4px; margin: -6px -4px -6px 0; padding: 6px 4px; border-radius: 10px;
  color: var(--blue); font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; transition: transform .2s var(--bounce); }
.sort-btn:active { transform: scale(.94); background: var(--fill); }
.sort-btn .ico { width: 15px; height: 15px; }
.stats { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 4px; font-size: 12px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.stat { display: inline-flex; align-items: center; gap: 3px; }
.stat .ico { width: 13px; height: 13px; stroke-width: 2.2; }
.stat.on { color: var(--blue); font-weight: 600; }
.group-f .f-ico { display: inline-block; width: 13px; height: 13px; vertical-align: -2px; }
/* A gap between sections of a pull-down menu (sort orders / direction). */
.menu-sep { height: 8px; background: var(--fill); }
.cell-detail { color: var(--label-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
.cell .chev .ico { width: 14px; height: 14px; stroke-width: 2.6; color: var(--label-3); }
.cell.danger { color: var(--red); justify-content: center; }
.cell.action { color: var(--blue); }
.cell.center { justify-content: center; }
.cell .check .ico { color: var(--blue); width: 20px; height: 20px; stroke-width: 2.6; }
.cell input[type=text], .cell input[type=password], .cell input[type=url] {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 17px; padding: 6px 0;
}
.cell .eye { color: var(--label-2); padding: 6px; }
.cell .eye .ico { width: 20px; height: 20px; }
textarea.cell-area {
  display: block; width: 100%; min-height: 180px; border: 0; outline: 0; resize: vertical;
  background: none; padding: 14px 16px; font-size: 17px; line-height: 1.4;
}
.status-ok { color: var(--green); } .status-err { color: var(--red); }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill-2); transition: background-color .25s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16);
  transition: transform .3s var(--bounce);
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

.seg {
  display: flex; gap: 2px; padding: 3px; margin: 0 16px 14px; border-radius: 20px; background: var(--fill);
  overflow-x: auto; scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; height: 32px; padding: 0 12px; border-radius: 17px; font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background-color .25s, box-shadow .25s;
}
.seg button.on { background: var(--bg-elev); box-shadow: 0 2px 8px rgba(0, 0, 0, .12); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #636366; } }
.seg button .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--label-3); margin-right: 6px; vertical-align: 2px; }
.seg button .dot.ok { background: var(--green); }
.sheet .search { margin: 0 16px 14px; }

.spinner {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--fill-2); border-top-color: var(--label-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 30px; }

/* ---------------------------------------------------- alert + menu */
.alert {
  position: absolute; left: 50%; top: 50%; width: min(320px, calc(100% - 48px));
  transform: translate(-50%, -50%) scale(1.12); opacity: 0;
  padding: 22px 18px 16px; border-radius: 34px; text-align: center;
  background: var(--glass-strong); pointer-events: auto;
  transition: transform .4s var(--bounce), opacity .2s;
}
.alert.show { transform: translate(-50%, -50%); opacity: 1; }
.alert h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.alert p { margin: 0 0 18px; font-size: 15px; color: var(--label-2); line-height: 1.35; }
.alert-btns { display: flex; gap: 10px; }
.alert-btns button { flex: 1; height: 48px; border-radius: 24px; background: var(--fill-2); font-weight: 600; font-size: 17px; }
.alert-btns .destructive { color: var(--red); }
.alert-btns .primary { background: var(--blue); color: #fff; }

.menu-scrim { position: absolute; inset: 0; pointer-events: auto; background: rgba(0, 0, 0, .14); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); opacity: 0; transition: opacity .3s; }
.menu-scrim.show { opacity: 1; }
.menu {
  position: absolute; width: 250px; border-radius: 24px; padding: 6px 0; overflow: hidden;
  background: var(--glass-strong); pointer-events: auto;
  transform: scale(.4); opacity: 0; transition: transform .45s var(--bounce), opacity .2s;
}
.menu.show { transform: none; opacity: 1; }
.menu button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 11px 18px; font-size: 17px; text-align: left; }
.menu button:active { background: var(--fill); }
.menu button .ico { width: 20px; height: 20px; }
.menu .destructive { color: var(--red); }
.menu hr { border: 0; height: 6px; margin: 4px 0; background: var(--fill); }

#toast {
  position: fixed; left: 50%; top: calc(var(--st) + 10px); z-index: 80;
  transform: translate(-50%, -140%); opacity: 0;
  padding: 11px 20px; border-radius: 22px; font-size: 15px; font-weight: 600;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(1.8); backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: var(--glass-shadow);
  transition: transform .5s var(--bounce), opacity .25s; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ------------------------------------------------- SillyTavern bits */
.char-strip {
  display: flex; gap: 14px; overflow-x: auto; scrollbar-width: none;
  padding: 2px max(20px, var(--sl)) 16px; margin-bottom: 2px;
  scroll-snap-type: x proximity;
}
.char-strip::-webkit-scrollbar { display: none; }
.char-tile {
  flex: none; width: 70px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  scroll-snap-align: start; transition: transform .25s var(--bounce);
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.char-tile:active { transform: scale(.92); }
.char-av {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  background: var(--fill); box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
}
.char-tile.add .char-av { color: var(--blue); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--blue) 35%, transparent); background: color-mix(in srgb, var(--blue) 8%, transparent); }
.char-tile.add .ico { width: 26px; height: 26px; }
.char-name { font-size: 12px; color: var(--label-2); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 860px) { .char-strip { padding-left: 16px; padding-right: 16px; } }

.row-av { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex: none; margin-top: 2px; background: var(--fill); }
.model-av { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; margin-left: -10px; flex: none; }
.welcome-icon.round { border-radius: 50%; width: 96px; height: 96px; object-fit: cover; box-shadow: 0 8px 26px rgba(0, 0, 0, .18); }

.who { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--label-2); }
.who img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.msg.assistant .md em { color: var(--label-2); }

.swipe { display: inline-flex; align-items: center; gap: 0; margin-left: 2px; font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.notice + .swipe { margin-top: 6px; }
.swipe span { min-width: 30px; text-align: center; }
.swipe button { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; transition: transform .2s var(--bounce), background-color .15s; }
.swipe button:active { background: var(--fill); transform: scale(.88); }
.swipe button:disabled { opacity: .3; cursor: default; }
.swipe .ico { width: 16px; height: 16px; stroke-width: 2.4; }

.char-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6px 24px 22px; }
.char-head img { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; object-position: top; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); }
.char-head.small img { width: 76px; height: 76px; }
.char-head.small img.app { border-radius: 18px; }
.char-head.small h3 { font-size: 20px; margin-top: 10px; }
/* the portrait in the character editor: tap to change */
.pic-btn { position: relative; border-radius: 50%; overflow: hidden; transition: transform .25s var(--bounce); }
.pic-btn:active { transform: scale(.95); }
.pic-btn img { display: block; box-shadow: none; }
.pic-btn span {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 0 9px; font-size: 13px; font-weight: 600; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .55));
}
.input-cell .cell-label { flex: none; }
.input-cell > div:last-child { flex: 1; min-width: 0; display: flex; }
.input-cell input[type=text] { text-align: right; color: var(--label-2); }
.input-cell input[type=text]:focus { color: var(--label); }
.cell.range-cell { padding-top: 0; min-height: 44px; }
.cell.range-cell::before { display: none; }
/* iOS slider: thin track, filled to the value, white knob */
input.range {
  -webkit-appearance: none; appearance: none; flex: 1; height: 28px; margin: 0; background: none; cursor: pointer;
}
input.range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--blue) var(--val, 50%), var(--fill-2) var(--val, 50%));
}
input.range::-moz-range-track { height: 4px; border-radius: 2px; background: var(--fill-2); }
input.range::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--blue); }
input.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; margin-top: -12px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16), 0 0 0 .5px rgba(0, 0, 0, .04);
}
input.range::-moz-range-thumb { width: 28px; height: 28px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15); }
.btn-col { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: -6px 0 24px; }
.btn-col .big-btn { margin-top: 0; }
.big-btn:disabled { background: var(--fill-2); color: var(--label-3); }
.plain-btn { padding: 10px 18px; font-size: 17px; color: var(--blue); }
.member.next { padding: 0 14px 0 10px; color: var(--blue); }
.member.next .ico { width: 18px; height: 18px; }
.member.muted img { filter: grayscale(1); opacity: .55; }
.char-head h3 { margin: 12px 0 2px; font-size: 24px; font-weight: 700; }
.char-head .by { font-size: 15px; color: var(--label-2); }
.tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 10px; }
.tags span { font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--fill); color: var(--label-2); }
.big-btn {
  margin-top: 16px; height: 50px; min-width: 200px; padding: 0 28px; border-radius: 25px;
  background: var(--blue); color: #fff; font-weight: 600; font-size: 17px;
  transition: transform .25s var(--bounce);
}
.big-btn:active { transform: scale(.95); }
.notes { padding: 14px 16px; font-size: 15px; line-height: 1.45; color: var(--label-2); white-space: pre-wrap; max-height: 240px; overflow-y: auto; }
.cell-av { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: none; }
textarea.cell-area.tall { min-height: 55vh; }
.seg.inline { margin: 0; }
.seg.effort button { padding: 0 8px; font-size: 13px; }

/* debug log */
.dbg { border-top: .5px solid var(--sep); }
.dbg:first-child { border-top: 0; }
.dbg summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; font-size: 15px; }
.dbg summary::-webkit-details-marker { display: none; }
.dbg-kind { font: 600 11px/1 var(--mono); text-transform: uppercase; padding: 4px 6px; border-radius: 6px; background: var(--fill); color: var(--label-2); }
.dbg-kind.error { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.dbg-kind.request { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.dbg-sum { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 13px; }
.dbg-at { font-size: 12px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.dbg pre { margin: 0; padding: 0 16px 14px; font: 12px/1.45 var(--mono); white-space: pre-wrap; word-break: break-all; color: var(--label-2); max-height: 50vh; overflow: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
