:root {
  --green-dark: #3c6b1f;
  --green: #6fa83a;
  --green-light: #cfe8a6;
  --cell-light: #e7f3c9;
  --cell-dark: #b8dd86;
  --panel: rgba(255, 255, 255, 0.14);
  --panel-border: rgba(255, 255, 255, 0.35);
  --red: #d8392b;
  --blue: #1f63d8;
  --text: #ffffff;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: #7fae3f url("../img/background.png") center / 520px repeat;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* Textselektion dort erlauben, wo sie sinnvoll ist (Chat, Eingaben) */
.chat .log, input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Spielseite fuellt die Fensterhoehe, kein Scrolling */
body.game { overflow: hidden; height: 100vh; height: 100dvh; }
body.game .wrap {
  height: 100vh; height: 100dvh; padding: 10px; display: flex;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
body.game .game-grid { width: 100%; height: 100%; align-items: stretch; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, rgba(255,255,255,0.18), rgba(40,70,15,0.45));
  pointer-events: none;
  z-index: 0;
}

.wrap {
  position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 18px;
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}

/* ---------- Buttons ---------- */
button, .btn {
  font: inherit;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  background: linear-gradient(#7cbb43, #4f8a24);
  box-shadow: 0 4px 0 #3a6717, var(--shadow);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
button:hover, .btn:hover { filter: brightness(1.07); }
button:active, .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #3a6717; }
button:disabled { filter: grayscale(.6) brightness(.9); cursor: not-allowed; }
button.ghost { background: var(--panel); box-shadow: var(--shadow); border: 1px solid var(--panel-border); }
button.red { background: linear-gradient(#e8584a, #b9281c); box-shadow: 0 4px 0 #8a1d14, var(--shadow); }
button.blue { background: linear-gradient(#3f86f0, #1c52c0); box-shadow: 0 4px 0 #143c8e, var(--shadow); }

input[type=text] {
  font: inherit;
  font-size: 16px; /* verhindert Auto-Zoom bei Fokus auf iOS Safari */
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.92);
  color: #234;
  outline: none;
  width: 100%;
}

/* ---------- Landing ---------- */
.landing { text-align: center; padding-top: 12px; }
.landing img.logo { width: min(320px, 72vw); filter: drop-shadow(0 8px 12px rgba(0,0,0,.3)); }
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 22px;
  margin: 18px auto;
  max-width: 460px;
  backdrop-filter: blur(4px);
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; text-shadow: 0 2px 4px rgba(0,0,0,.35); }
.field { margin: 12px 0; text-align: left; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 4px;
  cursor: pointer;
  font-weight: 700;
}
.advanced-toggle input { width: 18px; height: 18px; cursor: pointer; }
.advanced-hint { margin: 4px 0 12px; opacity: .85; font-size: 12px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

.teamselect { display: flex; gap: 14px; justify-content: center; margin: 8px 0 4px; }
.teamselect .team {
  flex: 0 0 auto;
  width: 120px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  padding: 10px;
  cursor: pointer;
  border: 3px solid transparent;
  background: rgba(0,0,0,0.12);
  transition: transform .1s, border-color .1s;
}
.teamselect .team img { width: 64px; height: 64px; object-fit: contain; }
.teamselect .team.red.sel { border-color: var(--red); background: rgba(216,57,43,.22); }
.teamselect .team.blue.sel { border-color: var(--blue); background: rgba(31,99,216,.22); }
.teamselect .team:hover { transform: translateY(-3px); }
.teamselect .team .lbl { font-weight: 800; font-size: 20px; }

.tabs { display: flex; gap: 8px; margin-bottom: 8px; }
.tabs button { flex: 1; }
.tabs button:not(.active) { background: var(--panel); box-shadow: var(--shadow); }
.lobby-actions { display: flex; gap: 10px; margin: 14px 0 8px; }
.lobby-actions .lobby-btn { flex: 1; }
.lobby-actions .lobby-btn:disabled { opacity: 0.45; }
.lobby-hint { margin: 8px 0 0; }
.setup-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.setup-btns button { flex: 1; min-width: 130px; }
.join-modal-panel h2 { margin: 0 0 8px; font-size: 28px; text-shadow: 0 2px 4px rgba(0,0,0,.35); }
.join-modal-panel p { margin: 0 0 12px; font-weight: 700; }
.join-modal-panel .field { margin: 0 0 14px; }
.join-modal-panel .msg { margin-top: 10px; }
.hidden { display: none !important; }
.msg { min-height: 20px; margin-top: 8px; font-weight: 700; }
.msg.error { color: #ffe08a; }
.codebox { font-size: 32px; font-weight: 900; letter-spacing: 6px; padding: 10px; }

/* ---------- Game layout ---------- */
.game-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 18px;
  align-items: stretch;
  min-height: 0;
}
@media (max-width: 900px) {
  .game-grid { grid-template-columns: 1fr; }
  body.game { overflow: auto; height: auto; }
  body.game .wrap { height: auto; display: block; }
  body.game .game-grid { height: auto; }
  .side { height: auto; overflow: visible; }
  .board-area { min-height: 56dvh; }
  .side .logo-sm { max-height: 56px; }
}

@media (max-width: 480px) {
  .wrap { padding: 10px; }
  body.game .wrap { padding: 8px; }
  .banner { font-size: 16px; padding: 6px 8px; }
  .side .box { padding: 8px 10px; }
  #giveUpBox button { padding: 12px 14px; }
  .timer-num { font-size: 30px; }
  .timer-wrap { width: 72px; flex: 0 0 72px; }
  .referee-turn { width: 90px; flex: 0 0 90px; }
}

.boardpanel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.banner {
  text-align: center;
  font-weight: 800;
  font-size: 20px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
  text-shadow: 0 2px 4px rgba(0,0,0,.4);
  min-height: 22px;
  flex: 0 0 auto;
}
#topBanner { margin-bottom: 10px; }
#bottomBanner { margin-top: 10px; }
.banner .name-red { color: #fff; }
.banner .name-blue { color: #fff; }
.banner-red {
  background: var(--red);
  box-shadow: inset 0 0 0 2px rgba(255, 200, 190, 0.45), var(--shadow);
}
.banner-blue {
  background: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(190, 215, 255, 0.45), var(--shadow);
}

/* Board */
.board-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.board-overlay-host {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.board-overlay-host .overlay.combat-fx {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.72);
  pointer-events: auto;
}
.board {
  position: relative;
  flex: 0 0 auto;
  border-radius: 14px;
  overflow: visible;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.4), var(--shadow);
  background: #cfe8a6;
  /* Verhindert Doppeltipp-Zoom/Scroll-Konflikte beim Tap-to-move auf iOS */
  touch-action: none;
}
#actions { flex: 0 0 auto; margin-top: 10px; text-align: center; position: relative; z-index: 20; }
.cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.cell.light { background: var(--cell-light); }
.cell.dark { background: var(--cell-dark); }
.cell.sel { outline: 4px solid #ffd83a; outline-offset: -4px; }

/* Zug-Pfeile (wie im Original) statt Punkten */
.cell.target { --arrow: rgba(33,72,16,.92); }
.cell.target.enemy { --arrow: rgba(214,57,43,.92); }
.cell.target::after {
  content: "";
  width: 0; height: 0;
  opacity: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.35));
}
.cell.hover-target { --arrow: rgba(88, 96, 82, 0.72); }
.cell.hover-target.enemy { --arrow: rgba(118, 102, 102, 0.72); }
.cell.hover-target::after {
  content: "";
  width: 0; height: 0;
  opacity: 0.88;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
.cell.target.arrow-up::after {
  border-left: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.target.arrow-down::after {
  border-left: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .20) solid transparent;
  border-top: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.target.arrow-left::after {
  border-top: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.target.arrow-right::after {
  border-top: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .20) solid transparent;
  border-left: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.hover-target.arrow-up::after {
  border-left: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.hover-target.arrow-down::after {
  border-left: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .20) solid transparent;
  border-top: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.hover-target.arrow-left::after {
  border-top: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .20) solid transparent;
  border-right: calc(var(--cell) * .30) solid var(--arrow);
}
.cell.hover-target.arrow-right::after {
  border-top: calc(var(--cell) * .20) solid transparent;
  border-bottom: calc(var(--cell) * .20) solid transparent;
  border-left: calc(var(--cell) * .30) solid var(--arrow);
}

.cell.placeable { cursor: pointer; box-shadow: inset 0 0 0 3px rgba(255,216,58,.6); }

.cell.mark-king {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(200, 150, 20, .35) 0,
    rgba(200, 150, 20, .35) 6px,
    rgba(255, 216, 58, .18) 6px,
    rgba(255, 216, 58, .18) 12px
  );
}
.cell.mark-trap {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(80, 80, 80, .22) 0,
    rgba(80, 80, 80, .22) 6px,
    rgba(120, 120, 120, .10) 6px,
    rgba(120, 120, 120, .10) 12px
  );
}

.piece {
  position: absolute;
  left: 0; top: 0;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: contain;
  transform-origin: 50% 100%;
  transition: left .42s cubic-bezier(.45,.05,.55,.95), top .42s cubic-bezier(.45,.05,.55,.95), opacity .35s;
  pointer-events: none;
  z-index: 10;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,.35));
}
.piece.idle-l { animation: piece-idle-l 0.6s ease-in-out; }
.piece.idle-r { animation: piece-idle-r 0.6s ease-in-out; }
@keyframes piece-idle-l {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  30% { transform: rotate(-4.5deg) translateY(-4px); }
  55% { transform: rotate(-3deg) translateY(-2px); }
}
@keyframes piece-idle-r {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  30% { transform: rotate(4.5deg) translateY(-4px); }
  55% { transform: rotate(3deg) translateY(-2px); }
}
.piece.hop {
  transform-origin: 50% 100%;
  animation: piece-jump .42s ease-in-out;
}
@keyframes piece-jump {
  0%   { transform: translateY(0) scale(1, 1); }
  18%  { transform: translateY(0) scale(1.08, .86); }   /* crouch */
  50%  { transform: translateY(-42%) scale(.98, 1.06); } /* airborne peak */
  82%  { transform: translateY(0) scale(1.07, .9); }    /* landing squash */
  100% { transform: translateY(0) scale(1, 1); }
}
.board { cursor: default; }
.cursor-ghost {
  position: absolute;
  pointer-events: none;
  z-index: 25;
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: contain;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.45));
  opacity: .92;
  transform: scale(1.05);
}
.piece.enemy-turn { }
.piece.dead { transition: opacity .35s, transform .35s; opacity: 0; transform: scale(.2) translateY(-30px); }

/* Side panel */
.side { display: flex; flex-direction: column; gap: 10px; height: 100%; min-height: 0; overflow-y: auto; }
.side .box {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  text-align: center;
  flex: 0 0 auto;
}

/* Am-Zug-Anzeige */
.turnbox { transition: background .2s, border-color .2s; }
.turn-label { font-weight: 800; font-size: 18px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.turnbox.red { background: rgba(216,57,43,.30); border-color: rgba(216,57,43,.65); }
.turnbox.blue { background: rgba(31,99,216,.30); border-color: rgba(31,99,216,.65); }
.turnbox.urgent.red { animation: turnglow-red 1.1s ease-in-out infinite; }
.turnbox.urgent.blue { animation: turnglow-blue 1.1s ease-in-out infinite; }
@keyframes turnglow-red {
  0%,100% { box-shadow: 0 0 0 2px rgba(232,88,74,.5), var(--shadow); }
  50% { box-shadow: 0 0 16px 3px rgba(232,88,74,.95), var(--shadow); }
}
@keyframes turnglow-blue {
  0%,100% { box-shadow: 0 0 0 2px rgba(63,134,240,.5), var(--shadow); }
  50% { box-shadow: 0 0 16px 3px rgba(63,134,240,.95), var(--shadow); }
}
.turn-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.side .logo-sm { width: 100%; max-height: 84px; object-fit: contain; }
.timer-ref-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.timer-wrap { position: relative; width: 92px; flex: 0 0 92px; transition: filter .2s; }
.timer-wrap img { width: 100%; display: block; }
.timer-wrap.red { filter: drop-shadow(0 0 10px rgba(232,88,74,.65)); }
.timer-wrap.blue { filter: drop-shadow(0 0 10px rgba(63,134,240,.65)); }
.timer-wrap.urgent { animation: timer-urgent 0.65s ease-in-out infinite; }
.timer-wrap.urgent.red { filter: drop-shadow(0 0 14px rgba(232,88,74,.95)); }
.timer-wrap.urgent.blue { filter: drop-shadow(0 0 14px rgba(63,134,240,.95)); }
@keyframes timer-urgent {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
.timer-num {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 900; color: #3c6b1f;
  text-shadow: 0 2px 0 rgba(255,255,255,.6);
}
.referee-turn {
  width: 114px;
  flex: 0 0 114px;
  animation: referee-bounce 1.8s ease-in-out infinite;
  transition: filter .25s, transform .25s;
}
.referee-turn img { width: 100%; display: block; }
.referee-turn.red { filter: drop-shadow(0 4px 8px rgba(232,88,74,.45)); }
.referee-turn.blue { filter: drop-shadow(0 4px 8px rgba(63,134,240,.45)); }
@keyframes referee-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.series-score-box { padding: 8px 10px !important; }
.series-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.series-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.series-team img {
  width: 48px;
  height: auto;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.35));
}
.series-num {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0,0,0,.4);
}
.series-team.red .series-num { color: var(--red); }
.series-team.blue .series-num { color: var(--blue); }
.series-sep {
  font-size: 24px;
  font-weight: 900;
  opacity: .85;
  padding: 0 2px;
  margin-bottom: 18px;
}

/* Chat */
.side .chat { flex: 1 1 auto; min-height: 90px; display: flex; flex-direction: column; }
.chat .log {
  flex: 1 1 auto; height: auto; min-height: 60px; overflow-y: auto; text-align: left;
  background: rgba(0,0,0,.18); border-radius: 10px; padding: 8px; margin-bottom: 8px;
  font-size: 14px;
}
.chat .log .ln { margin: 2px 0; word-wrap: break-word; }
.chat .log .ln.system { font-style: italic; opacity: 0.92; color: #e8f5d0; }
.chat .log .ln.notice { font-style: italic; opacity: 0.95; }
.chat .log .ln.notice.red { color: #ffb3a8; }
.chat .log .ln.notice.blue { color: #b9d0ff; }
.chat .log .ln.notice b { font-weight: 800; }
.chat .log .ln b.red { color: #ffb3a8; }
.chat .log .ln b.blue { color: #b9d0ff; }
.chat form { display: flex; gap: 6px; }
.chat input { flex: 1; }
.chat button { padding: 10px 14px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
  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));
}
.overlay .panel {
  background: linear-gradient(#6fa83a, #4f8a24);
  border: 3px solid rgba(255,255,255,.5);
  border-radius: 20px; padding: 26px 30px; text-align: center;
  box-shadow: var(--shadow); max-width: 420px;
  max-height: 90dvh; max-height: 90vh;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}
.overlay h1 { margin: 6px 0 10px; font-size: 34px; text-shadow: 0 3px 6px rgba(0,0,0,.4); }

/* Tiebreak chooser */
.choose { display: flex; gap: 14px; justify-content: center; margin-top: 14px; }
.choose .pick {
  width: 96px; height: 96px; border-radius: 16px;
  background: rgba(255,255,255,.92);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 3px solid transparent; transition: transform .1s, border-color .1s;
}
.choose .pick:hover { transform: translateY(-4px); border-color: #ffd83a; }
.choose .pick img { width: 78px; height: 78px; object-fit: contain; }
.choose .pick .cap { display:none; }
.waitline { margin-top: 12px; font-weight: 700; }

/* Clash effect */
.clash-fx {
  position: absolute; z-index: 20; pointer-events: none;
  background: url("../img/clash.png") center/contain no-repeat;
  animation: clashpop .7s ease forwards;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.4));
}
@keyframes clashpop {
  0% { transform: scale(.2) rotate(-12deg); opacity: 0; }
  35% { transform: scale(1.15) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 0; }
}

/* Trapdoor effect (Falltuer) */
.trap-hole {
  position: absolute; z-index: 39; pointer-events: none;
  background: url("../img/hole.png") center/contain no-repeat;
  transform-origin: center center;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.45));
  animation: holeopen 1.1s ease forwards;
}
@keyframes holeopen {
  0%   { opacity: 0; transform: scale(.35) rotate(-6deg); }
  20%  { opacity: 1; transform: scale(1.12) rotate(2deg); }
  75%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.96); }
}
.trap-fall {
  position: absolute; z-index: 40; pointer-events: none;
  background-repeat: no-repeat; background-position: center bottom; background-size: contain;
  filter: drop-shadow(0 4px 3px rgba(0,0,0,.35));
  animation: trapfall 1.05s cubic-bezier(.5,0,.9,.4) forwards;
}
@keyframes trapfall {
  0%   { opacity: 1; transform: translateY(-34%) scale(1) rotate(0); }
  35%  { opacity: 1; transform: translateY(2%)  scale(.92) rotate(6deg); }
  100% { opacity: 0; transform: translateY(48%) scale(.25) rotate(26deg); }
}

/* Endscreen (Game Over) */
.endscreen { text-align: center; }
.gameover {
  font-size: 46px; font-weight: 900; letter-spacing: 1px; color: #fff;
  -webkit-text-stroke: 3px #3c6b1f;
  text-shadow: 0 4px 0 #2c5114, 0 7px 10px rgba(0,0,0,.4);
  margin-bottom: 8px;
}
.es-scene {
  display: flex; align-items: flex-end; justify-content: center; gap: 6px;
  margin: 6px 0 4px;
}
.es-ref { width: 150px; align-self: center; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)); }
.es-fighter {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 112px;
  flex: 0 0 112px;
}
.es-fighter.win {
  width: 140px;
  flex: 0 0 140px;
}
.es-fighter.lose {
  width: 88px;
  flex: 0 0 88px;
}
.es-fighter-fig {
  position: relative;
  width: 100%;
  height: 118px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.es-fighter.win .es-fighter-fig { height: 150px; }
.es-fighter.lose .es-fighter-fig { height: 92px; }
.es-fighter img {
  width: 96px;
  height: 110px;
  object-fit: contain;
  object-position: center bottom;
  display: block;
  filter: drop-shadow(0 5px 6px rgba(0,0,0,.35));
}
.es-fighter.win img { width: 120px; height: 140px; }
.es-fighter.lose img { width: 76px; height: 88px; }
.es-fighter.win img { animation: winbob 1.2s ease-in-out infinite; }
@keyframes winbob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.es-crown {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  background: #ffd83a; color: #5a3d00; font-weight: 900; font-size: 11px;
  padding: 2px 8px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,.3); white-space: nowrap;
}
.es-result {
  margin: 8px 0 4px;
  font-size: 34px;
  font-weight: 800;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.9);
  paint-order: stroke fill;
}
.es-result.red { color: var(--red); }
.es-result.blue { color: var(--blue); }
.es-btns {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 14px;
}
.es-btns .btn, .es-btns button { min-width: 130px; min-height: 44px; }

/* Give up confirmation */
.confirm-modal p { margin: 8px 0 16px; font-weight: 700; }
.confirm-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.confirm-btns button { min-width: 130px; min-height: 44px; }
.confirm-btns-stacked {
  flex-direction: column;
  align-items: stretch;
  margin-top: 24px;
}
.confirm-btns-stacked button {
  width: 100%;
  min-width: 0;
}
.lobby-wait-btns {
  margin-top: 20px;
}

/* Combat result modal */
.combat-modal { text-align: center; }
.overlay.combat-fx { background: rgba(0,0,0,.72); }
.board-overlay-host .overlay.combat-fx { background: rgba(0,0,0,.72); }
.overlay .panel.combat-panel {
  max-width: 560px;
  min-width: min(480px, 92vw);
  width: min(560px, 92vw);
  padding: 20px 24px;
  background: transparent;
  border: none;
  box-shadow: none;
}
.board-overlay-host .overlay .panel.combat-panel {
  max-width: 96%;
  min-width: 0;
  width: 96%;
}
.cm-arena {
  position: relative;
  width: 100%;
  height: 260px;
  margin: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 12px;
  overflow: visible;
  --cm-lunge-offset: 190px;
}
.cm-fighter {
  flex: 0 0 auto;
  height: 210px;
  width: auto;
  max-width: 40%;
  object-fit: contain;
  object-position: center bottom;
  transform: translateX(0);
  opacity: 1;
  transition: transform 0.45s cubic-bezier(0.45, 0.05, 0.55, 0.95), opacity 0.25s ease, height 0.45s cubic-bezier(0.45, 0.05, 0.55, 0.95);
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.45));
  z-index: 2;
}
.cm-fighter.win { height: 265px; max-width: 44%; }
.cm-fighter.lose { height: 165px; max-width: 30%; }
.cm-arena.phase-hold .cm-fighter.win { animation: winbob 1.2s ease-in-out infinite; }
.cm-arena.phase-lunge .cm-blue,
.cm-arena.phase-clash .cm-blue { transform: translateX(var(--cm-lunge-offset)); }
.cm-arena.phase-lunge .cm-red,
.cm-arena.phase-clash .cm-red { transform: translateX(calc(-1 * var(--cm-lunge-offset))); }
.cm-arena.phase-return,
.cm-arena.phase-hold {
  justify-content: center;
  gap: 32px;
  padding: 0 16px;
}
.cm-arena.phase-clash .cm-fighter { opacity: 0; }
.cm-clash {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 390px;
  height: 390px;
  transform: translate(-50%, -50%) scale(0.7);
  background: url("../img/clash.png") center/contain no-repeat;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 3;
  pointer-events: none;
  transform-origin: center center;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.35));
}
.cm-clash::after {
  content: "";
  position: absolute;
  inset: 8%;
  background: url("../img/clash.png") center/contain no-repeat;
  opacity: 0.45;
  transform-origin: center center;
  pointer-events: none;
}
.cm-arena.phase-clash .cm-clash {
  opacity: 1;
  animation: cmClashPop 0.35s ease-out forwards, cmClashFight 0.3s 0.35s ease-in-out infinite;
}
.cm-arena.phase-clash .cm-clash::after {
  animation: cmClashFightAlt 0.22s 0.35s ease-in-out infinite;
}
.cm-arena.phase-return .cm-clash,
.cm-arena.phase-hold .cm-clash {
  animation: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
}
@keyframes cmClashPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.45) rotate(-14deg); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(6deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}
@keyframes cmClashFight {
  0%   { transform: translate(-50%, -50%) scale(0.96) rotate(-5deg); filter: brightness(1); }
  18%  { transform: translate(calc(-50% + 10px), calc(-50% - 7px)) scale(1.12) rotate(8deg); filter: brightness(1.18); }
  36%  { transform: translate(calc(-50% - 9px), calc(-50% + 8px)) scale(0.9) rotate(-9deg); filter: brightness(0.92); }
  54%  { transform: translate(calc(-50% + 7px), calc(-50% + 5px)) scale(1.15) rotate(7deg); filter: brightness(1.22); }
  72%  { transform: translate(calc(-50% - 11px), calc(-50% - 6px)) scale(0.93) rotate(-8deg); filter: brightness(0.95); }
  88%  { transform: translate(calc(-50% + 8px), calc(-50% + 4px)) scale(1.1) rotate(5deg); filter: brightness(1.12); }
  100% { transform: translate(-50%, -50%) scale(1.02) rotate(-4deg); filter: brightness(1.05); }
}
@keyframes cmClashFightAlt {
  0%   { transform: scale(0.88) rotate(6deg); opacity: 0.35; }
  25%  { transform: scale(1.05) rotate(-8deg); opacity: 0.55; }
  50%  { transform: scale(0.82) rotate(9deg); opacity: 0.4; }
  75%  { transform: scale(1.08) rotate(-6deg); opacity: 0.5; }
  100% { transform: scale(0.9) rotate(5deg); opacity: 0.38; }
}
.cm-win {
  margin-top: 2px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  -webkit-text-stroke: 2px rgba(255, 255, 255, 0.9);
  paint-order: stroke fill;
}
.cm-win.visible {
  opacity: 1;
  transform: translateY(0);
}
.cm-win.red { color: var(--red); }
.cm-win.blue { color: var(--blue); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 18px; border-radius: 12px;
  z-index: 60; font-weight: 700; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.small { font-size: 13px; opacity: .9; }
a { color: #ffe08a; }

/* --- Debug panel --- */
.dbg-panel {
  position: fixed; top: 10px; left: 10px; z-index: 80;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.dbg-toggle {
  font: 700 11px/1 monospace; letter-spacing: .5px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer;
  background: rgba(20,20,20,.7); color: #9fe89f; border: 1px solid #3a5a3a;
}
.dbg-toggle:hover { background: rgba(20,20,20,.9); }
.dbg-body { display: none; flex-direction: column; gap: 5px; }
.dbg-panel.open .dbg-body { display: flex; }
.dbg-btn {
  font: 600 12px/1 system-ui, sans-serif;
  padding: 6px 10px; border-radius: 6px; cursor: pointer; text-align: left;
  background: rgba(30,30,30,.82); color: #eee; border: 1px solid #555;
  min-width: 118px;
}
.dbg-btn:hover { background: rgba(60,60,60,.95); border-color: #888; }
.dbg-group {
  font: 700 10px/1 monospace; letter-spacing: 1px; text-transform: uppercase;
  color: #9fe89f; padding: 6px 2px 1px;
}
.dbg-btn.dbg-sub { font-size: 11px; padding: 4px 8px; }
.dbg-btn.dbg-tie { color: #ffd27a; border-color: #6a5a30; }
