/*
 * piweb — Discord-flavoured dark UI, phone first.
 *
 * Layout rules that matter on iOS Safari:
 *  - 100dvh (not 100vh) so the URL bar collapsing doesn't hide the composer
 *  - env(safe-area-inset-*) padding for the notch and home indicator
 *  - 16px input font, otherwise iOS zooms the page on focus
 */

:root {
  color-scheme: dark;
  --bg: #313338;
  --bg-alt: #2b2d31;
  --bg-dark: #1e1f22;
  --bg-input: #383a40;
  --bg-hover: rgb(255 255 255 / 0.1);
  --bg-3: #2b2d31;
  --border: #3f4147;
  --text: #dbdee1;
  --text-2: #b5bac1;
  --text-dim: #949ba4;
  --text-bright: #f2f3f5;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-light: #c4b5fd;
  --danger: #da373c;
  --thinking: #a78bfa;
  --tool: #3ba55d;
  --radius: 8px;
  --topbar-h: 48px;
}

:root[data-theme='light'] {
  color-scheme: light;
  /* Japanese minimal: white washi, warm stone neutrals and one quiet aizome
     accent. Surfaces stay flat so spacing and hairlines create the hierarchy. */
  --bg: #ffffff;
  --bg-alt: #fbfaf7;
  --bg-dark: #ebe8e1;
  --bg-input: #f4f2ed;
  --bg-hover: rgb(45 43 38 / 0.055);
  --bg-3: #f4f2ed;
  --border: #dedbd3;
  --text: #35332f;
  --text-2: #56534d;
  --text-dim: #74716a;
  --text-bright: #1f1e1a;
  --accent: #3f5f6f;
  --accent-hover: #324f5e;
  --accent-light: #557789;
  --danger: #ad4038;
  --thinking: #6e5c87;
  --tool: #397057;
}

* {
  box-sizing: border-box;
}

/*
 * The UA rule for [hidden] is `display: none`, but ANY author rule that sets
 * display (.login{display:grid}, .app{display:flex}, .typing, .autocomplete, …)
 * beats it — author styles win over the UA sheet regardless of specificity.
 * Without this the login overlay renders on top of the app forever even though
 * `hidden` is set. Keep this above every display rule.
 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    'gg sans',
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    'Helvetica Neue',
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── login ───────────────────────────────────────────────────────────── */

.login {
  display: grid;
  place-items: center;
  height: 100dvh;
  padding: 24px;
  background: var(--bg-dark);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px 24px;
  background: var(--bg-alt);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  font-size: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.login-card h1 {
  margin: 4px 0 0;
  font-size: 22px;
  color: var(--text-bright);
}

.login-sub {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.login-card input,
.composer textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 16px; /* < 16px makes iOS zoom on focus */
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
}

.btn-primary {
  padding: 12px 14px;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.btn-primary:active {
  background: var(--accent-hover);
}

.login-error {
  margin: 0;
  color: #f87171;
  font-size: 14px;
}

/* ── shell ───────────────────────────────────────────────────────────── */

.app {
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

/* Life is a protected presentation of one persistent default-model channel. */
.life-edge-hint {
  position: fixed;
  z-index: 30;
  top: 42%;
  right: max(0px, env(safe-area-inset-right));
  width: 48px;
  height: 64px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--tool) 82%, var(--text));
  opacity: 0.86;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  will-change: transform;
  transition:
    opacity 0.18s ease,
    transform 0.18s cubic-bezier(0.2, 0, 0, 1),
    color 0.18s ease;
}

.life-edge-hint:hover {
  opacity: 1;
  color: var(--text-bright);
  transform: translateX(-3px);
}

.life-edge-hint:hover .life-edge-drop {
  fill: color-mix(in srgb, var(--tool) 12%, var(--bg-alt));
  stroke: color-mix(in srgb, var(--tool) 70%, transparent);
}

.life-edge-hint svg {
  width: 48px;
  height: 64px;
  overflow: visible;
  filter: drop-shadow(-4px 3px 8px rgb(0 0 0 / 0.2));
}

.life-edge-drop {
  fill: color-mix(in srgb, var(--bg-alt) 92%, transparent);
  stroke: color-mix(in srgb, var(--tool) 50%, transparent);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  transition:
    fill 0.18s ease,
    stroke 0.18s ease;
}

.life-edge-leaf {
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.life-edge-hint:active .life-edge-drop {
  fill: color-mix(in srgb, var(--tool) 17%, var(--bg-alt));
  stroke: color-mix(in srgb, var(--tool) 78%, transparent);
}

.life-edge-hint:active {
  color: var(--text-bright);
  transform: translateX(-1px);
}

.life-edge-hint:focus-visible {
  outline: none;
}

.life-edge-hint:focus-visible .life-edge-drop {
  stroke: var(--tool);
  stroke-width: 2.6;
}

.life-swipe-preview {
  position: fixed;
  z-index: 53;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100dvh;
  background:
    radial-gradient(circle at 70% 34%, rgb(81 137 91 / 0.22), transparent 36%), var(--bg-alt);
  border-left: 1px solid color-mix(in srgb, var(--tool) 55%, transparent);
  box-shadow: -18px 0 42px rgb(0 0 0 / 0.28);
  pointer-events: none;
  will-change: transform, opacity;
  backface-visibility: hidden;
  contain: paint;
}

.life-swipe-preview.settling {
  pointer-events: auto;
}

/* During a Life pull, the current page—not the destination overlay—tracks the
   finger. The stationary Life preview sits underneath and is progressively
   revealed from the right. The water drop is nested in .main, so its rounded
   body and edge-attached point inherit the exact same page transform. */
.app.life-page-dragging .main {
  z-index: 54;
  background: var(--bg);
  box-shadow: 18px 0 42px rgb(0 0 0 / 0.3);
  will-change: transform;
}

.app.life-page-dragging .life-edge-hint {
  z-index: 55;
  transition: none;
}

.life-swipe-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-bright);
}

.life-swipe-mark svg {
  width: 48px;
  height: 48px;
  color: var(--tool);
}

.life-swipe-mark strong {
  font-size: 22px;
}

.life-swipe-mark span {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.life-swipe-cancel {
  min-width: 88px;
  min-height: 44px;
  margin-top: 16px;
  padding: 0 18px;
  border: 1px solid color-mix(in srgb, var(--text-dim) 55%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-input) 88%, transparent);
  color: var(--text-2);
  font: inherit;
}

.life-swipe-cancel:active {
  background: var(--bg-hover);
  color: var(--text-bright);
}

.app.life-mode .drawer,
.app.life-mode #btn-menu,
.app.life-mode #btn-gpt-usage,
.app.life-mode #btn-model,
.app.life-mode .topbar-title > .hash,
.app.life-mode .life-edge-hint {
  display: none;
}

.app.life-mode .topbar {
  position: relative;
  padding-right: max(4px, env(safe-area-inset-right));
}

/* Keep Status, Thinking, Life reset, safe overflow, and emergency Stop on the right;
   the absolutely centered title must never cover these hit targets. Status is
   the first right-side action while idle; Stop takes that role while busy. */
.app.life-mode #btn-status,
.app.life-mode #btn-stop:not([hidden]) {
  margin-left: auto;
}

.app.life-mode #btn-status[hidden] ~ #btn-thinking:not([hidden]),
.app.life-mode #btn-status[hidden] ~ #btn-life-new-session {
  margin-left: auto;
}

.app.life-mode #btn-stop:not([hidden]) ~ #btn-status,
.app.life-mode #btn-stop:not([hidden]) ~ #btn-thinking,
.app.life-mode #btn-stop:not([hidden]) ~ #btn-life-new-session,
.app.life-mode #btn-status:not([hidden]) ~ #btn-thinking,
.app.life-mode #btn-status:not([hidden]) ~ #btn-life-new-session,
.app.life-mode #btn-thinking:not([hidden]) ~ #btn-life-new-session,
.app.life-mode #btn-more {
  margin-left: 0;
}

.app.life-mode .topbar-title {
  position: absolute;
  left: 50%;
  max-width: min(54vw, 240px);
  transform: translateX(-50%);
  justify-content: center;
}

/* Busy Life has five mandatory right-side actions, so it always uses normal
   flex flow instead of an absolute title. Compact the labelled back action and
   decorative leaf only where they would squeeze the full “Life” name; idle Life
   needs normal flow plus the same compaction across phone widths. */
.app.life-mode.agent-busy .topbar-title {
  position: static;
  left: auto;
  flex: 0 1 auto;
  max-width: none;
  transform: none;
}

.app.life-mode.agent-busy .life-title-mark {
  display: none;
}

@media (max-width: 420px) {
  .app.life-mode .topbar-title {
    gap: 3px;
  }

  .app.life-mode .life-title-mark {
    display: none;
  }

  .app.life-mode.agent-busy .life-back {
    width: 34px;
    padding-inline: 0;
    justify-content: center;
  }

  .app.life-mode.agent-busy .life-back span {
    display: none;
  }
}

@media (max-width: 380px) {
  .app.life-mode .topbar-title {
    position: static;
    left: auto;
    flex: 0 1 auto;
    max-width: none;
    transform: none;
  }

  .app.life-mode .life-back {
    width: 34px;
    padding-inline: 0;
    justify-content: center;
  }

  .app.life-mode .life-back span,
  .app.life-mode .life-title-mark {
    display: none;
  }
}

.app.life-mode #session-name {
  cursor: default;
  margin-left: 0;
  padding-inline: 2px;
}

.app.life-mode #header-badge {
  display: none;
}

.app.life-mode #session-name:hover,
.app.life-mode #session-name:focus-visible {
  background: transparent;
}

.life-back {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 38px;
  padding: 0 7px 0 2px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
}

.life-back:active {
  background: var(--bg-input);
  color: var(--text-bright);
}

.life-back svg,
.life-title-mark svg {
  width: 18px;
  height: 18px;
}

.life-title-mark {
  display: inline-grid;
  place-items: center;
  color: var(--tool);
}

@media (min-width: 768px) {
  .life-swipe-preview {
    display: none;
  }
}

.main {
  position: relative; /* containing block for .jump-live */
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  background: var(--bg);
  border-bottom: 1px solid var(--bg-dark);
  flex: none;
}

@media (min-width: 600px) {
  .topbar {
    padding-left: max(60px, calc(env(safe-area-inset-left) + 12px));
  }
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--text-bright);
}

#session-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  cursor: text;
}

#session-name:hover,
#session-name:focus-visible {
  background: var(--bg-input);
  outline: none;
}

/* Inline rename: an in-place field rather than a native prompt(), which on iOS
   is a jarring system sheet that hides the thing being renamed. */
.name-edit {
  flex: 1;
  min-width: 0;
  padding: 3px 6px;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--text-bright);
  font: inherit;
  font-size: 16px; /* keep iOS from zooming */
  outline: none;
}

.hash {
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  user-select: none;
  padding: 2px 4px;
  border-radius: 4px;
  transition:
    color 0.15s ease,
    background-color 0.15s ease;
}

.hash:hover,
.hash:active {
  color: var(--text-bright);
  background: var(--bg-input);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-dim);
}

.icon-btn:active {
  background: var(--bg-input);
  color: var(--text-bright);
}

.icon-btn.send {
  color: var(--accent);
}

/* Keep the primary composer action reachable on touch devices. */
@media (pointer: coarse) {
  .composer .send {
    min-width: 44px;
    min-height: 44px;
  }
}

.evo-topbar-btn {
  width: 42px;
  color: var(--accent-light);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

/* ── drawer ──────────────────────────────────────────────────────────── */

.drawer {
  position: fixed;
  /* Above transcript controls (composer 40, menu 45, jump 50), but below the
     lightbox (60) and toast (70). An open drawer must own every tap in its area. */
  z-index: 55;
  top: 0;
  left: 0;
  width: 78%;
  max-width: 300px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-alt);
  transform: translateX(-100%);
  transition: transform 0.18s ease;
  padding-top: env(safe-area-inset-top);
}

.drawer.open {
  transform: translateX(0);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 54;
  background: rgb(0 0 0 / 0.5);
  /* Fades with the drawer; during an edge swipe JS drives opacity directly. */
  transition: opacity 0.18s ease;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--bg-dark);
  flex: none;
}

.drawer-title {
  font-weight: 700;
  color: var(--text-bright);
}

.drawer-actions {
  display: flex;
  align-items: center;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--text-dim);
  font-weight: 500;
}

.session-item.active {
  background: var(--bg-input);
  color: var(--text-bright);
}

.session-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
  -webkit-user-select: none; /* iOS Safari still requires the prefix */
  user-select: none;
  -webkit-touch-callout: none;
}

.session-name-edit {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 3px 6px;
  background: var(--bg-dark);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text-bright);
  font: inherit;
  font-size: 16px; /* keep iOS from zooming */
  outline: none;
}

.session-item .hash {
  font-size: 18px;
}

.session-item .unread-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--tool);
  box-shadow: 0 0 0 2px rgb(59 165 93 / 0.25);
}

/* Spinner = working now. Distinct shape from the unread dot on purpose: the
   two states must be tellable apart at a glance, not only by motion. */
.session-item .work-spinner {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.18);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .session-item .work-spinner {
    animation-duration: 2.4s;
  }
}

.session-item .del {
  width: 28px;
  height: 28px;
  color: var(--text-dim);
}

.drawer-foot {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--bg-dark);
  flex: none;
}

.text-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-dim);
  font-size: 14px;
}

.empty-note {
  padding: 24px 16px;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

/* ── messages ────────────────────────────────────────────────────────── */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Explicit, and not optional: with only overflow-y set, overflow-x computes
     to `auto` rather than `visible`, so one wide table turned the whole
     transcript into a horizontally draggable pane and pushed the messages off
     screen. Wide content scrolls inside its own box (.table-wrap, pre). */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  -webkit-touch-callout: none;
  padding: 12px 0 4px;
}

.msg {
  display: block;
  padding: 6px 14px;
}

.msg.msg-user {
  display: flex;
  gap: 10px;
  padding: 6px 14px;
}

.msg:hover {
  background: rgb(0 0 0 / 0.04);
}

.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
}

.msg-body {
  width: 100%;
  min-width: 0;
}

.msg.msg-user .msg-body {
  flex: 1;
}

/* A flex/grid child defaults to min-width:auto, refusing to shrink below its
   content's intrinsic width — which is how a table's full width leaks out to
   the ancestors even though .table-wrap scrolls. */
.msg-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-author {
  font-weight: 600;
  color: var(--text-bright);
  font-size: 14px;
}

/* ── Author role badges (EVO & Guider) ─────────────────────────────────── */

.role-badge,
.guider-author-badge,
.guider-card.guider-final > strong,
.msg-author.msg-author-evo {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.4;
  margin-bottom: 6px;
  border: 1px solid transparent;
  user-select: none;
  width: fit-content;
}

.role-badge::before,
.guider-author-badge::before,
.guider-card.guider-final > strong::before,
.msg-author.msg-author-evo::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Guider badge: teal accent */
.role-badge-guider,
.guider-author-badge,
.guider-card.guider-final > strong {
  border-color: rgba(101, 201, 196, 0.32);
  background: rgba(101, 201, 196, 0.12);
  color: #65c9c4;
}

.role-badge-guider::before,
.guider-author-badge::before,
.guider-card.guider-final > strong::before {
  background: #65c9c4;
  box-shadow: 0 0 6px rgba(101, 201, 196, 0.65);
}

/* EVO badge: aizome / violet accent */
.role-badge-evo,
.msg-author.msg-author-evo {
  border-color: rgba(167, 139, 250, 0.32);
  background: rgba(167, 139, 250, 0.12);
  color: #c4b5fd;
}

.role-badge-evo::before,
.msg-author.msg-author-evo::before {
  background: #a78bfa;
  box-shadow: 0 0 6px rgba(167, 139, 250, 0.65);
}

/* Light theme contrast safe rules (WCAG AA > 4.5:1) */
:root[data-theme='light'] .role-badge-guider,
:root[data-theme='light'] .guider-author-badge,
:root[data-theme='light'] .guider-card.guider-final > strong {
  border-color: rgba(32, 114, 109, 0.28);
  background: rgba(32, 114, 109, 0.09);
  color: #20726d;
}

:root[data-theme='light'] .role-badge-guider::before,
:root[data-theme='light'] .guider-author-badge::before,
:root[data-theme='light'] .guider-card.guider-final > strong::before {
  background: #20726d;
  box-shadow: 0 0 4px rgba(32, 114, 109, 0.4);
}

:root[data-theme='light'] .role-badge-evo,
:root[data-theme='light'] .msg-author.msg-author-evo {
  border-color: rgba(44, 75, 90, 0.25);
  background: rgba(44, 75, 90, 0.08);
  color: #2c4b5a;
}

:root[data-theme='light'] .role-badge-evo::before,
:root[data-theme='light'] .msg-author.msg-author-evo::before {
  background: #2c4b5a;
  box-shadow: 0 0 4px rgba(44, 75, 90, 0.35);
}

.msg-time {
  color: var(--text-dim);
  font-size: 11px;
}

.msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-text code {
  background: var(--bg-dark);
  padding: 1px 4px;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
}

.msg-text code,
.event-body code {
  cursor: copy;
  touch-action: manipulation;
}

.msg-text code:active,
.event-body code:active {
  opacity: 0.72;
}

.msg-text pre,
.event-body pre {
  max-width: 100%;
  margin: 6px 0;
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  /* Long tool output must scroll inside its own box; the page itself never
     scrolls sideways on a phone. */
  overflow-x: auto;
  white-space: pre;
  overflow-wrap: normal;
  -webkit-overflow-scrolling: touch;
}

.mermaid-wrap {
  margin: 12px 0;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mermaid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
}

.mermaid-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-bright);
}

.mermaid-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mermaid-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.mermaid-btn:hover,
.mermaid-btn:active {
  background: var(--bg-hover, rgba(255, 255, 255, 0.1));
  color: var(--text-bright);
}

.mermaid-scroll {
  padding: 16px;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 75dvh;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  display: flex;
  justify-content: flex-start;
  user-select: none;
}

.mermaid-chart {
  display: inline-block;
  min-width: max-content;
  margin: 0 auto;
  transform-origin: 0 0;
  will-change: transform;
}

.mermaid-chart svg {
  display: block;
  width: auto;
  min-width: 100%;
  max-width: none;
  height: auto;
  cursor: grab;
  fill: initial;
  stroke: initial;
  stroke-width: initial;
  stroke-linecap: initial;
  stroke-linejoin: initial;
}

/* ── mermaid modal fullscreen ── */
.mermaid-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mermaid-modal[hidden] {
  display: none !important;
}

.mm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.mm-modal-content {
  position: relative;
  z-index: 1;
  width: 94vw;
  height: 90dvh;
  max-width: 1200px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.mm-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
}

.mm-modal-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-bright);
}

.mm-modal-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mm-modal-body {
  flex: 1;
  overflow: hidden;
  touch-action: none;
  padding: 24px;
  display: grid;
  place-items: center;
  user-select: none;
}

.mm-modal-stage {
  transform-origin: 0 0;
  transition: transform 0.15s ease-out;
  display: inline-block;
  will-change: transform;
}

.mm-modal-stage svg {
  display: block;
  width: auto;
  max-width: none;
  height: auto;
  cursor: grab;
  fill: initial;
  stroke: initial;
  stroke-width: initial;
  stroke-linecap: initial;
  stroke-linejoin: initial;
}

.msg-text pre code,
.event-body pre code {
  display: block;
  width: max-content;
  min-width: 100%;
  background: none;
  padding: 0;
  color: #c9d1d9;
  font-size: 12.5px;
  line-height: 1.5;
}

/* highlight.js token palette, tuned for piweb's dark transcript. The library
   supplies only semantic spans; keeping the colours here avoids a second theme
   stylesheet and makes message and tool-event code blocks match. */
.hljs-comment,
.hljs-quote {
  color: #8b949e;
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-type,
.hljs-doctag {
  color: #ff7b72;
}

.hljs-title,
.hljs-title.class_,
.hljs-title.function_,
.hljs-section {
  color: #d2a8ff;
}

.hljs-string,
.hljs-regexp,
.hljs-template-tag,
.hljs-template-variable {
  color: #a5d6ff;
}

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link {
  color: #79c0ff;
}

.hljs-attr,
.hljs-attribute,
.hljs-variable,
.hljs-property,
.hljs-params {
  color: #ffa657;
}

.hljs-built_in,
.hljs-builtin-name,
.hljs-meta {
  color: #f2cc60;
}

.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
  color: #7ee787;
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

.hljs-addition {
  color: #aff5b4;
  background: rgb(46 160 67 / 0.16);
}

.hljs-deletion {
  color: #ffdcd7;
  background: rgb(248 81 73 / 0.16);
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.msg-files img {
  max-width: min(100%, 320px);
  max-height: 320px;
  border-radius: 8px;
  display: block;
}

.msg-inline-media {
  margin: 8px 0;
}

.msg-inline-media img,
.msg-text img {
  max-width: min(100%, 320px);
  max-height: 320px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}

.msg-inline-media .video-file {
  margin: 4px 0;
}

.video-file {
  width: min(100%, 320px);
  max-width: min(100%, 320px);
  overflow: hidden;
  border-radius: 8px;
  background: var(--bg-alt);
}

.video-file video {
  display: block;
  width: 100%;
  max-height: 320px;
  background: #000;
}

.video-download {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: #00a8fc;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  touch-action: manipulation;
}

.video-download:active,
.video-download:focus-visible {
  background: var(--bg-input);
  color: var(--text-bright);
  outline: none;
}

.file-link {
  display: inline-block;
  padding: 8px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #00a8fc;
  text-decoration: none;
  font-size: 14px;
}

/* ── streamed events (thinking / tools) ──────────────────────────────── */

@keyframes popInSlideUp {
  0% {
    opacity: 0;
    transform: translateY(14px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.event {
  margin: 4px 14px;
  border-radius: 8px;
  background: var(--bg-alt);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--border);
  overflow: hidden;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.event.partial,
.event.pop-in,
.msg.pop-in {
  animation: popInSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform, opacity;
}

.event.thinking {
  border-left-color: var(--thinking);
  background: rgba(167, 139, 250, 0.05);
}

.event.tool {
  border-left-color: var(--tool);
  background: rgba(99, 102, 241, 0.05);
}

.event.tool_result {
  border-left-color: #10b981;
  background: rgba(16, 185, 129, 0.05);
}

.event.system {
  border-left-color: var(--accent);
}

.event.error {
  border-left-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

.event summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
  transition:
    color 0.15s ease,
    background-color 0.15s ease;
}

.event summary:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.event summary::-webkit-details-marker {
  display: none;
}

.event-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform: rotate(0deg);
}

.event[open] > summary .event-chevron {
  transform: rotate(90deg);
}

.event summary .label {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.event summary .peek {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  opacity: 0.75;
}

.event[open] summary .peek {
  display: none;
}

/* Live clock on the tool call still in flight. Stays visible when the row is
   expanded — that is exactly when the reader is asking "is this thing alive?" */
.event summary .event-elapsed {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 999px;
  color: var(--accent, #5865f2);
  background: rgb(88 101 242 / 0.14);
}

.event summary .event-elapsed::before {
  content: '⏳ ';
}

@media (prefers-reduced-motion: no-preference) {
  .event summary .event-elapsed {
    animation: toolElapsedPulse 2s ease-in-out infinite;
  }

  @keyframes toolElapsedPulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.55;
    }
  }
}

.event-body-wrap {
  display: grid;
  grid-template-rows: 1fr;
}

.event .event-body {
  min-height: 0;
  padding: 0 12px 10px;
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 380px;
  overflow-y: auto;
  opacity: 1;
}

/* System/command output is short and worth reading without a tap. */
.event.system .event-body,
.event.error .event-body {
  padding-top: 2px;
}

/* ── typing indicator ────────────────────────────────────────────────── */

.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 16px 6px;
  color: var(--text-dim);
  font-size: 13px;
  flex: none;
}

.typing .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}

.typing .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing .dot:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-label {
  margin-left: 6px;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing .dot {
    animation: none;
    opacity: 0.7;
  }
  .drawer {
    transition: none;
  }
}

/* ── transcript selection & custom handles ────────────────────────────── */

.messages .msg-text,
.messages .event-body,
.messages .msg-text *,
.messages .event-body * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

@media (hover: hover) and (pointer: fine) {
  .messages .msg-text,
  .messages .event-body,
  .messages .msg-text *,
  .messages .event-body * {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Touch devices ship the custom transcript selection above, so no part of the
   shell may start a native selection: iOS otherwise anchors one outside the
   (user-select:none) transcript and expands it across the entire document. */
@media (hover: none) and (pointer: coarse) {
  body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  input,
  textarea,
  [contenteditable='true'] {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
  }
}

::selection {
  color: inherit;
  background: rgb(88 101 242 / 0.48);
}

::highlight(piweb-selection) {
  color: inherit;
  background-color: rgba(99, 102, 241, 0.28);
}

.custom-selection-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 35;
}

.custom-selection-overlay.active {
  pointer-events: none;
}

.custom-selection-overlay.dragging .sel-backdrop {
  pointer-events: none !important;
}

.sel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 33;
  background: transparent;
  pointer-events: auto;
}

.sel-highlight-boxes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 34;
}

.sel-highlight-rect {
  position: fixed;
  background: rgba(99, 102, 241, 0.25);
  border-radius: 4px;
  pointer-events: none;
  box-shadow: none;
}

/* ── iOS-style sleek teardrop selection handles ────────────────────────── */

.sel-handle {
  position: fixed;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  z-index: 36;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

.sel-handle-line {
  position: absolute;
  width: 2.5px;
  height: 100%;
  max-height: 20px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(99, 102, 241, 0.5);
}

.sel-handle-pin,
.sel-handle-knob {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  transition:
    transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
    background-color 0.15s ease;
}

.sel-handle-start {
  margin-left: -22px;
  margin-top: -22px;
}

.sel-handle-start .sel-handle-line {
  top: 12px;
}

.sel-handle-start .sel-handle-pin,
.sel-handle-start .sel-handle-knob {
  top: 4px;
}

.sel-handle-end {
  margin-left: -22px;
  margin-top: -22px;
}

.sel-handle-end .sel-handle-line {
  bottom: 12px;
}

.sel-handle-end .sel-handle-pin,
.sel-handle-end .sel-handle-knob {
  bottom: 4px;
}

.sel-handle:active .sel-handle-pin,
.sel-handle:active .sel-handle-knob,
.sel-handle.dragging .sel-handle-pin,
.sel-handle.dragging .sel-handle-knob {
  transform: scale(1.35);
  background: var(--accent-light);
  box-shadow: 0 0 10px var(--accent);
}

/* ── Apple-style Floating Glass Pill Action Bar ────────────────────────── */

.selection-actions {
  position: fixed;
  z-index: 42;
  display: flex;
  align-items: center;
  overflow: hidden;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(28, 28, 32, 0.88);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.55),
    0 2px 8px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  animation: actionsPop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 3px 6px;
  gap: 2px;
}

@keyframes actionsPop {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.88) translateY(6px);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
  }
}

.selection-actions button {
  min-width: 58px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}

.selection-actions button:active {
  background: rgba(255, 255, 255, 0.16);
}

.selection-actions button:disabled {
  color: rgba(255, 255, 255, 0.35);
}

/* ── composer ────────────────────────────────────────────────────────── */

.composer-wrap {
  position: relative;
  z-index: 40;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.composer-input-area {
  position: relative;
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.evo-action-dock {
  min-width: 0;
  margin-bottom: 2px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-alt) 92%, var(--accent));
  box-shadow: 0 -4px 18px rgb(0 0 0 / 0.18);
}

.evo-dock-copy {
  min-width: 0;
}

.evo-plan {
  margin: 4px 0 0;
  padding-left: 0;
  list-style: none;
}
.evo-plan-stage {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  color: var(--text-2);
}
.evo-plan-icon {
  width: 16px;
  flex: none;
  text-align: center;
}
.evo-plan-passed .evo-plan-icon {
  color: var(--tool);
}
.evo-plan-current {
  color: var(--text-bright);
  font-weight: 600;
}
.evo-plan-current .evo-plan-icon {
  color: var(--accent);
}
.evo-plan-failed .evo-plan-icon {
  color: var(--danger);
}
.evo-plan-untested {
  color: var(--text-dim);
}
.evo-plan-name {
  overflow-wrap: anywhere;
}
.evo-plan-objective {
  margin-left: auto;
  flex: none;
  font-size: 12px;
  color: var(--text-dim);
}
.evo-plan-empty {
  color: var(--text-dim);
}
.evo-pending-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 0;
}
.evo-pending-kind {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-light);
}
.evo-pending-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

#btn-evo-close {
  min-width: 44px;
  min-height: 44px;
}

.evo-dock-state {
  display: block;
  color: var(--accent-light);
  font-size: 12px;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.evo-dock-task {
  display: -webkit-box;
  max-width: 100%;
  margin: 4px 0 8px;
  overflow: hidden;
  color: var(--text-bright);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.evo-dock-stage,
.evo-dock-activity {
  margin: 4px 0;
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.evo-dock-stage {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-bright);
}

.evo-dock-activity {
  color: var(--text-dim);
}

.evo-dock-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.evo-dock-actions button {
  min-width: 64px;
  min-height: 44px;
  flex: 1 1 auto;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-input);
  color: var(--text-bright);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  touch-action: manipulation;
}

.evo-dock-actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.evo-dock-actions .danger {
  border-color: color-mix(in srgb, var(--danger) 70%, var(--border));
  color: var(--danger);
}

.evo-dock-actions button:disabled {
  opacity: 0.5;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 4px;
  background: var(--bg-input);
  border-radius: 10px;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 9px 4px;
  max-height: 40vh;
  resize: none;
  line-height: 1.4;
}

.quote-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 8px;
  padding: 6px 6px 6px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--text-dim);
  font-size: 13px;
  animation: quoteBannerIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  -webkit-user-select: none;
}

@keyframes quoteBannerIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.quote-preview-label {
  flex: none;
  color: var(--accent-light);
  font-weight: 700;
}

.quote-preview-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#quote-preview-remove {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}

#quote-preview-remove:hover,
#quote-preview-remove:active {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-bright);
  transform: scale(1.08);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 4px;
}

.upload-progress {
  padding: 8px 4px 6px;
  color: var(--text-dim);
  font-size: 12px;
}

.upload-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}

.upload-progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-alt);
}

.upload-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 120ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .upload-progress-bar {
    transition: none;
  }
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  max-width: 100%;
}

/* Image attachments show as a small square thumbnail with the remove button
   floated on the corner, so several fit across the composer. */
.chip.chip-image {
  position: relative;
  width: 52px;
  height: 52px;
  padding: 0;
  overflow: hidden;
}

.chip-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chip.chip-image .chip-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  font-size: 13px;
  line-height: 1;
}

.chip-remove {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-dim);
  line-height: 1;
  font-size: 16px;
}

.chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.chip button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--text-dim);
  line-height: 1;
  font-size: 16px;
}

/* ── slash autocomplete ──────────────────────────────────────────────── */

.autocomplete {
  /*
   * In normal flow, NOT absolutely positioned. Absolute + `max-height: 46vh`
   * overflowed off-screen with the keyboard open: `vh` tracks the layout
   * viewport, which iOS does not shrink for the keyboard, so the box became
   * taller than the visible area above the composer and got clipped at both
   * ends with nothing to scroll. As a flex item it is bounded by the column and
   * always scrolls internally instead.
   *
   * --ac-max is kept in sync with visualViewport by app.js (the keyboard only
   * changes the VISUAL viewport, which no CSS unit exposes).
   */
  flex: 0 1 auto;
  min-height: 0;
  max-height: var(--ac-max, 40dvh);
  margin-bottom: 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Don't chain the scroll to the page when the list hits its end. */
  overscroll-behavior: contain;
  /* Let the browser own vertical panning; taps are detected in JS. */
  touch-action: pan-y;
  background: var(--bg-alt);
  border: 1px solid var(--bg-dark);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
  z-index: 10;
}

.ac-head {
  /* Sticky so you can still see what the list is while scrolling it. */
  position: sticky;
  top: 0;
  background: var(--bg-alt);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--bg-dark);
}

.ac-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
}

.ac-item.sel {
  background: var(--bg-input);
}

.ac-name {
  color: var(--text-bright);
  font-weight: 600;
  font-size: 14px;
}

.ac-name .arg {
  color: var(--text-dim);
  font-weight: 400;
}

.ac-desc {
  color: var(--text-dim);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── wider screens ───────────────────────────────────────────────────── */

@media (min-width: 768px) {
  .drawer {
    position: relative;
    transform: none;
    width: 260px;
    max-width: none;
    border-right: 1px solid var(--bg-dark);
  }

  #btn-menu,
  .scrim {
    display: none;
  }

  .app.drawer-collapsed .drawer {
    display: none;
  }

  .app.drawer-collapsed #btn-menu {
    display: grid;
  }

  .messages {
    padding-inline: 8px;
  }
}

/* ── infinite scroll sentinel ─────────────────────────────────────────── */

.top-sentinel {
  padding: 12px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.top-sentinel.start {
  cursor: default;
  opacity: 0.6;
  font-size: 12px;
}

/* ── search ──────────────────────────────────────────────────────────── */

.search-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Sits between the topbar and the transcript, taking at most half the
     screen so the conversation behind it stays visible for context. */
  max-height: 55dvh;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--bg-dark);
  flex: none;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 12px;
  flex: none;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 16px; /* keep iOS from zooming */
  outline: none;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-results {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-bottom: 6px;
}

.search-hit {
  padding: 9px 14px;
  border-top: 1px solid var(--bg-dark);
}

.search-hit .hit-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 2px;
}

.search-hit .hit-who {
  font-weight: 600;
  color: var(--text);
}

.search-hit .hit-text {
  font-size: 13.5px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.search-hit mark {
  background: #b58900;
  color: #1e1f22;
  border-radius: 2px;
  padding: 0 1px;
}

.search-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* Flash the message you jumped to, so it is obvious where you landed. */
.msg.jump-target,
.event.jump-target {
  animation: jump-flash 2s ease-out;
}

@keyframes jump-flash {
  0%,
  40% {
    background: rgb(88 101 242 / 0.28);
  }
  100% {
    background: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg.jump-target,
  .event.jump-target {
    animation: none;
    outline: 2px solid var(--accent);
  }
}

.jump-live {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 96px;
  z-index: 50;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.4);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
  cursor: pointer;
}

.jump-live.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── rendered markdown ───────────────────────────────────────────────── */

.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4,
.msg-text h5,
.msg-text h6 {
  margin: 12px 0 6px;
  line-height: 1.3;
  color: var(--text-bright);
  font-weight: 700;
}

.msg-text h1 {
  font-size: 1.35em;
}
.msg-text h2 {
  font-size: 1.22em;
}
.msg-text h3 {
  font-size: 1.1em;
}
.msg-text h4,
.msg-text h5,
.msg-text h6 {
  font-size: 1em;
}

.msg-text > *:first-child {
  margin-top: 0;
}
.msg-text > *:last-child {
  margin-bottom: 0;
}

.msg-text p {
  margin: 0 0 8px;
}

.msg-text ul,
.msg-text ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}

.msg-text li {
  margin: 2px 0;
}

.msg-text blockquote {
  margin: 6px 0;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

.msg-text hr {
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.msg-text a {
  color: #00a8fc;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.msg-text a:hover {
  text-decoration: underline;
}

.msg-text strong {
  color: var(--text-bright);
}

/* A YouTube video link is a 44px touch target. The external player is loaded
   only after a real click, then stays inside the message at a mobile-safe size.
   Standard-width cards remain 16:9; min-height protects YouTube's 200px player
   requirement when user/event columns are narrower than 356px. */
.msg-text .youtube-inline-link,
.event-body .youtube-inline-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px;
  border-radius: 7px;
  line-height: 1.25;
  text-decoration: none;
  touch-action: manipulation;
}

.youtube-inline-link::before {
  content: '▶';
  flex: none;
  color: #ff3355;
  font-size: 12px;
}

.youtube-inline-link:active,
.youtube-inline-link[aria-expanded='true'] {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}

.youtube-inline-player {
  width: min(100%, 640px);
  margin: 10px 0 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101010;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.22);
}

.youtube-inline-frame {
  width: 100%;
  min-height: 200px;
  aspect-ratio: 16 / 9;
  background: #101010;
}

.youtube-inline-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.youtube-inline-actions {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px 6px;
  border-top: 1px solid rgb(255 255 255 / 0.12);
  background: color-mix(in srgb, var(--bg-alt) 94%, #101010);
}

.msg-text .youtube-inline-open,
.event-body .youtube-inline-open,
.youtube-inline-close {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-bright);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.msg-text .youtube-inline-open,
.event-body .youtube-inline-open {
  color: var(--accent-light);
}

.youtube-inline-open:active,
.youtube-inline-close:active {
  background: rgb(255 255 255 / 0.1);
}

/* Tables scroll inside their own box — the page must never scroll sideways. */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 8px 0;
}

.msg-text table {
  border-collapse: collapse;
  font-size: 13.5px;
}

.msg-text th,
.msg-text td {
  border: 1px solid var(--border);
  padding: 5px 9px;
  text-align: left;
  white-space: nowrap;
}

.msg-text th {
  background: var(--bg-alt);
  color: var(--text-bright);
}

/* ── math ────────────────────────────────────────────────────────────── */

.math-display {
  margin: 10px 0;
  /* A long equation scrolls in place rather than widening the page. */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.katex {
  font-size: 1.05em;
}

/* KaTeX ships light-theme colours; inherit the app's instead. */
.katex,
.katex .mord,
.katex .mbin,
.katex .mrel,
.katex .mopen,
.katex .mclose,
.katex .mpunct {
  color: inherit;
}

/* ── recently deleted ────────────────────────────────────────────────── */

.trash-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 0;
  margin-bottom: 6px;
}

.trash-entry svg {
  width: 16px;
  height: 16px;
}

.trash-count {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
  text-align: center;
}

/* Bottom sheet: reachable one-handed on a phone, unlike a centred modal. */
.sheet {
  position: fixed;
  inset: 0;
  /* Sheets can be launched from the drawer, so they sit above it (55) while
     remaining below the dedicated image lightbox (60). */
  z-index: 58;
  display: flex;
  align-items: flex-end;
  background: rgb(0 0 0 / 0.55);
}

dialog.sheet {
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: inherit;
}

dialog.sheet::backdrop {
  background: transparent;
}

.sheet-panel {
  width: 100%;
  /* --sheet-max is synced to visualViewport by app.js: with the keyboard open
     dvh still reports the full screen, so a dvh-only cap runs off-screen. */
  max-height: var(--sheet-max, 82dvh);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-alt);
  border-radius: 14px 14px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.evo-page {
  position: fixed;
  inset: 0;
  z-index: 58;
  background: var(--bg-alt);
}

.evo-page .evo-panel {
  height: 100%;
  max-height: none;
  border-radius: 0;
  padding-top: env(safe-area-inset-top);
  box-sizing: border-box;
}

.evo-panel {
  overflow: hidden;
  background: var(--bg-alt);
}

.evo-panel .sheet-head {
  justify-content: flex-start;
  gap: 12px;
}

.evo-panel .sheet-title {
  margin: 0;
}

.evo-overview-section {
  margin: 12px 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.evo-overview-section h3,
.evo-details-heading {
  margin: 0 0 8px;
  color: var(--text-bright);
  font-size: 15px;
}

.evo-details-heading {
  margin: 16px 16px 0;
}

.evo-overview-section p {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.evo-overview-section p:last-child {
  margin-bottom: 0;
}

/* Only the body scrolls: metadata cannot flex-shrink and clip the wait reason. */
.evo-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.evo-content:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.evo-status-message[data-state='error'],
.evo-status-message[data-state='not-found'] {
  color: var(--danger);
}

.evo-current {
  margin: 0 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.evo-current-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.evo-current-head strong {
  max-width: 50%;
  padding: 3px 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--text-bright);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evo-current p {
  margin: 8px 0 0;
  color: var(--text-bright);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.evo-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 12px 16px;
  padding: 1px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--border);
  overflow: hidden;
}

.evo-status-grid > div {
  min-width: 0;
  padding: 10px 12px;
  background: var(--bg-input);
}

.evo-status-grid > .evo-wide {
  grid-column: 1 / -1;
}

.evo-status-grid dt {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.evo-status-grid dd {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--text-bright);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evo-status-grid .evo-wide dd {
  overflow: visible;
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: normal;
}

#evo-run-wait {
  white-space: pre-wrap;
}

.evo-inspect {
  margin: 0 16px 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-dark);
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.evo-actions {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 4px 16px max(12px, env(safe-area-inset-bottom));
}

.evo-actions button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}

.evo-actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.evo-actions .danger {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  color: #f28b8d;
}

.evo-actions button:disabled {
  opacity: 0.4;
  cursor: default;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 12px 16px;
  border-bottom: 1px solid var(--bg-dark);
  flex: none;
}

.sheet-title {
  font-weight: 700;
  color: var(--text-bright);
}

.sheet-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.trash-panel .icon-btn {
  width: 44px;
  height: 44px;
}

.sheet-note {
  margin: 0;
  padding: 10px 16px 0;
  color: var(--text-dim);
  font-size: 12.5px;
  flex: none;
}

.project-panel {
  max-height: min(var(--sheet-max, 88dvh), 720px);
}

.project-refresh {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--accent-light);
  font: inherit;
  font-weight: 600;
}

.project-list {
  flex: 1 1 auto;
  min-height: 96px;
  overflow-y: auto;
  padding: 8px 12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.project-item {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text-bright);
  font: inherit;
  text-align: left;
}

.project-item::before {
  content: '⌘';
  color: var(--accent-light);
  font-weight: 700;
}

.project-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-create {
  flex: none;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.project-create label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-bright);
  font-size: 13px;
  font-weight: 700;
}

.project-create-row {
  display: flex;
  gap: 8px;
}

.project-create input {
  min-width: 0;
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--bg-input);
  color: var(--text-bright);
  font: inherit;
  font-size: 16px;
}

.project-create input:focus {
  border-color: var(--accent);
}

.project-create button {
  min-width: 82px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
}

.project-create > span {
  display: block;
  margin-top: 7px;
  color: var(--text-dim);
  font-size: 11.5px;
}

.trash-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 0 12px;
}

.trash-item {
  padding: 8px 16px 10px;
  border-top: 1px solid var(--bg-dark);
  transition: background 120ms ease;
}

.trash-item.selected {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.trash-item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.trash-item.selecting .trash-item-main {
  cursor: pointer;
}

.trash-item-copy {
  min-width: 0;
  flex: 1;
}

.trash-select-input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
  flex: none;
}

.trash-item .t-name {
  color: var(--text-bright);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.trash-item .t-meta {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 2px;
}

.trash-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.trash-actions button,
.trash-select-toggle,
.trash-bulk-bar button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.trash-select-toggle {
  min-width: 64px;
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  font-weight: 650;
}

.trash-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.trash-actions .danger,
.trash-bulk-bar .trash-bulk-danger {
  color: #fb7f7f;
  border-color: #5c2b2b;
}

.trash-bulk-bar {
  flex: none;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--bg-dark);
  background: var(--bg-alt);
}

#btn-trash-delete-all {
  width: 100%;
}

.trash-selection-tools {
  display: grid;
  grid-template-columns: minmax(84px, auto) 1fr minmax(118px, auto);
  align-items: center;
  gap: 8px;
}

#trash-selected-count {
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: center;
  white-space: nowrap;
}

.trash-bulk-bar button:disabled,
.trash-actions button:disabled,
.trash-select-toggle:disabled {
  opacity: 0.45;
}

@media (min-width: 768px) {
  #trash-sheet,
  #project-sheet {
    align-items: center;
    justify-content: center;
    padding: 24px;
  }

  #trash-sheet .trash-panel,
  #project-sheet .project-panel {
    width: min(640px, 100%);
    max-height: min(var(--sheet-max, 82dvh), 720px);
    border-radius: 14px;
    padding-bottom: 0;
  }
}

.deleted-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #4a3b12;
  color: #f5e3b3;
  font-size: 13px;
  flex: none;
}

.deleted-banner button {
  margin-left: auto;
  padding: 5px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ── image lightbox ──────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #0b0b0d;
  /* The surface owns its gestures: sideways pages, down dismisses. */
  touch-action: none;
  user-select: none;
  animation: lb-in 0.16s ease-out;
}

@keyframes lb-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.lb-bar {
  grid-row: 1;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px 12px;
  color: #fff;
}

.lb-count {
  padding: 4px 11px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lb-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lb-open {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.12);
  color: #fff;
  font-size: 13px;
  text-decoration: none;
}

.lb-bar .icon-btn {
  color: #fff;
}

.lb-bar .icon-btn:active {
  background: rgb(255 255 255 / 0.16);
}

.lb-stage {
  grid-row: 2;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  overflow: hidden;
}

/*
 * Small images are scaled UP to a comfortable size rather than left as a stamp
 * in a black void — an icon shown at its native 180px on a phone reads as a
 * mistake. `contain` keeps the aspect ratio, and the frame gives a transparent
 * or light-backgrounded image something to sit on.
 */
#lb-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.6);
  background: rgb(255 255 255 / 0.03);
  will-change: transform, opacity;
}

/* Square-ish small images (icons) get a sensible target size. */
#lb-img.fit-up {
  width: min(88vw, 62vh, 560px);
}

.lb-nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.12);
  color: #fff;
  backdrop-filter: blur(6px);
}

.lb-nav[disabled] {
  opacity: 0.2;
}

.lb-prev {
  left: 10px;
}
.lb-next {
  right: 10px;
}

/* ── filmstrip ── */

.lb-strip {
  grid-row: 3;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  overflow-x: auto;
  overscroll-behavior: contain;
  touch-action: pan-x;
  scrollbar-width: none;
}

.lb-strip::-webkit-scrollbar {
  display: none;
}

.lb-thumb {
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  opacity: 0.6;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  transition:
    opacity 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
  user-select: none;
}

.lb-thumb-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  pointer-events: none;
}

.lb-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.lb-thumb img.loaded {
  opacity: 1;
}

.lb-thumb.active {
  opacity: 1;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.16);
}

/* One image: the strip and the arrows are just clutter. */
.lightbox.single .lb-strip,
.lightbox.single .lb-nav {
  display: none;
}

@media (max-width: 767px) {
  .lb-nav {
    display: none;
  }
}

.msg-files img,
.msg-inline-media img,
.msg-text img {
  cursor: zoom-in;
}

/* ── header command shortcuts ────────────────────────────────────────── */

.icon-btn.danger {
  color: #f87171;
}

/* Five controls plus the session name is tight on a 390px phone; shaving the
   hit target to 34px keeps the name readable while staying above the ~32px
   comfortable-touch floor. */
@media (max-width: 420px) {
  .topbar .icon-btn {
    width: 34px;
    height: 34px;
  }

  .topbar .evo-topbar-btn {
    width: 36px;
  }

  .topbar {
    gap: 2px;
  }
}

.model-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 0 12px;
}

.model-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-top: 1px solid var(--bg-dark);
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 14px;
}

.model-item .m-ref {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-item .m-tag {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 11px;
}

.model-item.current {
  color: var(--text-bright);
  font-weight: 600;
}

.model-item.current::before {
  content: '✓';
  color: var(--accent);
}

.model-item:not(.current)::before {
  content: '';
  width: 1ch;
}

/* Thinking is a per-session setting. The bulb stays muted for the runtime
   default/off and becomes progressively brighter as the selected effort rises. */
#btn-thinking {
  position: relative;
}

#btn-thinking[data-level='minimal'],
#btn-thinking[data-level='low'] {
  color: #a5b4fc;
}

#btn-thinking[data-level='medium'],
#btn-thinking[data-level='high'],
#btn-thinking[data-level='xhigh'],
#btn-thinking[data-level='max'] {
  color: var(--thinking);
}

#btn-thinking[data-level='high']::after,
#btn-thinking[data-level='xhigh']::after,
#btn-thinking[data-level='max']::after {
  content: '';
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--thinking);
  box-shadow: 0 0 6px var(--thinking);
}

.thinking-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 0 12px;
}

.thinking-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 9px 16px;
  border: 0;
  border-top: 1px solid var(--bg-dark);
  background: none;
  color: var(--text);
  text-align: left;
}

.thinking-item::before {
  content: '';
  width: 9px;
  height: 9px;
  flex: none;
  border: 2px solid var(--border);
  border-radius: 50%;
}

.thinking-item.current {
  background: rgb(167 139 250 / 0.08);
  color: var(--text-bright);
}

.thinking-item.current::before {
  border-color: var(--thinking);
  background: var(--thinking);
  box-shadow: 0 0 0 3px rgb(167 139 250 / 0.16);
}

.thinking-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.thinking-name {
  font-weight: 650;
  text-transform: capitalize;
}

.thinking-description {
  color: var(--text-dim);
  font-size: 12px;
}

/* ── provider badge ──────────────────────────────────────────────────── */

.provider-badge {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}

/* Colour-coded by where the compute happens: green = this machine,
   NVIDIA green = NIM, and so on. Text label carries the meaning; colour is
   only a shortcut, so it still reads without colour vision. */
.provider-badge.local {
  background: rgb(59 165 93 / 0.18);
  border-color: rgb(59 165 93 / 0.5);
  color: #7ee2a8;
}

.provider-badge.nv {
  background: rgb(118 185 0 / 0.18);
  border-color: rgb(118 185 0 / 0.5);
  color: #a6e34d;
}

.provider-badge.gpt {
  background: rgb(16 163 127 / 0.18);
  border-color: rgb(16 163 127 / 0.5);
  color: #5fd3b8;
}

/* Codex variants — star / earth / sun / moon, each its own colour so they
   read apart at a glance (label still carries the meaning without colour). */
.provider-badge.astra {
  background: rgb(236 72 153 / 0.2);
  border-color: rgb(236 72 153 / 0.55);
  color: #f472b6;
}

/* Terracotta (clay/earth) — deliberately NOT green, so it reads apart from the
   LOCAL and GPT greens sitting right next to it in the drawer. */
.provider-badge.terra {
  background: rgb(224 122 95 / 0.2);
  border-color: rgb(224 122 95 / 0.55);
  color: #eeab97;
}

.provider-badge.sol {
  background: rgb(251 191 36 / 0.18);
  border-color: rgb(251 191 36 / 0.5);
  color: #fcd34d;
}

.provider-badge.luna {
  background: rgb(148 163 184 / 0.2);
  border-color: rgb(148 163 184 / 0.55);
  color: #cbd5e1;
}

.provider-badge.gem {
  background: rgb(66 133 244 / 0.18);
  border-color: rgb(66 133 244 / 0.5);
  color: #8ab4f8;
}

.provider-badge.xai {
  background: rgb(255 255 255 / 0.1);
  border-color: rgb(255 255 255 / 0.28);
  color: #e6e6e6;
}

.provider-badge.or {
  background: rgb(139 92 246 / 0.18);
  border-color: rgb(139 92 246 / 0.5);
  color: #c4b5fd;
}

.provider-badge.sak,
.provider-badge.other {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-dim);
}

#header-badge {
  margin-left: 2px;
}

/* ── sheet search ────────────────────────────────────────────────────── */

.sheet-search {
  flex: none;
  padding: 10px 16px 4px;
}

.sheet-search input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 16px; /* keep iOS from zooming on focus */
  outline: none;
}

.sheet-search input:focus {
  border-color: var(--accent);
}

.model-item .provider-badge {
  margin-left: 2px;
}

.model-item mark {
  background: rgb(88 101 242 / 0.35);
  color: inherit;
  border-radius: 2px;
}

/* ── drawer preference toggles ───────────────────────────────────────── */

.notif-toggle,
.drawer-theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 0;
  margin-bottom: 6px;
  text-align: left;
}

.notif-toggle svg,
.drawer-theme-toggle svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.notif-state {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 11px;
}

.notif-state.on {
  background: rgb(59 165 93 / 0.2);
  color: #7ee2a8;
}

.notif-state.blocked {
  background: rgb(218 55 60 / 0.18);
  color: #f4a3a5;
}

/* ── toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #101114;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.5);
  color: var(--text-bright);
  font-size: 13.5px;
  animation: toast-in 0.14s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.toast span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast button {
  flex: none;
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* A tapped link copies rather than navigating, so it should not look like a
   plain hyperlink invitation to leave the page. */
.msg-text a {
  text-decoration-style: dotted;
  text-decoration-line: underline;
  text-underline-offset: 2px;
}

/* ── login: remember me ──────────────────────────────────────────────── */

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.login-remember input {
  width: 16px;
  height: 16px;
  flex: none;
  accent-color: var(--accent);
}

/* ── overflow menu (⋯ in the topbar) ─────────────────────────────────────
   Anchored below the topbar on the right rather than being a bottom sheet:
   these are quick, low-commitment actions, and a sheet would be as heavy as
   the model picker. Sits above the topbar (z 45) but below the lightbox (60)
   and toasts (70). */
.menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 44;
  /* Invisible: its only job is to catch the tap that dismisses the menu. */
  background: transparent;
}

.menu-pop {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 4px);
  right: 8px;
  z-index: 45;
  min-width: 232px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.5);
  transform-origin: top right;
  animation: menu-in 110ms ease-out;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-pop {
    animation: none;
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  /* The menu enters at scale(.96); 46px keeps the transformed touch target
     above the 44px mobile minimum for the entire animation. */
  min-height: 46px;
  padding: 10px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.menu-item svg {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mi-label {
  flex: 1;
  min-width: 0;
}

/* The slash command the item runs, so the menu also teaches the typed form. */
.mi-cmd {
  flex: none;
  color: var(--text-dim);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--bg-input);
}

.menu-item.danger {
  color: #f28b8d;
}

.menu-item.danger:hover,
.menu-item.danger:focus-visible {
  background: rgb(218 55 60 / 0.16);
}

.menu-item[disabled] {
  opacity: 0.4;
  cursor: default;
}

.menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

.theme-icon-dark {
  display: none;
}

:root[data-theme='light'] .theme-icon-light {
  display: none;
}

:root[data-theme='light'] .theme-icon-dark {
  display: block;
}

/* ── media gallery ──────────────────────────────────────────────────────────
 *
 * Every image/video in the session as square tiles, Discord-style. Square is
 * the point: a mixed grid of native aspect ratios reads as clutter, and the
 * tile is a target to open the real thing, not a place to judge composition.
 */
.media-grid {
  display: grid;
  /* auto-fill, not auto-fit: tiles keep their size on a wide screen instead of
     stretching into rectangles and defeating the square. */
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
  padding: 0 12px 16px;
  overflow-y: auto;
}

.media-tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-3, #2b2d31);
  cursor: pointer;
}

.media-tile img,
.media-tile video {
  width: 100%;
  height: 100%;
  /* cover crops to the square; the lightbox shows the whole frame. */
  object-fit: cover;
  display: block;
}

.media-tile:focus-visible {
  outline: 2px solid var(--accent, #5865f2);
  outline-offset: 2px;
}

/* Video and audio need to be tellable apart from a photo at a glance. */
.media-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.66);
  color: #fff;
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.media-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 6px;
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-2, #b5bac1);
  word-break: break-all;
  text-align: center;
}

/* Video and audio open here instead of navigating the browser to a raw file.
   Keep the controls dark in either app theme so native media chrome has a
   stable, high-contrast canvas. */
.media-player {
  position: fixed;
  inset: 0;
  z-index: 61;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #0b0b0d;
  color: #fff;
  animation: lb-in 0.16s ease-out;
}

.media-player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px;
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
}

.media-player-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-player-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.media-player-download {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  color: #fff;
  text-decoration: none;
  touch-action: manipulation;
}

.media-player-download[data-ready='true'] {
  background: rgb(63 95 111 / 0.5);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.7);
}

.media-player-download[aria-busy='true'] svg {
  animation: media-download-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes media-download-pulse {
  to {
    opacity: 0.35;
    transform: translateY(2px);
  }
}

.media-player-download:active,
.media-player-download:focus-visible,
.media-player-close:active,
.media-player-close:focus-visible {
  background: rgb(255 255 255 / 0.16);
  color: #fff;
  outline: none;
}

.media-player-stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.media-player-video,
.media-player-audio {
  max-width: 100%;
}

.media-player-video {
  width: min(100%, 960px);
  max-height: 100%;
  border-radius: 10px;
  background: #000;
}

.media-player-audio {
  width: min(100%, 560px);
}

@media (prefers-reduced-motion: reduce) {
  .media-player {
    animation: none;
  }
}

/* ── light appearance refinements ───────────────────────────────────────────
 * Most surfaces use the semantic tokens at the top of this file. These rules
 * cover components whose dark-mode translucency or fixed colour needs a
 * contrast-safe daytime equivalent. The image viewer and selection pill stay
 * intentionally dark so photos and native-style selection controls do not jump
 * between appearances. */

:root[data-theme='light'] .login-card {
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgb(45 43 38 / 0.08);
}

:root[data-theme='light'] .session-item .work-spinner {
  border-color: rgb(45 43 38 / 0.14);
  border-top-color: var(--accent);
}

:root[data-theme='light'] .event {
  border-color: var(--border);
  border-left-color: var(--border);
  box-shadow: none;
}

:root[data-theme='light'] .event.thinking {
  background: #fbf9fc;
  border-left-color: var(--thinking);
}

:root[data-theme='light'] .event.tool {
  background: #f7faf8;
  border-left-color: var(--tool);
}

:root[data-theme='light'] .event.tool_result {
  background: #f7faf8;
  border-left-color: #397057;
}

:root[data-theme='light'] .event.system {
  background: var(--bg-alt);
  border-left-color: var(--accent);
}

:root[data-theme='light'] .event.error {
  background: #fff8f7;
  border-left-color: var(--danger);
}

:root[data-theme='light'] .event summary:hover,
:root[data-theme='light'] #quote-preview-remove:hover,
:root[data-theme='light'] #quote-preview-remove:active {
  background: rgb(45 43 38 / 0.045);
}

:root[data-theme='light'] .autocomplete,
:root[data-theme='light'] .menu-pop {
  box-shadow: 0 12px 32px rgb(45 43 38 / 0.1);
}

:root[data-theme='light'] .msg-text a,
:root[data-theme='light'] .video-download,
:root[data-theme='light'] .file-link {
  color: var(--accent);
}

/* Day-mode command output uses the same warm paper hierarchy as the rest of
   the Japanese-minimal palette instead of leaving a heavy dark rectangle in
   the transcript. Syntax colours are muted but remain contrast-safe. */
:root[data-theme='light'] .msg-text pre,
:root[data-theme='light'] .event-body pre {
  background: var(--bg-input);
  border-color: var(--border);
}

:root[data-theme='light'] .msg-text pre code,
:root[data-theme='light'] .event-body pre code {
  color: var(--text);
}

:root[data-theme='light'] .hljs-comment,
:root[data-theme='light'] .hljs-quote {
  color: #6f6a61;
}

:root[data-theme='light'] .hljs-keyword,
:root[data-theme='light'] .hljs-selector-tag,
:root[data-theme='light'] .hljs-literal,
:root[data-theme='light'] .hljs-type,
:root[data-theme='light'] .hljs-doctag {
  color: #963f43;
}

:root[data-theme='light'] .hljs-title,
:root[data-theme='light'] .hljs-title.class_,
:root[data-theme='light'] .hljs-title.function_,
:root[data-theme='light'] .hljs-section {
  color: #6e5c87;
}

:root[data-theme='light'] .hljs-string,
:root[data-theme='light'] .hljs-regexp,
:root[data-theme='light'] .hljs-template-tag,
:root[data-theme='light'] .hljs-template-variable {
  color: #315f73;
}

:root[data-theme='light'] .hljs-number,
:root[data-theme='light'] .hljs-symbol,
:root[data-theme='light'] .hljs-bullet,
:root[data-theme='light'] .hljs-link {
  color: #765322;
}

:root[data-theme='light'] .hljs-attr,
:root[data-theme='light'] .hljs-attribute,
:root[data-theme='light'] .hljs-variable,
:root[data-theme='light'] .hljs-property,
:root[data-theme='light'] .hljs-params {
  color: #8c4f2b;
}

:root[data-theme='light'] .hljs-built_in,
:root[data-theme='light'] .hljs-builtin-name,
:root[data-theme='light'] .hljs-meta {
  color: #6f5d24;
}

:root[data-theme='light'] .hljs-tag,
:root[data-theme='light'] .hljs-name,
:root[data-theme='light'] .hljs-selector-id,
:root[data-theme='light'] .hljs-selector-class {
  color: #397057;
}

:root[data-theme='light'] .hljs-addition {
  color: #2f684f;
  background: #e6f0e9;
}

:root[data-theme='light'] .hljs-deletion {
  color: #963f43;
  background: #f7e8e5;
}

/* Mermaid is rendered with an explicit dark diagram palette, so its chrome
   remains dark as one self-contained figure in either app appearance. */
:root[data-theme='light'] .mermaid-wrap,
:root[data-theme='light'] .mm-modal-content {
  background: #1c1c1a;
  border-color: #51534d;
  color: #e6e0d5;
}

:root[data-theme='light'] .mermaid-header,
:root[data-theme='light'] .mm-modal-head {
  background: #252622;
  border-color: #51534d;
  color: #b9b5ab;
}

:root[data-theme='light'] .mermaid-title,
:root[data-theme='light'] .mm-modal-title {
  color: #f4f0e6;
}

:root[data-theme='light'] .mermaid-btn {
  background: #31322e;
  border-color: #5d6058;
  color: #e6e0d5;
}

:root[data-theme='light'] .deleted-banner {
  background: #fcf6e8;
  color: #655630;
}

:root[data-theme='light'] .login-error,
:root[data-theme='light'] .trash-actions .danger,
:root[data-theme='light'] .trash-bulk-bar .trash-bulk-danger,
:root[data-theme='light'] .icon-btn.danger,
:root[data-theme='light'] .menu-item.danger {
  color: #b4232a;
}

:root[data-theme='light'] .trash-actions .danger,
:root[data-theme='light'] .trash-bulk-bar .trash-bulk-danger {
  border-color: #e3a9ac;
}

:root[data-theme='light'] .menu-item.danger:hover,
:root[data-theme='light'] .menu-item.danger:focus-visible {
  background: rgb(201 52 58 / 0.1);
}

:root[data-theme='light'] .provider-badge {
  background: #ffffff;
  border-color: var(--border);
}

:root[data-theme='light'] .provider-badge.local,
:root[data-theme='light'] .notif-state.on {
  color: #356348;
}

:root[data-theme='light'] .notif-state.on {
  background: #f0f5f1;
}

:root[data-theme='light'] .provider-badge.nv {
  color: #4d7400;
}

:root[data-theme='light'] .provider-badge.gpt {
  color: #087761;
}

:root[data-theme='light'] .provider-badge.astra {
  color: #9d174d;
}

:root[data-theme='light'] .provider-badge.terra {
  color: #963f2b;
}

:root[data-theme='light'] .provider-badge.sol {
  color: #805c00;
}

:root[data-theme='light'] .provider-badge.luna {
  color: #52606e;
}

:root[data-theme='light'] .provider-badge.gem {
  color: #245cb5;
}

:root[data-theme='light'] .provider-badge.xai {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text);
}

:root[data-theme='light'] .provider-badge.or {
  color: #6741ad;
}

:root[data-theme='light'] .notif-state.blocked {
  color: #a52b31;
}

:root[data-theme='light'] .toast {
  background: #ffffff;
  border-color: var(--border);
  box-shadow: 0 12px 32px rgb(45 43 38 / 0.12);
  color: var(--text-bright);
}

:root[data-theme='light'] ::selection {
  background: rgb(63 95 111 / 0.22);
}

:root[data-theme='light'] ::highlight(piweb-selection) {
  background-color: rgb(63 95 111 / 0.18);
}

/* The lightbox is always dark, including labels that would otherwise inherit
   the daytime text tokens. */
:root[data-theme='light'] .lb-thumb,
:root[data-theme='light'] .lb-thumb-num {
  color: #b5bac1;
}

/* ── streaming reply ────────────────────────────────────────────────────────
 *
 * The answer appears as it is generated rather than in one lump at the end.
 * Only the newly arrived tail fades in: animating the whole string on every
 * poll would restart the fade on text already read, which reads as flicker.
 */
.msg.partial .msg-text .ink {
  opacity: 0;
  transition: opacity 220ms ease-out;
}

.msg.partial .msg-text .ink.lit {
  opacity: 1;
}

/* A soft cursor so a pause in generation still looks alive rather than stuck. */
.msg.partial .msg-text::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  opacity: 0.5;
  animation: partial-caret 1s steps(2, start) infinite;
}

@keyframes partial-caret {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg.partial .msg-text .ink {
    opacity: 1;
    transition: none;
  }
  .msg.partial .msg-text::after {
    animation: none;
  }
}

/* The streaming thinking block reuses the finished row's look, so the swap when
 * the block closes is not a visible jump. Only the caret marks it as live. */
.event.thinking.partial .event-body .ink {
  opacity: 0;
  transition: opacity 220ms ease-out;
}

.event.thinking.partial .event-body .ink.lit {
  opacity: 1;
}

.event.thinking.partial .event-body::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  opacity: 0.4;
  animation: partial-caret 1s steps(2, start) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .event.thinking.partial .event-body .ink {
    opacity: 1;
    transition: none;
  }
  .event.thinking.partial .event-body::after {
    animation: none;
  }
}

/* Streaming markdown: completed blocks render normally, the unfinished tail
 * stays plain until its block closes. Keep the tail's whitespace so a
 * half-written table still lines up instead of collapsing onto one line. */
.grow-tail {
  white-space: pre-wrap;
}

.grow-done > :last-child {
  margin-bottom: 0;
}

/* Guider is a conversation lane, visually separate from direct EVO input. */
.guider-input::placeholder {
  color: #65c9c4;
  opacity: 0.9;
}
:root[data-theme='light'] .guider-input::placeholder {
  color: #2f8f89;
}
.guider-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
}
.guider-bar select {
  min-height: 44px;
  max-width: 100%;
  font-size: 16px;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.guider-bar small {
  width: 100%;
  font-size: 11px;
}
.guider-card {
  padding: 12px;
  margin: 8px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid #b29ade;
  border-radius: 10px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.guider-user-card {
  border-left-color: #65c9c4;
  background: rgba(101, 201, 196, 0.06);
}
/* The final answer reads as a normal message, not a boxed card. */
.guider-card.guider-final {
  border: none;
  background: none;
  padding: 0;
}
.guider-progress {
  padding: 7px 12px;
  margin-block: 3px;
  border-left-color: #65c9c4;
  font-size: 12px;
  color: var(--text-2);
}
.guider-progress strong { margin-right: 8px; }
.guider-progress-label { overflow-wrap: anywhere; }
.guider-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(101, 201, 196, 0.25);
  border-top-color: #65c9c4;
  border-radius: 50%;
  animation: guider-spin 0.75s linear infinite;
  vertical-align: -1px;
  margin-right: 6px;
  flex-shrink: 0;
}
@keyframes guider-spin {
  to { transform: rotate(360deg); }
}
.guider-thought-card {
  border-left-color: #a78bfa;
  background: rgba(167, 139, 250, 0.04);
}
.guider-thought-body {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  border-radius: 6px;
  font-family: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
  max-height: 240px;
  overflow-y: auto;
}
.guider-card p,
.guider-card li {
  white-space: pre-wrap;
}
.guider-card h4 {
  margin: 12px 0 4px;
}
.guider-card ul {
  padding-left: 20px;
}
.guider-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.guider-actions button {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.guider-actions button:disabled {
  opacity: 0.5;
}
@media (max-height: 540px) {
  .guider-conversation .evo-action-dock {
    padding: 4px 10px;
    gap: 2px;
    margin-top: 2px;
    margin-bottom: 2px;
  }
  .guider-conversation .evo-dock-task,
  .guider-conversation .evo-dock-stage,
  .guider-conversation .evo-dock-activity {
    display: none;
  }
  .guider-conversation .guider-bar {
    padding-top: 2px;
    padding-bottom: 2px;
    gap: 0 8px;
  }
}
.guider-conversation .jump-live {
  bottom: calc(var(--guider-composer-height, 96px) + 8px);
  min-height: 44px;
}
.guider-actions-log {
  margin: 10px 0 4px;
  font-size: 13px;
}
.guider-actions-log summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-2);
}
.guider-actions-log ol {
  margin: 4px 0 0;
  padding-left: 20px;
}
.guider-actions-log li {
  margin: 6px 0;
  white-space: normal;
}
.guider-actions-log li.failed code {
  color: var(--danger);
}
.guider-actions-log code {
  overflow-wrap: anywhere;
}
.guider-actions-log pre {
  margin: 4px 0 0;
  padding: 6px 8px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
