:root {
  /* Hintergrund / Brett */
  --bg-top: #ecf7a6;
  --bg-bot: #7eac38;
  --board-light: #d9ea80;
  --board-dark: #c3db5d;
  --frame: #8bb33b;
  --frame-edge: #6b9128;
  --ink: #2f4310;
  --muted: #6f7d39;
  /* Karten */
  --card: #fffdf4;
  --card-border: #ece6c8;
  /* Akzente (chunky Buttons) */
  --accent: #ffd24a;
  --accent-edge: #e7a81d;
  --accent-ink: #5b3d00;
  --go: #5ec154;
  --go-edge: #3a9a30;
  --wa: #34d171;
  --wa-edge: #18a64c;
  --danger: #ff5a45;
  --player: #2f6fe0;
  /* Schatten / Radien */
  --shadow-card: 0 16px 38px rgba(36, 54, 10, .26), 0 3px 10px rgba(36, 54, 10, .16);
  --shadow-soft: 0 6px 16px rgba(36, 54, 10, .15);
  --radius: 16px;
  --radius-lg: 24px;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  /* Weicher Mesh-Verlauf aus mehreren Grün-Tönen für einen frischen, modernen Look */
  background-color: #8bbb40;
  background:
    radial-gradient(1100px 720px at 50% -18%, #eefaa8 0%, rgba(238, 250, 168, 0) 55%),
    radial-gradient(820px 620px at 6% 102%, #54a23a 0%, rgba(84, 162, 58, 0) 58%),
    radial-gradient(900px 640px at 98% 108%, #74c07a 0%, rgba(116, 192, 122, 0) 56%),
    radial-gradient(760px 560px at 88% 4%, #c7e85f 0%, rgba(199, 232, 95, 0) 50%),
    linear-gradient(162deg, #a9d251 0%, #79aa37 100%);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.topbar, .side-label, .btn, .banner, .menu, .cyw, .result, .board, .setup-bar {
  user-select: none;
  -webkit-user-select: none;
}
.btn, .cell, .weapon-btn, .code-input { touch-action: manipulation; }

#app { width: 100%; max-width: 560px; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.logo {
  font-weight: 900;
  font-size: 26px;
  letter-spacing: .3px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(36, 54, 10, .28);
  white-space: nowrap;
}
.logo span { color: #fff0a6; }
.status {
  flex: 1;
  background: rgba(255, 255, 255, .9);
  border-radius: 14px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  min-height: 38px;
  display: flex;
  align-items: center;
  box-shadow: var(--shadow-soft);
}

/* ---- Buttons (verspielt, aber weicher/moderner) ---- */
.btn {
  border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-edge));
  color: var(--accent-ink);
  font-family: var(--font);
  font-weight: 800;
  font-size: 16px;
  min-height: 46px;
  padding: 12px 20px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-edge), 0 7px 14px rgba(36, 54, 10, .18);
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-edge), 0 3px 8px rgba(36, 54, 10, .16); }
.btn.big { font-size: 17px; padding: 13px 22px; margin-top: 12px; border-radius: 16px; }
.btn.primary {
  background: linear-gradient(180deg, var(--go), var(--go-edge));
  color: #fff;
  box-shadow: 0 4px 0 var(--go-edge), 0 7px 14px rgba(36, 54, 10, .18);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .15);
}
.btn.primary:active { box-shadow: 0 1px 0 var(--go-edge), 0 3px 8px rgba(36, 54, 10, .16); }
.btn.whatsapp {
  background: linear-gradient(180deg, var(--wa), var(--wa-edge));
  color: #fff;
  box-shadow: 0 4px 0 var(--wa-edge), 0 7px 14px rgba(36, 54, 10, .18);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
.btn.whatsapp:active { box-shadow: 0 1px 0 var(--wa-edge), 0 3px 8px rgba(36, 54, 10, .16); }
.btn.resume {
  background: linear-gradient(180deg, #4f9bf0, #2f6fe0);
  color: #fff;
  box-shadow: 0 4px 0 #2456b8, 0 7px 14px rgba(36, 54, 10, .18);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
.btn.resume:active { box-shadow: 0 1px 0 #2456b8, 0 3px 8px rgba(36, 54, 10, .16); }
.btn.link {
  background: none;
  box-shadow: none;
  color: var(--frame-edge);
  text-decoration: underline;
  font-weight: 700;
  padding: 4px;
  min-height: 0;
}

/* In-Game-Buttons (unter dem Brett) etwas größer & fingerfreundlich */
.setup-bar .btn {
  flex: 1;
  max-width: 220px;
  font-size: 17px;
  min-height: 52px;
}
.btn.link:hover { filter: none; }
.btn.link:active { transform: none; }

/* ---- Arena / Brett (weiches Felt-Panel statt dickem Rand) ---- */
.arena {
  background: linear-gradient(180deg, #93bd45, #7ba835);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow:
    var(--shadow-card),
    inset 0 0 0 2px rgba(255, 255, 255, .22),
    inset 0 2px 0 rgba(255, 255, 255, .28);
}
.side-label {
  text-align: center;
  font-weight: 800;
  letter-spacing: .4px;
  padding: 5px 0;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .22);
}
.side-label.opponent { color: #ffd9d3; }
.side-label.you { color: #d3e3ff; }

.board-wrap { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--board-dark);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .06), inset 0 0 22px rgba(40, 60, 10, .12);
}

/* Aufstellungs-Banner */
.banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.banner.show { opacity: 1; }
.banner span {
  font-size: clamp(22px, 7vw, 40px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 #4f6c14, 0 0 16px rgba(0, 0, 0, .3);
  text-align: center;
  padding: 0 10px;
}

.setup-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 14px;
}
.setup-bar:empty { display: none; }

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--board-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell.dark { background: var(--board-dark); }
.cell.selected { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 14px rgba(255, 210, 74, .55); }
.cell.target { cursor: pointer; }
.cell.target.attack { box-shadow: inset 0 0 0 3px var(--danger), inset 0 0 14px rgba(255, 90, 69, .4); }
.cell.placeable { cursor: pointer; }
.cell.placeable::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 9px;
  border: 3px solid #fff;
  background: rgba(255, 255, 255, .22);
  box-shadow: 0 0 0 2px rgba(58, 90, 18, .55), 0 0 12px rgba(255, 255, 255, .55);
  pointer-events: none;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .5; transform: scale(.86); }
  50% { opacity: 1; transform: scale(1); }
}
.cell .dot {
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .8);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

.piece {
  width: 92%;
  height: 92%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: default;
  transition: transform .08s;
}
.piece.player { cursor: pointer; }
.piece .sprite { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .12)); }
.cell.selected .piece { transform: translateY(-3px) scale(1.05); }

/* Figuren "leben": Wippen + Hüpfer */
.piece.fighter-idle { animation: bob 2.6s ease-in-out infinite; animation-delay: var(--bob, 0s); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4%); } }
.piece.hop { animation: hop .5s ease; }
@keyframes hop {
  0% { transform: translateY(0); }
  30% { transform: translateY(-26%) scale(1.05); }
  55% { transform: translateY(0); }
  72% { transform: translateY(-9%); }
  100% { transform: translateY(0); }
}

/* Niederlage einer Figur */
.defeat {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(7vw, 40px);
}
.defeat .ko-sprite {
  position: absolute;
  width: 96%;
  height: 96%;
  transform-origin: center;
  animation: koFly .9s cubic-bezier(.3, .7, .3, 1) forwards;
}
@keyframes koFly {
  0%   { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
  16%  { transform: translateY(6%) scale(1.2, .8); }
  30%  { transform: translateY(-8%) scale(.92, 1.12); filter: brightness(1.8) saturate(.3); }
  100% { transform: translateY(-130%) rotate(230deg) scale(.2); opacity: 0; }
}
.defeat .ko-burst { position: absolute; animation: koBurst .55s ease-out forwards; }
@keyframes koBurst {
  0% { transform: scale(.2); opacity: 0; }
  30% { transform: scale(1.6); opacity: 1; }
  100% { transform: scale(1.2); opacity: 0; }
}
.defeat .ko-puff { position: absolute; opacity: .9; animation: koPuff .9s ease-out forwards; }
@keyframes koPuff {
  0% { transform: scale(.3) translateY(10%); opacity: 0; }
  40% { opacity: .85; }
  100% { transform: scale(1.9) translateY(-35%); opacity: 0; }
}

/* Lade-Spinner */
.spinner {
  width: 42px;
  height: 42px;
  margin: 12px auto 4px;
  border: 5px solid rgba(36, 54, 10, .12);
  border-top-color: var(--go);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.menu-step {
  background: rgba(94, 193, 84, .12);
  border: 1px solid rgba(94, 193, 84, .35);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  color: #3d5e15;
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Kampf-Modal ---- */
.combat-ov { background: rgba(20, 30, 5, .6); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.combat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 26px 22px;
  text-align: center;
  min-width: min(360px, 90vw);
  animation: pop .2s cubic-bezier(.2, .9, .3, 1.2);
}
.cbt-arena {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: 150px;
}
.cbt { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cbt.me { animation: slideInL .45s cubic-bezier(.3, .8, .4, 1.3) both; }
.cbt.opp { animation: slideInR .45s cubic-bezier(.3, .8, .4, 1.3) both; }
@keyframes slideInL { 0% { transform: translateX(-130%); opacity: 0; } 70% { transform: translateX(10%); } 100% { transform: translateX(0); opacity: 1; } }
@keyframes slideInR { 0% { transform: translateX(130%); opacity: 0; } 70% { transform: translateX(-10%); } 100% { transform: translateX(0); opacity: 1; } }
.obj-wrap { position: relative; width: 86px; height: 86px; display: flex; align-items: center; justify-content: center; }
.cbt-obj { position: absolute; font-size: 64px; line-height: 1; }
.cbt-obj.half { display: none; }
.cbt-tag { font-weight: 800; color: var(--muted); }
.cbt.me .cbt-tag { color: var(--player); }
.cbt.opp .cbt-tag { color: #d24b3a; }

.cbt-clash { font-size: 42px; opacity: 0; animation: clashPop .45s ease-out .42s both; }
@keyframes clashPop { 0% { transform: scale(0) rotate(-30deg); opacity: 0; } 40% { transform: scale(1.6); opacity: 1; } 100% { transform: scale(1); opacity: 0; } }

.cbt.win .whole { animation: winnerPulse 1s ease .5s both; }
@keyframes winnerPulse {
  0% { transform: scale(1); }
  25% { transform: scale(1.4) rotate(-7deg); }
  45% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1.25); filter: drop-shadow(0 0 12px rgba(94, 193, 84, .9)); }
}
.cbt.lose .whole { animation: loserFlash .35s ease .5s both; }
@keyframes loserFlash { 0% { filter: none; } 45% { filter: brightness(2.2) saturate(5) hue-rotate(-25deg); transform: scale(1.05); } 100% { opacity: 0; } }
.cbt.lose .half { display: block; }
.cbt.lose .half.top { clip-path: inset(0 0 50% 0); animation: cutTop .75s ease .82s both; }
.cbt.lose .half.bot { clip-path: inset(50% 0 0 0); animation: cutBot .75s ease .82s both; }
@keyframes cutTop { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(-28px, -34px) rotate(-30deg); } }
@keyframes cutBot { 0% { opacity: 1; transform: translate(0, 0) rotate(0); } 100% { opacity: 0; transform: translate(28px, 38px) rotate(30deg); } }
.cbt.lose .slash {
  position: absolute; left: -10%; top: 48%; width: 120%; height: 5px; border-radius: 3px;
  background: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, .95);
  transform: scaleX(0) rotate(-26deg); transform-origin: left center;
  animation: slashSweep .28s ease .72s both;
}
@keyframes slashSweep { 0% { transform: scaleX(0) rotate(-26deg); opacity: 0; } 35% { opacity: 1; } 100% { transform: scaleX(1) rotate(-26deg); opacity: 0; } }

.cbt-caption { margin-top: 16px; font-size: 20px; font-weight: 900; color: var(--frame-edge); opacity: 0; animation: fadeUp .4s ease .7s both; }
.cbt-sub { margin-top: 4px; font-weight: 800; opacity: 0; animation: fadeUp .4s ease .9s both; }
.cbt-sub.good { color: #2f9a3a; }
.cbt-sub.bad { color: #d24b3a; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Overlays ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 42, 6, .42);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.cyw, .result, .menu {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 26px 26px;
  text-align: center;
  box-shadow: var(--shadow-card);
  max-width: 94vw;
  animation: pop .24s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.cyw h2, .result h2 { margin: 0 0 4px; color: var(--frame-edge); font-size: 24px; }
.cyw-sub { margin: 0 0 16px; font-weight: 700; color: var(--muted); }

.weapons { display: flex; gap: 12px; justify-content: center; }
.weapon-btn {
  border: 2px solid var(--card-border);
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 86px;
  box-shadow: var(--shadow-soft);
  transition: transform .08s ease, box-shadow .12s ease, border-color .12s;
}
.weapon-btn:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 10px 20px rgba(36, 54, 10, .18); }
.weapon-btn:active { transform: translateY(0); }
.weapon-btn .wi { font-size: 40px; line-height: 1; }
.weapon-btn .wn { font-weight: 800; color: var(--ink); }

.countdown { margin-top: 16px; font-size: 30px; font-weight: 900; color: var(--danger); }
.countdown span {
  display: inline-block;
  min-width: 54px;
  background: #fff;
  border: 3px solid var(--danger);
  border-radius: 50%;
  padding: 7px 0;
  box-shadow: var(--shadow-soft);
}

.result.win h2 { color: #2f9a3a; }
.result.lose h2 { color: #d24b3a; }
.result p { margin: 6px 0 0; font-weight: 700; color: var(--muted); }

/* ---- Menü & Lobby ---- */
.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: min(340px, 88vw);
}
.menu h2 { margin: 0; color: var(--frame-edge); font-size: 27px; }
.menu-sub { margin: -4px 0 8px; font-weight: 700; color: var(--muted); }
.menu .btn.big { width: 100%; }
.join-row { display: flex; gap: 8px; }
.code-input {
  flex: 1;
  border: 2px solid var(--card-border);
  border-radius: 12px;
  padding: 11px 12px;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  min-width: 0;
}
.code-input:focus { outline: none; border-color: var(--accent); }
.code-big {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--player);
  background: linear-gradient(180deg, #fff, #f3f7ff);
  border: 2px dashed #bcd0f5;
  border-radius: 14px;
  padding: 14px;
}
.menu-err { color: #d24b3a; font-weight: 800; margin: 0; min-height: 18px; }
.menu-hint { color: #2f9a3a; font-weight: 800; margin: 0; min-height: 18px; }

/* ---- Quizduell: Spieleliste & Formulare ---- */
.menu.games { min-width: min(420px, 92vw); }
.games-list { display: flex; flex-direction: column; gap: 8px; margin: 2px 0 6px; max-height: 46vh; overflow-y: auto; }
.game-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 2px solid var(--card-border); background: #fff; border-radius: 14px;
  padding: 12px 14px; cursor: pointer; font-family: var(--font); font-weight: 800; color: var(--ink);
  box-shadow: var(--shadow-soft); transition: transform .08s ease, border-color .12s;
}
.game-item:hover { transform: translateY(-2px); }
.game-item.active { border-color: var(--go); box-shadow: 0 0 0 2px rgba(94, 193, 84, .4), var(--shadow-soft); }
.gi-opp { font-size: 16px; }
.gi-badge { font-size: 12.5px; font-weight: 800; padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.gi-badge.turn { background: #e1f6da; color: #2f8a2f; }
.gi-badge.wait { background: #edefe1; color: #7a7f57; }
.gi-badge.won { background: #dcefd2; color: #2f8a2f; }
.gi-badge.lost { background: #f7ded9; color: #c0392b; }
.rename { color: var(--player); text-decoration: underline; cursor: pointer; font-weight: 800; }
.field { display: flex; flex-direction: column; gap: 4px; text-align: left; font-weight: 800; color: var(--muted); font-size: 13px; }
.text-input {
  border: 2px solid var(--card-border); border-radius: 12px; padding: 11px 12px;
  font-family: var(--font); font-size: 18px; font-weight: 700; color: var(--ink); width: 100%;
}
.text-input:focus { outline: none; border-color: var(--accent); }
.empty { opacity: .85; }

/* ============ Mobile (Hochformat) ============ */
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
  .logo { font-size: 22px; }
  .controls { margin-left: auto; }
  .controls .btn { font-size: 16px; min-height: 48px; padding: 12px 20px; }
  .status { order: 3; flex-basis: 100%; font-size: 14px; min-height: 34px; padding: 9px 12px; }
  .arena { padding: 9px; border-radius: 18px; }
  .side-label { font-size: 15px; padding: 4px 0; }
  .btn.big { font-size: 17px; padding: 14px 16px; min-height: 52px; }
  /* Spielfeld-Buttons unterm Brett: groß & über die Breite verteilt */
  .setup-bar { gap: 10px; margin-top: 14px; }
  .setup-bar .btn { flex: 1; max-width: none; font-size: 17px; min-height: 56px; padding: 14px 10px; }
  .cyw, .result, .menu { padding: 20px 16px; }
  .menu h2, .cyw h2, .result h2 { font-size: 22px; }
  .weapons { gap: 8px; }
  .weapon-btn { min-width: 0; flex: 1; padding: 12px 6px; }
  .weapon-btn .wi { font-size: 34px; }
  .weapon-btn .wn { font-size: 13px; }
  .countdown { font-size: 26px; }
  .code-big { font-size: 32px; letter-spacing: 5px; }
  .code-input { font-size: 18px; letter-spacing: 2px; padding: 11px 8px; }
}

/* ============ Niedrige Höhe (Querformat) ============ */
@media (max-height: 560px) and (orientation: landscape) {
  body { align-items: flex-start; }
  .board { max-width: calc((100dvh - 120px) * 7 / 6); margin: 0 auto; }
  .topbar { margin-bottom: 6px; }
}
