* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --bg: #F5F6FB;
    --surface: #FFFFFF;
    --primary: #4A5BEE;
    --primary-dark: #3A49D9;
    --text: #15172B;
    --text-muted: #8A8FA3;
    --border: #E8EAF4;
    --field-bg: #F2F3F9;
    --danger: #E8503F;
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 22px;
    --shadow-card: 0 1px 2px rgba(21, 23, 43, 0.04), 0 1px 8px rgba(21, 23, 43, 0.04);
}

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

.view {
    display: none;
    min-height: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ---------- App bar ---------- */

.appbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.appbar-logo {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}

.appbar-title {
    font-weight: 700;
    font-size: 17px;
    flex: 1;
    letter-spacing: -0.2px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--field-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}

.icon-btn svg { width: 18px; height: 18px; stroke: var(--text); }

/* ---------- Screen header (back + title) ---------- */

.screen-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 16px 4px;
}

.back-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.back-btn svg { width: 20px; height: 20px; stroke: var(--text); }

.screen-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* ---------- Content ---------- */

.content {
    flex: 1;
    padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
}

#create-circle-form, #join-code-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

h1 { margin: 40px 0 0; font-size: 28px; letter-spacing: -0.4px; }
h3 {
    margin: 4px 0 0;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
}
.subtitle { color: var(--text-muted); margin-top: 4px; }

/* ---------- Inputs ---------- */

.field {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="text"],
input[type="tel"] {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: none;
    background: var(--field-bg);
    color: var(--text);
    font-size: 16px;
}

input[type="text"]::placeholder,
input[type="tel"]::placeholder { color: var(--text-muted); }

.field-icon {
    position: absolute;
    right: 14px;
    pointer-events: none;
    display: flex;
}
.field-icon svg { width: 18px; height: 18px; stroke: var(--text-muted); }

.search-field input { padding-right: 42px; }

/* ---------- Buttons ---------- */

button {
    font-family: inherit;
    cursor: pointer;
}

.btn-primary {
    width: 100%;
    padding: 15px 18px;
    border-radius: var(--radius);
    border: none;
    background: var(--primary);
    color: white;
    font-size: 16px;
    font-weight: 700;
}
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
    width: 100%;
    padding: 15px 18px;
    border-radius: var(--radius);
    border: none;
    background: var(--field-bg);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    padding: 6px 0;
}

.btn-danger { background: var(--danger); color: white; }

/* ---------- Row action (icon + label, like a sheet option) ---------- */

.row-action {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 4px;
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    text-align: left;
}

.row-action .row-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--field-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.row-action .row-icon svg { width: 18px; height: 18px; stroke: var(--primary); }

/* ---------- Card list ---------- */

.card-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7B8BFF);
    color: white;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.card-row-title { flex: 1; font-weight: 600; font-size: 15.5px; }

.card-row .chevron { width: 16px; height: 16px; stroke: var(--text-muted); flex-shrink: 0; }

.owner-badge {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--primary);
    background: #ECEEFE;
    padding: 3px 8px;
    border-radius: 999px;
    flex-shrink: 0;
}

.kick-btn {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
}
.kick-btn svg { width: 14px; height: 14px; stroke: var(--danger); }

.call-member-btn {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    background: #ECEEFE;
}
.call-member-btn svg { width: 14px; height: 14px; stroke: var(--primary); }

.empty-hint {
    color: var(--text-muted);
    text-align: center;
    padding: 32px 16px;
    font-size: 14.5px;
}

.error { color: var(--danger); min-height: 1em; font-size: 14px; margin: 0; }

.hidden { display: none !important; }

/* ---------- FAB ---------- */

.fab {
    position: fixed;
    right: 20px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    box-shadow: 0 6px 16px rgba(74, 91, 238, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
}
.fab svg { width: 24px; height: 24px; stroke: white; }

/* ---------- Bottom sheet ---------- */

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 32, 0.45);
    z-index: 10;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.sheet-overlay.open { opacity: 1; pointer-events: auto; }

.sheet {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 14px 20px calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 80vh;
    overflow-y: auto;
}

.sheet-overlay.open .sheet { transform: translateY(0); }

.sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 4px;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.sheet-title { font-size: 17px; font-weight: 700; }

.sheet-close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: var(--field-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.sheet-close svg { width: 15px; height: 15px; stroke: var(--text-muted); }

.sheet-qr {
    width: 220px;
    height: 220px;
    margin: 4px auto;
    border-radius: var(--radius);
    background: white;
    border: 1px solid var(--border);
}

.sheet-link {
    text-align: center;
    font-size: 12.5px;
    color: var(--text-muted);
    word-break: break-all;
    margin: 0 0 4px;
}

/* ---------- Call screen (stays dark — standard for video calls) ---------- */

#view-call {
    position: relative;
    padding: 0;
    background: #0B0E14;
}

.remote-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 2px;
    height: 100%;
}

.remote-grid video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #1D2330;
}

#local-video {
    position: absolute;
    bottom: 112px;
    right: 16px;
    width: 96px;
    height: 136px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 2px solid var(--primary);
}

.call-controls {
    position: absolute;
    bottom: calc(28px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 18px;
}

.call-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.call-btn svg { width: 24px; height: 24px; stroke: white; }
.call-btn.active { background: white; }
.call-btn.active svg { stroke: #0B0E14; }
.call-btn.hangup { background: var(--danger); }
.call-btn.accept { background: #2FB66B; }

/* ---------- Incoming call ---------- */

.incoming-call-overlay {
    position: fixed;
    inset: 0;
    background: #0B0E14;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.incoming-call-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: white;
    text-align: center;
}

.incoming-avatar {
    width: 88px;
    height: 88px;
    font-size: 34px;
    margin-bottom: 16px;
    animation: incoming-pulse 1.2s ease-in-out infinite;
}

@keyframes incoming-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.incoming-caller { font-size: 22px; font-weight: 700; }
.incoming-circle { font-size: 15px; color: #9AA4B2; margin-bottom: 36px; }

.incoming-actions {
    display: flex;
    gap: 56px;
    margin-top: 12px;
}

.incoming-actions .call-btn {
    width: 64px;
    height: 64px;
}
