/* ---- Font (lokal gebündelt fürs Offline-PWA) ---- */
@font-face {
  font-family: 'Baloo 2';
  src: url('fonts/baloo2-500.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('fonts/baloo2-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('fonts/baloo2-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg-top: #8B6FE0;
  --bg-bot: #6A4FC0;
  --panel: #4A3494;
  --panel-hi: #5C43AE;
  --tile: #ffffff;
  --tile-ink: #2a2140;
  --tile-shadow: rgba(30, 16, 70, .35);
  --slot-empty: rgba(255, 255, 255, .13);
  --slot-line: rgba(255, 255, 255, .32);
  --ok: #37C871;
  --gold: #FFC24B;
  --coral: #FF6B6B;
  --ink-soft: rgba(255, 255, 255, .85);

  --font: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* bewusste Override-Strategie: .screen setzt display:flex und würde sonst das
   hidden-Attribut aushebeln */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: #fff;
  background: linear-gradient(160deg, var(--bg-top), var(--bg-bot));
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ============ Ladescreen ============ */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
}
.load-logo {
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 700;
  letter-spacing: .5px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, .12);
}
.load-bar {
  width: min(70%, 340px);
  height: 14px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .22);
  overflow: hidden;
}
.load-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: var(--gold);
  transition: width .15s ease;
}
.load-text { font-size: 1rem; color: var(--ink-soft); }

/* ============ Grundlayout ============ */
#game {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 10px;
}
.level-badge {
  font-size: 1.15rem;
  font-weight: 600;
  background: rgba(0, 0, 0, .18);
  padding: 6px 16px;
  border-radius: 99px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Burger-Menü ---- */
#menu-wrap { position: relative; }
.menu-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}
.menu-btn span {
  width: 20px;
  height: 2.5px;
  border-radius: 2px;
  background: #fff;
}
.menu-btn:active { transform: scale(.94); }

#menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: #fff;
  color: var(--tile-ink);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(30, 16, 70, .4);
  padding: 8px;
  z-index: 30;
  animation: pop .18s ease;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: start;
  border: none;
  background: none;
  font-family: var(--font);
  font-weight: 500;
  font-size: 1.05rem;
  color: var(--tile-ink);
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.menu-item:active { background: rgba(30, 16, 70, .08); }
@media (hover: hover) {
  .menu-item:hover { background: rgba(30, 16, 70, .06); }
}
.menu-extra {
  margin-top: 4px;
  border-top: 1px solid #eef1f3;
}
.menu-extra > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 1.05rem;
  cursor: pointer;
}
.menu-extra > summary::-webkit-details-marker { display: none; }
.menu-extra > summary::after {
  content: '▾';
  font-size: .8rem;
  color: #8a97a0;
  transition: transform .15s ease;
}
.menu-extra[open] > summary::after { transform: rotate(180deg); }
.menu-extra > summary:active { background: rgba(30, 16, 70, .08); }
@media (hover: hover) {
  .menu-extra > summary:hover { background: rgba(30, 16, 70, .06); }
}

.menu-jump {
  padding: 10px 14px 8px;
  margin-top: 0;
  border-top: none;
  padding-top: 4px;
}
.menu-jump label {
  display: block;
  font-size: .85rem;
  color: #5b6b73;
  margin-bottom: 6px;
}
.jump-row { display: flex; gap: 8px; }
#jump-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--tile-ink);
  padding: 8px 10px;
  border: 2px solid #dfe5e8;
  border-radius: 10px;
}
#jump-input:focus { outline: none; border-color: var(--bg-bot); }
#jump-input.invalid { border-color: var(--coral); }
#btn-jump {
  border: none;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  background: var(--bg-bot);
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
}
#btn-jump:active { transform: scale(.96); }

.menu-credit,
.menu-version {
  font-size: .8rem;
  color: #8a97a0;
  padding: 8px 14px 4px;
  margin-top: 4px;
  border-top: 1px solid #eef1f3;
}
.menu-version { border-top: none; padding-top: 2px; margin-top: 0; }

.coins {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
  background: rgba(0, 0, 0, .18);
  padding: 5px 16px 5px 10px;
  border-radius: 99px;
}
.coin-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE29A, var(--gold) 60%, #E39A17);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
  display: inline-block;
}
.coins.bump { animation: bump .35s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }

/* Bilder + Spielbereich teilen den Rest */
#pics-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;   /* erlaubt dem Raster zu schrumpfen, wenn der Spielbereich Platz braucht */
  padding: 4px;
}
#play-area {
  position: relative;   /* Bezug fürs Level-Complete-Overlay */
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 6px;
}

/* ============ Bildraster (2×2) ============ */
#pics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(4px, 1.4vmin, 10px);
  /* quadratisch, passt sich der verfügbaren Fläche an: volle Breite, aber die
     Höhe des (schrumpfbaren) #pics-area deckelt es — so weicht das Raster dem
     Spielbereich, wenn lange Wörter mehr Platz brauchen. */
  width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
}
.pic {
  position: relative;
  overflow: hidden;
  border-radius: clamp(8px, 2vmin, 16px);
  background: rgba(255, 255, 255, .08);
  box-shadow: 0 4px 12px rgba(30, 16, 70, .28);
}
.pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============ Slots (Lösungswort) ============ */
#slots-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.6vmin, 14px);
  max-width: 100%;
}
#slots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1.2vmin, 9px);
  min-width: 0;
  flex: 0 1 auto;
}
.slot {
  --sz: clamp(44px, 9vmin, 72px);
  width: var(--sz);
  height: var(--sz);
  border-radius: clamp(7px, 1.6vmin, 12px);
  background: var(--slot-empty);
  box-shadow: inset 0 0 0 2px var(--slot-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--sz) * .5);
  text-transform: uppercase;
}
.slot.filled {
  background: var(--tile);
  color: var(--tile-ink);
  box-shadow: 0 3px 0 var(--tile-shadow);
  cursor: pointer;
  animation: pvin .12s ease;
}
.slot.locked {
  background: radial-gradient(circle at 35% 30%, #FFE29A, var(--gold) 60%, #E39A17);
  cursor: default;
}
.slot.correct {
  background: var(--ok);
  color: #fff;
  box-shadow: 0 3px 0 #24924f;
}
@keyframes pvin { from { transform: translateY(6px); opacity: 0; } }
#slots.shake { animation: shake .4s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
#slots.shake .slot.filled:not(.locked) { background: var(--coral); color: #fff; }

/* Löschen-Button neben den Slots (letzten Buchstaben zurücknehmen) */
.back-btn {
  flex: 0 0 auto;
  width: clamp(44px, 8vmin, 62px);
  height: clamp(44px, 8vmin, 62px);
  border: none;
  border-radius: clamp(10px, 1.8vmin, 16px);
  background: rgba(0, 0, 0, .18);
  color: var(--coral);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.back-btn:active { transform: scale(.9); }
.back-btn .ico-svg { width: 60%; height: 60%; display: block; }

/* ============ Buchstaben-Vorrat ============ */
#supply {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(5px, 1.2vmin, 9px);
  max-width: min(100%, 560px);
}
.tile {
  --sz: clamp(48px, 10vmin, 78px);
  width: var(--sz);
  height: var(--sz);
  border-radius: clamp(9px, 1.8vmin, 16px);
  background: var(--tile);
  color: var(--tile-ink);
  font-size: calc(var(--sz) * .5);
  font-weight: 700;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 var(--tile-shadow);
  cursor: pointer;
  transition: transform .12s, background .12s, opacity .12s;
}
.tile.used {
  background: var(--panel-hi);
  color: rgba(255, 255, 255, .4);
  box-shadow: none;
  transform: scale(.9);
  cursor: default;
}
.tile:not(.used):active { transform: scale(.9); }

/* ============ Hinweis-Buttons ============ */
#hints {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
}
.hint-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  background: rgba(0, 0, 0, .18);
  padding: 10px 16px;
  border-radius: 99px;
  cursor: pointer;
}
.hint-btn:active { transform: scale(.95); }
.hint-btn.disabled { opacity: .4; pointer-events: none; }
.hint-btn .ico-svg { width: 24px; height: 24px; display: block; }
.hint-label { white-space: nowrap; }
.hint-cost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(0, 0, 0, .22);
  padding: 2px 9px 2px 8px;
  border-radius: 99px;
  font-weight: 700;
  color: var(--gold);
}
.hint-cost::after {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE29A, var(--gold) 60%, #E39A17);
  display: inline-block;
}

/* ============ Toast (Feedback über dem Spielbereich) ============ */
.toast {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translate(-50%, 6px) scale(.96);
  padding: 12px 28px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 1.35rem;
  white-space: nowrap;
  max-width: 92vw;
  background: #fff;
  color: var(--tile-ink);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 15;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.ok { background: var(--ok); color: #fff; }

/* ============ Level-Complete (Overlay über dem Spielbereich) ============ */
#complete {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  z-index: 20;
  background: rgba(30, 16, 70, .58);
  backdrop-filter: blur(2px);
  border-radius: 18px;
}
.complete-card {
  background: #fff;
  color: var(--tile-ink);
  border-radius: 24px;
  padding: 22px 30px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  animation: pop .4s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes pop {
  0% { transform: scale(.2); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.complete-burst { font-size: 2.8rem; }
.complete-card h2 { margin: 6px 0 4px; font-size: 1.7rem; font-weight: 700; }
.complete-card p { margin: 0 0 18px; color: #5b6b73; }
.primary-btn {
  border: none;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.45rem;
  color: #fff;
  background: var(--ok);
  width: 100%;
  padding: 18px 32px;
  border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 5px 0 #24924f;
}
.primary-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #24924f; }

/* ============ Querformat: Bilder | Spielbereich nebeneinander ============ */
@media (orientation: landscape) {
  #game {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "pics play";
    column-gap: 16px;
    padding-right: max(12px, env(safe-area-inset-right));
  }
  /* Die geräteeigene Tablet-UI sitzt in der unteren rechten Ecke (~100×200px).
     Der Spielbereich rechts ist horizontal UND vertikal zentriert, sein Inhalt
     bleibt also von der rechten Kante weg — die Ecke bleibt frei, ohne dass wir
     über die volle Höhe Platz opfern (visuell mit dem breitesten Level geprüft). */
  #topbar { grid-area: top; }
  #pics-area { grid-area: pics; min-width: 0; min-height: 0; }
  #play-area {
    grid-area: play;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    /* kleiner rechter Abstand, damit die unterste Reihe (Hinweise) auch bei großen
       Kacheln nicht in die untere rechte Ecke ragt (Tablet-UI). Weit unter dem
       früheren 130px-Overkill. */
    padding-right: 44px;
  }
  #pics {
    width: auto;
    height: min(100%, 100%);
    max-width: 100%;
    max-height: 100%;
  }
}

/* ============ Reduzierte Bewegung ============ */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
