/* Grundlayout: Viewport, HUD, Views, Safe Areas. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background:
    radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(80% 50% at 100% 100%, color-mix(in srgb, var(--accent-2) 10%, transparent), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ---------- App-Rahmen ---------- */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- HUD ---------- */

.hud {
  position: relative;
  z-index: 20;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: calc(var(--hud-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--s3) + var(--safe-right)) 0 calc(var(--s3) + var(--safe-left));
  background: linear-gradient(180deg, rgba(11, 6, 20, 0.96), rgba(11, 6, 20, 0.8));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  flex: 1 1 auto;
}

/* Die Knoepfe in der Kopfzeile geben NIE Platz ab. Ohne das hier schrumpft der
   Zurueck-Knopf auf seine min-width (36 px), waehrend seine Schrift nowrap
   bleibt und aus dem Kasten herausragt: man sieht "‹ HALLE", aber nur die
   mittleren 36 px sind der Knopf -- genau deshalb liess er sich am Telefon nur
   auf dem Pfeil treffen. Schrumpfen darf allein der Titel, der hat dafuer sein
   text-overflow: ellipsis. */
.hud-left > .btn {
  flex: 0 0 auto;
}

/* 44 px ist das Mindestmass fuer einen Finger (iOS). .btn-sm setzt 36 px; in
   der Kopfzeile ist das zu wenig, hier sitzt der einzige Weg zurueck. */
.hud-left > .btn-sm {
  min-height: 44px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: var(--fs-md);
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 60%, transparent);
  font-size: 18px;
}

.brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 70%, transparent);
}

.hud-title {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: var(--fs-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Views ---------- */

.views {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
}

.view.is-active {
  display: block;
}

.view-hub {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.view-game {
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.view-game.is-active {
  display: flex;
}

.view-enter {
  animation: view-in var(--t-slow) var(--ease-out) both;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Übergangsblende vom Automaten zum Spiel */
.zoom-veil {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  border-radius: var(--r-md);
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--accent) 45%, var(--bg-2)), var(--bg-0));
  transition:
    left var(--t-slow) var(--ease-out),
    top var(--t-slow) var(--ease-out),
    width var(--t-slow) var(--ease-out),
    height var(--t-slow) var(--ease-out),
    border-radius var(--t-slow) var(--ease-out),
    opacity var(--t-med) linear;
}

/* Partikel-Overlay über allem */
#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 70;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .view-enter {
    animation: none;
  }
}

@media (max-width: 420px) {
  .brand-text { display: none; }
}

@media (max-width: 420px) {
  .hud-title { display: none; }
}

/* V1.1: mit dem Spielkontroll-Knopf sind es vier Knoepfe in der Kopfzeile.
   Auf Telefonen reicht der Platz dann nicht mehr fuer das Wort "Halle" -- und
   da der Knopf hier nichts mehr abgibt (siehe .hud-left > .btn), wuerde die
   Zeile sonst ueberlaufen. Also nur der Pfeil, aber volle 44x44. */
@media (max-width: 599px) {
  .hud-back-label { display: none; }
  .hud-back { min-width: 44px; width: 44px; padding: 0; font-size: 20px; }
}

/* Ganz schmale Geraete (320 px): sechs Elemente passen nicht in die Zeile.
   Schmalere Raender, und die Level-Pille weicht -- sie zeigt nur an, die
   Zahl steht auch in der Statistik. Alles, was etwas tut, bleibt. */
@media (max-width: 374px) {
  .hud {
    padding-left: calc(var(--s2) + var(--safe-left));
    padding-right: calc(var(--s2) + var(--safe-right));
  }

  #hud-level {
    display: none;
  }
}

/* V1.2: fünf Elemente rechts (Guthaben, Level, Post, Pause, Einstellungen).
   Auf Telefonen weicht die Level-Pille (Level steht in Statistik und Laufschrift),
   die Abstände werden enger; alles, was etwas tut, bleibt mit 44 px treffbar. */
@media (max-width: 479px) {
  #hud-level { display: none; }
  .hud-right { gap: 6px; }
  .hud-left { gap: 6px; }
  .hud-right > .btn-icon { min-width: 44px; width: 44px; padding: 0; }
}
@media (max-width: 374px) {
  .hud-right { gap: 4px; }
  .hud-left { gap: 4px; }
  .hud-right > .btn-icon { min-width: 42px; width: 42px; }
  #hud-balance { padding-left: 8px; padding-right: 10px; }
}
.hud-right > .btn-icon { min-height: 44px; }
@media (max-width: 340px) {
  #hud-balance .coin-ico { display: none; }
  .hud-right, .hud-left { gap: 2px; }
  .hud-right > .btn-icon { min-width: 40px; width: 40px; }
}
.hud-right > .pill { min-height: 44px; }
