:root {
    --sab: env(safe-area-inset-bottom, 0px);
    --sat: env(safe-area-inset-top, 0px);
}

/* ── Landscape-Hinweis ──────────────────────────────── */
#landscape-hint {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: #111;
    color: #fff;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-family: Arial, sans-serif;
    font-size: 18px;
    text-align: center;
    pointer-events: none;
}

/* Sichtbarkeit wird per JS gesteuert (main.js), nicht per Media-Query:
   In eingebetteten iFrames (z.B. itch.io, GameDistribution) spiegelt die
   eigene iFrame-Höhe nicht die tatsächliche Geräte-Ausrichtung wider — ein
   kleines, breites Embed würde die Media-Query sonst fälschlich auslösen. */
#landscape-hint.show { display: flex; }

/* Verhindert, dass CSS display-Regeln das HTML hidden-Attribut überschreiben */
[hidden] { display: none !important; }

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Verhindert 300ms-Tap-Delay auf Mobile */
button {
    touch-action: manipulation;
}

input, textarea {
    user-select: text;
    -webkit-user-select: text;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: #222;
    display: flex;
    overflow: hidden;
    align-items: center;
    justify-content: center;
    overscroll-behavior: none;
}

/* Desktop-Breitbild-Embeds (z.B. 907×510 laut CrazyGames-Doku, nicht Vollbild)
   zeigen links/rechts (oder oben/unten) Platz neben dem Hochformat-Frame.
   Ein geblurrtes Hintergrundbild statt reinem Schwarz wirkt dort bewusst
   gestaltet statt unfertig. Deckt sich automatisch komplett ab, sobald
   #gameFrame den Viewport füllt (Mobile-Vollbild) — keine Media-Query nötig. */
#desktop-backdrop {
    position: fixed;
    inset: -40px;
    z-index: 0;
    background: url('bg_002.jpg') center/cover no-repeat;
    filter: blur(28px);
    pointer-events: none;
}

#gameFrame {
    transform-origin: center center;
    position: relative;
    z-index: 1;
    width: 390px;
    height: 844px;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Gleicher Blur-Trick wie #desktop-backdrop, nur innerhalb von #gameFrame:
   liegt hinter #gameArea, deckt die transparenten Stellen von start_007.png
   (Startbildschirm-Logo) ab, bevor das Canvas seinen ersten Frame zeichnet.
   Kein filter auf #gameArea selbst — das würde auch das Canvas-Kind
   während des eigentlichen Spielens verschwommen zeigen. */
#gameframe-backdrop {
    position: absolute;
    inset: -40px;
    z-index: 0;
    background: url('bg_002.jpg') center/cover no-repeat;
    filter: blur(28px);
    pointer-events: none;
}

#gameArea {
    flex: 1;
    position: relative;
    overflow: hidden;
    /* transparent statt #000: #gameframe-backdrop scheint sonst nie durch
       (siehe oben). Während des Spielens ohne sichtbaren Unterschied, da
       das Canvas jeden Frame komplett opak überzeichnet. */
    background: transparent;
    /* Ganze Fläche ist jetzt die Touch-Geste (siehe input-manager.js) — ohne
       das hier fängt der Browser schnelle vertikale Wischbewegungen (Boost-
       Geste) als Scroll/Zoom ab statt sie durchzureichen. */
    touch-action: none;
}

#startPoster {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    /* transparent statt #000: sonst schien hier ein eigenes Schwarz durch die
       transparenten Stellen von start_007.png statt des geblurrten
       #gameframe-backdrop dahinter — wirkte wie eine dunklere Glasscheibe
       gegenüber dem identisch geblurrten Hintergrund außerhalb des Frames. */
    background: transparent;
    z-index: 5;
    pointer-events: none;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.btn {
    width:80px;
    height:80px;
    margin:10px;
    border-radius:50%;
    border:none;
    background:#ffcc00;
    font-weight:bold;
    font-size:20px;
    box-shadow:0 4px #aa8800;
    /* touch-action: manipulation (von "button" geerbt) erlaubt dem Browser noch
       Pan/Zoom-Gesten über mehrere Finger — das kann bei einem zweiten
       gleichzeitigen Touch auf einen anderen Button dazu führen, dass der
       Browser ihn als Teil einer Geste abfängt statt ihn als eigenen
       pointerdown/touchstart durchzulassen. none unterbindet das komplett und
       macht Mehrfach-Touch über mehrere Buttons hinweg zuverlässig möglich. */
    touch-action: none;
}

.btn:active {
    box-shadow:none;
    transform:translateY(4px);
}

#startOverlay {
    position:absolute;
    inset:0;
    display:none;
    align-items:center;
    justify-content:center;
    z-index:100;
    background:transparent;
    color:#fff;
    text-align:center;
    padding:20px;
}

/* Schwarze Schrift, weiße Umrandung: Start-Screen-Text liegt direkt auf dem
   (variablen) Hintergrundbild ohne eigene Fläche dahinter — reines Weiß
   ging dort je nach Motiv unter. text-shadow statt -webkit-text-stroke,
   da Letzteres in älteren In-App-WebViews (Portale/Mobile) nicht sicher
   unterstützt wird. */
#startOverlay,
#startHint {
    color: #000;
    text-shadow:
        -1.5px -1.5px 0 #fff,
         1.5px -1.5px 0 #fff,
        -1.5px  1.5px 0 #fff,
         1.5px  1.5px 0 #fff,
         0     -1.5px 0 #fff,
         0      1.5px 0 #fff,
        -1.5px  0     0 #fff,
         1.5px  0     0 #fff;
}

#startOverlay button {
    font-size:18px;
    padding:12px 20px;
    border-radius:10px;
    border:none;
    background:#ffcc00;
    color:#000;
}

#startHint {
    margin-top:16px;
    font-family:Arial,sans-serif;
    font-size:11px;
    line-height:1.7;
    white-space:nowrap;
}

/* Ladefeedback: pulsiert dezent, solange im Hintergrund noch Assets laden.
   Bewusst textfrei (kein Übersetzungsbedarf für alle 26 Sprachen). */
.start-loading-hint {
    margin-top: 10px;
    font-size: 18px;
    opacity: 0.55;
    animation: start-loading-pulse 1.1s ease-in-out infinite;
}

@keyframes start-loading-pulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50%      { opacity: 0.75; transform: scale(1.12); }
}

/* RTL-Sprachen (Arabisch, Hebräisch) */
[dir="rtl"] #startOverlay {
    direction: rtl;
}
[dir="rtl"] #startHint {
    unicode-bidi: plaintext;
}

.pause-btn {
    position: absolute;
    /* var(--sat): Frame läuft jetzt bis unter Notch/Dynamic Island durch
       (siehe scaleFrame in game-loop.js) — der Button als einziges
       interaktives Element oben braucht den Sicherheitsabstand selbst. */
    top: calc(12px + var(--sat));
    right: 20px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: #ffcc00;
    color: #000;
    font-weight: bold;
    font-size: 20px;
    box-shadow: 0 3px #aa8800;
    z-index: 250;  /* über pause-overlay (200) und level-transition (200) */
    cursor: pointer;
}

.pause-btn:active {
    box-shadow: none;
    transform: translateY(2px);
}

/* ── Ad-Banner-Slots ─────────────────────────────────── */

.ad-banner-slot {
    width: 100%;
    min-height: 50px;
    background: #111;
    border-radius: 6px;
    overflow: hidden;
    text-align: center;
}

.ad-banner-slot.start-banner {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0px);
    left: 0;
    right: 0;
    height: 25vh;
    border-radius: 0;
    border-top: 2px solid #222;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Pause-Overlay — Fullscreen mit maximalem Ad-Bereich ─ */

#pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.93);
    display: flex;
    flex-direction: column;
    z-index: 200;
    font-family: Arial, sans-serif;
}

#pause-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    overflow: hidden;
}

.pause-title {
    padding: 16px;
    font-size: 22px;
    font-weight: bold;
    color: #ffcc00;
    letter-spacing: 2px;
    flex-shrink: 0;
    border-bottom: 1px solid #2a2a3a;
}

/* Ad-Fläche: füllt den gesamten verbleibenden Raum */
#pause-ad-banner {
    flex: 1;
    min-height: 80px;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* "Werbung entfernen" im Pause-Overlay */
#pause-box .ad-free-btn {
    flex-shrink: 0;
    width: 100%;
    padding: 11px 16px;
    border-radius: 0;
    border: none;
    border-top: 1px solid #2a2a3a;
    background: transparent;
    color: #ffcc00;
    font-size: 13px;
}

/* "Kauf wiederherstellen" im Pause-Overlay */
#pause-box .restore-btn {
    flex-shrink: 0;
    padding: 8px 16px;
    border-top: 1px solid #222;
    color: #555;
    font-size: 11px;
    width: 100%;
    text-align: center;
}

.pause-continue {
    flex-shrink: 0;
    width: 100%;
    padding: 16px;
    border-radius: 0;
    border: none;
    border-top: 2px solid #aa8800;
    background: #ffcc00;
    color: #000;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
}
.pause-continue:active { opacity: 0.75; }

/* ── Level-Transition — untere 30 % des Frames ───────── */

#level-transition {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30%;          /* ~253 px bei 844 px Framehöhe */
    background: rgba(10,10,20,0.97);
    border-top: 2px solid #ffcc00;
    z-index: 200;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
}

#lt-box {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Info-Leiste ganz oben: Level + Text | Countdown + ▶ */
#lt-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    gap: 10px;
    flex-shrink: 0;
    border-bottom: 1px solid #333;
}

#lt-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

#lt-level {
    font-size: 16px;
    font-weight: bold;
    color: #ffcc00;
    letter-spacing: 0.5px;
}

#lt-text {
    font-size: 12px;
    color: #ccc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#lt-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#lt-countdown {
    font-size: 13px;
    color: #888;
    min-width: 24px;
    text-align: right;
}

.lt-continue-btn {
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    background: #ffcc00;
    color: #000;
    font-weight: bold;
    font-size: 15px;
    cursor: pointer;
    white-space: nowrap;
}
.lt-continue-btn:active { opacity: 0.75; }
.lt-continue-btn:disabled { opacity: 0.4; cursor: default; }

/* Ad-Fläche: füllt den verbleibenden Raum (≈ 200 px) */
#lt-ad-banner {
    flex: 1;
    min-height: 80px;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* "Werbung entfernen" — schmale Zeile ganz unten */
#lt-noad-btn {
    flex-shrink: 0;
    width: 100%;
    padding: 8px;
    border-radius: 0;
    border: none;
    border-top: 1px solid #2a2a3a;
    background: transparent;
    color: #ffcc00;
    font-size: 12px;
    cursor: pointer;
}
#lt-noad-btn:active { opacity: 0.7; }

/* ── Ad-Free / Restore Buttons ───────────────────────── */

.ad-free-btn {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1.5px solid #ffcc00;
    background: transparent;
    color: #ffcc00;
    font-size: 14px;
    cursor: pointer;
}
.ad-free-btn:active { opacity: 0.7; }

.restore-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 0;
    text-decoration: underline;
}

/* ── Toast-Nachricht ────────────────────────────────── */

#ad-mgr-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #222;
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-family: Arial, sans-serif;
    font-size: 14px;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    white-space: nowrap;
}

#ad-mgr-toast.ad-mgr-toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
