/* calla — a warm private line.
   Palette: dusk indigo + a single amber "the line is warm" accent.
   Green/red are reserved strictly for answer/decline so call controls
   stay instantly readable. */

:root {
  --bg: #15131c;
  --bg-2: #1c1925;
  --surface: #221e2d;
  --surface-2: #2a2536;
  --line: #322c40;
  --text: #ece7f4;
  --muted: #9a91ac;
  --amber: #f2b441;
  --amber-ink: #2a1d05;
  --amber-soft: rgba(242, 180, 65, 0.14);
  --green: #46d889;
  --green-deep: #1f7d4d;
  --red: #f2576b;
  --red-deep: #a32136;

  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(120% 90% at 50% -10%, #221a2e 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* ---------- wordmark ---------- */

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 0.5ch;
}
.wordmark .dot {
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 var(--amber);
  animation: beacon 2.6s ease-out infinite;
}
@keyframes beacon {
  0% { box-shadow: 0 0 0 0 rgba(242, 180, 65, 0.5); }
  70%,
  100% { box-shadow: 0 0 0 10px rgba(242, 180, 65, 0); }
}

/* ---------- login ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
}

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* honeypot — kept far off-screen and out of the tab order */
.hp {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
#turnstile {
  margin: 4px 0 2px;
  min-height: 0;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 34px 30px 28px;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.7);
}
.login-card .wordmark {
  font-size: 30px;
  margin-bottom: 6px;
}
.login-card .tagline {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 26px;
}

label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 7px;
}
input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 15px;
  padding: 12px 14px;
  margin-bottom: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.btn-primary {
  width: 100%;
  background: var(--amber);
  color: var(--amber-ink);
  font-weight: 600;
  font-size: 15px;
  padding: 13px;
  border-radius: var(--r-sm);
  transition: transform 0.08s, filter 0.15s;
}
.btn-primary:hover {
  filter: brightness(1.06);
}
.btn-primary:active {
  transform: translateY(1px);
}

.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin: -6px 0 10px;
}

/* ---------- app shell ---------- */

#app-screen {
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* keep clear of the status bar / camera cutout on edge-to-edge Android */
  padding: calc(16px + env(safe-area-inset-top)) calc(22px + env(safe-area-inset-right)) 16px
    calc(22px + env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.topbar .wordmark {
  font-size: 21px;
}
.me {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
}
.me b {
  color: var(--text);
  font-weight: 600;
}
.linkbtn {
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
}
.linkbtn:hover {
  color: var(--text);
  background: var(--surface);
}

/* Quality / network toggles in the top bar */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.toggle:hover {
  color: var(--text);
}
.toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s;
}
.toggle input::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.toggle input:checked {
  background: var(--amber-soft);
  border-color: var(--amber);
}
.toggle input:checked::after {
  transform: translateX(13px);
  background: var(--amber);
}
.toggle:has(input:checked) {
  color: var(--text);
  border-color: var(--amber);
}
@media (max-width: 640px) {
  .toggle span {
    display: none;
  }
}

.main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

/* ---------- contacts ---------- */

.contacts {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
}
.contacts h2 {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 8px 10px 14px;
  font-weight: 600;
}

.contact {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  transition: background 0.12s;
}
.contact:hover {
  background: var(--surface);
}

.avatar {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: #fff;
}
.avatar .presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--muted);
  border: 2.5px solid var(--bg);
}
.avatar.online .presence {
  background: var(--green);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe {
  0%,
  100% { box-shadow: 0 0 0 0 rgba(70, 216, 137, 0.5); }
  50% { box-shadow: 0 0 0 4px rgba(70, 216, 137, 0); }
}

.contact .info {
  flex: 1 1 auto;
  min-width: 0;
}
.contact .name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact .status {
  font-size: 12.5px;
  color: var(--muted);
}
.contact .status.on {
  color: var(--green);
}

.call-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--amber-soft);
  color: var(--amber);
  display: grid;
  place-items: center;
  transition: background 0.12s, transform 0.08s;
}
.call-btn:hover {
  background: rgba(242, 180, 65, 0.24);
}
.call-btn:active {
  transform: scale(0.94);
}
.call-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.call-btn svg {
  width: 19px;
  height: 19px;
}

/* ---------- stage (idle + in-call) ---------- */

.stage {
  position: relative;
  min-width: 0;
  background: #0f0d15;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.stage-idle {
  text-align: center;
  color: var(--muted);
  padding: 30px;
}
.stage-idle .glyph {
  font-family: var(--font-display);
  font-size: 46px;
  color: var(--text);
  margin-bottom: 10px;
}
.stage-idle p {
  margin: 4px 0;
  font-size: 14px;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* show the whole incoming frame, never crop/zoom the caller */
  background: #0f0d15;
}

#local-video {
  position: absolute;
  right: 18px;
  bottom: 96px;
  width: 168px;
  max-width: 36vw;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: #000;
  box-shadow: 0 14px 40px -14px rgba(0, 0, 0, 0.8);
  transform: scaleX(-1); /* mirror self-view */
}

/* ---------- chat ---------- */

.chat {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  z-index: 5;
}
.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.chat-back {
  display: none;
}
.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex: 0 0 auto;
}
.chat-name {
  font-weight: 600;
  font-size: 15px;
}
.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.them {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 5px;
}
.bubble.me {
  align-self: flex-end;
  background: var(--amber-soft);
  border: 1px solid var(--amber);
  color: var(--text);
  border-bottom-right-radius: 5px;
}
.bubble .meta {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}
.bubble.undelivered .meta::after {
  content: " · not delivered";
  color: var(--red);
}
.chat-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.chat-input {
  display: flex;
  gap: 9px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.chat-input input {
  flex: 1 1 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-ui);
}
.chat-input input:focus {
  outline: none;
  border-color: var(--amber);
}
.btn-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--amber-ink);
  display: grid;
  place-items: center;
}
.btn-send svg {
  width: 20px;
  height: 20px;
}
.chat-note {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 0 0 8px;
  margin: 0;
}

/* message button + unread badge on contact rows */
.msg-btn {
  position: relative;
  background: none;
  color: var(--muted);
  padding: 8px;
  border-radius: var(--r-sm);
}
.msg-btn:hover {
  color: var(--text);
  background: var(--surface);
}
.msg-btn svg {
  width: 20px;
  height: 20px;
}
.unread {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--amber);
  color: var(--amber-ink);
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
}

.call-meta {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: calc(18px + env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 13, 21, 0.55);
  backdrop-filter: blur(8px);
  padding: 9px 15px 9px 11px;
  border-radius: 100px;
  border: 1px solid var(--line);
}
.call-meta .name {
  font-weight: 600;
  font-size: 14px;
}
.call-meta .timer {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--amber);
}

.controls {
  position: absolute;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: rgba(15, 13, 21, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 100px;
}
.ctrl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  transition: background 0.12s, transform 0.08s;
}
.ctrl:hover {
  background: #36304a;
}
.ctrl:active {
  transform: scale(0.94);
}
.ctrl svg {
  width: 22px;
  height: 22px;
}
.ctrl.off {
  background: #4a3344;
  color: var(--red);
}
.ctrl.hangup {
  background: var(--red);
  color: #fff;
}
.ctrl.hangup:hover {
  background: #ff6a7d;
}

/* ---------- call overlay (incoming / outgoing) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: radial-gradient(80% 60% at 50% 35%, #241a30 0%, #100e16 70%);
}
.overlay .label {
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.overlay .caller-name {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  margin-bottom: 30px;
}

.ring-avatar {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 46px;
  color: #fff;
  margin-bottom: 34px;
}
/* the signature: a signal pinging outward */
.ring-avatar::before,
.ring-avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--amber);
  animation: sonar 2s ease-out infinite;
}
.ring-avatar::after {
  animation-delay: 1s;
}
@keyframes sonar {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.9); opacity: 0; }
}

.overlay-actions {
  display: flex;
  gap: 50px;
  margin-top: 6px;
}
.big-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  background: none;
}
.big-action .ring {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  transition: transform 0.1s, filter 0.15s;
}
.big-action:hover .ring {
  filter: brightness(1.1);
}
.big-action:active .ring {
  transform: scale(0.93);
}
.big-action .ring svg {
  width: 28px;
  height: 28px;
}
.ring.accept {
  background: var(--green-deep);
}
.ring.decline {
  background: var(--red-deep);
}
.ring.decline.solo {
  background: var(--red-deep);
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 100px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .main {
    grid-template-columns: 1fr;
  }
  .stage {
    display: none;
  }
  body.in-call .contacts,
  body.chatting .contacts {
    display: none;
  }
  body.in-call .stage,
  body.chatting .stage {
    display: grid;
  }
  .chat-back {
    display: inline-block;
  }
  #local-video {
    bottom: 100px;
    width: 116px;
  }
}

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