/* Jelly Match – Styles (mobile-first, Light/Dark via prefers-color-scheme) */

:root {
  --bg: #f4effa;
  --bg-accent: #e9defc;
  --surface: #ffffff;
  --surface-2: #f3edfb;
  --text: #2b2140;
  --muted: #6f6584;
  --primary: #7c3aed;
  --primary-press: #6527d0;
  --accent: #ffd94a;
  --danger: #e14b4b;
  --border: #ddd2ef;
  --shadow: 0 6px 24px rgba(80, 40, 160, 0.14);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171224;
    --bg-accent: #241b3a;
    --surface: #221a36;
    --surface-2: #2c2247;
    --text: #f0eaff;
    --muted: #a99cc4;
    --primary: #9d6bff;
    --primary-press: #8450ec;
    --accent: #ffd94a;
    --border: #3b2f58;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  background: radial-gradient(circle at 20% 10%, var(--bg-accent), var(--bg) 60%);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.15; }
p { margin: 0.3em 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Screens ---------- */
.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  border-radius: 999px;
  padding: 0.65em 1.4em;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: transform 0.12s ease, filter 0.12s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow); }
.btn-primary:not(:disabled):hover { background: var(--primary-press); }
.btn-ghost { background: transparent; border: 2px solid var(--border); }
.btn-premium {
  background: linear-gradient(135deg, #ffd94a, #ff9d3a);
  color: #4a2c00;
  box-shadow: var(--shadow);
}
.btn-icon {
  padding: 0.35em 0.6em;
  font-size: 1.15rem;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  line-height: 1;
}
.btn-big { font-size: 1.35rem; padding: 0.7em 2.4em; }
.link-btn {
  background: none; border: none; padding: 0;
  color: var(--primary); text-decoration: underline;
  cursor: pointer; font: inherit;
}

/* ---------- Loading ---------- */
#screenLoading { justify-content: center; }
.loading-box { text-align: center; padding: 2rem; }
.loading-icon { animation: bob 1.6s ease-in-out infinite; }
.loading-title { font-size: 2rem; margin-top: 0.4rem; }
.loading-bar {
  width: min(70vw, 320px);
  height: 14px;
  margin: 1rem auto 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #d94af0);
  border-radius: 999px;
  transition: width 0.15s ease;
}

/* ---------- Start ---------- */
#screenStart { justify-content: space-between; }
.start-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem 1rem 0.5rem;
  text-align: center;
}
.logo-tiles {
  display: grid;
  grid-template-columns: repeat(5, 34px);
  grid-auto-rows: 34px;
  gap: 3px;
  margin-bottom: 0.5rem;
}
.logo-cell img {
  width: 100%; height: 100%;
  display: block;
  animation: bob 2.4s ease-in-out infinite;
}
.logo-cell:nth-child(2n) img { animation-delay: -0.6s; }
.logo-cell:nth-child(3n) img { animation-delay: -1.2s; }
.logo-cell:nth-child(5n) img { animation-delay: -1.8s; }
.game-title {
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 800;
  background: linear-gradient(120deg, var(--primary), #e14bb0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--muted); margin-bottom: 0.8rem; }
.start-actions { display: flex; gap: 0.7rem; flex-wrap: wrap; justify-content: center; margin-top: 0.9rem; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* ---------- Ad-Slot ---------- */
.ad-slot {
  width: min(92vw, 480px);
  min-height: 72px;
  margin: 0.6rem auto;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  text-align: center;
}
.ad-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.ad-placeholder { color: var(--muted); font-size: 0.85rem; }

/* ---------- Footer ---------- */
.app-footer {
  padding: 0.7rem 1rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.footer-nav { margin-top: 0.2rem; }

/* ---------- Level-Map ---------- */
#screenMap { justify-content: flex-start; }
.map-header {
  width: min(94vw, 560px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.9rem 0 0.4rem;
}
.map-header h2 { margin: 0; font-size: 1.4rem; }
.map-stars {
  font-weight: 800;
  color: #c98a00;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25em 0.8em;
}
.level-grid {
  width: min(94vw, 560px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
  padding: 0.6rem 0 1rem;
}
@media (min-width: 480px) {
  .level-grid { grid-template-columns: repeat(4, 1fr); }
}
.level-btn {
  font-family: inherit;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.3rem 0.55rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.level-btn:not(:disabled):hover { transform: translateY(-2px); }
.level-btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.level-num { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.level-btn:disabled .level-num { color: var(--muted); }
.level-name { font-size: 0.72rem; color: var(--muted); text-align: center; min-height: 2em; line-height: 1.05; }
.level-starrow { font-size: 0.95rem; color: var(--muted); letter-spacing: 0.1em; }
.level-starrow.has { color: #e6a800; }
.map-hint { padding: 0 1rem 1.2rem; text-align: center; }

/* ---------- Spielscreen ---------- */
#screenGame { justify-content: flex-start; gap: 0.3rem; }
.game-header {
  width: min(96vw, 560px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding-top: 0.6rem;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 0.45rem; }
.hud-level { font-weight: 800; font-size: 1rem; }
.hud-center { display: flex; gap: 0.9rem; }
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 3em; }
.hud-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.hud-value { font-weight: 800; font-size: 1.15rem; line-height: 1; }
.hud-moves.low { color: var(--danger); animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

.jelly-progress {
  width: min(96vw, 560px);
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}
.jelly-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8bc63e, #57a814);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.board-wrap {
  position: relative;
  width: min(96vw, 72vh, 560px);
  aspect-ratio: 1 / 1;
  margin: 0.3rem auto 0.8rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#board {
  touch-action: none;
  display: block;
  border-radius: 10px;
}

.toast {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  padding: 0.45em 1.2em;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Overlays (Tutorial, Level-Ende, Pause) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 40;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  width: min(92vw, 400px);
  padding: 1.2rem 1.3rem 1.1rem;
  text-align: center;
  animation: cardIn 0.25s ease;
}
@keyframes cardIn {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.tut-step.hidden { display: none; }
.tut-emoji { font-size: 2rem; margin: 0.2rem 0; }

.end-stars { font-size: 2.6rem; letter-spacing: 0.15em; margin: 0.3rem 0 0.1rem; }
.end-stars .star { color: var(--border); display: inline-block; }
.end-stars .star.earned { color: #f4b400; }
.end-stars .star.pop { animation: starPop 0.45s ease; }
@keyframes starPop {
  0% { transform: scale(0); }
  60% { transform: scale(1.5) rotate(12deg); }
  100% { transform: scale(1); }
}
.end-text { color: var(--muted); }

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

/* ---------- Modals (dialog) ---------- */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: min(92vw, 460px);
  padding: 1.3rem 1.4rem;
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(20, 10, 40, 0.55); }
.modal-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.premium-list { text-align: left; padding-left: 1.2rem; }

/* ---------- Taktik-Schule & Gelotst-Modus ---------- */
.taktik-modal {
  max-width: min(94vw, 520px);
  max-height: 88dvh;
  overflow-y: auto;
}
.taktik-cards {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin: 0.8rem 0;
}
.taktik-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 0.9rem 0.9rem;
  text-align: left;
}
.taktik-card h3 { font-size: 1.02rem; margin: 0 0 0.15rem; }
.taktik-card p { color: var(--muted); font-size: 0.88rem; margin: 0; }
.taktik-canvas {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0.45rem auto;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.guide-badge {
  background: var(--accent);
  color: #4a2c00;
  font-weight: 800;
  font-size: 0.68rem;
  border-radius: 999px;
  padding: 0.22em 0.65em;
  white-space: nowrap;
}
.guide-badge.hidden, .btn-icon.hidden { display: none; }
.btn-icon.guide-off { opacity: 0.5; }

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
