:root {
  --bg: #14161f;
  --panel: #1e2130;
  --cell-a: #262a3d;
  --cell-b: #2b3045;
  --line: #11131b;
  --text: #e8eaf2;
  --muted: #9aa0b8;
  --accent: #4fd1c5;
  --danger: #ff6b6b;
  --pad-size: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud h1 {
  margin: 0;
  font-size: 1.25rem;
}

.stats {
  display: flex;
  gap: 14px;
  font-size: 0.95rem;
  color: var(--muted);
}

.stats strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Plansza mieści się w szerokości ekranu i w wysokości pozostałej po panelu sterowania */
.board-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 330px) * 21 / 31));
  min-width: 200px;
}

.cell-flash {
  position: absolute;
  pointer-events: none;
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 10px 2px rgba(79, 209, 197, 0.7);
  opacity: 0;
  transition: opacity 0.15s;
}

.cell-flash.on {
  opacity: 1;
  transition: none;   /* podświetlenie od razu, wygaszanie płynne */
}

/* Sztywne kolumny i wiersze (minmax(0, 1fr)) — zawartość pola nie może rozepchać wiersza */
.board {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;  /* bez systemowego podświetlenia całej planszy po dotknięciu */
  display: grid;
  grid-template-columns: repeat(21, minmax(0, 1fr));
  grid-template-rows: repeat(31, minmax(0, 1fr));
  aspect-ratio: 21 / 31;
  width: 100%;
  gap: 1px;
  padding: 1px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

/* Ikony to tła SVG — skalują się do pola i nie mają marginesów jak emoji */
.cell {
  min-width: 0;
  min-height: 0;
  background-color: var(--cell-a);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 84%;
}

.cell.alt { background-color: var(--cell-b); }

.cell.robot {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='9' y='0.5' width='2' height='3' fill='%23c9ced9'/%3E%3Crect x='3' y='3' width='14' height='12.5' rx='3' fill='%23c9ced9'/%3E%3Crect x='5.5' y='6.5' width='3' height='3' fill='%23ff4d4d'/%3E%3Crect x='11.5' y='6.5' width='3' height='3' fill='%23ff4d4d'/%3E%3Crect x='6' y='11.5' width='8' height='1.6' fill='%23555c70'/%3E%3Crect x='5' y='15.5' width='3' height='4' fill='%23c9ced9'/%3E%3Crect x='12' y='15.5' width='3' height='4' fill='%23c9ced9'/%3E%3C/svg%3E");
}

.cell.player {
  background-color: #1f4f4a;
  box-shadow: inset 0 0 0 2px var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='6' r='4.2' fill='%234fd1c5'/%3E%3Cpath d='M2.5 19.5c0-4.5 3.4-7.5 7.5-7.5s7.5 3 7.5 7.5z' fill='%234fd1c5'/%3E%3C/svg%3E");
}

.cell.flame {
  background-color: #4a2318;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 1c1 4 6 6 6 11a6 6 0 0 1-12 0c0-3 2-4 2-7 2 1 3 3 3 5 1-2 2-5 1-9z' fill='%23ff7b29'/%3E%3Cpath d='M10 10c1 2 3 3 3 5a3 3 0 0 1-6 0c0-2 2-3 3-5z' fill='%23ffd166'/%3E%3C/svg%3E");
  animation: flicker 0.8s infinite alternate;
}

.cell.dead {
  background-color: #8a1f1f;
  box-shadow: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 4l12 12M16 4L4 16' stroke='%23ffffff' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.cell.boom { animation: boom 0.5s ease-out; }

@keyframes flicker {
  from { filter: brightness(0.9); }
  to   { filter: brightness(1.3); }
}

@keyframes boom {
  0%   { transform: scale(1.8); background-color: #ffd166; }
  100% { transform: scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 11, 16, 0.7);
  border-radius: 6px;
  padding: 16px;
}

.overlay[hidden] { display: none; }

.overlay-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  max-width: 280px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.overlay-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--danger);
}

.btn-primary {
  margin-top: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #0b1a19;
  font-weight: 700;
  cursor: pointer;
}

.side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.status {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  font-size: 0.95rem;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, var(--pad-size));
  grid-template-rows: repeat(3, var(--pad-size));
  gap: 6px;
}

.pad-btn {
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 3px 0 #0c0d13;
  transition: transform 0.05s, background 0.15s;
}

.pad-btn:active:not(:disabled),
.pad-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0c0d13, 0 0 14px rgba(79, 209, 197, 0.6);
  background: var(--accent);
  color: #0b1a19;
  transition: none;   /* podświetlenie od razu, wygaszanie płynne */
}

.pad-btn.pressed .cap,
.pad-btn:active:not(:disabled) .cap { color: #0b1a19; }

.pad-btn:disabled { opacity: 0.45; cursor: default; }

.controls {
  display: flex;
  gap: 14px;
}

.pad-center {
  align-self: center;
  justify-self: center;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--panel);
}

.actions {
  display: grid;
  grid-template-rows: repeat(3, var(--pad-size));
  gap: 6px;
  width: calc(var(--pad-size) * 1.25);
}

.tele  { background: #3b2f63; }
.wait  { background: #4a3d1c; }
.safe  { background: #1c4a33; }

.pad-btn.action {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 1.3rem;
  line-height: 1;
}

.cap {
  font-size: 0.6rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--accent);
  color: #0b1a19;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 22px;
}

.pad-btn.wait.active {
  opacity: 1;
  background: #b8892a;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { filter: brightness(0.85); }
  to   { filter: brightness(1.2); }
}

.hint, .rules {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  max-width: 320px;
}

/* Telefony: ukryj podpowiedź klawiatury, zmniejsz pad na niskich ekranach */
@media (hover: none) {
  .hint { display: none; }
}

@media (max-width: 819px) {
  .rules { display: none; }
}

@media (max-height: 700px) {
  :root { --pad-size: 52px; }
  .board-wrap { width: min(100%, calc((100dvh - 270px) * 21 / 31)); }
}

/* Szersze ekrany: sterowanie obok planszy */
@media (min-width: 820px) {
  .game {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 28px;
  }
  .board-wrap { width: min(calc(100vw - 400px), calc((100dvh - 70px) * 21 / 31)); }
  .side {
    width: 320px;
    padding-top: 20px;
  }
}
