/* Nice Chat — pastel + Comic Sans by day, black + green in debugger mode. */
:root {
  --font: "Comic Sans MS", "Comic Sans", "Comic Neue", "Chalkboard SE", "Segoe Print", cursive;
  --mono: "Fira Code", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --bg: #fff6fb;
  --paper: #ffffff;
  --ink: #3b2f4a;
  --muted: #8a7f99;
  --line: #3b2f4a;

  --pink: #ffd6e7;
  --mint: #d3f8e2;
  --lemon: #fff5b8;
  --sky: #cfe9ff;
  --lilac: #e4d4ff;
  --peach: #ffe0c7;

  --good: #6ccf8a;
  --meh: #f5c542;
  --bad: #ff6b8a;

  --track: #f3eff7;
  --glass: rgba(255, 255, 255, 0.7);
  --radius: 22px;
  --shadow: 0 6px 0 rgba(59, 47, 74, 0.12);
  --fs: 14px;

  --amp: 6px;
  --rot: 2deg;
  --wiggle-dur: 0.5s;
}

* { box-sizing: border-box; }
html { font-size: var(--fs); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.4;
  overflow-x: hidden;
}
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1, h2 { margin: 0 0 0.4rem; letter-spacing: 0.01em; }
h2 { font-size: 1.05rem; }

/* pastel blobs in the background */
.blobs { position: fixed; inset: 0; z-index: -1; pointer-events: none; filter: blur(48px); opacity: 0.9; }
.blobs span { position: absolute; border-radius: 50%; animation: drift 24s ease-in-out infinite alternate; }
.blobs .b1 { width: 45vw; height: 45vw; left: -12vw; top: -14vw; background: var(--pink); }
.blobs .b2 { width: 40vw; height: 40vw; right: -14vw; top: 10vh; background: var(--sky); animation-delay: -6s; }
.blobs .b3 { width: 38vw; height: 38vw; left: 20vw; bottom: -20vw; background: var(--lemon); animation-delay: -12s; }
.blobs .b4 { width: 30vw; height: 30vw; right: 18vw; bottom: -8vw; background: var(--mint); animation-delay: -18s; }
@keyframes drift { to { transform: translate(6vw, 4vh) scale(1.08); } }

.card {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------- header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.9rem 1.4rem 0.4rem;
}
.brand { display: flex; align-items: baseline; gap: 0.5rem; text-decoration: none; }
.brand-heart { font-size: 1.6rem; display: inline-block; animation: beat 1.6s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.18); } 30% { transform: scale(1); } 45% { transform: scale(1.12); } }
.brand-name { font-size: 1.7rem; font-weight: 700; text-shadow: 2px 2px 0 var(--pink); }
.brand-tag { font-size: 0.9rem; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.presence {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.9rem;
  background: var(--mint); border: 2px solid var(--line); border-radius: 999px; font-weight: 700;
}
.presence .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px rgba(108, 207, 138, 0.35); animation: pulse 1.8s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(108, 207, 138, 0.15); } }
.faces { margin-left: 0.3rem; font-size: 1.1rem; letter-spacing: -0.2rem; }

.debug-toggle { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; font-weight: 700; }
.debug-toggle input { display: none; }
.switch { width: 3.2rem; height: 1.7rem; border: 2px solid var(--line); border-radius: 999px; background: var(--lilac); position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 0.15rem; left: 0.15rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--line); transition: transform 0.2s; }
.debug-toggle input:checked + .switch { background: #39ff14; }
.debug-toggle input:checked + .switch::after { transform: translateX(1.5rem); }

/* phone-only: the rail folds into a bottom sheet behind this pill */
.rail-toggle, .rail-head, .rail-backdrop { display: none; }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1rem;
  padding: 0.5rem 1.2rem 0.8rem; max-width: 1200px; margin: 0 auto;
  height: calc(100vh - 7.6rem); min-height: 420px;
}
.chat { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.rail { display: flex; flex-direction: column; gap: 1rem; min-height: 0; overflow-y: auto; padding-bottom: 0.5rem; }
.rail .card { padding: 0.9rem 1rem; flex-shrink: 0; }

/* ---------------------------------------------------------------- thread */
.thread { flex: 1; overflow-y: auto; padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; scroll-behavior: smooth; }
.thread-hello { text-align: center; color: var(--muted); margin: auto; max-width: 30rem; }
.thread-hello .big { font-size: 2.8rem; }

.msg { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.6rem; align-items: start; animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { transform: scale(0.85) translateY(10px); opacity: 0; } }
/* --tint is chosen per author (hash of name+emoji) so one person always gets one color */
.msg { --tint: var(--pink); }
.msg[data-tint="1"] { --tint: var(--mint); }
.msg[data-tint="2"] { --tint: var(--lilac); }
.msg[data-tint="3"] { --tint: var(--sky); }
.msg[data-tint="4"] { --tint: var(--peach); }
.msg .avatar {
  width: 2.7rem; height: 2.7rem; display: grid; place-items: center; font-size: 1.6rem;
  background: var(--tint); border: 2px solid var(--line); border-radius: 50%;
}
.msg .bubble { background: var(--tint); border: 2px solid var(--line); border-radius: 4px 20px 20px 20px; padding: 0.55rem 0.9rem; position: relative; }
.msg.mine .bubble { background: var(--lemon); }
.msg .meta { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.85rem; }
.msg .name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.msg .time { color: var(--muted); }
.msg .nice-badge { margin-left: auto; font-size: 0.8rem; padding: 0.05rem 0.5rem; background: var(--paper); border: 2px solid var(--line); border-radius: 999px; white-space: nowrap; }
.msg .text { margin: 0.15rem 0 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.msg .probs { display: none; }

/* reactions */
.msg .reacts { display: flex; justify-content: flex-end; gap: 0.35rem; margin-top: 0.4rem; }
/* gray ghost until you click it; lights up in color once it's yours */
.react {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.1rem 0.55rem; min-width: 2.2rem;
  background: transparent; border: 2px solid var(--muted); border-radius: 999px; cursor: pointer;
  color: var(--muted); filter: grayscale(1); opacity: 0.55;
  font-size: 0.85rem; line-height: 1.3; transition: transform 0.15s, background 0.15s, opacity 0.15s, filter 0.15s;
}
@media (hover: hover) { .react:hover { transform: translateY(-1px) scale(1.06); opacity: 0.85; } }
.react:disabled { cursor: progress; }
.react .n { font-weight: 700; font-size: 0.8rem; }
.react .n:empty { display: none; }
.react.has { opacity: 0.8; }
.react.on { background: var(--lemon); border-color: var(--ink); color: var(--ink); filter: none; opacity: 1; box-shadow: 0 2px 0 var(--ink); }
.react.pop .e { animation: react-pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); display: inline-block; }
@keyframes react-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.5) rotate(-10deg); } 100% { transform: scale(1); } }

/* ---------------------------------------------------------------- composer */
.composer { border-top: 2px solid var(--line); padding: 0.8rem 1rem 0.9rem; background: var(--glass); }
.compose-row { display: flex; gap: 0.7rem; align-items: flex-end; }
/* your emoji doubles as the "change my look" button */
.me-emoji { position: relative; font-size: 2rem; line-height: 1; padding: 0 0 0.4rem; background: none; border: 0; cursor: pointer; font-family: inherit; transition: transform 0.15s; }
.me-emoji:disabled { cursor: default; }
.me-emoji::after { content: "✏️"; position: absolute; right: -0.35rem; bottom: 0.2rem; font-size: 0.8rem; line-height: 1; opacity: 0; transition: opacity 0.15s; }
.me-emoji:not(:disabled):hover, .me-emoji:focus-visible { transform: scale(1.12) rotate(-8deg); }
.me-emoji:not(:disabled):hover::after, .me-emoji:focus-visible::after { opacity: 1; }
#draft {
  flex: 1; resize: none; min-height: 3.2rem; max-height: 9rem; padding: 0.7rem 1rem; font-size: 1.15rem;
  border: 2px solid var(--line); border-radius: 18px; background: var(--paper); outline: none;
}
#draft:focus { box-shadow: 0 0 0 4px var(--sky); }
#draft:disabled { background: var(--track); }
.send {
  padding: 0.75rem 1.4rem; font-size: 1.15rem; font-weight: 700; cursor: pointer;
  background: var(--good); border: 2px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  transition: transform 0.1s, background 0.2s;
}
@media (hover: hover) { .send:hover:not(:disabled) { transform: translateY(-2px); } }
.send:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.send:disabled { background: #e3dfe9; color: var(--muted); cursor: not-allowed; box-shadow: none; }
.send.pending { background: var(--meh); }
.send.blocked { background: var(--bad); color: #fff; }

/* the wiggle: amplitude, rotation and duration scale with how mean the message is */
.send.wiggle, .join-btn.wiggle { animation: wiggle var(--wiggle-dur) cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes wiggle {
  0%, 100% { transform: translateX(0) rotate(0); }
  10% { transform: translateX(calc(-1 * var(--amp))) rotate(calc(-1 * var(--rot))); }
  20% { transform: translateX(var(--amp)) rotate(var(--rot)); }
  30% { transform: translateX(calc(-1 * var(--amp))) rotate(calc(-1 * var(--rot))); }
  40% { transform: translateX(var(--amp)) rotate(var(--rot)); }
  50% { transform: translateX(calc(-0.8 * var(--amp))) rotate(calc(-0.8 * var(--rot))); }
  60% { transform: translateX(calc(0.8 * var(--amp))) rotate(calc(0.8 * var(--rot))); }
  70% { transform: translateX(calc(-0.5 * var(--amp))) rotate(calc(-0.5 * var(--rot))); }
  80% { transform: translateX(calc(0.5 * var(--amp))) rotate(calc(0.5 * var(--rot))); }
  90% { transform: translateX(calc(-0.2 * var(--amp))) rotate(0); }
}
body.quake .layout { animation: quake 0.5s ease-out both; }
@keyframes quake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(4px, -2px); }
}
body.quake::after { content: ""; position: fixed; inset: 0; pointer-events: none; background: rgba(255, 107, 138, 0.35); animation: flash 0.5s ease-out both; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.verdict { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.6rem; min-height: 2rem; }
.verdict-face { font-size: 1.7rem; line-height: 1; transition: transform 0.2s; }
.meter { width: 120px; height: 1rem; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--track); flex-shrink: 0; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--bad), var(--meh), var(--good)); background-size: 120px 100%; transition: width 0.35s cubic-bezier(0.2, 1.2, 0.4, 1); }
.verdict-text { font-size: 0.95rem; color: var(--muted); flex: 1; }
.chars { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chars:empty { display: none; }
.chars.over { color: var(--bad); font-weight: 700; }
.verdict.thinking .verdict-face { animation: think 0.8s linear infinite; }
@keyframes think { to { transform: rotate(360deg); } }
/* plain text tips, not pills — pills read like chat bubbles */
.reasons { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.3rem; margin: 0.3rem 0 0 0.2rem; font-size: 0.85rem; color: var(--muted); }
.reasons:empty { display: none; }
.reasons::before { content: "tips:"; font-weight: 700; margin-right: 0.15rem; }
.tip { color: #b5485f; font-weight: 700; }
.tip + .tip::before { content: "·"; color: var(--muted); font-weight: 400; margin-right: 0.3rem; }

/* ---------------------------------------------------------------- rail */
.hint, .how { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0; }
.probs { display: grid; gap: 0.35rem; margin-top: 0.4rem; }
.prob { display: grid; grid-template-columns: 9.5rem 1fr 3rem; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.prob .bar { display: block; height: 0.7rem; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--track); }
.prob .bar i { display: block; height: 100%; background: var(--sky); transition: width 0.3s; }
.prob.hot .bar i { background: var(--bad); }
.prob .val { text-align: right; font-variant-numeric: tabular-nums; }
.prob.detail { display: none; }
body.debug .prob.detail { display: grid; }
.prob.group { grid-template-columns: 1fr; font-weight: 700; margin-top: 0.3rem; }
.live .prob { grid-template-columns: minmax(5.6rem, auto) 1fr 2.4rem; font-size: 0.75rem; }
.prob .lbl { min-width: 0; overflow-wrap: anywhere; }
.live .prob.group { grid-template-columns: 1fr; }
.live-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }

.fame ol { margin: 0.3rem 0 0; padding-left: 1.3rem; font-size: 0.9rem; }
.fame li { margin-bottom: 0.35rem; }
.fame .who { font-weight: 700; }
.fame .score { color: var(--muted); font-size: 0.8rem; }

.stats dl { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; margin: 0.3rem 0 0.5rem; }
.stats dl div { background: var(--sky); border: 2px solid var(--line); border-radius: 12px; padding: 0.3rem 0.6rem; }
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; }

/* ---------------------------------------------------------------- footer */
.foot { display: flex; justify-content: center; align-items: center; gap: 0.6rem; padding: 0 1rem 0.8rem; font-size: 0.75rem; color: var(--muted); }

/* ---------------------------------------------------------------- join */
.modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgba(59, 47, 74, 0.35); backdrop-filter: blur(6px); z-index: 10; }
.modal.hidden { display: none; }
.join { position: relative; width: min(440px, 100%); padding: 1.6rem 1.8rem; background: var(--lemon); animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
.join-close { position: absolute; top: 0.7rem; right: 0.8rem; width: 2rem; height: 2rem; border: 2px solid var(--line); border-radius: 50%; background: var(--paper); font-family: inherit; font-weight: 700; cursor: pointer; }
.join-close.hidden { display: none; }
.join-err .reasons { display: inline-flex; margin: 0 0 0 0.3rem; vertical-align: baseline; }
.join-err .reasons::before { content: "—"; font-weight: 400; }
.join h1 { font-size: 2rem; text-shadow: 2px 2px 0 var(--pink); }
.join-sub { margin: 0 0 1rem; color: var(--ink); }
.field { display: block; margin-bottom: 1rem; }
.field > span { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 0.35rem; }
.field input { width: 100%; padding: 0.7rem 1rem; font-size: 1.15rem; border: 2px solid var(--line); border-radius: 16px; background: var(--paper); outline: none; }
.field input:focus { box-shadow: 0 0 0 4px var(--sky); }
.shuffle { font-size: 0.8rem; padding: 0.15rem 0.7rem; border: 2px solid var(--line); border-radius: 999px; background: var(--paper); cursor: pointer; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); gap: 0.35rem; max-height: 11rem; overflow-y: auto; padding: 0.35rem; background: var(--paper); border: 2px solid var(--line); border-radius: 16px; }
.emoji-grid button { font-size: 1.5rem; line-height: 1; padding: 0.3rem 0; border: 2px solid transparent; border-radius: 12px; background: transparent; cursor: pointer; transition: transform 0.1s; }
@media (hover: hover) { .emoji-grid button:hover { transform: scale(1.2); background: var(--sky); } }
.emoji-grid button[aria-checked="true"] { border-color: var(--line); background: var(--pink); }
.join-preview { display: flex; align-items: center; gap: 0.5rem; font-size: 1.3rem; font-weight: 700; margin-bottom: 1rem; }
.pv-emoji { font-size: 2rem; }
.join-btn { width: 100%; padding: 0.85rem; font-size: 1.3rem; font-weight: 700; background: var(--good); border: 2px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); cursor: pointer; }
.join-btn:active { transform: translateY(3px); box-shadow: none; }
.join-err { min-height: 1.2rem; margin: 0.4rem 0 0; color: #c0304f; font-weight: 700; }
.join-fine { margin: 0.3rem 0 0; font-size: 0.8rem; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 5.5rem; transform: translate(-50%, 20px); opacity: 0; padding: 0.6rem 1.2rem; background: var(--ink); color: #fff; border-radius: 999px; font-weight: 700; transition: all 0.25s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 960px) {
  html { font-size: 14px; }
  .layout { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .chat { height: 70vh; }
  .rail { overflow: visible; }
  .brand-tag { display: none; }
}

/* ================================================================ DEBUGGER
   Hacker mode: black background, green everything, monospace, probabilities everywhere. */
body.debug {
  --font: var(--mono);
  --bg: #050805;
  --paper: #0a120a;
  --ink: #39ff14;
  --muted: #1f9a2a;
  --line: #39ff14;
  --pink: #0b1a0b; --mint: #0b1a0b; --lemon: #0b1a0b; --sky: #0e230e; --lilac: #0b1a0b; --peach: #0e230e;
  --good: #39ff14; --meh: #b6ff3b; --bad: #ff3b3b;
  --track: #061006;
  --glass: rgba(5, 8, 5, 0.85);
  --radius: 6px;
  --shadow: 0 0 18px rgba(57, 255, 20, 0.18);
  --fs: 13px;
  font-family: var(--mono);
  text-shadow: 0 0 6px rgba(57, 255, 20, 0.35);
}
body.debug .blobs { display: none; }
body.debug::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(57, 255, 20, 0.04) 0 2px, transparent 2px 4px);
}
body.debug .brand-name, body.debug .join h1 { text-shadow: 0 0 12px #39ff14; }
body.debug .brand-heart { animation: none; }
body.debug .brand-heart::after, body.debug .send-emoji { filter: grayscale(1) brightness(1.6); }
body.debug .card { box-shadow: var(--shadow); }
body.debug .msg .bubble { border-radius: 4px; }
body.debug .msg .avatar { filter: grayscale(0.6); }
body.debug .msg .probs { display: grid; margin-top: 0.5rem; padding-top: 0.4rem; border-top: 1px dashed var(--muted); gap: 0.2rem; }
body.debug .msg .probs .prob { font-size: 0.72rem; grid-template-columns: 8.5rem 1fr 3rem; }
body.debug .send { color: #050805; text-shadow: none; }
body.debug .send.blocked { color: #fff; }
body.debug .send:disabled { background: #123312; color: var(--muted); }
body.debug #draft { background: #030503; caret-color: #39ff14; }
body.debug #draft::placeholder { color: var(--muted); }
body.debug .meter-fill { background: linear-gradient(90deg, #ff3b3b, #b6ff3b, #39ff14); background-size: 120px 100%; }
body.debug .prob .bar i { background: #1f9a2a; box-shadow: 0 0 8px #39ff14; }
body.debug .prob.hot .bar i { background: #ff3b3b; box-shadow: 0 0 8px #ff3b3b; }
body.debug .stats dl div { background: #030503; }
body.debug .toast { background: #39ff14; color: #050805; text-shadow: none; }
body.debug .nice-badge { background: #030503; }
body.debug .tip { color: #ff3b3b; }
body.debug .react { background: #030503; border-color: #1f5f1f; color: #6fbf6f; border-radius: 4px; }
body.debug .react.on { background: #123312; border-color: #39ff14; color: #39ff14; box-shadow: 0 0 8px #39ff14; }
body.debug .debug-toggle input:checked + .switch::after { background: #050805; }
body.debug .modal { background: rgba(0, 0, 0, 0.8); }
body.debug .join { background: var(--paper); }

/* ================================================================ PHONES
   (after the debugger rules so they win). Portrait phones by width; landscape phones by height + touch.
   The thread + composer fill the visual viewport, the rail folds into a bottom sheet and the live Jev
   read becomes a scrolling strip above the composer. app.js mirrors this query in MOBILE. */
@media (max-width: 640px), ((max-height: 520px) and (pointer: coarse)) {
  html { font-size: 14px; overflow: hidden; }
  body {
    display: flex; flex-direction: column;
    height: 100dvh;
    height: var(--vvh, 100vh);          /* visual viewport height, kept fresh by app.js */
    min-height: 0; overflow: hidden; overscroll-behavior: none;
    transform: translateY(var(--vvt, 0px)); /* iOS pans instead of resizing for the keyboard; follow it */
  }
  .blobs { overflow: hidden; } /* body is now the containing block for fixed children; keep the blobs from widening it */

  /* header: one compact row */
  .top {
    flex-wrap: nowrap; gap: 0.5rem; flex-shrink: 0;
    padding: calc(0.35rem + env(safe-area-inset-top)) max(0.7rem, env(safe-area-inset-right)) 0.3rem max(0.7rem, env(safe-area-inset-left));
  }
  .brand { min-width: 0; gap: 0.35rem; align-items: center; }
  .brand-heart { font-size: 1.3rem; }
  .brand-name { font-size: 1.35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-tag, .faces, .presence-word, .debug-label { display: none; }
  .top-right { flex-wrap: nowrap; flex-shrink: 0; gap: 0.5rem; }
  .presence { padding: 0.3rem 0.65rem; font-size: 0.95rem; }
  .debug-toggle { min-height: 44px; }
  .rail-toggle {
    display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 0.5rem;
    font-size: 1.25rem; line-height: 1; background: var(--lemon); border: 2px solid var(--line); border-radius: 999px; cursor: pointer;
  }
  .rail-toggle[aria-expanded="true"] { background: var(--pink); }

  /* the chat fills whatever is left */
  .layout {
    flex: 1; min-height: 0; height: auto; display: grid; grid-template-columns: minmax(0, 1fr);
    max-width: none; width: 100%; gap: 0;
    padding: 0.25rem max(0.5rem, env(safe-area-inset-right)) 0.35rem max(0.5rem, env(safe-area-inset-left));
  }
  .chat { height: auto; min-height: 0; }
  .thread { padding: 0.7rem 0.6rem; gap: 0.6rem; overscroll-behavior: contain; }
  .thread-hello .big { font-size: 2.2rem; }
  .thread-hello p { font-size: 0.95rem; }
  .msg { gap: 0.45rem; }
  .msg .avatar { width: 2.2rem; height: 2.2rem; font-size: 1.3rem; }
  .msg .bubble { padding: 0.5rem 0.7rem; }
  .msg .meta { flex-wrap: wrap; gap: 0.2rem 0.5rem; }
  .msg .text { font-size: 1rem; }

  /* rail → bottom sheet */
  .rail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; max-height: 80%;
    overflow-y: auto; overscroll-behavior: contain; gap: 0.7rem;
    padding: 0.5rem 0.8rem calc(0.8rem + env(safe-area-inset-bottom));
    background: var(--bg); border: 2px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
    box-shadow: 0 -8px 30px rgba(59, 47, 74, 0.25);
    transform: translateY(105%); visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.2, 1, 0.4, 1), visibility 0s 0.28s;
  }
  .rail.open { transform: none; visibility: visible; transition: transform 0.28s cubic-bezier(0.2, 1, 0.4, 1); }
  .rail-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-weight: 700; }
  .rail-close {
    min-width: 44px; min-height: 44px; display: grid; place-items: center;
    background: var(--paper); border: 2px solid var(--line); border-radius: 999px; font-size: 1rem; cursor: pointer;
  }
  .rail-backdrop { display: block; position: fixed; inset: 0; z-index: 14; background: rgba(59, 47, 74, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .rail-backdrop.show { opacity: 1; pointer-events: auto; }
  body.debug .rail { border-radius: 10px 10px 0 0; box-shadow: 0 -8px 30px rgba(57, 255, 20, 0.2); }
  body.debug .rail-backdrop { background: rgba(0, 0, 0, 0.7); }

  /* live Jev read → horizontal strip of chips above the composer (app.js moves it into .chat) */
  .live {
    flex-shrink: 0; border: 0; border-top: 2px solid var(--line); border-radius: 0; box-shadow: none;
    background: var(--glass); padding: 0.4rem 0.6rem 0.3rem;
  }
  .live.empty, .live h2, .live .hint { display: none; }
  .live .probs { display: flex; gap: 0.4rem; margin: 0; padding-bottom: 0.3rem; overflow-x: auto; scrollbar-width: thin; }
  .live .prob {
    flex: 0 0 auto; width: 6.6rem; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "lbl val" "bar bar";
    row-gap: 0.15rem; column-gap: 0.3rem; font-size: 0.7rem; padding: 0.25rem 0.5rem;
    border: 2px solid var(--line); border-radius: 12px; background: var(--paper);
  }
  .live .prob.hot { background: var(--peach); }
  .live .prob .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .live .prob.group { width: auto; grid-template-columns: 1fr; grid-template-areas: none; border: 0; background: none; padding: 0.25rem 0.1rem; margin: 0; align-self: center; white-space: nowrap; }
  .live-meta { font-size: 0.75rem; margin-top: 0.1rem; overflow-wrap: anywhere; }

  /* per-message probabilities (debugger): stack label/value over the bar */
  .prob, body.debug .msg .probs .prob { grid-template-columns: 1fr 3rem; grid-template-areas: "lbl val" "bar bar"; row-gap: 0.1rem; }
  .prob .lbl { grid-area: lbl; } .prob .val { grid-area: val; text-align: right; } .prob .bar { grid-area: bar; }
  .prob.group { grid-template-columns: 1fr; grid-template-areas: none; }

  /* composer: one row, 16px text so iOS doesn't zoom, sits above the keyboard */
  .composer { padding: 0.5rem 0.6rem calc(0.55rem + env(safe-area-inset-bottom)); }
  .compose-row { flex-wrap: nowrap; gap: 0.45rem; }
  .me-emoji { font-size: 1.6rem; padding-bottom: 0.6rem; }
  #draft { flex: 1 1 auto; min-width: 0; font-size: 16px; min-height: 44px; max-height: 7.5rem; padding: 0.55rem 0.8rem; }
  .send { margin-left: 0; flex-shrink: 0; min-height: 44px; padding: 0.6rem 0.9rem; font-size: 1.05rem; white-space: nowrap; }
  .verdict { gap: 0.5rem; margin-top: 0.4rem; min-height: 1.8rem; }
  .verdict-face { font-size: 1.5rem; }
  .meter { width: 72px; }
  .verdict-text { font-size: 0.85rem; min-width: 0; }

  /* footer: tiny, but still there */
  .foot { flex-shrink: 0; gap: 0.4rem; padding: 0 0.5rem calc(0.15rem + env(safe-area-inset-bottom)); font-size: 0.72rem; }
  .foot img { height: 18px; }
  .toast { bottom: 6.5rem; }

  /* join card: fits, scrolls inside the modal when the keyboard eats the screen */
  .modal { display: flex; padding: max(0.6rem, env(safe-area-inset-top)) 0.6rem max(0.6rem, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  .modal.hidden { display: none; }
  .join { margin: auto; width: 100%; padding: 1rem 1rem 0.8rem; }
  .join h1 { font-size: 1.6rem; }
  .join-sub { font-size: 0.9rem; margin-bottom: 0.7rem; }
  .field { margin-bottom: 0.7rem; }
  .field > span { flex-wrap: wrap; gap: 0.3rem; }
  .field input { font-size: 16px; padding: 0.6rem 0.9rem; }
  .emoji-grid { max-height: 8.6rem; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 0.25rem; }
  .emoji-grid button { min-height: 44px; padding: 0; }
  .join-preview { margin-bottom: 0.7rem; font-size: 1.15rem; }
  .pv-emoji { font-size: 1.7rem; }
  .join-btn { position: sticky; bottom: 0.2rem; z-index: 1; min-height: 48px; padding: 0.7rem; font-size: 1.15rem; }
  .join-fine { font-size: 0.72rem; }
}

/* ================================================================ TOUCH
   Fingers, not cursors: every control gets a ≥44px hit area (the small pills via an invisible halo). */
@media (pointer: coarse) {
  .react { position: relative; padding: 0.4rem 0.75rem; min-width: 2.8rem; font-size: 0.95rem; }
  .react::before { content: ""; position: absolute; inset: -7px; border-radius: inherit; }
  .msg .reacts { gap: 0.7rem; margin-top: 0.5rem; }
  .shuffle { position: relative; padding: 0.45rem 0.9rem; }
  .shuffle::before { content: ""; position: absolute; inset: -7px; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .emoji-grid button { min-height: 44px; }
  .debug-toggle { min-height: 44px; }
  .send, .join-btn { min-height: 44px; }
}
