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

:root {
  --bg-top: #2CB5D8;
  --bg-bot: #1487AC;
  --wheel: #0C4A63;
  --wheel-hi: #12678A;
  --tile: #ffffff;
  --tile-ink: #20323b;
  --tile-shadow: rgba(6, 44, 60, .35);
  --cell-empty: rgba(255, 255, 255, .13);
  --cell-line: rgba(255, 255, 255, .30);
  --ok: #37C871;
  --gold: #FFC24B;
  --coral: #FF6B6B;
  --ink-soft: rgba(255, 255, 255, .85);

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

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* bewusste Override-Strategie: .screen/.overlay setzen display:flex und würden
   sonst das hidden-Attribut aushebeln (Author schlägt UA-Stylesheet) */
[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, .16);
  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, .16);
  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(6, 44, 60, .35);
  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(6, 44, 60, .08); }
@media (hover: hover) {
  .menu-item:hover { background: rgba(6, 44, 60, .06); }
}
.menu-jump {
  padding: 10px 14px 8px;
  margin-top: 4px;
  border-top: 1px solid #eef1f3;
}
.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-version {
  font-size: .8rem;
  color: #8a97a0;
  padding: 8px 14px 4px;
  margin-top: 4px;
  border-top: 1px solid #eef1f3;
}

.coins {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
  background: rgba(0, 0, 0, .16);
  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); } }

/* Board + Input teilen den Rest */
#board-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px;
}
#input-area {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ============ Gitter ============ */
#board {
  --gap: 5px;
  --cell: 40px;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
}
.cell {
  aspect-ratio: 1;
  border-radius: clamp(4px, 1.4vmin, 10px);
}
.cell.slot {
  background: var(--cell-empty);
  box-shadow: inset 0 0 0 2px var(--cell-line);
}
.cell.filled {
  background: var(--tile);
  color: var(--tile-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: calc(var(--cell) * .52);
  text-transform: uppercase;
  box-shadow: 0 3px 0 var(--tile-shadow);
}
.cell.pop { animation: pop .32s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes pop {
  0% { transform: scale(.2); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.cell.hint { box-shadow: 0 3px 0 var(--tile-shadow), 0 0 0 3px var(--gold); }

/* ============ Vorschau ============ */
#preview {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}
#preview:empty::before {
  content: 'Buchstaben antippen';
  color: rgba(255, 255, 255, .45);
  font-size: 1rem;
}
.pv-tile {
  min-width: 40px;
  height: 46px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--tile);
  color: var(--tile-ink);
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 var(--tile-shadow);
  animation: pvin .12s ease;
}
@keyframes pvin { from { transform: translateY(6px); opacity: 0; } }
#preview.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); }
}
#preview.shake .pv-tile { background: var(--coral); color: #fff; }

/* ============ Toast ============ */
.toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 18px;
  border-radius: 99px;
  font-weight: 600;
  font-size: 1.05rem;
  background: #fff;
  color: var(--tile-ink);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--ok); color: #fff; }
.toast.gold { background: var(--gold); color: #5a3c00; }

/* ============ Rad ============ */
#wheel-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
#wheel {
  position: relative;
  width: var(--wheel-size);
  height: var(--wheel-size);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, var(--wheel-hi), var(--wheel) 70%);
  box-shadow: inset 0 4px 14px rgba(0, 0, 0, .35), 0 8px 22px rgba(0, 0, 0, .28);
}
.wheel-tile {
  position: absolute;
  width: var(--wtile);
  height: var(--wtile);
  margin: calc(var(--wtile) / -2) 0 0 calc(var(--wtile) / -2);
  border-radius: 16px;
  background: var(--tile);
  color: var(--tile-ink);
  font-size: calc(var(--wtile) * .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;
}
.wheel-tile.used {
  background: var(--wheel-hi);
  color: rgba(255, 255, 255, .5);
  box-shadow: none;
  transform: scale(.9);
}
.wheel-tile:active { transform: scale(.9); }

.action-btn {
  flex: 0 0 auto;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .18);
  color: #fff;
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}
.action-btn:active { transform: scale(.92); }
.action-btn .cost {
  font-size: .72rem;
  color: var(--gold);
  font-weight: 700;
}
.action-btn.disabled { opacity: .4; pointer-events: none; }
/* gleiche Größe/Farbe wie die anderen Buttons; nur die Position weicht ab
   (im Hochformat unten-rechts am Rad; im Querformat per Media-Query links) */
.back-btn {
  position: absolute;
  right: -6px;
  bottom: -6px;
}
.ico-svg {
  width: 27px;
  height: 27px;
  display: block;
}

/* ============ Level-Complete ============ */
.overlay { background: rgba(6, 44, 60, .72); backdrop-filter: blur(3px); z-index: 20; }
.complete-card {
  background: #fff;
  color: var(--tile-ink);
  border-radius: 28px;
  padding: 34px 40px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  animation: pop .4s cubic-bezier(.3, 1.4, .5, 1);
}
.complete-burst { font-size: 3.4rem; }
.complete-card h2 { margin: 8px 0 4px; font-size: 1.8rem; font-weight: 700; }
.complete-card p { margin: 0 0 22px; color: #5b6b73; }
.primary-btn {
  border: none;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  background: var(--ok);
  padding: 14px 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: Gitter | Rad nebeneinander ============ */
@media (orientation: landscape) {
  #game {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "board input";
    column-gap: 12px;
  }
  #topbar { grid-area: top; }
  #board-area { grid-area: board; min-width: 0; min-height: 0; }
  #input-area { grid-area: input; justify-content: center; min-width: 0; min-height: 0; }

  /* Alle drei Aktions-Buttons links vom Rad stapeln, damit die rechte untere
     Ecke frei bleibt (dort liegt Tablet-UI). Rad bleibt zentriert. */
  #btn-hint, #btn-shuffle, #btn-back {
    position: absolute;
    left: -74px;
    right: auto;
    bottom: auto;
  }
  #btn-hint    { top: calc(50% - 93px); }
  #btn-shuffle { top: calc(50% - 25px); }
  #btn-back    { top: calc(50% + 43px); }
}

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