/* Duet — warm, mobile-first styling. No external fonts or libraries. */

:root {
  --bg: #faf6f2;
  --card: #ffffff;
  --text: #3b2f2f;
  --muted: #8a7a76;
  --accent: #c25460;
  --accent-dark: #a03e50;
  --mine: #c25460;
  --mine-text: #fff;
  --theirs: #efe6e0;
  --theirs-text: #3b2f2f;
  --border: #e8ddd6;
  --danger: #c0392b;
  --ok: #3e9c5f;
  --shadow: 0 4px 18px rgba(80, 40, 40, .10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1719;
    --card: #2a2225;
    --text: #f0e7e4;
    --muted: #a8938f;
    --accent: #d76a76;
    --accent-dark: #b6505f;
    --mine: #b6505f;
    --mine-text: #fff;
    --theirs: #3a2f33;
    --theirs-text: #f0e7e4;
    --border: #4a3c40;
    --shadow: 0 4px 18px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.screen { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ── Join screen ─────────────────────────── */
#join-screen { align-items: center; justify-content: center; padding: 16px; }

.join-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.logo { color: var(--accent); }
.join-card h1 { margin: 4px 0 2px; font-size: 2rem; letter-spacing: .5px; }
.tagline { margin: 0 0 20px; color: var(--muted); }

#join-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
#join-form label { font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
#join-form input[type="text"], #join-form input[type="password"] {
  font-size: 1rem;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
#join-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.check { flex-direction: row !important; align-items: center; gap: 8px !important; cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }

.btn {
  font-size: 1rem;
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.error { color: var(--danger); font-size: .9rem; margin: 0; }
.hint { color: var(--muted); font-size: .78rem; line-height: 1.45; margin: 4px 0 0; }

/* ── Top bar ─────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.status { display: flex; align-items: center; gap: 7px; font-size: .85rem; flex: 1; min-width: 0; }
#status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; flex-shrink: 0; }
.dot[data-state="offline"] { background: #b0a5a1; }
.dot[data-state="connected"] { background: #d9a441; }
.dot[data-state="peer-online"] { background: var(--ok); }

.safety {
  font-size: .72rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

.icon-btn {
  background: none; border: none; color: var(--muted);
  padding: 6px; cursor: pointer; border-radius: 8px; display: flex;
}
.icon-btn:hover { color: var(--accent); }

/* ── Tabs ────────────────────────────────── */
#tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 10px; background: none; border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted); font-size: .95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  font-size: .7rem; padding: 1px 7px; min-width: 18px;
}

/* ── Panes ───────────────────────────────── */
.pane { display: none; flex: 1; min-height: 0; }
.pane.active { display: flex; flex-direction: column; }

/* ── Chat ────────────────────────────────── */
#messages {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: .95rem;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 5px; }
.bubble.theirs { align-self: flex-start; background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 5px; }
.bubble.system { align-self: center; background: none; color: var(--muted); font-size: .78rem; padding: 3px; }
.bubble.broken { align-self: flex-start; background: var(--theirs); color: var(--danger); font-style: italic; font-size: .85rem; }
.bubble .meta {
  display: block; font-size: .66rem; opacity: .75; margin-top: 3px; text-align: right;
}
.bubble .sender { display: block; font-size: .7rem; opacity: .8; margin-bottom: 2px; font-weight: 600; }

#typing-indicator {
  padding: 2px 18px 6px; color: var(--muted); font-size: .8rem;
  display: flex; align-items: center; gap: 3px;
}
#typing-indicator span {
  width: 5px; height: 5px; background: var(--muted); border-radius: 50%;
  animation: blink 1.2s infinite;
}
#typing-indicator span:nth-child(2) { animation-delay: .2s; }
#typing-indicator span:nth-child(3) { animation-delay: .4s; margin-right: 4px; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

#chat-form {
  display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--border);
}
#chat-input {
  flex: 1; font-size: 1rem; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 22px;
  background: var(--bg); color: var(--text);
}
#chat-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.icon-btn.send { color: var(--accent); }

/* ── Call pane ───────────────────────────── */
#call-idle {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 20px;
  text-align: center; color: var(--muted);
}
.call-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

#call-active { flex: 1; position: relative; background: #14100f; display: flex; }
#remote-video { width: 100%; height: 100%; object-fit: cover; }
#remote-audio-only {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; color: #d8c8c4;
}
#local-video {
  position: absolute; top: 14px; right: 14px;
  width: 110px; max-height: 160px;
  border-radius: 12px; border: 2px solid rgba(255,255,255,.35);
  object-fit: cover;
  transform: scaleX(-1); /* mirror the self-view, like every camera app */
  background: #222;
}
#call-info {
  position: absolute; top: 14px; left: 14px;
  background: rgba(0,0,0,.45); color: #fff;
  border-radius: 10px; padding: 5px 11px;
  font-size: .8rem; display: flex; gap: 10px;
}
#btn-tap-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--accent); color: #fff; border: none;
}
#call-controls {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  display: flex; justify-content: center; gap: 16px;
}
.ctl {
  width: 54px; height: 54px; border-radius: 50%;
  border: none; cursor: pointer;
  background: rgba(255,255,255,.18); color: #fff;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ctl.danger { background: var(--danger); }
.ctl[data-on="true"] .off { display: none; }
.ctl[data-on="false"] .on { display: none; }
.ctl[data-on="false"] { background: rgba(255,255,255,.55); color: #222; }

/* ── Overlays ────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 12, 14, .72);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.ring-card, .settings-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 30px 26px; text-align: center; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 16px; align-items: center;
}
.settings-card { align-items: stretch; text-align: left; }
.settings-card h2 { margin: 0; }
.ring-pulse {
  color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.ring-buttons { display: flex; gap: 14px; }

/* ── Toast ───────────────────────────────── */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 12px;
  font-size: .88rem; z-index: 99; box-shadow: var(--shadow);
  max-width: 90%; text-align: center;
}
#toast button {
  background: none; border: none; color: inherit;
  text-decoration: underline; cursor: pointer; font-size: inherit; padding: 0 0 0 8px;
}
