/* Chat app — calm and functional: the video leads, the paper frames it. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

.app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 344px;
  grid-template-rows: 64px 1fr auto auto;
  grid-template-areas: "bar side" "stage side" "banner side" "controls side";
}

/* ── top bar ── */
.bar { grid-area: bar; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.bar .logo { width: 112px; }
.online { font-size: 14px; color: var(--ink-2); }
.online::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--violet); margin-right: .5em; vertical-align: .05em;
}
.online:empty::before { display: none; }

/* ── stage ── */
/* Desktop: them and you side by side, two 4:3 frames as large as the space allows (--g is the gap). */
.stage-box { grid-area: stage; min-width: 0; min-height: 0; display: grid; place-items: center; padding: 0 20px; container-type: size; }
.stage {
  --g: 18px; position: relative;
  width: min(100cqw - 6px, (100cqh - 6px) * 8 / 3 + var(--g)); height: min(100cqh - 6px, (100cqw - 6px - var(--g)) * 3 / 8);
}
.tile { position: absolute; overflow: hidden; border: 2px solid var(--ink); border-radius: 6px; box-shadow: 6px 6px 0 var(--lav); }
.tile-remote { inset: 0 calc(50% + var(--g) / 2) 0 0; background: var(--ink); }
.remote { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .5s var(--ease); }
.app[data-state="connected"] .remote { opacity: 1; }
.tile-self { inset: 0 0 0 calc(50% + var(--g) / 2); background: #2a2433; }
.self { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); transition: opacity .3s; }
.self.rear { transform: none; }
.self.off { opacity: .15; }

.icon.icon-float {
  position: absolute; z-index: 4; width: 42px; height: 42px;
  background: #18141fb3; color: var(--slip); border-color: #f8f4ec55;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.icon-float svg { width: 18px; height: 18px; }
/* overlays sit on their half (--r: from the right edge of the stage to their frame) */
.stage { --r: calc(50% + var(--g) / 2); }
/* Report stays apart from the bar, on their video */
.icon.report { top: 14px; right: calc(var(--r) + 14px); }
.icon.report:hover { background: var(--danger); border-color: var(--danger); }
.app:not([data-state="connected"]) .report { display: none; }

/* reactions: a row of emoji above the bar, and emoji floating up on both screens */
.reacts { position: absolute; z-index: 6; left: -2px; bottom: calc(100% + 10px); display: flex; padding: 3px; border-radius: 30px; background: #18141fb3; border: 2px solid #f8f4ec55; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.reacts[hidden] { display: none; }
.reacts button { width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: none; font-size: 24px; line-height: 1; cursor: pointer; transition: transform .15s var(--ease); }
.reacts button:hover, .reacts button:focus-visible { transform: scale(1.2); }
.reacts button:active { transform: scale(.9); }
.fx { position: absolute; inset: 0 var(--r) 0 0; z-index: 5; pointer-events: none; overflow: hidden; }
.fx span { position: absolute; bottom: 14%; font-size: clamp(40px, 6vw, 68px); line-height: 1; animation: rise 2.2s var(--ease) forwards; }
@keyframes rise {
  0% { opacity: 0; transform: translateY(30px) scale(.4); }
  15% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: translate(var(--x), -300px) scale(1); }
}
.flip[hidden] { display: none; }

/* waiting / idle: a drawn eye glancing around */
.status, .idle {
  position: absolute; inset: 0 var(--r) 0 0; z-index: 2; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  text-align: center; padding: 24px; color: var(--slip);
}
.app[data-state="searching"] .status { display: flex; }
.app[data-state="idle"] .idle { display: flex; }
.status p, .idle-title { margin: 0; font: 400 clamp(1.6rem, 3vw, 2.2rem)/1.05 var(--display); }
.look { width: 120px; color: var(--lav); }
.look .pen { stroke-width: 3.2; }
.look .pupil { animation: glance 3.2s var(--ease) infinite alternate; }
@keyframes glance { 0%, 25% { transform: translateX(-22px); } 75%, 100% { transform: translateX(22px); } }

/* ── gate (age + consent + camera) ── */
.gate {
  position: fixed; inset: 0; z-index: 20; display: none; place-items: center; padding: 16px;
  background: var(--lav); overflow: auto; color: var(--ink);
}
.gate::before {
  content: ""; position: absolute; width: 60vmax; height: 40vmax; left: -18vmax; bottom: -16vmax;
  background: var(--paper); clip-path: var(--torn); transform: rotate(-8deg);
}
.app[data-state="gate"] .gate { display: grid; }
.gate .sticker { position: absolute; right: max(4vw, 12px); top: max(5vh, 14px); }
.ticket {
  position: relative; width: min(460px, 100%); padding: 30px 30px 24px;
  background: var(--slip); transform: rotate(-1deg);
  -webkit-mask: radial-gradient(circle 12px at 0 61%, #0000 98%, #000), radial-gradient(circle 12px at 100% 61%, #0000 98%, #000);
  -webkit-mask-composite: source-in; mask-composite: intersect;
}
.ticket .logo { width: 120px; margin-bottom: 20px; }
.ticket h2 { margin: 0 0 12px; font: 400 clamp(2.4rem, 8vw, 3.4rem)/.9 var(--display); }
.gate-text { margin: 0; color: var(--ink-2); font-size: 16px; }
.perf { border: 0; border-top: 2px dashed #18141f40; margin: 22px -30px 20px; }
.ticket .check { margin: 0 0 18px; }
.ticket .btn { width: 100%; }
.gate-error { min-height: 1.4em; margin: 12px 0 0; color: var(--danger); font-size: 15px; }
.gate-error:empty { min-height: 0; margin: 0; }
.stub { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; font-size: 13px; color: var(--ink-2); }

/* ── controls ── */
/* one set: every button in a single strip, Next beside it */
.controls {
  grid-area: controls; display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 18px 20px calc(16px + env(safe-area-inset-bottom));
}
.set { position: relative; display: flex; border: 2px solid var(--ink); border-radius: 6px; background: var(--slip); box-shadow: 4px 4px 0 var(--ink); }
.set > .icon { border: 0; border-radius: 0; background: none; }
.set > .icon + .icon { border-left: 2px solid var(--ink); }
.set > .icon:first-child { border-radius: 4px 0 0 4px; }
.set > .icon:last-of-type { border-radius: 0 4px 4px 0; }
.set > .icon:hover { background: #fff; }
.set > .icon[aria-pressed="true"] { background: var(--ink); }
.set > .icon[disabled] { opacity: 1; color: #18141f55; }
.set > .icon[disabled] svg { opacity: .5; }
/* Stop and Next: one pair */
.go { display: flex; border: 2px solid var(--ink); border-radius: 6px; box-shadow: 4px 4px 0 var(--ink); }
.go > .icon { border: 0; border-radius: 4px 0 0 4px; }
.go > .next { border: 0; border-left: 2px solid var(--ink); border-radius: 0 4px 4px 0; box-shadow: none; transform: none; }
.go > .next:hover { background: var(--violet-2); }
.icon {
  position: relative; flex: none; width: 50px; height: 50px; border-radius: 4px;
  display: grid; place-items: center; padding: 0; cursor: pointer;
  background: var(--slip); border: 2px solid var(--ink); color: var(--ink);
  transition: background .15s, color .15s, transform .15s var(--ease);
}
.icon:hover { background: #fff; }
.icon:active { transform: translateY(1px); }
.icon[disabled] { opacity: .35; pointer-events: none; }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon .slash { display: none; }
.icon[aria-pressed="true"] { background: var(--ink); color: var(--slip); }
.icon[aria-pressed="true"] .slash { display: block; }
.dot { position: absolute; top: 7px; right: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--violet); border: 2px solid var(--slip); }
.dot[hidden] { display: none; }
.next { min-height: 50px; padding: 0 20px; }
.next kbd { font: 12px/1 var(--text); padding: 3px 5px; border: 1px solid #fff8; border-radius: 3px; opacity: .85; }
#stopBtn rect { fill: currentColor; }
.chat-toggle { display: none; }

/* ── side: messages + ad ── */
.side {
  grid-area: side; display: flex; flex-direction: column; min-height: 0;
  border-left: 2px solid var(--ink); padding: 18px 20px 16px; background: var(--paper-2);
}
.side-head { display: flex; align-items: center; justify-content: space-between; height: 44px; font: 400 1.4rem/1 var(--display); }
.close-chat { display: none; width: 40px; height: 40px; }
.log { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 8px 2px; display: flex; flex-direction: column; gap: 8px; }
.log li {
  max-width: 85%; padding: 8px 12px; font-size: 15px; line-height: 1.4; overflow-wrap: anywhere;
  background: var(--slip); border: 2px solid var(--ink); border-radius: 3px 12px 12px 12px; align-self: flex-start;
}
.log li.me { align-self: flex-end; background: var(--lav); border-radius: 12px 3px 12px 12px; }
.log li.sys { align-self: center; background: none; border: 0; color: var(--ink-2); font-size: 13px; padding: 4px 0; }
.compose { display: flex; gap: 8px; padding: 10px 0 14px; }
.compose input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px; border-radius: 4px;
  background: #fff; border: 2px solid var(--ink); outline: none;
}
.compose input:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.compose input::placeholder { color: var(--ink-2); }
.compose input:disabled { background: var(--slip); }
.send { background: var(--violet); color: #fff; }
.send:hover { background: var(--violet-2); }

/* ── ad slots: paper frame + "Ad" tab ── */
.ad-row { grid-area: banner; display: none; justify-content: center; padding: 18px 20px 0; min-width: 0; }
.ads-on .ad-row { display: flex; }
.ad-wrap { display: none; position: relative; flex: none; max-width: 100%; }
.ads-on .ad-wrap { display: block; }
.ad-wrap .ad { background: var(--slip); outline: 2px solid var(--ink); box-shadow: 4px 4px 0 var(--lav); max-width: 100%; }
.ad-tag { position: absolute; z-index: 1; left: -6px; top: -11px; transform: rotate(-3deg); padding: 0 6px; font-size: 11px; background: var(--lav); color: var(--ink); border: 2px solid var(--ink); }
.ad-side { margin-top: 12px; align-self: center; }

/* ── dialog + toast ── */
.sheet {
  width: min(420px, calc(100% - 32px)); padding: 26px; border-radius: 4px;
  background: var(--slip); color: var(--ink); border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--ink);
}
.sheet::backdrop { background: #18141fb3; }
.sheet h2 { margin: 0 0 4px; font: 400 2rem/1 var(--display); }
.sheet p { margin: 0 0 18px; color: var(--ink-2); font-size: 15px; }
.reasons { display: grid; gap: 8px; margin-bottom: 18px; }
.reasons button {
  text-align: left; padding: 13px 16px; border-radius: 3px; cursor: pointer;
  background: #fff; border: 2px solid var(--ink);
}
.reasons button:hover, .reasons button:focus-visible { background: var(--lav); }
.reasons .block-only { background: var(--paper-2); margin-bottom: 6px; }
.sheet .btn { width: 100%; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: 76px; transform: translateX(-50%) rotate(-1deg);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 3px;
  background: var(--ink); color: var(--slip); font-size: 15px; box-shadow: 4px 4px 0 var(--lav);
}
.toast[hidden] { display: none; }

/* ── mobile ── */
@media (max-width: 899px) {
  body { background: var(--paper); }
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto auto; grid-template-areas: "stage" "banner" "controls"; }
  .bar {
    position: fixed; z-index: 4; top: 0; left: 0; right: 0; height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
    background: linear-gradient(#18141fbf, #18141f00);
  }
  .bar .logo { width: 96px; color: var(--lav); }
  .online { color: var(--slip); }
  .online::before { background: var(--lav); }
  /* split screen: them on top, you below */
  .stage-box { display: block; padding: 0; container-type: normal; }
  .stage { --r: 0px; width: 100%; height: 100%; background: var(--ink); overflow: hidden; }
  .tile { border: 0; border-radius: 0; box-shadow: none; }
  .tile-remote { inset: 0 0 50% 0; background: #221d2a; }
  .tile-self { inset: calc(50% + 3px) 0 0 0; }
  .status, .idle { bottom: 50%; padding-top: calc(56px + env(safe-area-inset-top)); }
  .look { width: 96px; }
  .fx { bottom: 50%; }
  .icon.report { top: calc(60px + env(safe-area-inset-top)); right: 12px; }
  .controls { gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ink); }
  .icon { width: 48px; height: 48px; }
  .set { box-shadow: 3px 3px 0 var(--ink); }
  .set > .icon, .go > .icon { width: 42px; }
  .go { flex: 1; max-width: 190px; box-shadow: 3px 3px 0 var(--ink); }
  /* no room for seven: their sound sits on their video, like the camera switch on yours */
  .set > .icon.spk {
    position: fixed; z-index: 4; top: calc(60px + env(safe-area-inset-top)); right: 62px; width: 42px; height: 42px;
    border: 2px solid #f8f4ec55; border-radius: 4px; background: #18141fb3; color: var(--slip);
  }
  .app:not([data-state="connected"]) .spk { display: none; }
  .next { flex: 1; min-width: 0; min-height: 48px; padding: 0 10px; }
  .next kbd { display: none; }
  .chat-toggle { display: grid; }
  .ad-row { padding: 14px 12px 10px; border-top: 2px solid var(--ink); background: var(--paper-2); }

  /* messages become a bottom sheet */
  .side {
    position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; height: 62dvh;
    border: 0; border-top: 2px solid var(--ink); border-radius: 12px 12px 0 0;
    padding: 12px 16px calc(4px + env(safe-area-inset-bottom));
    transform: translateY(105%); visibility: hidden; transition: transform .35s var(--ease), visibility 0s .35s;
    box-shadow: 0 -10px 40px #0004;
  }
  .app.chat-open .side { transform: none; visibility: visible; transition-delay: 0s; }
  .close-chat { display: grid; }
  .ad-side { display: none !important; }
  .ticket { padding: 26px 22px 20px; }
  .perf { margin-inline: -22px; }
  .gate .sticker { width: 88px; height: 88px; font-size: 1.1rem; top: 10px; right: 10px; }
}
@media (max-width: 899px) and (max-height: 640px) {
  .gate .sticker { display: none; }
}
