/* Zahlen-Merge – warme, eigenständige Optik. Mobile-first, Light/Dark via Tokens. */

:root {
  --bg: #faf3e7;
  --panel: #fff9ef;
  --text: #4a3526;
  --muted: #8a7360;
  --accent: #c2571f;
  --accent-hover: #a84717;
  --premium: #8c5a13;
  --premium-bg: #f7e2b6;
  --board-bg: #b09378;
  --cell-bg: #c9b099;
  --overlay-bg: rgba(250, 240, 226, 0.82);
  --card-bg: #fffdf8;
  --shadow: 0 10px 30px rgba(74, 53, 38, 0.14);
  --border: #e6d7c3;
  --score-bg: #6d523c;
  --score-text: #f9efe2;
  --toast-bg: #4a3526;
  --toast-text: #faf3e7;

  /* Kachel-Rampe: von Creme über Bernstein/Terrakotta zu tiefem Beeren-Violett. */
  --t2-bg: #f7ead9;    --t2-fg: #6b5443;
  --t4-bg: #f2dcb8;    --t4-fg: #6b5443;
  --t8-bg: #f6c689;    --t8-fg: #684526;
  --t16-bg: #f3ae62;   --t16-fg: #5f3c1a;
  --t32-bg: #ee9750;   --t32-fg: #572f10;
  --t64-bg: #e77f3d;   --t64-fg: #4d270b;
  --t128-bg: #de6430;  --t128-fg: #fff4e8;
  --t256-bg: #d14d2b;  --t256-fg: #fff4e8;
  --t512-bg: #bd3a2e;  --t512-fg: #ffefe6;
  --t1024-bg: #a52e40; --t1024-fg: #ffeae4;
  --t2048-bg: #892f55; --t2048-fg: #ffe9dc;
  --t4096-bg: #672a60; --t4096-fg: #f7e3ff;
  --t8192-bg: #472358; --t8192-fg: #f0dcff;
  --tsuper-bg: #2e1d44;--tsuper-fg: #ffd9a0;

  --slide-ms: 120ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221812;
    --panel: #2c2018;
    --text: #f0e3d3;
    --muted: #b09a86;
    --accent: #e0763a;
    --accent-hover: #ef8b50;
    --premium: #f3cd85;
    --premium-bg: #4a3a1c;
    --board-bg: #3a2b20;
    --cell-bg: #4d3a2c;
    --overlay-bg: rgba(24, 16, 11, 0.82);
    --card-bg: #34261c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --border: #4d3b2c;
    --score-bg: #4d3a2c;
    --score-text: #f5e8d8;
    --toast-bg: #f0e3d3;
    --toast-text: #2c2018;
    --t2-bg: #e9dcc8; --t4-bg: #e6cfa4;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Rubik", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.app {
  width: 100%;
  max-width: 470px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Kopf ---------- */
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.game-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  line-height: 1.1;
}

.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.scores { display: flex; gap: 8px; }

.score-box {
  position: relative;
  background: var(--score-bg);
  color: var(--score-text);
  border-radius: 10px;
  padding: 6px 14px;
  min-width: 76px;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.score-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.score-value {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-float {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
  pointer-events: none;
  animation: floatUp 700ms ease-out forwards;
}

@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 0); }
  to   { opacity: 0; transform: translate(-50%, -34px); }
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}

.mode-btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

.mode-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.actions { display: flex; gap: 8px; }

.btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}

.btn:active { transform: scale(0.96); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-premium {
  background: var(--premium-bg);
  color: var(--premium);
  border: 1px solid var(--premium);
}

/* ---------- Spielfeld ---------- */
.board-wrap {
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--board-bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.grid-bg {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 4), 1fr);
  gap: var(--gap, 10px);
  padding: var(--pad, 10px);
}

.grid-cell {
  background: var(--cell-bg);
  border-radius: 8px;
}

.tile-layer { position: absolute; inset: 0; }

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell, 90px);
  height: var(--cell, 90px);
  transition: transform var(--slide-ms) ease-in-out;
  will-change: transform;
}

.tile-layer.no-anim .tile { transition: none; }

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: calc(var(--cell, 90px) * 0.42);
  line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08);
}

.tile-inner[data-digits="3"] { font-size: calc(var(--cell, 90px) * 0.35); }
.tile-inner[data-digits="4"] { font-size: calc(var(--cell, 90px) * 0.29); }
.tile-inner[data-digits="5"] { font-size: calc(var(--cell, 90px) * 0.24); }
.tile-inner[data-digits="6"] { font-size: calc(var(--cell, 90px) * 0.2); }

.tile-2 .tile-inner    { background: var(--t2-bg);    color: var(--t2-fg); }
.tile-4 .tile-inner    { background: var(--t4-bg);    color: var(--t4-fg); }
.tile-8 .tile-inner    { background: var(--t8-bg);    color: var(--t8-fg); }
.tile-16 .tile-inner   { background: var(--t16-bg);   color: var(--t16-fg); }
.tile-32 .tile-inner   { background: var(--t32-bg);   color: var(--t32-fg); }
.tile-64 .tile-inner   { background: var(--t64-bg);   color: var(--t64-fg); }
.tile-128 .tile-inner  { background: var(--t128-bg);  color: var(--t128-fg); }
.tile-256 .tile-inner  { background: var(--t256-bg);  color: var(--t256-fg); }
.tile-512 .tile-inner  { background: var(--t512-bg);  color: var(--t512-fg); }
.tile-1024 .tile-inner { background: var(--t1024-bg); color: var(--t1024-fg); }
.tile-2048 .tile-inner {
  background: var(--t2048-bg);
  color: var(--t2048-fg);
  box-shadow: 0 0 18px rgba(222, 100, 48, 0.55), inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.tile-4096 .tile-inner { background: var(--t4096-bg); color: var(--t4096-fg); }
.tile-8192 .tile-inner { background: var(--t8192-bg); color: var(--t8192-fg); }
.tile-super .tile-inner {
  background: var(--tsuper-bg);
  color: var(--tsuper-fg);
  box-shadow: 0 0 18px rgba(255, 217, 160, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

/* Spawn: kurz verzögert einblenden, damit die Gleit-Animation zuerst lesbar ist. */
.tile-new .tile-inner {
  animation: tileSpawn 160ms ease-out 90ms backwards;
}

@keyframes tileSpawn {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 1; transform: scale(1); }
}

/* Merge-Pop */
.tile-pop .tile-inner {
  animation: tilePop 170ms ease-in-out;
}

@keyframes tilePop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: overlayIn 240ms ease-out;
  z-index: 5;
}

.overlay.hidden { display: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px 20px;
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.overlay-card h2 {
  font-size: 1.35rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.overlay-text {
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.5;
}

.overlay-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- Sonstiges ---------- */
.hint {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.5;
}

.ad-slot {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
}

.ad-label {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.ad-placeholder {
  font-size: 0.8rem;
  color: var(--muted);
}

.premium-row { text-align: center; }

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
  padding-bottom: 8px;
}

.footer-nav { margin-top: 4px; }

.link-btn {
  font: inherit;
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 4px;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- Modals ---------- */
.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  color: var(--text);
  padding: 22px 20px;
  max-width: min(92vw, 440px);
  box-shadow: var(--shadow);
  margin: auto;
}

.modal::backdrop { background: rgba(20, 12, 6, 0.55); }

.modal h2 { color: var(--accent); margin-bottom: 10px; }
.modal p { margin-bottom: 10px; line-height: 1.55; }
.premium-list { margin: 0 0 12px 20px; line-height: 1.7; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ---------- Lern-Modus (Tutorial + Strategie-Schule) ---------- */
.btn-help {
  min-width: 40px;
  padding-left: 0;
  padding-right: 0;
  font-weight: 800;
  color: var(--accent);
}

.learn-row { text-align: center; }

.btn-learn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.learn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  flex: none;
}

.modal h2 .learn-badge { vertical-align: 2px; margin-right: 4px; }

.tutorial-modal { width: min(92vw, 400px); text-align: center; }

.tut-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.tut-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.tut-dot.is-active { background: var(--accent); }

.tut-text {
  font-size: 0.9rem;
  line-height: 1.5;
  min-height: 4.05em; /* 3 Zeilen – Brett springt beim Textwechsel nicht */
}

.tut-board {
  width: min(100%, 280px);
  margin: 0 auto 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tut-task {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.45;
  min-height: 2.9em;
  margin-bottom: 4px;
}

.tut-task.shake { animation: tutShake 320ms ease-in-out; }

@keyframes tutShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.tut-actions { justify-content: space-between; }

.tile-focus .tile-inner {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.school-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  text-align: left;
}

.school-card h3 {
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.school-card p {
  margin-bottom: 0;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.5;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 50;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Reduzierte Bewegung ---------- */
@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile-new .tile-inner,
  .tile-pop .tile-inner,
  .overlay,
  .tut-task.shake,
  .score-float { animation: none; }
  .score-float { opacity: 0; }
  .btn:active { transform: none; }
}

/* ---------- Größere Screens ---------- */
@media (min-width: 520px) {
  .game-title { font-size: 2rem; }
  .app { gap: 16px; }
}
