/* ── Reset & Base ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #0f172a;   /* slate-900 */
    --bg2:       #1e293b;   /* slate-800 */
    --border:    #334155;   /* slate-700 */
    --text:      #f1f5f9;   /* slate-100 */
    --muted:     #94a3b8;   /* slate-400 */
    --green:     #16a34a;
    --green-h:   #15803d;
    --red:       #dc2626;
    --red-h:     #b91c1c;
    --amber:     #d97706;
    --blue:      #2563eb;
    --radius:    1.5rem;
    --btn-h:     5rem;     /* Min button height — elderly-friendly */
    --font:      'Inter', 'Segoe UI', system-ui, sans-serif;
}

html, body {
    height: 100%; width: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 20px;   /* Base large for elderly */
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ── Screen management ───────────────────────────────────────────── */
.screen {
    position: fixed; inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1.5rem;
}
.screen.active { display: flex; }

/* ── ══ Sleeping ══ ─────────────────────────────────────────────── */
#screen-sleeping {
    background: #010409;
    cursor: pointer;
    touch-action: auto;
}
.sleep-clock {
    font-size: clamp(4rem, 15vw, 9rem);
    font-weight: 200;
    letter-spacing: -0.02em;
    color: rgba(255,255,255,0.7);
}
.sleep-hint {
    font-size: 1rem;
    color: rgba(255,255,255,0.2);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* ── ══ Connecting / Error shared ══ ──────────────────────────────*/
.status-icon { font-size: 3.5rem; }
.status-label { font-size: 1.4rem; color: var(--muted); text-align: center; }

.spinner {
    width: 3rem; height: 3rem;
    border: 4px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── ══ Idle / Home ══ ───────────────────────────────────────────── */
#screen-idle { gap: 1rem; }
.idle-clock {
    font-size: clamp(3.5rem, 12vw, 7rem);
    font-weight: 200;
    color: var(--text);
}
.idle-date {
    font-size: 1.1rem;
    color: var(--muted);
    margin-bottom: 1rem;
}

.call-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: clamp(160px, 40vw, 220px);
    height: clamp(160px, 40vw, 220px);
    border-radius: 50%;
    border: none;
    background: linear-gradient(145deg, var(--green), #166534);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 40px rgba(22,163,74,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
    gap: 0.5rem;
}
.call-btn:active { transform: scale(0.95); box-shadow: 0 4px 20px rgba(22,163,74,0.3); }
.call-btn-icon { font-size: 3.5rem; }
.call-btn-label { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.1em; }

.auto-call-bar { width: 100%; max-width: 480px; text-align: center; margin-top: 1rem; }
.auto-call-label { font-size: 1rem; color: var(--amber); margin-bottom: 0.5rem; }
.auto-call-progress {
    height: 6px; border-radius: 3px; background: var(--bg2); overflow: hidden; margin-bottom: 0.75rem;
}
.auto-call-track {
    height: 100%; background: var(--amber);
    transition: width 1s linear;
    width: 100%;
}

/* ── Idle screen “Back to Start” button ─────────────────────── */
/* position:fixed on .screen IS a containing block for absolute children  */
.idle-sleep-btn {
    position: fixed;
    top: 1.2rem;
    right: 1.2rem;
    z-index: 9999;
    width: clamp(90px, 20vw, 130px);
    height: clamp(90px, 20vw, 130px);
    border-radius: 1.25rem;
    border: 2px solid var(--border);
    background: var(--bg2);
    color: var(--muted);
    cursor: pointer;
    display: none;   /* hidden by default; shown by sibling selector below */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
/* Show only when the idle screen is active (CSS sibling — no JS needed) */
#screen-idle.active ~ #btn-idle-sleep { display: flex; }
.idle-sleep-btn:active { transform: scale(0.93); background: #2a3a4e; }
.idle-sleep-btn .sleep-graphic { font-size: clamp(2.5rem, 8vw, 3.5rem); line-height: 1; }
.idle-sleep-btn .sleep-label  { font-size: clamp(0.7rem, 2.5vw, 0.9rem); font-weight: 700;
                                  letter-spacing: 0.06em; text-transform: uppercase;
                                  color: var(--muted); text-align: center; }

/* ── ══ Ringing shared ══ ─────────────────────────────────────────*/
.ring-pulse {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    width: 140px; height: 140px;
}
.ring-pulse::before, .ring-pulse::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: 50%;
    background: var(--amber);
    opacity: 0.3;
    animation: pulse-ring 1.2s ease-out infinite;
}
.ring-pulse::after { animation-delay: 0.4s; }
.ring-pulse.ring-green::before,
.ring-pulse.ring-green::after { background: var(--green); }
@keyframes pulse-ring {
    0%   { transform: scale(0.8); opacity: 0.4; }
    100% { transform: scale(1.8); opacity: 0; }
}
.ring-icon {
    font-size: 4rem;
    position: relative; z-index: 1;
    animation: ring-shake 0.6s ease-in-out infinite alternate;
}
@keyframes ring-shake {
    from { transform: rotate(-12deg); }
    to   { transform: rotate(12deg); }
}

.ring-label { font-size: 1.8rem; font-weight: 600; text-align: center; }
.ring-sub   { font-size: 1rem;  color: var(--muted); text-align: center; }

.answer-row { display: flex; gap: 2rem; margin-top: 1rem; }

/* ── Shared buttons ─────────────────────────────────────────────── */
.cancel-btn, .answer-btn, .decline-btn, .hangup-btn {
    min-height: var(--btn-h);
    padding: 0 2.5rem;
    border-radius: var(--radius);
    border: none;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s;
}
.cancel-btn  { background: var(--bg2); color: var(--muted); border: 1px solid var(--border); }
.answer-btn  { background: var(--green); color: #fff;  min-width: 160px; }
.decline-btn { background: var(--red);   color: #fff;  min-width: 160px; }
.hangup-btn  { background: var(--red);   color: #fff;  min-width: 220px; }
.cancel-btn:active, .answer-btn:active, .decline-btn:active, .hangup-btn:active {
    transform: scale(0.96);
}

/* ── ══ Active call ══ ───────────────────────────────────────────── */
.call-screen { padding: 0; }

.remote-video {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    background: #000;
    z-index: 0;
}
.local-video {
    position: absolute;
    top: 1rem; right: 1rem;
    width: min(30vw, 180px);
    aspect-ratio: 4/3;
    object-fit: cover;
    border-radius: 1rem;
    border: 2px solid var(--border);
    z-index: 2;
}
.call-duration {
    position: absolute;
    top: 1rem; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.5);
    padding: 0.4rem 1rem;
    border-radius: 999px;
    font-size: 1rem;
    color: #fff;
    z-index: 2;
}
.stt-overlay {
    position: absolute;
    bottom: 7rem; left: 0; right: 0;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(to top, rgba(0,0,0,0.75), transparent);
    z-index: 3;
    display: flex; flex-direction: column; gap: 0.25rem;
    pointer-events: none;
}
.stt-line {
    color: #fff;
    font-size: clamp(1rem, 3vw, 1.4rem);
    text-shadow: 0 0 8px rgba(0,0,0,0.9);
    line-height: 1.4;
}
.stt-speaker { color: rgba(255,255,255,0.5); font-size: 0.85em; }

.call-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 6.5rem;
    display: flex; align-items: center; justify-content: center;
    gap: 1.5rem;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(10px);
    z-index: 4;
}
.ctrl-btn {
    width: 4.5rem; height: 4.5rem;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, transform 0.1s;
}
.ctrl-btn:active { transform: scale(0.9); }
.ctrl-btn.active { background: var(--blue); }
.hangup-ctrl {
    width: 5.5rem; height: 5.5rem;
    background: var(--red);
    font-size: 2rem;
}
.hangup-ctrl:hover { background: var(--red-h); }

/* ── Utilities ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── ══ Wake Countdown ══ ─────────────────────────────────────── */
#screen-wake-countdown { gap: 2rem; background: var(--bg); }

.countdown-ring {
    width: clamp(120px, 30vw, 200px);
    height: clamp(120px, 30vw, 200px);
    border-radius: 50%;
    border: 6px solid rgba(255,255,255,0.15);
    display: flex; align-items: center; justify-content: center;
    animation: countdown-pulse 1s ease-in-out infinite;
}
@keyframes countdown-pulse {
    0%, 100% { border-color: rgba(255,255,255,0.15); }
    50%       { border-color: rgba(255,255,255,0.45); }
}
.countdown-digit {
    font-size: clamp(3.5rem, 12vw, 8rem);
    font-weight: 200;
    color: var(--text);
}
.countdown-hint {
    font-size: 1rem;
    color: var(--muted);
    text-align: center;
}

/* 3 mode-select buttons in a row */
.mode-buttons {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}
.mode-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: clamp(90px, 22vw, 160px);
    height: clamp(90px, 22vw, 160px);
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--bg2);
    color: var(--text);
    cursor: pointer;
    gap: 0.5rem;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.mode-btn:not([disabled]):hover { background: #2d3f55; border-color: #4a6080; }
.mode-btn:not([disabled]):active { transform: scale(0.94); }
.mode-icon  { font-size: 2.5rem; }
.mode-label { font-size: 1rem; font-weight: 600; }

/* ── ══ Idle — dual call buttons ══ ──────────────────────────── */
.call-buttons {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}
.call-btn-care {
    background: linear-gradient(145deg, #1d6d9e, #134e73);
    box-shadow: 0 8px 40px rgba(29,109,158,0.4);
}
.call-btn-care:active { box-shadow: 0 4px 20px rgba(29,109,158,0.3); }

/* ── ══ Media screen ══ ───────────────────────────────────────── */
#screen-media { padding: 0; position: fixed; inset: 0; }

.media-label-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3.5rem;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    z-index: 10;
    font-size: 1.1rem;
    color: rgba(255,255,255,0.7);
    letter-spacing: 0.08em;
    pointer-events: none;
}

.media-sleep-btn {
    position: absolute;
    top: 0.6rem; right: 0.75rem;
    z-index: 11;
    width: 3rem; height: 2.2rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.55);
    color: rgba(255,255,255,0.7);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.media-sleep-btn:active { background: rgba(0,0,0,0.8); }

.media-iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    border: none;
    background: #000;
    z-index: 1;
}

.media-iframe.hidden    { display: none; }

/* ── Native audio player UI ───────────────────────────────────────────────── */
.media-audio-ui {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    background: radial-gradient(ellipse at 50% 40%, #0f3460 0%, #0f172a 70%);
}
.media-audio-ui.hidden { display: none; }

.audio-visualiser {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 64px;
}
.audio-visualiser span {
    display: block;
    width: 10px;
    border-radius: 5px;
    background: #60a5fa;
    animation: wave 1.2s ease-in-out infinite;
}
.audio-visualiser span:nth-child(1) { animation-delay: 0s;    height: 24px; }
.audio-visualiser span:nth-child(2) { animation-delay: 0.15s; height: 40px; }
.audio-visualiser span:nth-child(3) { animation-delay: 0.3s;  height: 56px; }
.audio-visualiser span:nth-child(4) { animation-delay: 0.15s; height: 40px; }
.audio-visualiser span:nth-child(5) { animation-delay: 0s;    height: 24px; }

@keyframes wave {
    0%, 100% { transform: scaleY(1);    opacity: 0.8; }
    50%       { transform: scaleY(1.8); opacity: 1;   }
}

.audio-status {
    font-size: 1.1rem;
    color: #94a3b8;
    font-weight: 500;
    letter-spacing: 0.03em;
}
