/* Sandbox: setup tabs + chat with the character's sprite beside it (desktop) or above it (phone) */
body.sbx { height: auto; min-height: 100%; overscroll-behavior: auto; }
.sbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top)); background: rgba(22,18,28,.96); border-bottom: 1px solid var(--line); }
.sbar h1 { margin: 0; font-size: 19px; } .sbar h1 small { color: var(--accent); font-size: 12px; font-weight: 600; margin-left: 6px; }
.sbar .back { color: var(--ink); text-decoration: none; font-size: 20px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; }
.grow { flex: 1; }
button.ghost { background: transparent; }
button.big { padding: 12px 22px; font-size: 16px; }
#setup { max-width: 1180px; margin: 0 auto; padding: 12px 16px 96px; }
.blk { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px 0; }
.blk h2 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 10px 0; }
.row > input { flex: 1; min-width: 200px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.row label { flex: 1; min-width: 130px; }
label.chk { display: flex; gap: 8px; align-items: center; } label.chk input { width: auto; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.tabs { display: flex; gap: 6px; overflow-x: auto; position: sticky; top: calc(53px + env(safe-area-inset-top)); z-index: 5;
  background: var(--bg); padding: 8px 0; scrollbar-width: none; }
.tabs button { white-space: nowrap; border-radius: 999px; padding: 8px 14px; font-size: 14px; }
.tabs button.on { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 13px; padding: 5px 11px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.k { font-size: 12px; padding: 1px 7px; border-radius: 999px; }
.chip.love, .k.love { background: #b8335b; border-color: #e0466e; color: #fff; }
.chip.like, .k.like { background: #2d6b52; border-color: #4fbf8a; color: #fff; }
.chip.no, .k.no { background: #3a2626; border-color: #e06a4a; color: #e8a08c; text-decoration: line-through; }
.kgroup h4 { margin: 12px 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
/* character grid */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cc { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; display: grid; }
.cc.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224,70,110,.25); }
.cc .pic { aspect-ratio: 3/4; background: linear-gradient(160deg, #2b2337, #1a1522); display: grid; place-items: end center; overflow: hidden; }
.cc .pic img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.cc .pic .ini { font-size: 46px; color: var(--muted); place-self: center; }
.cc .meta { padding: 8px 10px; } .cc .meta b { display: block; font-size: 14px; } .cc .meta small { color: var(--muted); font-size: 12px; }
/* scenarios */
.scgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.sc { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; font-size: 13px; }
.sc.on { border-color: var(--accent); } .sc b { display: block; font-size: 14px; margin-bottom: 2px; } .sc small { color: var(--accent2); }
.sc.ai { border-style: dashed; }
.slider { display: grid; grid-template-columns: 180px 1fr 110px; gap: 12px; align-items: center; margin: 16px 0; }
.slider input { padding: 0; accent-color: var(--accent); } .slider b { color: var(--accent); text-transform: capitalize; }
.go { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; display: flex; gap: 12px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgba(22,18,28,.97); border-top: 1px solid var(--line); }
.sess { display: grid; gap: 8px; }
.srow { display: flex; gap: 10px; align-items: center; background: var(--panel2); border-radius: 10px; padding: 8px 10px; }
.srow img { width: 40px; height: 40px; object-fit: cover; object-position: top; border-radius: 8px; background: var(--panel); }
.srow .t { flex: 1; min-width: 0; cursor: pointer; } .srow small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* chat: the page itself never scrolls - only the message list does */
html:has(body.chatting), body.chatting { height: 100%; overflow: hidden; }
body.chatting { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
body.chatting .sbar { flex: none; }
#chat { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(240px, 32%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.stage { position: relative; min-height: 0; background: radial-gradient(ellipse at 50% 80%, #3a2340, #16121c 70%); overflow: hidden; display: grid; place-items: end center; }
.stage img { max-width: 100%; max-height: 92%; object-fit: contain; transition: opacity .25s; }
.stage .who { position: absolute; top: 12px; left: 14px; right: 14px; } .stage .who small { display: block; color: var(--muted); font-size: 12px; }
.stage .seg { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; background: var(--box); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 5px 11px; font-size: 13px; text-transform: capitalize; }
.seg button.on { background: var(--accent); color: #fff; }
.log { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#msgs { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.m { max-width: min(78ch, 100%); padding: 10px 14px; border-radius: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.m.char { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; }
.m.user { background: #3a2248; align-self: flex-end; }
.m em { color: #c7b8db; } .m q { color: #fff; } .m q::before { content: '"'; } .m q::after { content: '"'; }
.m .nm { display: block; font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.m .ed { position: absolute; top: 4px; right: 6px; opacity: 0; padding: 2px 6px; font-size: 12px; background: transparent; border: 0; }
.m:hover .ed { opacity: .7; }
.m.img { padding: 4px; background: var(--panel); align-self: flex-start; } .m.img img { max-width: min(420px, 100%); max-height: 70vh; border-radius: 10px; display: block; cursor: zoom-in; }
.m.typing::after { content: '▍'; animation: blink 1s infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.composer { flex: none; border-top: 1px solid var(--line); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.tools button { font-size: 13px; padding: 6px 10px; white-space: nowrap; }
.tools button.sit { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.inrow { display: flex; gap: 8px; align-items: end; } .inrow textarea { flex: 1; min-width: 0; font-size: 16px; }
.pics { flex: none; border-top: 1px solid var(--line); padding: 8px 12px; max-height: 38vh; overflow-y: auto; overflow-x: hidden; background: var(--panel); }
.pics h4 { margin: 6px 0 2px; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.pics .row > input { min-width: 0; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(440px, 100%); z-index: 20; background: var(--panel); border-left: 1px solid var(--line);
  padding: 16px; overflow-y: auto; } .dhead { display: flex; justify-content: space-between; align-items: center; }
.drawer .slider { grid-template-columns: 80px 1fr 90px; }
#mem textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: 13px; }
#mem h3 small { font-weight: 400; font-size: 11px; }
.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.92); display: grid; place-items: center; cursor: zoom-out; }
.viewer img { max-width: 96vw; max-height: 96vh; }
@media (max-width: 760px) {
  /* phone: a slim character strip on top (sprite cropped to the face), then the messages, then the composer - nothing overlaps */
  #chat { grid-template-columns: minmax(0, 1fr); grid-template-rows: 112px minmax(0, 1fr); }
  .stage { place-items: start start; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, #2a1a30, #16121c); }
  .stage img { position: absolute; left: 8px; top: 6px; width: 100px; height: 150px; max-height: none; object-fit: cover; object-position: top; }
  .stage .who { left: 118px; top: 14px; }
  .stage .seg { left: 118px; right: 8px; transform: none; bottom: 10px; overflow: hidden; }
  .seg button { padding: 4px 8px; font-size: 12px; flex: 1; }
  #msgs { padding: 10px; }
  .tools button { padding: 5px 8px; font-size: 12px; }
  .slider { grid-template-columns: 1fr 90px; } .slider span { grid-column: 1 / -1; }
  .cgrid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .go #pick { display: none; }
}
/* no sideways scrolling anywhere */
html:has(body.sbx), body.sbx { overflow-x: hidden; }
.tabs { flex-wrap: wrap; overflow: visible; }
.row > input { min-width: min(200px, 100%); }
/* ---------- modes, duo, mood, swipes, chips, panels ---------- */
body[data-mode="casual"] .notCasual, body:not([data-mode="spicy"]) .spicyOnly { display: none !important; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
.modes button { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 14px; }
.modes button small { color: var(--muted); font-size: 12px; }
.modes button.on { border-color: var(--accent); background: linear-gradient(135deg, rgba(224,70,110,.25), rgba(143,107,216,.2)); }
label.duoT { flex: none; }
.cc.on2 { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(143,107,216,.3); }
.cc .pic { position: relative; }
.cc .slot { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #fff; border-radius: 999px; width: 22px; height: 22px; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.cc.on2 .slot { background: var(--accent2); }
a.ghostbtn { color: var(--ink); text-decoration: none; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 14px; }
.stage .sprites { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.stage .sprites img { max-width: 100%; max-height: 92%; object-fit: contain; transition: opacity .25s; }
.stage.duo .sprites img { max-width: 50%; }
.segs { position: absolute; bottom: 12px; left: 8px; right: 8px; display: grid; gap: 6px; justify-items: center; }
.stage .segs .seg { position: static; transform: none; }
.segl { font-size: 11px; color: var(--muted); padding: 5px 6px; }
.moodm { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.moodm .hbar { width: 70px; height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; }
.moodm .hbar i { display: block; height: 100%; background: linear-gradient(90deg, #8f6bd8, #e0466e); }
.moodm .mw { color: var(--muted); text-transform: capitalize; }
.moodm .dl { font-weight: 700; } .moodm .dl.up { color: var(--ok); } .moodm .dl.down { color: var(--bad); }
.m .acts { position: absolute; top: 2px; right: 4px; display: flex; gap: 0; opacity: 0; transition: opacity .15s; }
.m:hover .acts, .m:focus-within .acts { opacity: .8; }
.m .acts button { background: transparent; border: 0; padding: 2px 5px; font-size: 13px; }
.m.char.cont { margin-top: -6px; }
.m.roll { align-self: center; font-size: 13px; font-weight: 600; color: #f3e6b0; background: rgba(240, 200, 80, .1); padding: 4px 12px; border: 1px solid rgba(240, 200, 80, .45); border-radius: 999px; }
.iacts button.armed { background: #b3263a; color: #fff; border-color: #e04a5e; }
.m.note { align-self: center; font-size: 12px; color: var(--muted); background: transparent; padding: 2px 10px; border: 1px dashed var(--line); }
.m.aside { align-self: flex-start; background: #1f2a2a; border: 1px solid #2f4a44; }
.m.aside small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.m.img { position: relative; } .m.img .iacts { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.m.img .iacts button { padding: 4px 8px; background: var(--box); border-radius: 10px; font-size: 14px; }
.swipe { align-self: flex-start; display: flex; align-items: center; gap: 6px; margin-top: -6px; font-size: 13px; color: var(--muted); }
.swipe button { padding: 2px 10px; }
.rchips { display: flex; flex-wrap: wrap; gap: 6px; align-self: flex-start; max-width: 100%; }
.rchips .chip { text-align: left; font-size: 13px; }
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.gi { position: relative; } .gi img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.gi span { position: absolute; bottom: 4px; right: 4px; display: flex; gap: 3px; } .gi button { padding: 2px 6px; font-size: 12px; background: var(--box); }
.quote { background: var(--panel2); border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 10px; margin: 6px 0; white-space: pre-wrap; font-size: 14px; }
.seg.wide { display: flex; margin: 10px 0; background: var(--panel2); border-radius: 999px; padding: 3px; } .seg.wide button { flex: 1; }
#log { background-size: cover; background-position: center; }
@media (hover: none) { .m .acts { opacity: .6; } }
@media (max-width: 760px) {
  .modes button small { display: none; }
  .stage .sprites { inset: auto; left: 8px; top: 6px; width: 100px; height: 150px; justify-content: flex-start; gap: 4px; }
  .stage .sprites img { position: static; width: 100px; height: 150px; object-fit: cover; object-position: top; }
  .stage.duo .sprites { width: 170px; } .stage.duo .sprites img { width: 82px; }
  .stage.duo .who, .stage.duo .segs { left: 186px; }
  .stage .who { right: 8px; }
  .segs { left: 118px; right: 8px; bottom: 8px; justify-items: stretch; }
  .stage .segs .seg { overflow: hidden; }
}
/* duo scene-setting line without a name */
.m.char.narr { font-style: italic; color: #c7b8db; background: transparent; border-style: dashed; }
@media (max-width: 760px) {
  #chat:has(.stage.duo) { grid-template-rows: 158px minmax(0, 1fr); }
  .stage.duo .who { top: 6px; } .stage.duo .who small { display: none; }
  .stage.duo .segs { bottom: 6px; gap: 4px; }
  .stage.duo .seg button { padding: 3px 6px; font-size: 11px; } .stage.duo .segl { padding: 3px 4px; font-size: 10px; }
  .stage.duo .sprites { top: 4px; height: 150px; }
}
