/* ============================================================================
   call.css — Phase R7 — Call pane (green identity).

   Green is the active-life color — the moment of connection. The call
   stages are full-screen takeovers presented via YStage, layered over
   the existing call idle card. They use the contact's avatar_full and
   background_full where available (R5b/R5c) so the visual carries the
   relationship.

   Three stage flavors share the .cs-stage shell:
     • .cs-incoming  — caller's avatar full-bleed, breathing ring
     • .cs-outgoing  — recipient's avatar, ringback ripple
     • .cs-incall    — active call surface; remote video center,
       self-video corner, action bar at bottom
   ========================================================================= */

.cs-stage {
    --cs-color-0: #7af7a8;       /* primary green */
    --cs-color-1: #4ad682;       /* deeper grass */
    --cs-color-2: #ddffe6;       /* highlight */
    --cs-color-3: rgba(74, 214, 130, 0.16);
    --cs-color-4: rgba(74, 214, 130, 0.32);
    --cs-glass:   rgba(8, 22, 14, 0.58);
    --cs-glass-2: rgba(12, 30, 18, 0.78);
    --cs-border:  rgba(122, 247, 168, 0.22);
    --cs-border-strong: rgba(122, 247, 168, 0.42);
    --cs-fg:      #f0fff5;
    --cs-fg-2:    #b8d6c2;
    --cs-fg-3:    #6f8a78;

    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    color: var(--cs-fg);
    background:
        radial-gradient(ellipse at 50% -10%, var(--cs-color-3), transparent 55%),
        linear-gradient(180deg, rgba(8, 22, 14, 0.96), rgba(4, 12, 8, 0.99));
    overflow: hidden;
}

/* Backdrop layer (contact.background_full or caller artwork). */
.cs-stage[data-has-bg="true"]::before {
    content: '';
    position: absolute; inset: 0;
    z-index: 0;
    background-image: var(--cs-bg-image);
    background-size: cover;
    background-position: center;
    opacity: 0.32;
    pointer-events: none;
}
.cs-stage > * { position: relative; z-index: 1; }

/* ── Top ribbon (connection quality / state) ────────────────────── */

.cs-stage .cs-topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 10px 16px env(safe-area-inset-top, 0);
    padding-top: max(10px, env(safe-area-inset-top, 0));
    font-size: 12px;
    color: var(--cs-fg-2);
}
.cs-stage .cs-quality {
    display: flex; gap: 4px; align-items: center;
    font-variant-numeric: tabular-nums;
}
.cs-stage .cs-quality-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--cs-color-1);
    box-shadow: 0 0 8px var(--cs-color-3);
}
.cs-stage .cs-quality[data-state="poor"] .cs-quality-dot { background: #f5b94c; box-shadow: 0 0 8px rgba(245,185,76,.32); }
.cs-stage .cs-quality[data-state="lost"] .cs-quality-dot { background: #ff6b6b; box-shadow: 0 0 8px rgba(255,107,107,.32); }

.cs-stage .cs-state {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--cs-color-0);
}

/* ── Hero: caller / recipient avatar + name ─────────────────────── */

.cs-stage .cs-hero {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 18px;
    padding: 20px 18px;
    min-height: 0;
}
.cs-stage .cs-avatar-wrap {
    position: relative;
    width: clamp(200px, 36vmin, 280px);
    aspect-ratio: 1 / 1;
    margin-bottom: 8px;
}
.cs-stage .cs-avatar-orb {
    width: 100%; height: 100%;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    background-color: var(--cs-color-1);
    color: #052915;
    display: grid; place-items: center;
    font-size: clamp(64px, 12vmin, 120px);
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55),
                inset 0 0 0 4px rgba(255, 255, 255, 0.06);
}

/* Spherical-harmonic ringback ripple (outgoing + incoming). */
.cs-stage .cs-ripple {
    position: absolute; inset: -22px;
    border-radius: 50%;
    border: 2px solid rgba(122, 247, 168, 0.32);
    animation: cs-ripple-pulse 2.6s cubic-bezier(.4,0,.6,1) infinite;
    pointer-events: none;
}
.cs-stage .cs-ripple::after {
    content: '';
    position: absolute; inset: -32px;
    border-radius: 50%;
    border: 1px solid rgba(122, 247, 168, 0.18);
    animation: cs-ripple-pulse 2.6s cubic-bezier(.4,0,.6,1) infinite;
    animation-delay: 1.2s;
}
@keyframes cs-ripple-pulse {
    0%   { transform: scale(0.92); opacity: 0; }
    20%  { opacity: 0.7; }
    100% { transform: scale(1.18); opacity: 0; }
}

.cs-stage .cs-hero-name {
    margin: 0;
    font-size: clamp(22px, 3.2vmin, 32px);
    font-weight: 600;
    letter-spacing: -0.01em;
    text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}
.cs-stage .cs-hero-sub {
    margin: 0;
    font-size: 13px;
    color: var(--cs-fg-2);
    opacity: .85;
    line-height: 1.45;
    max-width: 460px;
}
.cs-stage .cs-narrator {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 12px; color: var(--cs-fg-2);
    margin-top: 6px;
}
.cs-stage .cs-narrator-host { width: 36px; height: 36px; }

/* ── Quick-reply input (incoming) ───────────────────────────────── */

.cs-stage .cs-reply {
    display: flex; gap: 8px; align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--cs-border);
    border-radius: 999px;
    background: var(--cs-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    width: min(560px, 92vw);
    margin: 0 auto;
}
.cs-stage .cs-reply-input {
    flex: 1; appearance: none;
    background: transparent;
    border: 0;
    color: var(--cs-fg);
    outline: none;
    font: inherit; font-size: 14px;
    padding: 4px 8px;
}
.cs-stage .cs-reply-input::placeholder { color: var(--cs-fg-3); }
.cs-stage .cs-reply-send {
    appearance: none;
    border: 1px solid var(--cs-border-strong);
    background: linear-gradient(180deg, var(--cs-color-0), var(--cs-color-1));
    color: #052915;
    font-weight: 600; font-size: 13px;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
}
.cs-stage .cs-reply-send:disabled { opacity: .55; cursor: not-allowed; }

/* ── Action grid ────────────────────────────────────────────────── */

.cs-stage .cs-actions {
    padding: 18px 16px max(20px, env(safe-area-inset-bottom, 0));
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 10px;
    background: linear-gradient(0deg, rgba(8, 22, 14, 0.85), transparent);
}
.cs-stage .cs-act {
    appearance: none;
    border: 1px solid var(--cs-border);
    background: var(--cs-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--cs-fg);
    border-radius: 16px;
    padding: 12px 14px;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    font: inherit; font-size: 12.5px; line-height: 1.3;
    transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.cs-stage .cs-act:hover  { transform: translateY(-2px); background: var(--cs-glass-2); border-color: var(--cs-border-strong); }
.cs-stage .cs-act:active { transform: translateY(0); }
.cs-stage .cs-act .cs-act-icon { font-size: 22px; line-height: 1; }
.cs-stage .cs-act .cs-act-label { font-size: 12px; font-weight: 500; text-align: center; }
.cs-stage .cs-act.primary {
    background: linear-gradient(180deg, var(--cs-color-0), var(--cs-color-1));
    color: #052915;
    border-color: var(--cs-border-strong);
    box-shadow: 0 8px 22px rgba(74, 214, 130, 0.35);
}
.cs-stage .cs-act.primary:hover { box-shadow: 0 14px 32px rgba(74, 214, 130, 0.45); }
.cs-stage .cs-act.danger {
    background: linear-gradient(180deg, #ff8a7a, #cf3a30);
    color: #2a0c08;
    border-color: rgba(207, 58, 48, 0.6);
    box-shadow: 0 8px 22px rgba(207, 58, 48, 0.35);
}
.cs-stage .cs-act.warn {
    background: linear-gradient(180deg, #ffd070, #ec9a2c);
    color: #3b2300;
    border-color: rgba(236, 154, 44, 0.6);
}

/* ── In-call surface (R7c) ──────────────────────────────────────── */

.cs-stage.cs-incall {
    /* Remote video fills the screen; everything else floats over it. */
    background: #000;
}
.cs-stage.cs-incall .cs-remote-video {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    background: #000;
    z-index: 0;
}
.cs-stage.cs-incall .cs-self-tile {
    position: absolute;
    right: 14px;
    top: max(60px, env(safe-area-inset-top, 0));
    width: clamp(96px, 22vmin, 160px);
    aspect-ratio: 3 / 4;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
    z-index: 2;
    background: #000;
}
.cs-stage.cs-incall .cs-self-tile video {
    width: 100%; height: 100%;
    object-fit: cover;
    transform: scaleX(-1);   /* mirror own preview */
}
.cs-stage.cs-incall .cs-incall-actions {
    position: absolute;
    left: 0; right: 0;
    bottom: 0;
    display: flex; gap: 10px; flex-wrap: wrap;
    justify-content: center;
    padding: 18px 16px max(20px, env(safe-area-inset-bottom, 0));
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.65), transparent);
    z-index: 3;
}
.cs-stage.cs-incall .cs-icon-btn {
    appearance: none;
    width: 56px; height: 56px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background .15s ease, transform .12s ease;
}
.cs-stage.cs-incall .cs-icon-btn:hover    { background: rgba(255, 255, 255, 0.12); }
.cs-stage.cs-incall .cs-icon-btn:active   { transform: scale(0.96); }
.cs-stage.cs-incall .cs-icon-btn.is-on    { background: var(--cs-color-3); border-color: var(--cs-border-strong); color: var(--cs-color-0); }
.cs-stage.cs-incall .cs-icon-btn.danger   { background: #cf3a30; border-color: #cf3a30; color: #fff; }
.cs-stage.cs-incall .cs-incall-topbar {
    position: absolute;
    left: 0; right: 0;
    top: 0;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top, 0));
    z-index: 2;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent);
    color: #fff;
}
.cs-stage.cs-incall .cs-incall-name { font-weight: 600; font-size: 14px; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
.cs-stage.cs-incall .cs-min-btn {
    appearance: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    cursor: pointer;
    display: grid; place-items: center;
    font-size: 14px;
    transition: background .15s ease;
}
.cs-stage.cs-incall .cs-min-btn:hover { background: rgba(255, 255, 255, 0.12); }

@media (prefers-reduced-motion: reduce) {
    .cs-stage .cs-ripple,
    .cs-stage .cs-ripple::after { animation: none; }
    .cs-stage .cs-act,
    .cs-stage.cs-incall .cs-icon-btn { transition: none; }
}
