:root {
  --bg: #eae6df;
  --panel: #ffffff;
  --header: #075e54;
  --header-text: #ffffff;
  --mine: #d9fdd3;
  --theirs: #ffffff;
  --text: #111b21;
  --muted: #667781;
  --line: #d7d9db;
  --accent: #00a884;
  --danger: #e5484d;
  --shadow: 0 1px 1px rgba(11, 20, 26, .13);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --panel: #111b21;
    --header: #202c33;
    --header-text: #e9edef;
    --mine: #005c4b;
    --theirs: #202c33;
    --text: #e9edef;
    --muted: #8696a0;
    --line: #2a3942;
    --shadow: 0 1px 1px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
/* A class with an explicit display must not defeat the hidden attribute. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- shell */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 820px; margin: 0 auto; background: var(--panel); }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--header); color: var(--header-text); flex: none;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 16px;
}
.who { flex: 1; min-width: 0; }
.who strong { display: block; font-size: 16px; font-weight: 600; }
.who span { font-size: 12.5px; opacity: .75; }
.topbar button {
  background: transparent; border: 0; color: inherit; cursor: pointer;
  font-size: 20px; padding: 8px; border-radius: 50%; line-height: 1;
}
.topbar button:hover { background: rgba(255, 255, 255, .12); }
.topbar button:disabled { opacity: .35; cursor: default; background: none; }

/* --------------------------------------------------------------- thread */
#thread { flex: 1; overflow-y: auto; padding: 16px 14px 8px; background: var(--bg); }
.day { text-align: center; margin: 14px 0; }
.day span {
  background: var(--panel); color: var(--muted); font-size: 12px;
  padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow);
}
.bubble {
  max-width: min(78%, 520px); margin: 3px 0; padding: 7px 10px 5px;
  border-radius: 8px; box-shadow: var(--shadow); position: relative;
  word-wrap: break-word; white-space: pre-wrap;
}
.bubble.mine { margin-left: auto; background: var(--mine); border-top-right-radius: 2px; }
.bubble.theirs { margin-right: auto; background: var(--theirs); border-top-left-radius: 2px; }
.bubble time { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 0 8px; }
.empty { text-align: center; color: var(--muted); margin-top: 25vh; padding: 0 24px; }

/* ------------------------------------------------------------ composer */
.composer { display: flex; gap: 8px; padding: 10px; background: var(--header); flex: none; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 20px; padding: 11px 15px;
  font: inherit; background: var(--panel); color: var(--text);
  max-height: 120px; min-height: 42px; outline: none;
}
.composer button {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 18px; cursor: pointer;
}
.composer button:disabled { opacity: .5; cursor: default; }

/* ---------------------------------------------------------------- login */
.center { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.card {
  background: var(--panel); border-radius: 16px; padding: 32px 28px;
  width: min(360px, 100%); box-shadow: 0 8px 30px rgba(0, 0, 0, .18); text-align: center;
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.card input {
  width: 100%; padding: 12px 14px; font: inherit; text-align: center; letter-spacing: 2px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
}
.card button {
  width: 100%; margin-top: 12px; padding: 12px; font: inherit; font-weight: 600;
  border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
}
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* --------------------------------------------------------------- banner */
#banner {
  display: none; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--accent); color: #fff; flex: none;
}
#banner.show { display: flex; }
#banner .grow { flex: 1; font-weight: 600; }
#banner button { border: 0; border-radius: 20px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-yes { background: #fff; color: var(--accent); }
.btn-no { background: rgba(0, 0, 0, .25); color: #fff; }

/* ----------------------------------------------------------------- call */
#callscreen {
  position: fixed; inset: 0; z-index: 50; display: none;
  flex-direction: column; background: #0b141a; color: #fff;
}
#callscreen.show { display: flex; }
.stage { flex: 1; position: relative; display: grid; place-items: center; overflow: hidden; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #000; }
#localVideo {
  position: absolute; right: 14px; bottom: 14px; width: 26vw; max-width: 160px;
  border-radius: 10px; object-fit: cover; background: #000; box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
#remoteVideo[hidden], #localVideo[hidden] { display: none; }
.voice-face { text-align: center; }
.voice-face .avatar { width: 96px; height: 96px; font-size: 34px; margin: 0 auto 18px; }
.voice-face h2 { margin: 0 0 6px; font-size: 22px; font-weight: 500; }
.voice-face p { margin: 0; color: #8696a0; }
.controls { display: flex; justify-content: center; gap: 18px; padding: 24px; flex: none; }
.controls button {
  width: 58px; height: 58px; border-radius: 50%; border: 0; font-size: 22px;
  background: rgba(255, 255, 255, .16); color: #fff; cursor: pointer;
}
.controls button.off { background: #fff; color: #0b141a; }
.controls button.hangup { background: var(--danger); }
.hint { text-align: center; color: #ffd77a; font-size: 13px; padding: 0 20px 12px; }

/* Voice-only calls: keep the video element alive (it carries the audio)
   but out of sight, and show the avatar instead. */
.stage.audio-only #remoteVideo {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
.stage:not(.audio-only) .voice-face { display: none; }

.joinbtn {
  margin-top: 22px; padding: 14px 30px; font: inherit; font-size: 16px; font-weight: 600;
  border: 0; border-radius: 28px; background: var(--accent); color: #fff; cursor: pointer;
}
.tap-to-hear {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, .6); color: #fff; font-weight: 600; cursor: pointer; z-index: 5;
}
