/* Chat app shell. Lives under the site header, fills the viewport. */
:root { --hdr: 56px; --rail: 336px; }
@media (min-width: 700px) { :root { --hdr: 68px; } }
body.chat-body { overflow: hidden; }
.capp { height: calc(100dvh - var(--hdr)); display: grid; grid-template-columns: 1fr; background: var(--bg); }
@media (min-width: 900px) { .capp { grid-template-columns: var(--rail) minmax(0, 1fr); } }

/* ---------- avatars */
.ava { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 800; font-size: 15px; color: #0b0b0e; flex-shrink: 0; letter-spacing: 0; user-select: none; }
.ava-sm { width: 28px; height: 28px; font-size: 12px; }
.ava-lg { width: 64px; height: 64px; font-size: 26px; }
.ava-you { background: var(--yellow); color: var(--yellow-ink); }
.stack { display: inline-flex; flex-shrink: 0; }
.stack .ava { border: 2px solid var(--panel); margin-left: -10px; }
.stack .ava:first-child { margin-left: 0; }

/* ---------- rail */
.rail { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.rail-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.rail-top h1 { font-size: 20px; margin: 0; }
.cpill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 8px 14px; font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; border: 1px solid transparent; cursor: pointer; line-height: 1; }
.cpill-solid { background: var(--yellow); color: var(--yellow-ink); }
.cpill-solid:hover { filter: brightness(1.07); }
.cpill-ghost { border-color: var(--line); color: var(--ink-2); background: transparent; }
.cpill-ghost:hover { border-color: var(--yellow); color: var(--yellow-2); }
.cpill svg { width: 14px; height: 14px; }
.rail-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.conv { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 10px; border-radius: 14px; background: none; border: 0; color: var(--ink); cursor: pointer; }
.conv:hover { background: rgba(255, 255, 255, .04); }
.conv.is-active { background: rgba(255, 191, 58, .1); }
.conv-title { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prev { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-time { color: var(--muted-2); font-size: 11px; align-self: start; padding-top: 4px; }
.rail-empty { color: var(--muted); font-size: 13.5px; padding: 28px 18px; text-align: center; line-height: 1.6; }
.rail-cast { border-top: 1px solid var(--line); padding: 10px 16px 14px; }
.rail-cast-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.rail-cast-head h2 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0; }
.cast-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cast-row::-webkit-scrollbar { display: none; }
.cast-chip { display: grid; justify-items: center; gap: 5px; background: none; border: 0; color: var(--ink-2); cursor: pointer; padding: 2px; min-width: 58px; }
.cast-chip span { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58px; }
.cast-chip:hover .ava { outline: 2px solid var(--yellow); outline-offset: 2px; }
.cast-add .ava { background: transparent; border: 1.5px dashed var(--line-2, #3a3a46); color: var(--muted); font-size: 20px; }

/* ---------- stage */
.stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.stage-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.stage-title { min-width: 0; flex: 1; }
.stage-title h2 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-title p { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { padding: 0; width: 38px; height: 38px; border-radius: 50%; display: inline-grid; place-items: center; background: none; border: 1px solid transparent; color: var(--ink-2); cursor: pointer; flex-shrink: 0; }
.icon-btn:hover { background: rgba(255, 255, 255, .06); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.back { display: none; }
@media (max-width: 899px) { .back { display: inline-grid; } }

.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.group { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; align-items: end; max-width: min(760px, 92%); }
.group-me { grid-template-columns: minmax(0, 1fr); align-self: flex-end; justify-items: end; }
.group .ava { align-self: end; margin-bottom: 20px; }
.group-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.group-me .group-body { align-items: flex-end; }
.who { font-size: 12px; font-weight: 700; margin: 0 0 2px 4px; }
.bubble { padding: 9px 13px; border-radius: 18px; line-height: 1.5; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; width: fit-content; max-width: 100%; }
.group-me .bubble { background: var(--yellow); color: var(--yellow-ink); border-color: transparent; border-radius: 18px; border-bottom-right-radius: 6px; border-bottom-left-radius: 18px; }
.stamp { font-size: 11px; color: var(--muted-2); margin: 2px 4px 0; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: rgba(255, 255, 255, .04); padding: 5px 12px; border-radius: 999px; }
.sys a { color: var(--yellow); }
.typing { display: grid; grid-template-columns: 36px auto; gap: 10px; align-items: center; }
.typing .bubble { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: tdot 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes tdot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.composer { padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; border-radius: 22px; padding: 11px 16px; font-size: 16px; line-height: 1.4; }
/* 16px or larger: iOS Safari zooms the page when a smaller field takes focus. */
.capp input, .capp textarea, .sheet input, .sheet textarea { font-size: 16px; }
.send { padding: 0; width: 44px; height: 44px; border-radius: 50%; background: var(--yellow); color: var(--yellow-ink); border: 0; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.send:disabled { opacity: .4; cursor: not-allowed; }
.send svg { width: 20px; height: 20px; }
.composer-hint { font-size: 12px; color: var(--muted); margin: 8px 4px 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.composer-hint .coin { width: 14px; height: 14px; margin: 0 2px 0 0; }
.paywall { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 14px; background: rgba(255, 191, 58, .1); border: 1px solid rgba(255, 191, 58, .35); margin-bottom: 10px; font-size: 13.5px; }
.paywall a { flex-shrink: 0; }

.stage-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 40px 24px; color: var(--muted); }
.stage-empty .ava { margin: 0 auto 14px; }
.stage-empty h2 { color: var(--ink); font-size: 20px; margin: 0 0 6px; }
.stage-empty p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; max-width: 320px; }

/* ---------- phone: one pane at a time */
@media (max-width: 899px) {
  .capp.is-room .rail { display: none; }
  .capp:not(.is-room) .stage { display: none; }
}

/* ---------- sheets */
dialog.sheet { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); }
@media (max-width: 599px) {
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: calc(100dvh - 24px); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px; }
.sheet-head h2 { font-size: 18px; margin: 0; }
.sheet-body { padding: 8px 18px 18px; display: grid; gap: 4px; overflow-y: auto; }
.sheet-body .field { margin-top: 10px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }
.sheet-foot .cpill { padding: 12px 18px; font-size: 13px; }
.ava-preview { display: flex; align-items: center; gap: 14px; padding: 6px 0 2px; }
.ava-preview p { margin: 0; color: var(--muted); font-size: 13px; }
.ava-preview strong { display: block; color: var(--ink); font-size: 15px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 6px; }
.tile { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); text-align: left; cursor: pointer; }
.tile[aria-pressed="true"] { border-color: var(--yellow); background: rgba(255, 191, 58, .1); }
.tile strong { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet .err { color: var(--red); font-size: 13px; min-height: 1.2em; margin: 6px 0 0; }
.persona-text { white-space: pre-wrap; color: var(--ink-2); font-size: 14px; line-height: 1.55; margin: 8px 0 0; }
.danger { color: var(--red); border-color: rgba(255, 90, 90, .4); }
.danger:hover { border-color: var(--red); color: var(--red); }

/* ---------- settings */
.rail-top-actions { display: flex; align-items: center; gap: 6px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.switch:first-of-type { border-top: 0; }
.switch strong { display: block; font-size: 15px; }
.switch span { display: block; color: var(--muted); font-size: 13px; line-height: 1.5; margin-top: 3px; }
.toggle { position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--panel-3); border: 1px solid var(--line); padding: 0; cursor: pointer; flex-shrink: 0; transition: background .18s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: transform .18s, background .18s; }
.toggle[aria-checked="true"] { background: var(--yellow); border-color: var(--yellow); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); background: var(--yellow-ink); }
.typing .who-typing { font-size: 11.5px; color: var(--muted); margin: 0 0 3px 4px; }

/* ---------- portraits */
.ava.has-img { background-size: cover; background-position: center top; color: transparent; text-indent: -9999px; overflow: hidden; }
.ava-xl { width: 96px; height: 96px; font-size: 38px; }
.looks-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.looks-row .cpill { padding: 11px 14px; white-space: nowrap; }
.looks-row .cpill:disabled { opacity: .5; cursor: progress; }
.sheet .fine { margin: 4px 0 0; min-height: 1.2em; }
.ava-preview .ava.is-making { animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.bubble .act { font-style: italic; color: var(--muted); }
.group-me .bubble .act { color: rgba(22, 13, 0, .62); }
.you-btn { gap: 7px; padding-left: 5px; }
.you-ava { width: 24px; height: 24px; font-size: 11px; }
