/* Kwentuhan
   Palette: deep sea, mango, paper, ink, alert red.
   Type: Bricolage Grotesque for the wordmark and headings, Instrument Sans for everything else. */

:root {
  --sea: #0f2b3a;
  --sea-2: #183e52;
  --mango: #ffc83d;
  --mango-deep: #e9a900;
  --paper: #f3f7f9;
  --white: #ffffff;
  --ink: #0f2b3a;
  --ink-soft: #55707f;
  --line: #d6e1e7;
  --alert: #c8323a;

  --display: "Bricolage Grotesque", "Arial Narrow", system-ui, sans-serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--sea);
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--mango);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */

.btn {
  border: 0;
  border-radius: 12px;
  padding: 0.8em 1.1em;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--mango); color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--mango-deep); }

.btn-quiet { background: var(--white); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-danger { background: var(--white); color: var(--alert); box-shadow: inset 0 0 0 1.5px var(--alert); }
.btn-send { background: var(--sea); color: var(--white); border-radius: 10px; }
.btn-big { font-size: 1.125rem; padding: 0.95em 1.4em; width: 100%; }

/* ---------- Gate ---------- */

.gate {
  min-height: 100%;
  display: flex;
  align-items: center;
  padding: calc(2rem + var(--safe-top)) 1.5rem calc(2rem + var(--safe-bottom));
  color: var(--white);
}

.gate-inner { width: 100%; max-width: 30rem; margin: 0 auto; }

.wordmark {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3rem, 15vw, 6rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
  margin: 0 0 1rem -0.04em;
  color: var(--mango);
}

.lede { font-size: 1.2rem; margin: 0 0 1.75rem; max-width: 24rem; }

.rules {
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}
.rules li {
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  color: #d5e3ea;
}

.agree {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  font-weight: 500;
  cursor: pointer;
}
.agree input { width: 1.35rem; height: 1.35rem; margin: 0.1rem 0 0; accent-color: var(--mango); flex: none; }

.fine { font-size: 0.875rem; color: #a9c0cb; margin: 0.9rem 0 0; }

/* ---------- App shell ----------
   Phones: the two videos split the screen in half (stranger on top, you below)
   and the chat floats over the bottom, see-through. */

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #071720;
}

.bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: calc(0.6rem + var(--safe-top)) 1rem 1.25rem;
  color: var(--white);
  background: linear-gradient(rgba(7, 23, 32, 0.75), rgba(7, 23, 32, 0));
  pointer-events: none;
}
.brand { font-family: var(--display); font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em; color: var(--mango); }
.online { font-size: 0.875rem; color: #d5e3ea; }

/* ---------- Video tiles ---------- */

.stage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
}

.tile {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #071720;
}
.tile-local { background: var(--sea-2); }

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.stage.has-video #remote { opacity: 1; }
.stage.has-local:not(.cam-off) #local { opacity: 1; }
.stage.mirrored #local { transform: scaleX(-1); }

.tile-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 3rem 1.25rem 1rem;
  text-align: center;
  color: #a9c0cb;
  font-size: 1.05rem;
}
.tile-msg-local { place-items: start center; padding-top: 3.5rem; }
.stage.has-video #stageMsg { display: none; }
.stage.has-local:not(.cam-off) .tile-msg-local { display: none; }

.stage.searching #stageMsg { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.45; } }

.av {
  position: absolute;
  left: 0.6rem;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  border: 0;
  border-radius: 999px;
  padding: 0.45em 0.9em;
  font-size: 0.875rem;
  font-weight: 500;
  background: rgba(7, 23, 32, 0.6);
  color: var(--white);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.chip[aria-pressed="true"] { background: var(--alert); }
.chip:disabled { opacity: 0.5; }

/* ---------- Chat (see-through over the video on phones) ---------- */

.chat {
  --them-bg: rgba(255, 255, 255, 0.86);
  --them-fg: var(--ink);
  --them-line: transparent;
  --me-bg: rgba(15, 43, 58, 0.7);
  --sys-fg: #ffffff;
  --field-bg: rgba(7, 23, 32, 0.45);
  --field-fg: #ffffff;
  --field-line: rgba(255, 255, 255, 0.4);
  --field-hint: rgba(255, 255, 255, 0.75);
  --quiet-bg: rgba(7, 23, 32, 0.5);
  --quiet-fg: #ffffff;
  --quiet-line: rgba(255, 255, 255, 0.4);
  --danger-fg: #ffb3b6;
  --danger-line: #ff8a90;

  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(rgba(7, 23, 32, 0), rgba(7, 23, 32, 0.55) 60%);
  pointer-events: none;            /* taps pass through to the video controls */
}
.chat > * { pointer-events: auto; }

.log {
  flex: 0 1 auto;
  max-height: 22vh;
  max-height: 22dvh;
  overflow-y: auto;
  margin: 0;
  padding: 1.5rem 0.75rem 0.4rem;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(transparent, #000 1.5rem);
  mask-image: linear-gradient(transparent, #000 1.5rem);
}
.log:empty { padding: 0; }

.log li { max-width: 82%; overflow-wrap: anywhere; flex: none; }

.log .them, .log .me { padding: 0.45rem 0.8rem; border-radius: 14px; }
.log .them { align-self: flex-start; background: var(--them-bg); color: var(--them-fg); box-shadow: inset 0 0 0 1px var(--them-line); border-bottom-left-radius: 4px; }
.log .me { align-self: flex-end; background: var(--me-bg); color: var(--white); border-bottom-right-radius: 4px; }
.log .sys { align-self: center; max-width: 100%; text-align: center; font-size: 0.875rem; color: var(--sys-fg); padding: 0.2rem 0; text-shadow: 0 1px 3px rgba(7, 23, 32, 0.8); }

.typing { margin: 0; padding: 0 0.9rem 0.3rem; font-size: 0.875rem; color: var(--sys-fg); text-shadow: 0 1px 3px rgba(7, 23, 32, 0.8); }

.composer { display: flex; gap: 0.5rem; padding: 0.4rem 0.75rem; }
.composer input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--field-line);
  border-radius: 10px;
  padding: 0.7em 0.9em;
  background: var(--field-bg);
  color: var(--field-fg);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.composer input::placeholder { color: var(--field-hint); opacity: 1; }
.composer input:disabled { opacity: 0.6; }

.controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem 0.75rem;
}
.chat .btn-quiet { background: var(--quiet-bg); color: var(--quiet-fg); box-shadow: inset 0 0 0 1.5px var(--quiet-line); }
.chat .btn-danger { background: var(--quiet-bg); color: var(--danger-fg); box-shadow: inset 0 0 0 1.5px var(--danger-line); }
.chat .btn-send { background: var(--mango); color: var(--ink); }

/* ---------- Report dialog ---------- */

.dlg {
  border: 0;
  border-radius: 16px;
  padding: 1.5rem;
  width: min(92vw, 24rem);
  color: var(--ink);
}
.dlg::backdrop { background: rgba(7, 23, 32, 0.6); }
.dlg h2 { font-family: var(--display); font-weight: 800; font-size: 1.5rem; letter-spacing: -0.02em; margin: 0 0 0.25rem; }
.dlg p { margin: 0 0 1rem; color: var(--ink-soft); }
.dlg label { display: flex; gap: 0.6rem; align-items: center; padding: 0.6rem 0; border-top: 1px solid var(--line); cursor: pointer; }
.dlg input[type="radio"] { width: 1.15rem; height: 1.15rem; accent-color: var(--alert); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

/* ---------- Wide screens: videos side by side, solid chat panel on the right ---------- */

@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr 24rem;
    grid-template-rows: auto 1fr;
    column-gap: 1rem;
    padding: 0 1rem 1rem;
    background: var(--sea);
  }
  .bar { position: static; grid-column: 1 / -1; padding: 0.6rem 0; background: none; }
  .online { color: #a9c0cb; }

  .stage {
    position: relative;
    inset: auto;
    grid-template-rows: none;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    min-height: 0;
  }
  .tile { border-radius: 18px; }
  .tile-msg, .tile-msg-local { place-items: center; padding: 3rem 1.25rem; }
  .av { top: auto; bottom: 0.75rem; }

  .chat {
    --them-bg: var(--white);
    --them-line: var(--line);
    --me-bg: var(--sea);
    --sys-fg: var(--ink-soft);
    --field-bg: var(--white);
    --field-fg: var(--ink);
    --field-line: var(--line);
    --field-hint: var(--ink-soft);
    --quiet-bg: var(--white);
    --quiet-fg: var(--ink);
    --quiet-line: var(--line);
    --danger-fg: var(--alert);
    --danger-line: var(--alert);

    position: static;
    min-height: 0;
    background: var(--paper);
    border-radius: 18px;
    pointer-events: auto;
  }
  .log { flex: 1; max-height: none; padding: 1rem 1rem 0.5rem; -webkit-mask-image: none; mask-image: none; }
  .log .sys, .typing { text-shadow: none; }
  .composer input { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .chat .btn-send { background: var(--sea); color: var(--white); }
}

/* ---------- Compact phone overlay: smaller text and buttons so less of the video is covered ---------- */

@media (max-width: 899px) {
  .chat { background: linear-gradient(rgba(7, 23, 32, 0), rgba(7, 23, 32, 0.45) 70%); }

  .log { max-height: 17vh; max-height: 17dvh; padding: 1.25rem 0.6rem 0.3rem; gap: 0.25rem; }
  .log li { font-size: 0.8125rem; line-height: 1.35; }
  .log .them, .log .me { padding: 0.3rem 0.6rem; border-radius: 11px; }
  .log .sys { font-size: 0.75rem; padding: 0.1rem 0; }
  .typing { font-size: 0.75rem; padding: 0 0.7rem 0.2rem; }

  .composer { gap: 0.4rem; padding: 0.25rem 0.6rem; }
  /* The field stays at 16px text: anything smaller makes iPhones zoom in when you tap it. */
  .composer input { padding: 0.4em 0.7em; border-radius: 9px; border-width: 1px; }

  .controls { gap: 0.4rem; padding: 0.15rem 0.6rem 0.5rem; }
  .chat .btn { font-size: 0.8125rem; padding: 0.55em 0.9em; border-radius: 9px; }

  .av { gap: 0.3rem; left: 0.5rem; top: 0.5rem; }
  .chip { font-size: 0.75rem; padding: 0.35em 0.7em; }

  .brand { font-size: 1.05rem; }
  .online { font-size: 0.75rem; }
  .tile-msg { font-size: 0.9375rem; }
}

/* ---------- Icon buttons: mic, camera, flip, send ---------- */

.chip {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.chip svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chip .slash { display: none; }
.chip[aria-pressed="true"] .slash { display: inline; }

.composer { align-items: center; }
.composer input { border-radius: 999px; padding: 0.4em 0.95em; }

.chat .btn.btn-send {
  flex: none;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.btn-send svg { width: 1.2rem; height: 1.2rem; fill: currentColor; transform: translateX(1px); }

/* Smaller Find / Stop / Report on phones */
@media (max-width: 899px) {
  .controls { gap: 0.35rem; padding: 0.1rem 0.6rem 0.45rem; }
  .controls .btn { font-size: 0.75rem; padding: 0.42em 0.8em; border-radius: 999px; }
  .av { gap: 0.35rem; }
}

/* ---------- Chat toggle: on phones the chat box is hidden until you tap the chat icon ---------- */

.controls { display: flex; align-items: center; }
.controls #main { flex: 1; }

.chat-toggle {
  position: relative;
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--quiet-bg);
  color: #ffffff;
  box-shadow: inset 0 0 0 1.5px var(--quiet-line);
  cursor: pointer;
}
.chat-toggle svg { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.chat-toggle[aria-expanded="true"] { background: var(--mango); color: var(--ink); box-shadow: none; }

.badge {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--alert);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1.1rem;
  text-align: center;
}

.toast {
  align-self: center;
  max-width: calc(100% - 1.2rem);
  margin: 0 0.6rem 0.35rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(7, 23, 32, 0.65);
  color: #ffffff;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 899px) {
  .app:not(.chat-open) .log,
  .app:not(.chat-open) .typing,
  .app:not(.chat-open) .composer { display: none; }
  .app:not(.chat-open) .chat { background: linear-gradient(rgba(7, 23, 32, 0), rgba(7, 23, 32, 0.3)); padding-top: 1rem; }
}

@media (min-width: 900px) {
  .chat-toggle, .toast { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
