/* ===== Minigames (js/minigame-ui.js) ===== */

/* Kühlungs-Leiste unten: liegt über allen Fenstern (Modal z-index 100). */
#mg-hud {
  position: absolute; z-index: 140;
  left: calc(10px + var(--sal)); right: calc(10px + var(--sar));
  bottom: calc(10px + var(--sab));
  max-width: 620px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 8px;
  background: linear-gradient(180deg, rgba(24,30,40,.94), rgba(14,18,26,.94));
  border: 2px solid rgba(255,255,255,.12);
  border-radius: 18px;
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
  color: #eef3f8;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
#mg-hud.hidden { display: none; }
#mg-hud.hot { border-color: #ff4b3a; animation: mg-hot .5s ease-in-out infinite alternate; }
#mg-hud.surge:not(.hot) { border-color: #ff9a2e; }
#mg-hud.done { border-color: #39d06a; }
#mg-hud.boom { animation: mg-shake .12s linear 6; }
@keyframes mg-hot { to { box-shadow: 0 0 0 4px rgba(255,75,58,.35), 0 8px 22px rgba(0,0,0,.35); } }
@keyframes mg-shake { 25% { transform: translate(-5px, 2px); } 75% { transform: translate(5px, -2px); } }

#mg-exit {
  flex: none; width: 34px; height: 34px; border-radius: 10px;
  border: none; background: rgba(255,255,255,.1); color: #cfd8e3;
  font-size: 15px; font-weight: 800; cursor: pointer; align-self: flex-start;
}
.mg-meter { flex: 1; min-width: 0; }
.mg-meter-head, .mg-meter-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mg-meter-head b { white-space: nowrap; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.mg-meter-head span { font-size: 12px; font-weight: 800; color: #aeb9c6; text-align: right; }
#mg-hud.hot .mg-meter-head span { color: #ff6b5b; }
#mg-hud.surge:not(.hot) .mg-meter-head span { color: #ffb15c; }
#mg-hud.done .mg-meter-head span { color: #5fe08a; }
.mg-meter-foot { font-size: 11px; color: #8d9aab; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.mg-track {
  position: relative; height: 14px; margin-top: 4px; border-radius: 8px; overflow: hidden;
  background: linear-gradient(90deg, #1d4d7a, #2a3442);
}
.mg-fill {
  height: 100%; width: 20%;
  background: linear-gradient(90deg, #3fb6ff 0%, #ffd23a 55%, #ff6a2a 80%, #ff2a1a 100%);
  background-size: 620px 100%;
  transition: width .15s linear;
}
.mg-warn-tick { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.75); }

#mg-pump {
  flex: none; width: 82px; height: 82px; margin: -26px 0 -4px;
  border-radius: 50%; border: 4px solid #fff;
  background: radial-gradient(circle at 50% 35%, #63d2ff, #1a86d6 70%);
  box-shadow: 0 6px 0 #0f5f9e, 0 10px 18px rgba(0,0,0,.35);
  color: #fff; cursor: pointer; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  touch-action: manipulation;
}
#mg-pump img { width: 50px; height: 50px; margin-top: -4px; pointer-events: none; }
#mg-pump span { font-size: 12px; font-weight: 900; letter-spacing: .06em; margin-top: -6px; }
#mg-pump:disabled { filter: grayscale(.8); opacity: .6; cursor: default; }
#mg-pump.hit { animation: mg-pump .22s ease-out; }
#mg-hud.hot #mg-pump:not(:disabled) { animation: mg-pump-call .45s ease-in-out infinite alternate; }
@keyframes mg-pump { 40% { transform: scale(.86); box-shadow: 0 2px 0 #0f5f9e; } }
@keyframes mg-pump-call { to { transform: scale(1.08); } }

/* Während eines Minigames: Fenster und Meldungen über der Leiste halten */
/* --advisor-h hält auch die angedockten Blätter (Hochformat) über der Leiste */
#game-root.mg-active { --advisor-h: 104px; }
@media (orientation: landscape) {
  #game-root.mg-active #modal-backdrop { padding-bottom: calc(112px + var(--sab)); }
}
#game-root.mg-active #toasts { bottom: calc(120px + var(--sab)); }
#game-root.mg-active #pill-cool { display: none; }
/* Max' Tutorial-Leiste lag genau unter der Minigame-Leiste (beide unten) – im
   Minigame gibt es kein Tutorial; der Investor rückt über die Leiste. */
#game-root.mg-active #advisor, #game-root.mg-active #tut-dim,
#game-root.mg-active #tut-spot, #game-root.mg-active #tut-arrow { display: none !important; }
#game-root.mg-active #investor-offer { bottom: calc(118px + var(--sab)); }

/* Roter Rand bei Hitze */
#mg-vignette {
  position: absolute; inset: 0; z-index: 9; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(255,40,20,.55) 100%);
  transition: opacity .3s;
}
#mg-vignette.pulse { animation: mg-vig .6s ease-in-out infinite alternate; }
@keyframes mg-vig { to { filter: brightness(1.5); } }

/* Dialog Max/Sam und Ergebnisfenster */
#mg-overlay {
  position: absolute; inset: 0; z-index: 160;
  display: flex; align-items: flex-end; justify-content: center;
  padding: calc(12px + var(--sat)) calc(10px + var(--sar)) calc(16px + var(--sab)) calc(10px + var(--sal));
  background: rgba(8,12,18,.45);
}
#mg-overlay.mg-result-wrap { align-items: center; background: rgba(8,12,18,.6); }
.mg-dialog { display: flex; align-items: flex-end; width: min(600px, 100%); }
.mg-dialog.swap .mg-portrait { animation: mg-pop .3s ease-out; }
.mg-dialog.swap .mg-line { animation: mg-fade .3s ease-out; }
.mg-portrait { width: 132px; height: 172px; object-fit: contain; object-position: bottom; flex: none; margin: 0 -6px -8px -4px; z-index: 1;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.35)); }
.mg-bubble {
  flex: 1; background: #fff; color: var(--text); border-radius: 16px; padding: 12px 14px 10px;
  border: 3px solid #1a86d6; box-shadow: 0 8px 20px rgba(0,0,0,.3); min-height: 120px;
  display: flex; flex-direction: column;
}
.mg-speaker { font-size: 11px; font-weight: 900; letter-spacing: .05em; color: #1a86d6; text-transform: uppercase; }
.mg-line { margin: 4px 0 8px; font-size: 15px; font-weight: 700; line-height: 1.35; flex: 1; }
.mg-dialog-actions { display: flex; justify-content: space-between; align-items: center; }
.mg-dots { font-size: 11px; color: var(--text-dim); font-weight: 800; }
@keyframes mg-pop { from { transform: translateY(12px) scale(.94); opacity: 0; } }
@keyframes mg-fade { from { opacity: 0; transform: translateY(4px); } }

.mg-result {
  width: min(420px, 100%); background: #fff; color: var(--text); border-radius: 20px;
  padding: 18px 18px 14px; text-align: center; box-shadow: 0 14px 40px rgba(0,0,0,.45);
  animation: mg-pop .35s ease-out; position: relative;
}
.mg-result small { font-weight: 900; letter-spacing: .1em; font-size: 12px; color: var(--text-dim); }
.mg-result h2 { margin: 4px 0 8px; font-size: 22px; }
.mg-result p { margin: 0 0 8px; font-size: 14px; line-height: 1.4; }
.mg-result.boom { border: 4px solid #ff4b3a; }
.mg-result.boom small { color: #e2412f; }
.mg-result.win { border: 4px solid #39d06a; padding-top: 96px; margin-top: 70px; }
.mg-result.win small { color: #23a650; }
.mg-result.win .mg-portrait { position: absolute; left: 50%; top: -82px; transform: translateX(-50%); width: 140px; height: 170px; margin: 0; }
.mg-result-ico { font-size: 54px; line-height: 1; animation: mg-shake .12s linear 5; }

/* Game over: dunkle Karte, Kopf = Kartenbild des Levels (rot getönt), Sam ragt heraus */
.mg-over {
  width: min(420px, 100%); border-radius: 22px; overflow: hidden; position: relative;
  background: linear-gradient(180deg, #1b2230, #121822); color: #eef3f8;
  border: 3px solid #ff4b3a;
  box-shadow: 0 0 0 4px rgba(255,75,58,.18), 0 18px 46px rgba(0,0,0,.55);
  animation: mg-over-in .5s cubic-bezier(.2,1.4,.4,1);
}
@keyframes mg-over-in { 0% { transform: translateY(24px) scale(.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
.mg-over-hero {
  position: relative; height: 142px; overflow: hidden;
  background-color: #2a3240; background-position: center 40%; background-size: cover; background-repeat: no-repeat;
}
.mg-over-hero::before {   /* rot-dunkle Tönung, unten in die Karte auslaufend */
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(120,10,0,.35) 0%, rgba(40,8,8,.55) 55%, #1b2230 100%);
}
.mg-over[data-kind="blackout"] .mg-over-hero::before,
.mg-over[data-kind="overload"] .mg-over-hero::before {
  background: linear-gradient(180deg, rgba(10,20,60,.55) 0%, rgba(8,10,24,.7) 55%, #1b2230 100%);
}
.mg-over-hero { filter: saturate(.75); }
.mg-over-glitch {   /* Störstreifen, kurz nach dem Aufpoppen */
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,.08) 0 2px, transparent 2px 5px);
  animation: mg-over-glitch 1.4s steps(6) .1s 1;
}
@keyframes mg-over-glitch { 0%, 100% { opacity: 0; transform: none; } 20% { opacity: 1; transform: translateX(-6px); } 40% { opacity: .6; transform: translateX(5px); } 60% { opacity: .9; } }
.mg-over-sam {
  position: absolute; right: 2px; bottom: -14px; width: 112px; height: 142px;
  object-fit: contain; object-position: bottom;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.5));
  animation: mg-pop .45s ease-out .15s both;
}
.mg-over-title { position: absolute; left: 16px; right: 112px; bottom: 10px; text-align: left; }
.mg-over-title small {
  display: inline-block; font-size: 11px; font-weight: 900; letter-spacing: .12em;
  color: #fff; background: #e2412f; padding: 3px 8px; border-radius: 6px;
}
.mg-over-title h2 {
  margin: 6px 0 0; font-size: 26px; line-height: 1.05; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.45), 0 0 18px rgba(255,90,60,.45);
  animation: mg-shake .12s linear 4 .2s;
}
.mg-over[data-kind="blackout"] .mg-over-title h2,
.mg-over[data-kind="overload"] .mg-over-title h2 { text-shadow: 0 2px 0 rgba(0,0,0,.45), 0 0 18px rgba(80,170,255,.6); }
.mg-over-body { padding: 10px 16px 16px; }
.mg-over-cause { margin: 0 0 10px; font-size: 13.5px; color: #b8c3d1; line-height: 1.35; }
.mg-over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mg-over-stats div {
  background: rgba(255,255,255,.06); border: 1.5px solid rgba(255,255,255,.08);
  border-radius: 12px; padding: 7px 4px 6px; text-align: center;
}
.mg-over-stats b { display: block; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.mg-over-stats small { font-size: 10px; font-weight: 900; letter-spacing: .1em; color: #8d9aab; }
.mg-over-track { height: 8px; margin: 10px 0 2px; border-radius: 5px; background: rgba(255,255,255,.1); overflow: hidden; }
.mg-over-track i { display: block; height: 100%; min-width: 4px; border-radius: 5px;
  background: linear-gradient(90deg, #ffb13a, #ff4b3a); animation: mg-over-bar .9s ease-out .25s both; }
@keyframes mg-over-bar { from { width: 0 !important; } }
.mg-over-tip {
  margin: 10px 0 2px; padding: 8px 10px; border-radius: 12px; text-align: left;
  background: rgba(55,182,255,.1); border: 1.5px solid rgba(55,182,255,.3);
  font-size: 12.5px; line-height: 1.35; color: #d6e6f5;
}
.mg-over-tip b { display: inline-block; margin-right: 6px; padding: 1px 6px; border-radius: 5px; background: #37b6ff; color: #0d1a28; font-size: 10px; letter-spacing: .08em; }
.mg-over .mg-actions { margin-top: 12px; }
.mg-over .btn.gray { background: linear-gradient(180deg, #4a5564, #39424f); box-shadow: 0 3px 0 #252c35; color: #e3e9f0; }
.mg-next { color: var(--text-dim); font-size: 13px !important; }
.mg-actions { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.mg-actions .btn { flex: 1; max-width: 180px; }

/* Level-Auswahl */
.mg-intro-text { margin: 0 0 10px; font-size: 13px; color: var(--text-dim); line-height: 1.4; }
.mg-levels { display: grid; gap: 8px; }
.mg-level {
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 8px;
  background: #fff; border-radius: 14px; box-shadow: 0 2px 0 rgba(0,0,0,.06);
  border: 2px solid #e4e9ef;
}
.mg-level > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mg-level b { font-size: 15px; }
.mg-level small { font-size: 12px; color: var(--text-dim); line-height: 1.3; }
.mg-level .mg-stats { color: #23a650; font-weight: 800; }
.mg-level .btn { margin: 0; flex: none; min-width: 92px; }
.mg-lvl-num {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; color: #fff;
  background: radial-gradient(circle at 40% 30%, #ff9a4a, #e2412f);
}
.mg-level.locked { opacity: .55; }
.mg-level.locked .mg-lvl-num { background: #aab6c2; }
.mg-lock { font-size: 18px; }

@media (prefers-reduced-motion: reduce) {
  #mg-hud.hot, #mg-hud.boom, #mg-hud.hot #mg-pump:not(:disabled), #mg-vignette.pulse, .mg-result-ico,
  .mg-over, .mg-over-glitch, .mg-over-sam, .mg-over-title h2, .mg-over-track i { animation: none; }
}

/* 3D-Icon vor dem Wert der Zusatzaufgabe (z. B. Floodgate-Welle) */
#mg-temp { display: inline-flex; align-items: center; gap: 4px; }
.mg-val-ico { width: 30px; height: 30px; margin: -6px 0 -6px -4px; object-fit: contain; }
.mg-val { font-style: normal; }
