/* Shabbat gate — the screen the site shows from candle lighting until havdalah. Ported from
   moraltogether.com. Deliberately a single dusk look: this is a night screen, and it takes
   over the whole viewport, so it does not follow the site's own colours. */

html.shabbat-closed,
html.shabbat-closed body {
    overflow: hidden !important;
    height: 100%;
    background: #070a11;
}

/* styles.css keeps a stable scrollbar gutter; with nothing to scroll it would show as a dark
   strip down the screen's edge. */
html.shabbat-closed {
    scrollbar-gutter: auto !important;
}

/* While the gate is up it is the only thing left on the page; display: none also takes the
   hidden site out of the keyboard's reach. */
html.shabbat-closed body > *:not(.shabbat-gate) {
    display: none !important;
}

.shabbat-gate {
    --gate-ink: #f4f1e8;
    --gate-dim: rgba(244, 241, 232, 0.72);
    --gate-faint: rgba(244, 241, 232, 0.6);
    --gate-flame: #f0ab3d;
    --gate-hair: rgba(244, 241, 232, 0.14);

    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: grid;
    place-items: center;
    padding: max(2rem, env(safe-area-inset-top)) 1.5rem max(2rem, env(safe-area-inset-bottom));
    color: var(--gate-ink);
    font-family: 'Rubik', 'Arial Hebrew', 'Noto Sans Hebrew', sans-serif;
    text-align: center;
    overscroll-behavior: contain;
    background-color: #070a11;
}

.shabbat-gate:focus {
    outline: none;
}

/* Layer order inside the gate: the poster is a pseudo-element at the back, the video sits
   above it at z-index -2, the vignette above that at -1, and the words on top. The vignette
   has to be its own layer — as a background gradient it would end up underneath the video.

   The poster is the video's own first frame, so the swap is invisible. It is left vivid; the
   shade lives under the words instead. */
.shabbat-gate::before {
    content: "";
    position: absolute;
    z-index: -3;
    inset: 0;
    background-image: url("assets/shabbat/shabbat-bg.jpg");
    background-image: image-set(url("assets/shabbat/shabbat-bg.webp") type("image/webp"), url("assets/shabbat/shabbat-bg.jpg") type("image/jpeg"));
    background-size: cover;
    background-position: center 58%;
    background-repeat: no-repeat;
    filter: saturate(1.12) contrast(1.05) brightness(1.06);
    pointer-events: none;
}

/* A wide or dense screen stretches the 1280 px frame past its resolution, so those get the
   1920 one — switched together with the loop in shabbat-gate.js. */
@media (min-width: 1600px), (min-resolution: 1.5dppx) {
    .shabbat-gate::before {
        background-image: url("assets/shabbat/shabbat-bg-1920.jpg");
        background-image: image-set(url("assets/shabbat/shabbat-bg-1920.webp") type("image/webp"), url("assets/shabbat/shabbat-bg-1920.jpg") type("image/jpeg"));
    }
}

.shabbat-gate__video {
    position: absolute;
    z-index: -2;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 58%;
    opacity: 0;
    transition: opacity 900ms ease;
    filter: saturate(1.12) contrast(1.05) brightness(1.06);
    pointer-events: none;
}

.shabbat-gate__video.is-ready {
    opacity: 1;
}

/* A faint vignette at the very edges is all the picture itself gets. */
.shabbat-gate::after {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0;
    background: radial-gradient(125% 105% at 50% 46%, rgba(5, 8, 14, 0) 0%, rgba(5, 8, 14, 0.08) 62%, rgba(5, 8, 14, 0.42) 100%);
    pointer-events: none;
}

.shabbat-gate__card {
    position: relative;
    z-index: 0;
    max-width: 34rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.15rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

/* The words need their own pool of shade: the tablecloth in the picture is bright, and a
   hard-edged panel would fight it. This one has no edges at all. */
.shabbat-gate__card::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: -6rem -11rem -6.5rem;
    background: radial-gradient(closest-side at 50% 50%, rgba(4, 7, 13, 0.95) 0%, rgba(4, 7, 13, 0.88) 42%, rgba(4, 7, 13, 0.6) 70%, rgba(4, 7, 13, 0) 100%);
    pointer-events: none;
}

.shabbat-gate__logo {
    height: clamp(3.2rem, 9vw, 4.2rem);
    width: auto;
}

.shabbat-gate__title {
    margin: 0.5rem 0 0;
    font-size: clamp(2rem, 7vw, 3rem);
    font-weight: 600;
    line-height: 1.08;
    text-wrap: balance;
}

.shabbat-gate__body {
    margin: 0;
    max-width: 30rem;
    font-size: clamp(1rem, 2.6vw, 1.1rem);
    line-height: 1.68;
    color: var(--gate-dim);
    text-wrap: pretty;
}

.shabbat-gate__times {
    margin: 1.4rem 0 0;
    display: grid;
    grid-template-columns: auto auto;
    align-items: baseline;
    justify-content: center;
    gap: 0.55rem 1.4rem;
    padding-top: 1.4rem;
    border-top: 1px solid var(--gate-hair);
    width: min(24rem, 100%);
}

.shabbat-gate__label {
    justify-self: end;
    font-size: 0.85rem;
    color: var(--gate-faint);
    white-space: nowrap;
}

.shabbat-gate__value {
    justify-self: start;
    margin: 0;
    font-size: 1.3rem;
    font-variant-numeric: tabular-nums;
    color: var(--gate-flame);
}

/* A clock reading is always left to right, even inside Hebrew; the duration, written with
   Hebrew abbreviations, follows the language. */
.shabbat-gate__time {
    direction: ltr;
    unicode-bidi: isolate;
}

/* A portrait screen filled by a landscape picture keeps about a quarter of its width — the
   candles and the cup would be cropped away. So phones get a portrait still as a band at the
   bottom, and the words take the quiet space above it. No video here (shabbat-gate.js). */
@media (orientation: portrait) and (max-width: 46rem) {
    .shabbat-gate {
        align-content: start;
        padding-top: max(2.5rem, env(safe-area-inset-top));
    }

    .shabbat-gate::before {
        /* Full width, never cropped sideways: the candles stand at 6% and 92% of the frame.
           On a tall screen the picture cannot reach the top, so a gradient carries the dark
           down over its edge — otherwise the seam shows as a straight line. */
        background-image:
            linear-gradient(180deg, #070a11 0%, #070a11 14%, rgba(7, 10, 17, 0.55) 26%, rgba(7, 10, 17, 0) 38%),
            url("assets/shabbat/shabbat-bg-mobile.jpg");
        background-image:
            linear-gradient(180deg, #070a11 0%, #070a11 14%, rgba(7, 10, 17, 0.55) 26%, rgba(7, 10, 17, 0) 38%),
            image-set(url("assets/shabbat/shabbat-bg-mobile.webp") type("image/webp"), url("assets/shabbat/shabbat-bg-mobile.jpg") type("image/jpeg"));
        background-size: auto, 100% auto;
        background-position: center, center bottom;
    }

    .shabbat-gate::after {
        background: linear-gradient(180deg, rgba(7, 10, 17, 0.88) 0%, rgba(7, 10, 17, 0.62) 22%, rgba(5, 8, 14, 0.22) 48%, rgba(5, 8, 14, 0.12) 70%, rgba(5, 8, 14, 0.45) 100%);
    }

    /* On a phone the words sit right on the tablecloth; the shade alone is not enough for the
       smallest lines. */
    .shabbat-gate__card {
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
    }

    .shabbat-gate__card::before {
        inset: -3.5rem -3rem -4.5rem;
        background: radial-gradient(closest-side at 50% 50%, rgba(4, 7, 13, 0.94) 0%, rgba(4, 7, 13, 0.88) 48%, rgba(4, 7, 13, 0.6) 76%, rgba(4, 7, 13, 0) 100%);
    }
}

@media (max-width: 30rem) {
    .shabbat-gate__times {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 0.15rem;
    }

    .shabbat-gate__label,
    .shabbat-gate__value {
        justify-self: center;
    }

    .shabbat-gate__value {
        margin-bottom: 0.55rem;
    }
}

/* A phone on its side is about 390 px tall: the full layout would push the counter off the
   bottom of a screen that cannot be scrolled. Tighter here, and the gate scrolls itself as a
   last resort. */
@media (max-height: 32rem) {
    .shabbat-gate {
        overflow-y: auto;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .shabbat-gate__card {
        gap: 0.5rem;
    }

    /* The full-size pool would reach past the screen and make it scroll for nothing. */
    .shabbat-gate__card::before {
        inset: -1rem -8rem;
    }

    .shabbat-gate__logo {
        height: 2.6rem;
    }

    .shabbat-gate__title {
        margin: 0;
        font-size: 1.9rem;
    }

    .shabbat-gate__body {
        line-height: 1.5;
    }

    .shabbat-gate__times {
        margin-top: 0.4rem;
        padding-top: 0.7rem;
        gap: 0.2rem 1.4rem;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .shabbat-gate {
        animation: shabbat-gate-in 600ms ease-out both;
    }
}

@keyframes shabbat-gate-in {
    from { opacity: 0; transform: translateY(0.6rem); }
    to { opacity: 1; transform: none; }
}
