/* ==========================================================================
   Ilmtal Brauerei – Ladebildschirm
   Animiertes Bierglas mit Wappen, das sich schäumend füllt.
   Vollständig eigenständig: nur lokale Assets, keine externen Ressourcen.
   Der Füllstand wird über die Custom Property --p (0..1) gesteuert,
   die js/loader.js pro Frame setzt.
   ========================================================================== */

/* Scroll-Sperre, solange der Ladebildschirm sichtbar ist */
html.is-loading,
html.is-loading body {
    overflow: hidden;
}

.page-loader {
    --p: 0;              /* Füllstand 0..1, von js/loader.js gesetzt */
    --s: 1;              /* Skalierung des Glases (Responsive)       */
    --glass-w: 190px;
    --glass-h: 268px;

    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5000; /* über der Top-Navigation (1000) und den Modals (2000) */

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.6rem;

    /* identisch zum Seitenhintergrund, damit die Ausblendung nahtlos wirkt */
    background: radial-gradient(circle at center, #2a2a2a 0%, #121212 100%);

    transition: opacity 0.55s ease, visibility 0.55s;
    will-change: opacity;
}

/* Ausblenden: Overlay verschwindet, das Glas hebt sich leicht an */
.page-loader.is-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.page-loader.is-done .loader-stage {
    transform: scale(calc(var(--s) * 1.08)) translateY(-14px);
}

/* --------------------------------------------------------------------------
   Bühne, Glas und Henkel
   -------------------------------------------------------------------------- */

/* Breite = Glaskörper. Der Henkel ragt rechts heraus, ohne die Breite zu
   vergrößern – so steht das Glas exakt über Schriftzug und Fortschrittsbalken. */
.loader-stage {
    position: relative;
    width: var(--glass-w);
    height: var(--glass-h);
    transform: scale(var(--s));
    transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    /* nur Deckkraft animieren – die transform trägt hier Skalierung und Ausblendung */
    animation: loader-fade-plain 0.55s ease forwards;
}

/* Eigener Layer für das dezente Schwanken, damit die Ausblendung
   auf .loader-stage davon unabhängig bleibt */
.loader-tilt {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 50% 100%;
    animation: loader-tilt 5s ease-in-out infinite;
    will-change: transform;
}

.loader-glass {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--glass-w);
    height: var(--glass-h);
    z-index: 1;
    background: rgba(245, 245, 245, 0.04);
    border-radius: 6px 6px 34px 34px;
    box-shadow:
        0 0 0 2px rgba(255, 255, 255, 0.12),
        0 12px 34px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

/* Lichtkante am oberen Glasrand */
.loader-glass::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 10px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0));
    z-index: 5;
}

/* Der Henkel setzt bündig an der Glaskante an – nicht darunter, sonst
   schimmert er durch das Glas hindurch. */
.loader-handle {
    position: absolute;
    top: 72px;
    left: calc(var(--glass-w) - 2px);
    width: 60px;
    height: 116px;
    z-index: 0;
    border: 15px solid rgba(255, 255, 255, 0.11);
    border-left: none;
    border-radius: 0 56px 56px 0;
    box-shadow:
        inset 0 4px 10px rgba(0, 0, 0, 0.22),
        inset 0 -4px 10px rgba(255, 255, 255, 0.07);
}

/* --------------------------------------------------------------------------
   Füllung: Bier, Schaum, Bläschen
   -------------------------------------------------------------------------- */

/* Trägt den Füllstand. Wird nur per transform bewegt (kein Layout-Reflow). */
.loader-fill {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 100%;
    transform: translateY(calc(100% - var(--p) * 100%));
    will-change: transform;
}

/* Deckend, damit der Henkel nicht durch das Bier schimmert */
.loader-body {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: -24px; /* Überstand, damit unten keine Kante sichtbar wird */
    background:
        linear-gradient(to bottom, rgba(255, 255, 255, 0.10), rgba(0, 0, 0, 0.12)),
        linear-gradient(to right, #cf9a4a, #e0b166 45%, #cf9a4a);
    overflow: hidden; /* schneidet die Bläschen an der Oberfläche ab */
}

/* Hebt die Bewegung der Füllung wieder auf, damit die Bläschen immer vom
   Glasboden aufsteigen und nicht mit dem Pegel nach unten wandern. */
.loader-bubbles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--glass-h);
    transform: translateY(calc(var(--p) * var(--glass-h) - var(--glass-h)));
    will-change: transform;
}

.loader-foam {
    position: absolute;
    left: -4%;
    right: -4%;
    top: -14px;
    height: 28px;
    background: linear-gradient(to bottom,
        rgba(255, 255, 255, 0.98),
        rgba(255, 255, 255, 0.75));
    border-radius: 50% 50% 4px 4px / 70% 70% 4px 4px;
    filter: blur(1.6px); /* lässt Band und Blasen zu einer Krone verschmelzen */
    /* Schaum erscheint erst, wenn wirklich Bier im Glas steht */
    opacity: clamp(0, calc((var(--p) - 0.04) * 10), 1);
}

.loader-foam-blob {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    animation: loader-foam-blob 2.6s ease-in-out infinite alternate;
    will-change: transform;
}

/* Die Blasen überlappen einander leicht und ragen nur wenig über das Band –
   zusammen mit dem Weichzeichner ergibt das eine unregelmäßige Schaumkrone. */
.loader-foam-blob:nth-child(1) {
    width: 64px;
    height: 20px;
    top: -5px;
    left: 2%;
    animation-delay: 0.4s;
}

.loader-foam-blob:nth-child(2) {
    width: 56px;
    height: 18px;
    top: -3px;
    left: 33%;
    animation-delay: 1.3s;
}

.loader-foam-blob:nth-child(3) {
    width: 60px;
    height: 19px;
    top: -6px;
    left: 61%;
    animation-delay: 0.9s;
}

.loader-bubble {
    position: absolute;
    bottom: 6%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%,
        rgba(255, 255, 255, 0.85),
        rgba(255, 255, 255, 0.35) 60%,
        rgba(255, 255, 255, 0.08));
    animation: loader-bubble-rise ease-in infinite;
    will-change: transform, opacity;
}

.loader-bubble:nth-child(1) { width: 11px; height: 11px; left: 18%; animation-duration: 3.0s; animation-delay: 0.1s; }
.loader-bubble:nth-child(2) { width: 7px;  height: 7px;  left: 34%; animation-duration: 3.6s; animation-delay: 0.9s; }
.loader-bubble:nth-child(3) { width: 9px;  height: 9px;  left: 50%; animation-duration: 2.7s; animation-delay: 0.4s; }
.loader-bubble:nth-child(4) { width: 6px;  height: 6px;  left: 65%; animation-duration: 3.9s; animation-delay: 1.4s; }
.loader-bubble:nth-child(5) { width: 8px;  height: 8px;  left: 78%; animation-duration: 3.2s; animation-delay: 0.6s; }
.loader-bubble:nth-child(6) { width: 5px;  height: 5px;  left: 26%; animation-duration: 2.4s; animation-delay: 1.8s; }

/* --------------------------------------------------------------------------
   Glasreflexion und Wappen
   -------------------------------------------------------------------------- */

.loader-shine {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
    background: linear-gradient(135deg,
        rgba(255, 255, 255, 0.12) 0%,
        rgba(255, 255, 255, 0) 45%,
        rgba(255, 255, 255, 0.06) 100%);
    overflow: hidden;
}

/* wandernder Lichtstreifen über dem Glas */
.loader-shine::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -70px;
    width: 40px;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0),
        rgba(255, 255, 255, 0.16),
        rgba(255, 255, 255, 0));
    animation: loader-sheen 3.4s ease-in-out infinite;
    will-change: transform;
}

/* Das Wappen sitzt wie aufgedruckt auf dem Glas – über dem Bier,
   der dunkle Schlagschatten hält es auch vor gefülltem Glas lesbar. */
.loader-logo {
    position: absolute;
    top: 53%;
    left: 50%;
    width: 62%;
    height: auto;
    z-index: 4;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
    filter:
        drop-shadow(0 3px 7px rgba(0, 0, 0, 0.55))
        drop-shadow(0 0 14px rgba(217, 166, 85, 0.35));
}

.loader-logo.is-ready {
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Schriftzug und Fortschrittsbalken
   -------------------------------------------------------------------------- */

.loader-word {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: #d9a655;
    opacity: 0;
    animation: loader-fade 0.55s ease 0.12s forwards;
}

.loader-bar {
    width: 190px;
    height: 3px;
    background-color: rgba(245, 245, 245, 0.12);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
    animation: loader-fade 0.55s ease 0.18s forwards;
}

.loader-bar-fill {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #d9a655;
    transform-origin: left center;
    transform: scaleX(var(--p));
}

.loader-hint {
    font-size: 0.8rem;
    font-style: italic;
    letter-spacing: 2px;
    color: rgba(245, 245, 245, 0.55);
    opacity: 0;
    animation: loader-fade 0.55s ease 0.24s forwards;
}

/* --------------------------------------------------------------------------
   Altersabfrage (nur beim ersten Besuch)
   -------------------------------------------------------------------------- */

.loader-gate {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    max-width: 23rem;
    padding: 0 1.2rem;
    text-align: center;
    opacity: 0;
    animation: loader-fade 0.5s ease 0.15s forwards;
}

/* muss die display:flex-Regel oben ausstechen */
.loader-gate[hidden] {
    display: none;
}

/* Beim Öffnen bekommt der Dialog selbst den Fokus, damit Screenreader ihn
   vorlesen – ohne dass eine der beiden Antworten vorbelegt aussieht. */
.loader-gate:focus {
    outline: none;
}

.loader-gate-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 1px;
    color: rgba(245, 245, 245, 0.92);
}

.loader-gate-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.9rem;
}

/* Alle Werte ausdrücklich gesetzt: modal.css bringt eine globale
   button-Regel mit, deren Reste sonst hier durchschlagen. */
.loader-gate-button {
    min-width: 7rem;
    padding: 0.7rem 1.6rem;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 1px;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s, transform 0.2s;
}

.loader-gate-button.is-yes {
    background-color: #d9a655;
    color: #121212;
}

.loader-gate-button.is-yes:hover {
    background-color: #c69144;
    transform: translateY(-2px);
}

.loader-gate-button.is-no {
    background-color: transparent;
    color: #d9a655;
    border-color: rgba(217, 166, 85, 0.5);
}

.loader-gate-button.is-no:hover {
    background-color: rgba(217, 166, 85, 0.15);
    transform: translateY(-2px);
}

.loader-gate-button:focus-visible {
    outline: 2px solid #d9a655;
    outline-offset: 3px;
}

.loader-gate-note {
    font-size: 0.75rem;
    font-style: italic;
    line-height: 1.6;
    letter-spacing: 1px;
    color: rgba(245, 245, 245, 0.45);
}

/* Solange gefragt wird, ruhen Fortschrittsbalken und Untertitel */
.page-loader.is-gated .loader-bar,
.page-loader.is-gated .loader-hint {
    display: none;
}

/* --------------------------------------------------------------------------
   Keyframes
   -------------------------------------------------------------------------- */

@keyframes loader-fade {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes loader-fade-plain {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes loader-tilt {
    0%, 100% { transform: rotate(-0.8deg); }
    50%      { transform: rotate(0.8deg); }
}

@keyframes loader-foam-blob {
    0%   { transform: translateY(0) scale(1); }
    100% { transform: translateY(-3px) scale(1.06); }
}

@keyframes loader-bubble-rise {
    0%   { transform: translate3d(0, 0, 0) scale(0.7); opacity: 0; }
    12%  { opacity: 0.85; }
    55%  { transform: translate3d(6px, -95px, 0) scale(1.05); opacity: 0.6; }
    100% { transform: translate3d(-4px, -185px, 0) scale(0.75); opacity: 0; }
}

@keyframes loader-sheen {
    0%, 100% { transform: translateX(0) skewX(-12deg); }
    50%      { transform: translateX(285px) skewX(-12deg); }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 480px), (max-height: 620px) {
    .page-loader { --s: 0.8; gap: 1.2rem; }
    .loader-word { font-size: 1.15rem; }
    .loader-bar  { width: 150px; }

    .loader-gate { gap: 0.9rem; }
    .loader-gate-title { font-size: 0.95rem; }
    .loader-gate-button {
        min-width: 6rem;
        padding: 0.6rem 1.2rem;
        font-size: 0.95rem;
    }
}

/* --------------------------------------------------------------------------
   Barrierefreiheit: bei reduzierter Bewegung nur der Füllstand, keine Zierde
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .page-loader,
    .page-loader * {
        animation: none !important;
        transition-duration: 0.01ms !important;
    }

    .loader-stage,
    .loader-word,
    .loader-bar,
    .loader-hint {
        opacity: 1;
    }
}
