/* ==========================================================================
   Tokens
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #090d1b;
  --surface: #0e1425b8;
  --surface-raised: #172038;
  --surface-hover: #202c4b;
  --surface-input: #0a1020;
  --pill-bg: #12182ad9;
  --caption-bg: #07101bc7;

  --text: #f3f5ff;
  --text-strong: #ffffff;
  --text-muted: #b4bfdc;
  --text-subtle: #9ca8c9;

  --border: #ffffff1c;
  --border-strong: #ffffff2e;
  --border-faint: #ffffff16;

  --accent: #8056ff;
  --accent-alt: #cf3ef2;
  --accent-focus: #a080ff;
  --bubble-in: #202a45;
  --bubble-out: #7047d1;

  --success: #75f0b4;
  --success-border: #46db9b66;
  --danger: #ffabb1;
  --danger-border: #ff758066;
  --warning: #f8dfaa;
  --warning-strong: #ffe7b1;
  --warning-bg: #402c0d44;
  --warning-border: #ffc65d3b;

  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --gap: 16px;
  --shell-width: 1120px;

  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ==========================================================================
   Base
   ========================================================================== */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 80% 0%, #3d1b703d, transparent 36rem),
    radial-gradient(circle at 0% 100%, #123a703d, transparent 35rem), var(--bg);
}

h1,
h2 {
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.app-shell {
  width: min(var(--shell-width), calc(100% - 40px));
  margin: 0 auto;
  padding: 82px 0 36px;
}

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.brand {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #ffffff33;
  border-radius: 14px;
  color: var(--text-strong);
  font-size: 28px;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 2px;
  color: #aab4d5;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.app-header h1 {
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  letter-spacing: -0.05em;
}

.connection-status {
  padding: 9px 13px;
  border: 1px solid #ffffff1f;
  border-radius: var(--radius-pill);
  background: var(--pill-bg);
  color: #cdd5ef;
  font-size: 0.875rem;
  white-space: nowrap;
}

.connection-status[data-tone='success'] {
  border-color: var(--success-border);
  color: var(--success);
}

.connection-status[data-tone='error'] {
  border-color: var(--danger-border);
  color: var(--danger);
}

/* ==========================================================================
   Video
   ========================================================================== */

.video-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(230px, 0.7fr);
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.video-card {
  position: relative;
  min-height: 260px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #1b2441, #0d1223 60%), #111827;
  box-shadow: 0 25px 55px #00000036;
}

.video-card--remote {
  aspect-ratio: 16 / 9;
}

.video-card--local {
  aspect-ratio: 4 / 3;
}

.video-card video {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-card--local video {
  transform: scaleX(-1);
}

.video-card figcaption {
  position: absolute;
  z-index: 1;
  bottom: 13px;
  left: 13px;
  padding: 5px 9px;
  border: 1px solid #ffffff25;
  border-radius: var(--radius-pill);
  background: var(--caption-bg);
  font-size: 0.8rem;
  font-weight: 650;
}

.empty-video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(250px, 82%);
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.45;
  text-align: center;
  transform: translate(-50%, -50%);
}

.video-card.has-video .empty-video {
  display: none;
}

/* ==========================================================================
   Presence
   ========================================================================== */

.lobby-presence {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.lobby-presence::before {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-subtle);
  content: '';
}

.lobby-presence[data-state='ready']::before {
  background: var(--success);
  box-shadow: 0 0 0 4px #75f0b42b;
}

.lobby-presence[data-state='busy']::before {
  background: var(--warning);
}

.age-gate {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 14px;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.4;
}

.age-gate input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--accent);
  flex: none;
}

/* ==========================================================================
   Controls
   ========================================================================== */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 22px;
}

.button {
  min-height: 43px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.button--primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-alt));
  box-shadow: 0 7px 20px #7f40c044;
  color: var(--text-strong);
}

.button--primary:hover:not(:disabled) {
  filter: brightness(1.12);
}

.button--secondary {
  border-color: var(--border-strong);
  background: var(--surface-raised);
  color: #eff3ff;
}

.button--secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

/* ==========================================================================
   Chat
   ========================================================================== */

.chat-panel {
  overflow: hidden;
  border: 1px solid #ffffff1a;
  border-radius: var(--radius-md);
  background: var(--surface);
}

.chat-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 15px 17px;
  border-bottom: 1px solid var(--border-faint);
}

.chat-heading h2 {
  font-size: 1rem;
}

.chat-heading span {
  color: var(--text-subtle);
  font-size: 0.8rem;
}

.messages {
  display: flex;
  min-height: 130px;
  max-height: 220px;
  margin: 0;
  padding: 14px 17px;
  overflow-y: auto;
  flex-direction: column;
  gap: 7px;
  list-style: none;
}

.message {
  width: fit-content;
  max-width: min(78%, 550px);
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  overflow-wrap: anywhere;
}

.message--incoming {
  background: var(--bubble-in);
}

.message--outgoing {
  align-self: flex-end;
  background: var(--bubble-out);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
  padding: 12px;
  border-top: 1px solid var(--border-faint);
}

.chat-form input {
  min-width: 0;
  padding: 0 13px;
  border: 1px solid #ffffff2c;
  border-radius: 11px;
  outline: none;
  background: var(--surface-input);
  color: var(--text-strong);
}

.chat-form input:focus {
  border-color: var(--accent-focus);
  box-shadow: 0 0 0 3px #8e6eff2b;
}

/* ==========================================================================
   Safety note
   ========================================================================== */

.safety-note {
  margin-top: 17px;
  padding: 13px 15px;
  border: 1px solid var(--warning-border);
  border-radius: 13px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.87rem;
  line-height: 1.5;
}

.safety-note strong {
  color: var(--warning-strong);
}

/* ==========================================================================
   Phone (≤ 640px)
   ========================================================================== */

@media (max-width: 640px) {
  /* Layout */
  .app-shell {
    width: min(100% - 24px, var(--shell-width));
    padding: 64px 0 calc(20px + env(safe-area-inset-bottom));
  }

  /* Header */
  .app-header {
    grid-template-columns: auto 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }

  .eyebrow {
    display: none;
  }

  .connection-status {
    grid-column: 1 / -1;
    justify-self: start;
    max-width: 100%;
    white-space: normal;
  }

  /* Video: remote fills the card, local floats in the corner */
  .video-grid {
    position: relative;
    display: block;
    margin-bottom: 12px;
  }

  .video-card--remote {
    min-height: 0;
    height: min(62svh, 133vw);
    aspect-ratio: auto;
    border-radius: var(--radius-md);
  }

  .video-card--local {
    position: absolute;
    z-index: 2;
    top: 10px;
    right: 10px;
    width: 30%;
    min-width: 96px;
    max-width: 150px;
    min-height: 0;
    aspect-ratio: 3 / 4;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 24px #00000066;
  }

  .video-card--local figcaption {
    bottom: 6px;
    left: 6px;
    padding: 3px 7px;
    font-size: 0.7rem;
  }

  .empty-video {
    width: min(220px, 60%);
    font-size: 0.95rem;
  }

  /* Controls: primary action on its own row, the rest share one */
  .controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .controls .button {
    min-height: 48px;
    padding: 0 10px;
  }

  .controls .button--primary,
  #invite-button {
    grid-column: 1 / -1;
  }

  /* Chat: 16px input text keeps iOS from zooming on focus */
  .messages {
    min-height: 90px;
    max-height: 28svh;
  }

  .chat-form input,
  .chat-form .button {
    min-height: 46px;
    font-size: 16px;
  }

  /* Safety note */
  .safety-note {
    font-size: 0.8rem;
  }
}
