:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --card: #151a24;
  --line: #262d3d;
  --text: #eef0f5;
  --muted: #8d95a9;
  --accent: #3dd9b0;
  --danger: #ff5d6c;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] {
  display: none !important;
}

/* ---------- Join screen ---------- */

#join {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.sub {
  margin: 0 0 8px;
  color: var(--muted);
}

label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.field {
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding-right: 6px;
}

.field:focus-within {
  border-color: var(--accent);
}

input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  padding: 15px 14px;
}

button {
  font: inherit;
  cursor: pointer;
}

button.link {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 10px;
}

button.primary,
button.ghost {
  border-radius: 14px;
  padding: 15px;
  font-weight: 600;
}

button.primary {
  background: var(--accent);
  color: #06241c;
  border: 0;
}

button.primary:disabled {
  opacity: 0.6;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

#err {
  min-height: 1.4em;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

#err.ok {
  color: var(--accent);
}

.fine {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Call screen ---------- */

#call {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#local {
  position: absolute;
  right: 14px;
  top: calc(14px + env(safe-area-inset-top));
  width: 28vw;
  max-width: 150px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #111;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s;
}

#local.mirror {
  transform: scaleX(-1);
}

#local.cam-off {
  opacity: 0.2;
}

#status,
.pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 200px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 24, 33, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 14px;
  text-align: center;
  transition: opacity 0.25s;
}

#status {
  top: calc(18px + env(safe-area-inset-top));
}

#status.bad {
  color: var(--danger);
}

/* Until the call is live, the status sits in the middle of the screen. */
#call:not(.live) #status {
  top: 50%;
  max-width: calc(100% - 48px);
  transform: translate(-50%, -50%);
  font-size: 18px;
  padding: 14px 22px;
}

/* Once live, tuck the status to the left so it never sits over the self-view. */
#call.live #status {
  left: 14px;
  transform: none;
  max-width: calc(100% - 190px);
  text-align: left;
}

.pill {
  top: calc(64px + env(safe-area-inset-top));
  border: 0;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 28px 16px calc(22px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  transition: opacity 0.25s;
}

#call.idle .bar,
#call.idle #status.hideable {
  opacity: 0;
  pointer-events: none;
}

.round {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.round.off {
  background: #fff;
  color: #111;
}

.round.end {
  background: var(--danger);
}

.round svg {
  width: 25px;
  height: 25px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.slash {
  display: none;
}

.round.off .slash {
  display: block;
}

/* ---------- Chat ---------- */

.badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #06241c;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

#chat {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: var(--vt, 0px);
  bottom: var(--kb, 0px);
  display: flex;
  flex-direction: column;
  background: #0e1118;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 8px 10px 18px;
  border-bottom: 1px solid var(--line);
}

.chat-head .note {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.chat-x {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
}

.chat-x svg,
.send svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
}

#msgs > :first-child {
  margin-top: auto;
}

.msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.me {
  align-self: flex-end;
  background: var(--accent);
  color: #06241c;
  border-bottom-right-radius: 4px;
}

.msg.them {
  align-self: flex-start;
  background: #232a3a;
  border-bottom-left-radius: 4px;
}

.st {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  opacity: 0.7;
  text-align: end;
}

.msg.fail .st {
  color: #7a0f1a;
  font-weight: 600;
  opacity: 1;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.composer input {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 11px 16px;
}

.composer input:focus {
  border-color: var(--accent);
}

.send {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #06241c;
  display: grid;
  place-items: center;
}

/* While chatting on a phone, chat fills the screen and the video shrinks to a small
   floating tile (tap it to go back to the call, or drag it out of the way). */
#call.chatting .bar {
  display: none;
}

@media (max-width: 759px) {
  #call.chatting {
    --tw: 100px;
  }

  #call.chatting.kbd {
    --tw: 68px;
  }

  #call.chatting #remote {
    inset: auto;
    top: calc(var(--vt, 0px) + env(safe-area-inset-top) + 66px);
    right: 10px;
    width: var(--tw);
    height: calc(var(--tw) * 4 / 3);
    z-index: 6;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
    touch-action: none;
    cursor: pointer;
  }

  #call.chatting #local {
    display: none;
  }
}

@media (max-width: 400px) {
  .bar {
    gap: 12px;
  }

  .round {
    width: 54px;
    height: 54px;
  }
}

/* Wide screens: chat sits beside the video instead of over it. */
@media (min-width: 760px) {
  #chat {
    left: auto;
    width: 360px;
    top: 0;
    bottom: 0;
    border-left: 1px solid var(--line);
  }

  #call.chatting .bar {
    display: flex;
    right: 360px;
  }

  #call.chatting #remote {
    right: 360px;
    width: calc(100% - 360px);
  }

  #call.chatting #local {
    right: 374px;
  }
}
