:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efe9e0;
  --text: #1f2a2e;
  --muted: #5d6b70;
  --line: #e2dad0;
  --brand: #2f6f6a;
  --brand-ink: #ffffff;
  --sos: #d9573b;
  --sos-glow: rgba(217, 87, 59, 0.28);
  --me: #2f6f6a;
  --me-ink: #ffffff;
  --them: #ece5da;
  --warn-bg: #fff4e5;
  --warn-line: #f0c48a;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(31, 42, 46, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a1c;
    --surface: #1a2427;
    --surface-2: #223034;
    --text: #e8eeee;
    --muted: #9aaaae;
    --line: #2c3a3e;
    --brand: #5fb3aa;
    --brand-ink: #0d1517;
    --sos: #ef7558;
    --sos-glow: rgba(239, 117, 88, 0.25);
    --me: #3f8c84;
    --me-ink: #ffffff;
    --them: #263438;
    --warn-bg: #2d2516;
    --warn-line: #6b5426;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---------- Layout ---------- */
.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  gap: 12px;
}
.logo { font-weight: 700; letter-spacing: 0.02em; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 20%, transparent); }

/* ---------- Crisis strip ---------- */
.crisis {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}
.crisis a { font-weight: 600; text-decoration: none; }

/* ---------- Home ---------- */
.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
  padding: 12px 0 24px;
}
.home h1 { font-size: 1.6rem; line-height: 1.25; margin: 0; max-width: 22ch; }
.home p { margin: 0; max-width: 36ch; }

.sos {
  position: relative;
  width: min(68vw, 260px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--sos) 80%, #fff), var(--sos));
  color: #fff;
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: 0 14px 40px var(--sos-glow), 0 0 0 12px var(--sos-glow);
  animation: pulse 2.6s ease-in-out infinite;
  touch-action: manipulation;
}
.sos small { display: block; font-weight: 500; font-size: 0.9rem; opacity: 0.92; margin-top: 6px; }
.sos:active { transform: scale(0.97); }
.sos:focus-visible { outline: 3px solid var(--text); outline-offset: 6px; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 14px 40px var(--sos-glow), 0 0 0 10px var(--sos-glow); }
  50% { box-shadow: 0 14px 40px var(--sos-glow), 0 0 0 24px transparent; }
}
@media (prefers-reduced-motion: reduce) { .sos, .breath-circle { animation: none !important; } }

.presence {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.presence .dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa; }
.presence.on .dot { background: #3bb273; box-shadow: 0 0 0 3px rgba(59, 178, 115, 0.2); }

.promises { display: grid; gap: 8px; padding: 0; margin: 0; list-style: none; font-size: 0.92rem; color: var(--muted); }

.stories-link {
  display: flex; align-items: center; gap: 12px; text-align: left; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; width: 100%; max-width: 340px; box-shadow: var(--shadow);
}
.stories-link-ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #f5c451, #e8913a 50%, #d9573b);
}

/* ---------- Session ---------- */
.session { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.waiting { display: grid; gap: 14px; text-align: center; }
.waiting h2 { margin: 0; font-size: 1.15rem; }
.breath {
  display: grid;
  place-items: center;
  height: 150px;
}
.breath-circle {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--brand) 25%, transparent);
  border: 2px solid var(--brand);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand);
  transition: transform 4s ease-in-out;
}
.breath-circle.big { transform: scale(1.9); }

.slider-row { display: grid; gap: 6px; text-align: left; }
.slider-row label { font-weight: 600; font-size: 0.92rem; display: flex; justify-content: space-between; }
input[type="range"] { width: 100%; accent-color: var(--sos); }

.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
  font-size: 0.93rem;
}
.warn strong { display: block; margin-bottom: 4px; }
.warn ul { margin: 6px 0 0; padding-left: 18px; }

.sponsor-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.sponsor-head .who { flex: 1; min-width: 0; }
.sponsor-head .who b { display: block; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}
.msg { max-width: 82%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 5px; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 5px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 0.85rem; text-align: center; padding: 2px 8px; }
.msg .meta { display: block; font-size: 0.72rem; opacity: 0.75; margin-top: 2px; }
.typing { font-size: 0.82rem; color: var(--muted); height: 1.2em; padding-left: 4px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 22px;
  padding: 10px 16px;
  max-height: 140px;
  min-height: 44px;
}
.composer textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand);
  color: var(--brand-ink);
  min-height: 44px;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--sos); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.block { width: 100%; }

/* ---------- Live call ---------- */
.chat-area { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.session.in-call .chat-area { display: none; }
.session.in-call.chat-open .chat-area {
  display: flex; flex: none; height: 42dvh;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 10px; margin-top: 8px;
}
.session.in-call.chat-open .composer { background: var(--surface); }

.call {
  position: relative; flex: 1; min-height: 340px; border-radius: 24px; overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #2f6f6a, #0e1719 75%); color: #fff;
  display: grid; place-items: center;
}
.call .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; background: #000; }
.call.remote-video .remote { opacity: 1; }
.call.remote-video .call-face { opacity: 0; pointer-events: none; }
.call-face { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 20px; transition: opacity .3s; z-index: 1; }
.call-face b { font-size: 1.35rem; }
.call-sub { opacity: .8; font-size: .92rem; }
.call-remote-muted { font-size: .78rem; background: rgba(0,0,0,.35); padding: 2px 10px; border-radius: 999px; }
.call-ring { padding: 10px; border-radius: 50%; margin-bottom: 8px; animation: callring 1.6s ease-out infinite; }
.call.live .call-ring { animation: breathe 4s ease-in-out infinite; }
.call-avatar { width: 112px; height: 112px; font-size: 2.6rem; background: #f6f3ee; color: #2f6f6a; }
@keyframes callring { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.35); } 100% { box-shadow: 0 0 0 28px rgba(255,255,255,0); } }
@keyframes breathe { 50% { box-shadow: 0 0 0 14px rgba(95,179,170,.25); } }

.call-top {
  position: absolute; z-index: 2; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 8px;
  font-size: .85rem; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: #f5c451; }
.call.live .live-dot { background: #3bb273; box-shadow: 0 0 0 3px rgba(59,178,115,.3); }
.call-timer { margin-left: auto; font-variant-numeric: tabular-nums; }

.call .pip {
  position: absolute; z-index: 3; top: 44px; right: 12px; width: 96px; aspect-ratio: 3/4; object-fit: cover;
  border-radius: 14px; border: 2px solid rgba(255,255,255,.7); transform: scaleX(-1); background: #000;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.call-note {
  position: absolute; z-index: 3; left: 12px; right: 12px; bottom: 104px; text-align: center;
  background: rgba(0,0,0,.55); padding: 8px 12px; border-radius: 12px; font-size: .88rem;
}
.call-controls {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 14px;
  padding: 14px 10px 16px; background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0));
}
.call-controls button {
  background: none; border: 0; color: #fff; display: grid; justify-items: center; gap: 4px; cursor: pointer;
  font-size: .75rem; font-weight: 600; padding: 0; min-width: 58px;
}
.call-controls .ci {
  position: relative; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255,255,255,.18); backdrop-filter: blur(8px); transition: background .15s, transform .1s;
}
.call-controls button:active .ci { transform: scale(.92); }
.call-controls svg { width: 26px; height: 26px; fill: currentColor; }
.call-controls .off .ci { background: #fff; color: #1f2a2e; }
.call-controls .on .ci { background: rgba(255,255,255,.38); }
.call-controls .end .ci { background: #e5484d; }
.call-controls button:disabled { opacity: .45; }
.call-controls .badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; border-radius: 999px; padding: 0 5px;
  background: #e5484d; color: #fff; font-size: .72rem; font-style: normal; display: grid; place-items: center;
}
@media (prefers-reduced-motion: reduce) { .call-ring { animation: none !important; } }

/* ---------- Ended ---------- */
.ended { flex: 1; display: grid; place-content: center; text-align: center; gap: 16px; padding: 24px 0; }
.ended h2 { margin: 0; font-size: 1.5rem; }

/* ---------- Sponsor dashboard ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field input {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 11px 14px;
}
.field input:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.error { color: var(--sos); font-size: 0.9rem; min-height: 1.2em; }

.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.switch { position: relative; width: 58px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line); cursor: pointer; transition: background 0.2s;
}
.switch span::after {
  content: ""; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch input:checked + span { background: #3bb273; }
.switch input:checked + span::after { transform: translateX(26px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

.queue { display: grid; gap: 10px; margin-top: 14px; }
.req {
  background: var(--surface);
  border: 2px solid var(--sos);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 8px;
  animation: ring 1.4s ease-in-out infinite;
}
@keyframes ring { 50% { box-shadow: 0 0 0 6px var(--sos-glow); } }
.req-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pill { font-size: 0.8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.pill.hot { background: var(--sos); color: #fff; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.stack { display: grid; gap: 14px; }
.tips { font-size: 0.88rem; color: var(--muted); margin: 0; padding-left: 18px; }
