*{box-sizing:border-box}
:root{color-scheme:dark;--panel:#172532;--panel2:#203545;--ink:#edf5f7;--muted:#a9bdc8;--gold:#f6c66b;--green:#7ed6a0;--red:#ff8379}
body{margin:0;background:radial-gradient(ellipse at 50% 0,#243e50 0,#111c27 62%);color:var(--ink);font-family:Inter,Segoe UI,Arial,sans-serif;min-height:100vh;padding:22px}
.shell{max-width:1320px;margin:auto}
.topbar{display:flex;justify-content:space-between;align-items:center;gap:20px;margin:0 0 16px}
.eyebrow{font-size:11px;letter-spacing:2px;color:var(--gold);font-weight:800}
h1{font-size:clamp(28px,4vw,42px);margin:5px 0 2px;letter-spacing:-1px}
.topbar p{margin:0;color:var(--muted)}
.top-actions{display:flex;gap:9px}
button{border:1px solid #536d7d;background:#263d4d;color:white;border-radius:10px;padding:11px 17px;font-weight:750;cursor:pointer}
button:hover:not(:disabled){filter:brightness(1.16)}
button:disabled{opacity:.45;cursor:not-allowed}
button.primary{background:linear-gradient(135deg,#e9ad4f,#d88738);border:0;color:#1b2630}
.hud{display:grid;grid-template-columns:repeat(4,minmax(90px,1fr)) minmax(190px,1.5fr);gap:9px;margin-bottom:10px}
.stat{background:linear-gradient(145deg,#203646,#172936);border:1px solid #3a5362;border-radius:11px;padding:10px 13px;min-height:65px}
.stat span{display:block;font-size:10px;letter-spacing:1.3px;color:#a9c0cc;font-weight:800}
.stat strong{display:block;font-size:22px;margin-top:4px}
.stat small{display:block;color:#b5c8d1;font-size:11px;margin-top:1px}
.game-wrap{position:relative;border:1px solid #526c7b;border-radius:14px;overflow:hidden;background:#79c9e8;box-shadow:0 20px 60px #0006}
canvas{display:block;width:100%;height:auto;aspect-ratio:1200/650;cursor:crosshair;touch-action:none}
.overlay{position:absolute;inset:0;display:grid;place-items:center;background:#0b1828a8;backdrop-filter:blur(4px)}
.overlay.hidden{display:none}
.dialog{width:min(440px,90%);text-align:center;padding:27px;background:#182b39f2;border:1px solid #6d8796;border-radius:18px;box-shadow:0 18px 55px #0008}
.dialog-mark{width:52px;height:52px;display:grid;place-items:center;margin:0 auto 12px;border-radius:15px;background:#f2bd60;color:#23313b;font-weight:950;font-size:19px}
.dialog h2{margin:0 0 9px;font-size:25px}
.dialog p{color:#c0d0d8;line-height:1.5;margin:0 0 20px}
.helpbar{display:flex;flex-wrap:wrap;gap:14px 22px;align-items:center;padding:13px 3px;color:#c2d1d9;font-size:12px}
kbd{background:#253b4a;border:1px solid #536d7d;border-radius:5px;padding:4px 7px;color:#fff;font-weight:700;margin-right:5px}
.legend{display:inline-block;width:9px;height:9px;border-radius:50%;margin-right:6px}
.legend.danger{background:#ff786e;box-shadow:0 0 9px #ff786e}
.legend.safe{background:#82d7a3;box-shadow:0 0 9px #82d7a3}
.reload{margin-left:auto;min-width:180px;display:flex;align-items:center;gap:9px}
.meter{height:7px;width:90px;background:#354c5a;border-radius:9px;overflow:hidden}
.meter i{display:block;height:100%;width:100%;background:#f1bd61;transition:width .08s linear}
.note{color:#829aa8;font-size:11px;margin:2px 0}
@media(max-width:760px){body{padding:10px}.topbar{align-items:flex-start;flex-direction:column}.hud{grid-template-columns:repeat(2,1fr)}.stat.ammo{grid-column:span 2}.helpbar{gap:10px}.reload{margin-left:0;width:100%}}

.landscape-panel{background:linear-gradient(145deg,#203646,#172936);border:1px solid #3a5362;border-radius:12px;padding:12px;margin:0 0 10px}
.landscape-heading{display:flex;justify-content:space-between;align-items:baseline;gap:12px;margin-bottom:9px}
.landscape-heading strong{font-size:13px;letter-spacing:.4px}
.landscape-heading span{font-size:11px;color:var(--muted)}
.landscape-options{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:8px}
button.landscape-choice{display:flex;flex-direction:column;align-items:center;gap:3px;padding:8px 5px;background:#1b2d39;border:1px solid #496171;border-radius:9px;font-size:12px}
button.landscape-choice span{font-size:21px;line-height:1.2}
button.landscape-choice small{font-size:10px;color:#a9bdc8;font-weight:500;text-align:center}
button.landscape-choice.selected{border-color:#f6c66b;background:#39402f;box-shadow:inset 0 0 0 1px #f6c66b66}
button.landscape-choice:disabled{opacity:.65;cursor:default}
@media(max-width:900px){.landscape-options{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:520px){.landscape-heading{align-items:flex-start;flex-direction:column;gap:4px}.landscape-options{grid-template-columns:repeat(2,minmax(0,1fr))}}

/* Version 0.6: Farm health meter and critical warning */
.health-track{height:7px;margin-top:7px;background:#354c5a;border-radius:9px;overflow:hidden}
.health-track i{display:block;height:100%;width:100%;background:linear-gradient(90deg,#d95e55,#e9b84f 55%,#79c98c);border-radius:9px;transition:width .25s ease}
.stat.farm-health.critical{border-color:#ff625b;box-shadow:0 0 0 1px #ff625b66,inset 0 0 22px #b72f2f35;animation:critical-pulse 1s ease-in-out infinite alternate}
.stat.farm-health.critical strong{color:#ff8178}
.stat.farm-health.critical .health-track i{background:#f04d4d}
@keyframes critical-pulse{from{box-shadow:0 0 0 1px #ff625b55,inset 0 0 10px #b72f2f22}to{box-shadow:0 0 0 2px #ff625baa,inset 0 0 24px #b72f2f66}}


/* Music control */
#musicBtn[aria-pressed="true"] { border-color: #78b99a; color: #c8f2d8; }
#musicBtn { white-space: nowrap; }



/* ==========================================
   CHEMTRAIL DEFENDER – MOBILE OVERLAY SYSTEM
   ========================================== */

@media (max-width: 900px) {

  /* Vollbild als gemeinsame Bühne */
  body.mobile-game-active .game-wrap {
    display: block;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    background: #79c9e8;
  }

  /* Spielfeld füllt die Bühne */
  body.mobile-game-active .mobile-playfield {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 0;
    background: #79c9e8;
  }

  body.mobile-game-active #game {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    touch-action: none;
  }

  /* Statusanzeigen oben als transparente Ebene */
  body.mobile-game-active .mobile-hud {
    position: absolute;
    z-index: 10;
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    margin: 0;
    pointer-events: none;
  }

  body.mobile-game-active .mobile-hud .stat {
    min-width: 0;
    min-height: 0;
    padding: 5px;
    text-align: center;
    border: 0;
    border-radius: 6px;
    background: rgba(255,255,255,.22);
    box-shadow: none;
    overflow: hidden;
  }

  body.mobile-game-active .mobile-hud .stat span {
    color: #142d3a;
    font-size: 9px;
    letter-spacing: 0;
    white-space: nowrap;
  }

  body.mobile-game-active .mobile-hud .stat strong {
    color: #102633;
    font-size: clamp(12px, 2.5vw, 20px);
    margin-top: 2px;
    white-space: nowrap;
    text-shadow: 0 1px 2px #ffffff88;
  }

  body.mobile-game-active .mobile-hud .stat small {
    color: #193947;
    font-size: 9px;
  }

  body.mobile-game-active .mobile-hud .health-track {
    height: 4px;
    margin-top: 3px;
  }

  /* Alte untere Leiste wird zur transparenten Overlay-Ebene */
  body.mobile-game-active .mobile-bottom-bar {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 12;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    pointer-events: none;
  }

  /* Joystick fest links unten */
  body.mobile-game-active .mobile-joystick-area {
    display: flex;
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: center;
    gap: 3px;
    pointer-events: auto;
  }

  body.mobile-game-active .mobile-aim-area {
    display: flex;
    position: relative;
    left: auto;
    bottom: auto;
    width: 88px;
    height: 88px;
    border: 3px solid #ffffffdd;
    border-radius: 50%;
    background: #17253244;
    align-items: center;
    justify-content: center;
    touch-action: none;
    pointer-events: auto;
  }

  body.mobile-game-active .mobile-joystick-knob {
    width: 34px;
    height: 34px;
    border: 2px solid white;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffffff, #9eb8c5);
    box-shadow: 0 2px 8px #0008;
    pointer-events: none;
  }

  body.mobile-game-active .mobile-control-label {
    color: white;
    font-size: 10px;
    font-weight: 900;
    text-shadow: 0 1px 4px #000;
  }

  /* Ereignisanzeige transparent über dem Spielfeld */
  body.mobile-game-active .mobile-event-panel {
    position: absolute;
    left: 50%;
    bottom: 105px;
    transform: translateX(-50%);
    width: min(55%, 420px);
    min-width: 180px;
    padding: 5px 10px;
    color: #ffffff;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
    text-shadow: 0 2px 4px #000c;
    overflow: hidden;
    pointer-events: none;
  }

  body.mobile-game-active .mobile-event-panel strong {
    display: block;
    color: #ffe09a;
    font-size: 11px;
    margin-bottom: 3px;
  }

  /* Raketen- und Nachladeanzeige unten mittig */
  body.mobile-game-active .mobile-weapon-status {
    display: flex;
    position: absolute;
    z-index: 13;
    left: calc(50% - 290px);
    bottom: max(12px, env(safe-area-inset-bottom));
    transform: none;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,.24);
    color: #142d3a;
    pointer-events: none;
  }

  body.mobile-game-active .mobile-rocket-icon {
    font-size: 22px;
  }

  body.mobile-game-active .mobile-reload {
    min-width: 70px;
    font-size: 10px;
    font-weight: 800;
    color: #142d3a;
  }

  body.mobile-game-active .mobile-reload .meter {
    display: block;
    width: 70px;
    height: 5px;
    margin-top: 3px;
  }

  /* Pause und Spiel beenden unten mittig */
  body.mobile-game-active .mobile-action-controls {
    display: flex;
    position: absolute;
    left: calc(50% + 6px);
    bottom: max(12px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    flex-direction: row;
    align-items: center;
    gap: 6px;
    pointer-events: auto;
  }

  body.mobile-game-active .mobile-action-controls > button:not(.fire-button) {
    width: auto;
    padding: 7px 10px;
    font-size: 11px;
    border-radius: 7px;
  }

  /* Pause leicht nach links, Spiel beenden etwas weiter nach rechts */
  body.mobile-game-active #pauseBtn {
    transform: translateX(-47px);
  }

  body.mobile-game-active .exit-game-button {
    margin-left: 8px;
    transform: translateX(48px);
  }

  /* Feuerknopf rechts unten */
  body.mobile-game-active .fire-button {
    display: flex;
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    width: 82px;
    height: 82px;
    min-width: 82px;
    min-height: 82px;
    padding: 0;
    border-radius: 50%;
    font-size: 15px;
    font-weight: 900;
    line-height: 1;
    text-align: center;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
  }

  /* Spiel beenden sitzt direkt neben Pause in der unteren Aktionsleiste */
  body.mobile-game-active .exit-game-button {
    display: block;
    position: static;
    width: auto;
    padding: 7px 10px;
    font-size: 11px;
    border-radius: 7px;
    pointer-events: auto;
  }

  /* Reservierter Platz für spätere saisonale Events */
  body.mobile-game-active .event-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 30;
    pointer-events: none;
  }

  body.mobile-game-active .event-overlay.active {
    display: block;
  }
}
