/* ==========================================
   PLINGORIA ADVENTURE - HAUPT-STYLESHEET
   Das Spielfeld hat immer das Format der Design-Bilder (941 x 1672 Bild-Pixel).
   --u ist ein Bild-Pixel auf dem Bildschirm: Positionen und Schriftgrößen
   werden damit gerechnet, so passt alles auf die gemalten Felder.
   ========================================== */

:root {
    --bg: #1a1033;
    --bg-light: #3b2477;
    --panel: #2d1f57;
    --panel-border: #6a55b8;
    --panel-shadow: #140a2c;
    --gold: #ffc93c;
    --gold-light: #ffe58a;
    --gold-dark: #b87700;
    --orange: #ff7a1a;
    --blue: #2fa8e0;
    --red: #e8453c;
    --green: #3cc45a;
    --text: #ffffff;
    --field: rgba(18, 10, 36, 0.0); /* gemalte Felder sind schon dunkel */
    --outline: 0 0.06em 0 rgba(0, 0, 0, 0.55), 0 0 0.12em rgba(0, 0, 0, 0.6);
    /* Spiel-Schrift (PLINGORIA_Font_V3/plingoria-font.css), dahinter Ersatz für fehlende Zeichen */
    --font-display: "Plingoria Adventure", "Lilita One", "Arial Rounded MT Bold", system-ui, sans-serif;
    --font-body: system-ui, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { height: 100%; background: var(--bg); }

body {
    height: 100%;
    overflow: hidden;
    overflow: clip;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Abstand zu Notch und Home-Leiste, wenn das Spiel als App läuft */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

img { -webkit-user-drag: none; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }

/* Spiel-Schrift, wie bei Cartoon-Spielen */
#hud, #message, #village-message, .side-panel, #spin-button, #bet-box, #energy-bar, .plot-tag, #village-name,
#village-progress-box, .screen-title, .world-card-info, .world-card-status, #modal h2, .modal-button, .big-reward,
.float-text, .modal-result, .dig-spot, .house-emoji, #celebration, #modal.pack {
    font-family: var(--font-display);
    letter-spacing: 0.02em;
}

/* Unscharfer Hintergrund neben dem Spielfeld */
#backdrop {
    position: fixed;
    inset: -60px;
    background-color: var(--bg);
    filter: blur(28px) brightness(0.5) saturate(1.2);
}

/* ---------- Spielfeld ---------- */
#game-app {
    --avail-w: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
    --avail-h: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    --stage-w: min(var(--avail-w), var(--avail-h) * 941 / 1672);
    position: relative;
    flex-shrink: 0;
    width: var(--stage-w);
    height: calc(var(--stage-w) * 1672 / 941);
    overflow: hidden;
    overflow: clip; /* nie verschieben lassen (z. B. wenn ein Knopf den Fokus bekommt) */
    container-type: size;
    --u: calc(100cqw / 941);
    isolation: isolate; /* eigene Ebene: Fenster (#overlay) liegen immer über allem im Spielfeld */
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

/* Element auf einem gemalten Feld: --x/--y/--w/--h in Bild-Pixeln */
.at {
    position: absolute;
    left: calc(var(--x) * var(--u));
    top: calc(var(--y) * var(--u));
    width: calc(var(--w) * var(--u));
    height: calc(var(--h) * var(--u));
}

/* Unsichtbare Knöpfe auf gemalten Knöpfen: beim Drücken kurz aufhellen */
.hit { border-radius: 22%; }
.hit:active:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.hit:focus { outline: none; }
.hit:focus-visible, .side-panel:focus-visible, #spin-button:focus-visible, #energy-bar:focus-visible,
.plot-tag:focus-visible, .world-card:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 2px; }

/* Bildschirme: immer nur einer ist sichtbar */
.screen { position: absolute; inset: 0; z-index: 1; display: none; }
.screen.active { display: block; animation: fade-in 0.2s ease-out; }
.screen-bg { position: absolute; inset: 0; }
/* Hintergrund aus zwei Bild-Hälften (oben/unten), siehe Scene.background */
.split-bg { background-position: top, bottom; background-size: 100% 50.05%, 100% 50.05%; background-repeat: no-repeat; }

/* ---------- Kopfleiste ---------- */
/* Kopfleiste und Navigation liegen über dem ganzen Spielfeld, nur ihre Knöpfe fangen Klicks */
#hud, #tab-bar { position: absolute; inset: 0; z-index: 50; pointer-events: none; }
#hud button, #tab-bar button { pointer-events: auto; }
#hud .hud-field {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: calc(14 * var(--u));
    font-size: calc(34 * var(--u));
    text-shadow: var(--outline);
    white-space: nowrap;
    pointer-events: none;
}
#coin-box.gain { animation: coin-pulse 0.35s ease-in-out infinite alternate; }
#world-badge { border-radius: 50%; display: grid; place-items: center; }
#world-number {
    margin-top: calc(6 * var(--u));
    font-size: calc(36 * var(--u));
    font-weight: normal;
    color: #fff;
    text-shadow: 0 calc(3 * var(--u)) 0 #0d5a4a, 0 0 calc(6 * var(--u)) rgba(0, 0, 0, 0.7);
}
#shield-badge { border-radius: 50%; }
#shield-count {
    position: absolute;
    right: calc(-4 * var(--u));
    bottom: calc(-2 * var(--u));
    min-width: calc(38 * var(--u));
    height: calc(38 * var(--u));
    padding: 0 calc(6 * var(--u));
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: linear-gradient(#4fc3f7, #1b6fae);
    border: calc(3 * var(--u)) solid #fff;
    font-size: calc(24 * var(--u));
    line-height: 1;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}
#shield-badge.empty #shield-count { background: linear-gradient(#a59cc4, #5a5275); }
#menu-button { border-radius: 18%; }

/* ---------- Slot-Bildschirm ---------- */
.side-panel { border-radius: 14%; }
.side-panel:active { background: rgba(255, 255, 255, 0.12); }
.panel-field {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(4 * var(--u));
    font-size: max(10px, calc(26 * var(--u)));
    line-height: 1;
    text-shadow: var(--outline);
    white-space: nowrap;
}
.panel-meter {
    width: 82%;
    height: calc(12 * var(--u));
    background: rgba(0, 0, 0, 0.55);
    border-radius: calc(6 * var(--u));
    overflow: hidden;
}
#tula-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #4fc3f7, #7ef08a); transition: width 0.4s; }
#panel-tula.active .panel-field { color: #b3ecff; }
#panel-tula.active { animation: panel-glow 1.6s ease-in-out infinite; }
#panel-bonus.ready { animation: panel-glow 1.2s ease-in-out infinite; }
#panel-bonus.ready .panel-field { color: var(--gold-light); }

/* Tulas Schutzblase */
#tula-bubble {
    z-index: 3;
    border-radius: 50%;
    border: calc(4 * var(--u)) solid rgba(160, 230, 255, 0.85);
    background: radial-gradient(ellipse at center, rgba(120, 210, 255, 0.05), rgba(80, 180, 255, 0.35));
    box-shadow: 0 0 calc(30 * var(--u)) rgba(80, 200, 255, 0.7), inset 0 0 calc(40 * var(--u)) rgba(80, 200, 255, 0.5);
    pointer-events: none;
    opacity: 0;
    transform: scale(0.7);
    transition: opacity 0.4s, transform 0.4s;
}
#tula-bubble.on { opacity: 1; transform: scale(1); animation: dome 2s ease-in-out infinite; }

/* Walzen auf den hellen Feldern */
#reel-window { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.reel { overflow: hidden; overflow: clip; border-radius: calc(6 * var(--u)); }
.reel::after {
    content: "";
    position: absolute;
    inset: 0;
    /* obere und untere Reihe leicht abdunkeln: gewonnen wird nur in der Mitte */
    background: linear-gradient(rgba(70, 45, 15, 0.3), rgba(70, 45, 15, 0.08) 31%, transparent 34%, transparent 66%, rgba(70, 45, 15, 0.08) 69%, rgba(70, 45, 15, 0.3));
    pointer-events: none;
}
.reel-strip { position: absolute; inset: 0; display: flex; flex-direction: column; }
.cell { flex: 1; display: flex; align-items: center; justify-content: center; padding: 6%; min-height: 0; }
.cell img { width: 100%; height: 100%; object-fit: contain; }
.reel.spinning .reel-strip { animation: reel-spin 0.12s linear infinite; }
.reel.spinning img { filter: blur(2px); }
.reel.stopped .reel-strip { animation: reel-stop 0.3s ease-out; }

/* Gewinnlinie: Rahmen um die mittlere Reihe */
.winline {
    border: calc(5 * var(--u)) solid var(--gold);
    border-radius: calc(14 * var(--u));
    box-shadow: 0 0 calc(12 * var(--u)) var(--gold);
    opacity: 0.85;
}
#reel-window.win .winline { animation: glow 0.5s ease-in-out 2; }
#reel-window.big-win .winline { animation: glow 0.3s ease-in-out 6; }
#reel-window.big-win .reel { animation: big-win 0.5s ease-in-out 3; }

#float-layer { z-index: 5; }
.float-text {
    position: absolute;
    left: 50%;
    top: 45%;
    transform: translate(-50%, -50%);
    font-size: calc(76 * var(--u));
    color: var(--gold);
    text-shadow: 0 calc(5 * var(--u)) 0 #7a4a00, 0 0 calc(20 * var(--u)) rgba(0, 0, 0, 0.7);
    white-space: nowrap;
    animation: float-up 1.4s ease-out forwards;
}
.float-text.big { top: 30%; font-size: calc(104 * var(--u)); color: #fff; text-shadow: 0 calc(5 * var(--u)) 0 #c25b00, 0 0 calc(26 * var(--u)) var(--gold); }
.float-text.energy { color: #7ef08a; text-shadow: 0 calc(5 * var(--u)) 0 #11702a, 0 0 calc(20 * var(--u)) rgba(0, 0, 0, 0.7); }
.float-text.low { top: 72%; } /* zweiter Text gleichzeitig (z. B. Tagesbonus), damit sich nichts überdeckt */

/* Meldungen: kleine Pille zwischen Walzen und SPIN */
#message, #village-message {
    position: absolute;
    left: 50%;
    z-index: 30;
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: calc(860 * var(--u));
    padding: calc(8 * var(--u)) calc(24 * var(--u));
    background: rgba(20, 10, 40, 0.9);
    border: calc(3 * var(--u)) solid var(--gold);
    border-radius: calc(30 * var(--u));
    color: var(--gold);
    font-size: max(11px, calc(30 * var(--u)));
    line-height: 1.2;
    text-align: center;
    pointer-events: none;
    animation: message-in 0.25s ease-out;
}
#message { top: calc(1084 * var(--u)); }
#village-message { top: calc(1400 * var(--u)); }
#message:empty, #village-message:empty { display: none; }

/* SPIN auf dem gemalten Sechseck */
#spin-button {
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    line-height: 1;
    clip-path: polygon(11% 0, 89% 0, 100% 50%, 89% 100%, 11% 100%, 0 50%);
    -webkit-touch-callout: none;
    transition: background-color 0.1s;
}
#spin-label {
    font-size: calc(96 * var(--u));
    text-shadow: 0 calc(6 * var(--u)) 0 #0b5e8a, 0 0 calc(18 * var(--u)) rgba(0, 40, 80, 0.7);
    transition: transform 0.05s;
}
#spin-hint { margin-top: calc(6 * var(--u)); font-size: max(9px, calc(24 * var(--u))); text-shadow: var(--outline); opacity: 0.95; }
#spin-button:active { background: rgba(0, 30, 60, 0.18); }
/* Tastatur-Fokus: der Rahmen würde vom Sechseck abgeschnitten, deshalb leuchtet die Schrift */
#spin-button:focus-visible { outline: none; background: rgba(255, 230, 140, 0.2); }
#spin-button:focus-visible #spin-label { color: var(--gold-light); text-shadow: 0 calc(6 * var(--u)) 0 #0b5e8a, 0 0 calc(24 * var(--u)) var(--gold); }
#spin-button:active #spin-label { transform: translateY(calc(4 * var(--u))) scale(0.97); }
#spin-button.busy { background: rgba(10, 20, 40, 0.28); }
#spin-button.busy #spin-label { opacity: 0.75; }
#spin-button.auto { animation: auto-glow 1s ease-in-out infinite; }
#spin-button.auto #spin-label { color: #d8ffde; text-shadow: 0 calc(6 * var(--u)) 0 #11702a, 0 0 calc(18 * var(--u)) rgba(0, 60, 20, 0.7); }

/* Einsatz */
#bet-box {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: calc(10 * var(--u));
    padding-top: calc(6 * var(--u));
    text-shadow: var(--outline);
    pointer-events: none;
}
#bet-box small { font-size: max(9px, calc(22 * var(--u))); opacity: 0.85; }
#bet-display { font-size: calc(40 * var(--u)); color: var(--gold-light); }
#bet-minus:disabled, #bet-plus:disabled { background: rgba(20, 10, 40, 0.55); }

/* Energie-Feld */
#energy-bar { z-index: 2; border-radius: calc(20 * var(--u)); }
.energy-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 calc(16 * var(--u));
    overflow: hidden;
    border-radius: calc(10 * var(--u));
    font-size: calc(30 * var(--u));
    text-shadow: var(--outline);
}
#energy-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: linear-gradient(rgba(126, 240, 138, 0.95), rgba(31, 158, 62, 0.95));
    border-radius: inherit;
    transition: width 0.4s;
}
.energy-text, #energy-timer { position: relative; white-space: nowrap; }
#energy-timer { font-size: max(9px, calc(22 * var(--u))); }
#energy-bar.gain .energy-field { animation: energy-glow 0.35s ease-in-out infinite alternate; }
#energy-bar:active .energy-field { filter: brightness(1.15); }

/* Navigation unten: rote Punkt am Insel-Knopf, wenn etwas gebaut werden kann */
.tab { border-radius: calc(30 * var(--u)); }
.badge {
    position: absolute;
    top: calc(10 * var(--u));
    right: calc(44 * var(--u));
    width: calc(34 * var(--u));
    height: calc(34 * var(--u));
    border-radius: 50%;
    background: var(--red);
    border: calc(4 * var(--u)) solid #fff;
    animation: pulse 1s ease-in-out infinite;
}

/* ---------- Dorf bauen ---------- */
#village-name {
    z-index: 2600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(10 * var(--u));
    font-size: max(10px, calc(28 * var(--u)));
    text-shadow: var(--outline);
    white-space: nowrap;
    pointer-events: none;
}
#village-name small { font-size: 0.75em; color: var(--gold-light); }
#village-progress-box {
    z-index: 2600;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: calc(12 * var(--u));
    background: rgba(0, 0, 0, 0.25);
    pointer-events: none;
}
#village-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: linear-gradient(var(--gold-light), var(--gold) 55%, #e09a14);
    border-radius: inherit;
    transition: width 0.5s;
}
#village-percent { position: relative; font-size: max(10px, calc(28 * var(--u))); text-shadow: var(--outline); }
#village-chest { z-index: 2600; }
#village-chest.ready { animation: chest-wiggle 2.4s ease-in-out infinite; }

#village-fx { position: absolute; inset: 0; z-index: 1450; pointer-events: none; overflow: hidden; }
/* ohne eigenen z-index: Gebäude, Wetter (1450) und Preisschilder (2000) liegen so in einer Ebene */
#village-plots { position: absolute; inset: 0; }
#village-effects { position: absolute; inset: 0; z-index: 2500; pointer-events: none; }

/* Gebäude auf den Bauplätzen (auch in den kleinen Dorf-Ansichten) */
.plot { display: flex; align-items: flex-end; justify-content: center; }
#village-plots .plot { cursor: pointer; }
.house {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center bottom;
    transform-origin: center bottom;
    filter: drop-shadow(0 calc(8 * var(--u)) calc(6 * var(--u)) rgba(0, 0, 0, 0.35));
    transition: transform 0.15s;
}
#village-plots .plot:active .house { transform: scale(0.97); }
.house-emoji {
    width: auto;
    height: auto;
    font-size: calc(var(--h) * 0.82 * var(--u));
    line-height: 1;
}
.plot.damaged .house { filter: grayscale(0.85) brightness(0.55); transform: rotate(-4deg); }
.plot.just-built .house { animation: house-appear 0.8s ease-out both; }
.smoke {
    position: absolute;
    left: 45%;
    top: 5%;
    z-index: 2;
    font-size: calc(var(--w) * 0.28 * var(--u));
    animation: smoke 2.2s ease-out infinite;
}
.build-cloud { z-index: 2; pointer-events: none; }

/* Preisschild unter jedem Bauplatz */
.plot-tag {
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(2 * var(--u));
    background: rgba(25, 14, 50, 0.88);
    border: calc(4 * var(--u)) solid var(--gold);
    border-radius: calc(20 * var(--u));
    box-shadow: 0 calc(5 * var(--u)) 0 rgba(0, 0, 0, 0.45);
    line-height: 1;
    text-shadow: 0 1px 0 #000;
}
.plot-tag:active { transform: translateY(calc(3 * var(--u))); box-shadow: 0 calc(2 * var(--u)) 0 rgba(0, 0, 0, 0.45); }
.tag-name { display: none; } /* Name steht im aria-label und in der Meldung beim Bauen */
.tag-dots { color: var(--gold); font-family: var(--font-body); font-size: calc(18 * var(--u)); letter-spacing: calc(3 * var(--u)); }
.tag-price { font-size: max(11px, calc(32 * var(--u))); }
.plot-tag.too-expensive { border-color: #8a80aa; }
.plot-tag.too-expensive .tag-price { color: #c9c2e0; }
.plot-tag.damaged { border-color: var(--red); background: rgba(90, 15, 15, 0.9); }
.plot-tag.maxed { border-color: var(--green); }
.plot-tag.maxed .tag-price { color: #9ff0ac; }

/* Wetter */
.fx { position: absolute; }
.fx-snow { width: 1cqh; height: 1cqh; border-radius: 50%; background: #fff; animation: fall 6s linear infinite; }
.fx-sparkle { width: 1cqh; height: 1cqh; border-radius: 50%; background: #f4ff8a; box-shadow: 0 0 1.6cqh #f4ff8a; animation: firefly 4s ease-in-out infinite; }
.fx-embers { width: 0.9cqh; height: 0.9cqh; border-radius: 50%; background: #ffb347; box-shadow: 0 0 1.2cqh #ff6a00; animation: rise 5s linear infinite; }
.fx-stars { width: 0.7cqh; height: 0.7cqh; border-radius: 50%; background: #fff; box-shadow: 0 0 1cqh #b9e6ff; animation: twinkle 3s ease-in-out infinite; }

/* ---------- Weltkarte ---------- */
#screen-map {
    z-index: 100;
    overflow-y: auto;
    padding: calc(30 * var(--u)) calc(40 * var(--u)) calc(60 * var(--u));
    background: radial-gradient(circle at 50% -10%, var(--bg-light), var(--bg) 70%);
}
#map-head { position: sticky; top: calc(-30 * var(--u)); z-index: 5; display: flex; align-items: center; justify-content: center; padding: calc(16 * var(--u)) 0; background: linear-gradient(var(--bg) 70%, transparent); }
.screen-title { color: var(--gold); font-size: calc(68 * var(--u)); font-weight: normal; text-shadow: 0 calc(4 * var(--u)) 0 #000; }
#map-close {
    position: absolute;
    right: 0;
    width: calc(84 * var(--u));
    height: calc(84 * var(--u));
    border-radius: 50%;
    background: linear-gradient(#4b3591, #2d1f57);
    border: calc(4 * var(--u)) solid var(--gold);
    font-size: calc(40 * var(--u));
}

#world-list { position: relative; display: flex; flex-direction: column; gap: calc(36 * var(--u)); isolation: isolate; }
/* Gestrichelter Weg zwischen den Welten */
#world-list::before {
    content: "";
    position: absolute;
    left: 50%;
    top: calc(40 * var(--u));
    bottom: calc(40 * var(--u));
    z-index: -1;
    border-left: calc(10 * var(--u)) dashed rgba(255, 201, 60, 0.45);
}
.world-card {
    position: relative;
    height: calc(300 * var(--u));
    flex-shrink: 0;
    overflow: hidden;
    border-radius: calc(36 * var(--u));
    border: calc(6 * var(--u)) solid var(--panel-border);
    box-shadow: 0 calc(10 * var(--u)) 0 var(--panel-shadow);
    text-align: left;
}
.world-card:nth-of-type(odd) { margin-right: 8%; }
.world-card:nth-of-type(even) { margin-left: 8%; }
/* Zusammenfassung der nicht gezeigten Welten (Weltkarte zeigt nur einen Ausschnitt, worldMap.js) */
.world-more {
    align-self: center;
    padding: calc(10 * var(--u)) calc(32 * var(--u));
    border-radius: 999px;
    background: rgba(20, 10, 40, 0.8);
    border: calc(4 * var(--u)) solid var(--panel-border);
    font-family: var(--font-display);
    font-size: calc(32 * var(--u));
}
/* Ganzes Welt-Bild, die Karte zeigt den mittleren Streifen mit den Bauplätzen */
/* Kleine Vorschau weltNN_karte.avif (ganzes Bild in einer Datei, nicht die großen Hälften) */
.world-card-image { position: absolute; left: 0; top: 50%; width: 100%; aspect-ratio: 941 / 1672; transform: translateY(-50%); background: center / 100% 100% no-repeat; }
.world-card.current, .world-card.here { border-color: var(--gold); box-shadow: 0 calc(10 * var(--u)) 0 var(--gold-dark), 0 0 calc(40 * var(--u)) rgba(255, 201, 60, 0.55); }
.world-card.done { border-color: var(--green); }
.world-card.locked .world-card-image { filter: brightness(0.38) saturate(0.4); }
.world-card.locked::after {
    content: "🔒";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: calc(96 * var(--u));
    filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.6));
}
.world-card-info {
    position: absolute;
    left: calc(16 * var(--u));
    top: calc(16 * var(--u));
    z-index: 1;
    padding: calc(8 * var(--u)) calc(20 * var(--u));
    background: rgba(20, 10, 40, 0.8);
    border-radius: calc(22 * var(--u));
    line-height: 1.1;
}
.world-card-info small { display: block; font-size: calc(26 * var(--u)); opacity: 0.8; }
.world-card-info b { font-size: calc(42 * var(--u)); font-weight: normal; }
.world-card-status {
    position: absolute;
    right: calc(16 * var(--u));
    top: calc(16 * var(--u));
    z-index: 1;
    padding: calc(6 * var(--u)) calc(20 * var(--u));
    border-radius: 999px;
    background: #5a5275;
    font-size: calc(30 * var(--u));
}
.world-card.done .world-card-status { background: var(--green); }
.world-card.current .world-card-status { background: var(--gold); color: #4a2a00; }

/* ---------- Welt geschafft (Banner-Animation) ---------- */
#celebration { position: absolute; inset: 0; z-index: 200; background: rgba(10, 5, 25, 0.55); animation: fade-in 0.2s ease-out; }
.celebration-frame { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.celebration-title {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(78 * var(--u));
    color: #fff;
    text-shadow: 0 calc(6 * var(--u)) 0 #8a1010, 0 0 calc(18 * var(--u)) rgba(120, 0, 0, 0.6);
    white-space: nowrap;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.celebration-title.shown { opacity: 1; transform: scale(1); }
.celebration-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(28 * var(--u));
    text-align: center;
    font-size: calc(42 * var(--u));
    line-height: 1.25;
    text-shadow: 0 calc(3 * var(--u)) 0 #000, 0 0 calc(14 * var(--u)) rgba(0, 0, 0, 0.8);
    background: radial-gradient(ellipse at center, rgba(10, 5, 25, 0.8), rgba(10, 5, 25, 0.55) 45%, transparent 72%);
    animation: pop-in 0.3s ease-out;
}
.celebration-text b { color: var(--gold-light); font-weight: normal; }
.celebration-text .big-reward { font-size: calc(80 * var(--u)); }
.celebration-next {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(#3b2a14, #1c1206);
    border: calc(5 * var(--u)) solid var(--gold);
    border-radius: 999px;
    box-shadow: 0 0 calc(24 * var(--u)) rgba(255, 180, 40, 0.7);
    font-size: calc(40 * var(--u));
    color: #fff;
    animation: pop-in 0.3s ease-out;
}

/* ---------- Fenster (Angriff, Raubzug, Hinweise) ---------- */
#overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(8, 4, 20, 0.8);
    animation: fade-in 0.15s ease-out;
}

#modal {
    width: 100%;
    max-width: 420px;
    max-height: 100%;
    overflow-y: auto;
    padding: 18px 16px 16px;
    background: linear-gradient(#3b2a73, #241a4d);
    border: 3px solid var(--gold);
    border-radius: 22px;
    box-shadow: 0 6px 0 var(--gold-dark), 0 16px 40px rgba(0, 0, 0, 0.6);
    text-align: center;
    animation: pop-in 0.25s ease-out;
}
#modal.action { max-width: 470px; padding: 12px; }
#modal h2 { color: var(--gold); font-size: 1.5rem; font-weight: normal; margin-bottom: 8px; text-shadow: 0 2px 0 #000; }
.modal-text { line-height: 1.4; }
.modal-text p + p, .modal-text p + .help-list, .modal-text .help-list + p, .modal-text p + .modal-scene { margin-top: 8px; }

.modal-button {
    width: 100%;
    margin-top: 14px;
    padding: 12px;
    border-radius: 14px;
    background: linear-gradient(#5a43a8, #3b2a73);
    border: 2px solid var(--panel-border);
    box-shadow: 0 4px 0 var(--panel-shadow);
    font-size: 1.1rem;
    text-shadow: 0 1px 0 #000;
}
.modal-button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--panel-shadow); }
.modal-button.primary { background: linear-gradient(#7ef08a, #2fbf4f 60%, #1d9a3a); border-color: #d4ffd9; box-shadow: 0 4px 0 #11702a; }
.modal-button.danger { border-color: var(--red); }
.modal-button:focus { outline: none; }
.modal-button:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 3px; } /* nur bei Tastatur-Bedienung */
.modal-row { display: flex; gap: 10px; }

.modal-result { min-height: 2.8em; margin-top: 10px; font-size: 1.15rem; line-height: 1.35; }
.modal-result b { color: var(--gold); font-weight: normal; }
.big-reward { font-size: 2rem; color: var(--gold); text-shadow: 0 3px 0 #7a4a00; }
/* Goldmünze im Text (Scene.goldIcon): so hoch wie die Schrift, auf der Grundlinie wie ein Emoji */
.coin-inline { height: 1.05em; width: auto; vertical-align: -0.18em; filter: drop-shadow(0 0.06em 0 rgba(0, 0, 0, 0.45)); }
.coin-inline.small { height: 0.8em; vertical-align: -0.1em; }

/* Kleine Dorf-Ansicht (Ausschnitt der Welt-Karte) in Fenstern */
.scene {
    position: relative;
    width: 100%;
    aspect-ratio: 941 / 800;
    overflow: hidden;
    overflow: clip; /* nie verschieben lassen (Fokus auf Zielscheiben) */
    container-type: inline-size;
    --u: calc(100cqw / 941);
}
.scene-world {
    position: absolute;
    left: 0;
    top: calc(var(--view-top) * -1 * var(--u));
    width: 100%;
    height: calc(1672 * var(--u));
}
.modal-scene { overflow: hidden; overflow: clip; border-radius: 14px; border: 2px solid var(--gold); }

/* Angriff und Raubzug */
.action-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; text-align: left; }
#modal .action-header h2 { margin-bottom: 2px; }
.action-header p { font-size: 0.95rem; }
.action-coin { width: 64px; height: 64px; flex-shrink: 0; animation: bounce 0.6s ease-out; }
.action-scene { position: relative; overflow: hidden; overflow: clip; border-radius: 16px; border: 3px solid var(--gold); }

/* Punkte in Bild-Koordinaten der Dorf-Ansicht (--px/--py) */
.target, .attacker, .dig-spot {
    position: absolute;
    left: calc(var(--px) * var(--u));
    top: calc(var(--py) * var(--u));
}
.target {
    z-index: 3000;
    transform: translate(-50%, -50%);
    font-size: calc(90 * var(--u));
    line-height: 1;
    filter: drop-shadow(0 0 6px #ff2d2d);
    animation: target-pulse 0.9s ease-in-out infinite;
}
.scene.aimed .target { display: none; }

.attacker {
    z-index: 3001;
    width: calc(220 * var(--u));
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: left 0.5s ease-in, top 0.5s ease-in, opacity 0.3s;
}
.attacker.flying { animation: spin-fly 0.5s linear; }
.attacker.done { opacity: 0; transition-delay: 0s, 0s, 0.25s; }

.boom {
    position: absolute;
    left: 50%;
    top: 10%;
    z-index: 3;
    font-size: calc(var(--w) * 0.5 * var(--u));
    transform: translateX(-50%);
    animation: boom 0.7s ease-out forwards;
}
.plot.hit { animation: shake 0.5s; }

.shield-dome {
    position: absolute;
    left: -6%;
    right: -6%;
    top: calc(540 * var(--u));
    height: calc(1000 * var(--u));
    z-index: 2999;
    display: flex;
    justify-content: center;
    border-radius: 50%;
    border: 3px solid rgba(160, 230, 255, 0.9);
    background: radial-gradient(ellipse at center, rgba(120, 210, 255, 0.1), rgba(80, 180, 255, 0.45));
    box-shadow: 0 0 30px rgba(80, 200, 255, 0.8), inset 0 0 40px rgba(80, 200, 255, 0.6);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.shield-dome span { margin-top: calc(160 * var(--u)); font-size: calc(200 * var(--u)); }
.scene.shielded .shield-dome { opacity: 1; transform: scale(1); }

.dig-spot {
    z-index: 3000;
    width: calc(130 * var(--u));
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: radial-gradient(#7a4e28, #4a2d14);
    border: 3px dashed #e0a868;
    color: #ffe2a8;
    font-size: calc(30 * var(--u));
    line-height: 1.1;
    animation: target-pulse 1.1s ease-in-out infinite;
}
.dig-mark { font-size: 1.8em; color: #ff5a4f; text-shadow: 0 2px 0 #000; }
.dig-spot.digging { animation: dig-shake 0.15s linear infinite; }
.digger { width: 90%; }
.dig-spot.dug, .dig-spot.missed { animation: none; border-style: solid; }
.dig-spot.dug { background: radial-gradient(#4a2d14, #24150b); border-color: var(--gold); }
.dig-spot.missed { opacity: 0.6; background: radial-gradient(#4a2d14, #24150b); }
.find-icon { font-size: 1.7em; }
.dig-spot small { font-size: 0.85em; text-shadow: 0 1px 0 #000; }

/* Anleitung und Menü */
.help-list { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.help-list li { display: flex; align-items: center; gap: 10px; }
.help-list img { width: 44px; height: 44px; flex-shrink: 0; }
.menu-list .modal-button { margin-top: 10px; }
.menu-hint { margin-top: 14px; font-size: 0.85rem; opacity: 0.75; line-height: 1.4; }
.menu-version { margin-top: 10px; font-size: 0.75rem; opacity: 0.5; }

/* Notfallpaket ("Energie aufgebraucht?"): Texte auf der gemalten Vorlage (Bild-Pixel 1024 x 1536) */
#modal.pack {
    position: relative;
    width: min(400px, 94vw, calc((100dvh - 24px) * 1024 / 1536));
    max-width: none;
    max-height: none;
    aspect-ratio: 1024 / 1536;
    overflow: visible;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: url("../images/fenster/energie_leer.avif") center / 100% 100% no-repeat;
    container-type: inline-size;
    --u: calc(100cqw / 1024);
}
#modal.pack .pack-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    font-size: calc(76 * var(--u));
    line-height: 1.05;
    color: var(--gold);
    text-shadow: 0 calc(6 * var(--u)) 0 #6b2f00, 0 0 calc(14 * var(--u)) rgba(0, 0, 0, 0.6);
}
#modal.pack .pack-title span { color: #8fe3ff; text-shadow: 0 calc(6 * var(--u)) 0 #0b4f8a, 0 0 calc(14 * var(--u)) rgba(0, 0, 0, 0.6); }
.pack-ribbon { display: grid; place-items: center; font-size: calc(52 * var(--u)); color: #fff; text-shadow: 0 calc(4 * var(--u)) 0 #7a0c2a; }
.pack-info { display: grid; place-items: center; font-size: calc(38 * var(--u)); text-shadow: 0 calc(3 * var(--u)) 0 #000; }
.pack-amount { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.pack-amount small { font-size: calc(28 * var(--u)); color: #c9e9ff; }
.pack-amount b { font-size: calc(60 * var(--u)); font-weight: normal; color: var(--gold-light); text-shadow: 0 calc(4 * var(--u)) 0 #000; }
.pack-buy {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(4 * var(--u));
    border-radius: calc(70 * var(--u));
    line-height: 1;
    color: #fff;
}
.pack-buy b { font-size: calc(62 * var(--u)); font-weight: normal; text-shadow: 0 calc(5 * var(--u)) 0 #0d6b25; }
.pack-buy small { font-size: calc(32 * var(--u)); text-shadow: 0 calc(3 * var(--u)) 0 #0d6b25; }
.pack-buy:not(.primary) { background: rgba(35, 25, 60, 0.6); }
.pack-buy:not(.primary) small { color: #ffd9d9; }
.pack-buy:active { filter: brightness(1.1); transform: translateY(calc(3 * var(--u))); }
.pack-buy.shake { animation: shake 0.45s; }
.pack-wait { border-radius: 999px; font-size: calc(24 * var(--u)); white-space: nowrap; color: #eadfff; text-shadow: 0 2px 0 #000; }
.pack-wait:active, .pack-close:active { background: rgba(255, 255, 255, 0.15); }
.pack-close { border-radius: 50%; }

/* ---------- Animationen ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes message-in { from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes bounce { 0% { transform: scale(0.3); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes coin-pulse { from { transform: scale(1); } to { transform: scale(1.06); } }
@keyframes energy-glow { from { box-shadow: inset 0 0 0 rgba(126, 240, 138, 0); } to { box-shadow: inset 0 0 calc(18 * var(--u)) #b6ffbf; } }
@keyframes panel-glow { 0%, 100% { box-shadow: 0 0 0 rgba(255, 220, 120, 0); } 50% { box-shadow: 0 0 calc(30 * var(--u)) rgba(255, 220, 120, 0.85); } }
@keyframes auto-glow { 0%, 100% { background: rgba(60, 220, 100, 0.12); } 50% { background: rgba(60, 220, 100, 0.32); } }
@keyframes chest-wiggle { 0%, 80%, 100% { transform: rotate(0); } 84% { transform: rotate(-6deg); } 88% { transform: rotate(6deg); } 92% { transform: rotate(-4deg); } 96% { transform: rotate(3deg); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 calc(12 * var(--u)) var(--gold); } 50% { box-shadow: 0 0 calc(44 * var(--u)) var(--gold), inset 0 0 calc(26 * var(--u)) var(--gold); } }
@keyframes big-win { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.25) drop-shadow(0 0 calc(20 * var(--u)) var(--gold)); } }
@keyframes float-up {
    0% { transform: translate(-50%, -20%) scale(0.6); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    70% { opacity: 1; }
    100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}
@keyframes reel-spin { from { transform: translateY(-6%); } to { transform: translateY(6%); } }
@keyframes reel-stop { 0% { transform: translateY(8%); } 60% { transform: translateY(-3%); } 100% { transform: translateY(0); } }
@keyframes house-appear {
    0%, 45% { opacity: 0; transform: scale(0.6); }
    75% { opacity: 1; transform: scale(1.08); }
    100% { opacity: 1; transform: scale(1); }
}
@keyframes smoke { 0% { transform: translateY(0) scale(0.6); opacity: 0.9; } 100% { transform: translateY(-0.6em) scale(1.4); opacity: 0; } }
@keyframes fall { from { transform: translateY(-20cqh); } to { transform: translateY(110cqh); } }
@keyframes rise { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-60cqh); opacity: 0; } }
@keyframes firefly { 0%, 100% { transform: translate(0, 0); opacity: 0.2; } 50% { transform: translate(3cqw, -5cqh); opacity: 1; } }
@keyframes twinkle { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }
@keyframes dome { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }
@keyframes target-pulse { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.12); } }
@keyframes dig-shake { 0%, 100% { transform: translate(-50%, -50%) rotate(-6deg); } 50% { transform: translate(-50%, -50%) rotate(6deg); } }
@keyframes spin-fly { from { rotate: 0deg; } to { rotate: 360deg; } }
@keyframes boom { 0% { transform: translateX(-50%) scale(0.3); opacity: 1; } 70% { opacity: 1; } 100% { transform: translateX(-50%) scale(1.8); opacity: 0; } }
@keyframes shake {
    0%, 100% { translate: 0; }
    20% { translate: -6px; } 40% { translate: 6px; }
    60% { translate: -4px; } 80% { translate: 4px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
