/* Kolory biorą się z motywu Telegrama (jasny/ciemny), z rozsądnymi wartościami zapasowymi */
:root {
  --bg: var(--tg-theme-bg-color, #f4f6f9);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14202e);
  --muted: var(--tg-theme-hint-color, #6b7a8c);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d9483b);
  --water: #cfe6f7;
  --water-line: #a9cbe6;
  --ship: #2f4a63;
  --hit: #e2543f;
  --sunk: #8d2c20;
  --ok: #2e9e5b;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f1720; --card: #18232f; --text: #e6edf3; --muted: #8b9bab;
  }
}
:root.dark { --water: #1d3a52; --water-line: #2b5170; --ship: #b8cde0; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
main { max-width: 480px; margin: 0 auto; padding: 12px 12px 32px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 24px 0; }
.small { font-size: 13px; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn + .btn { margin-top: 8px; }
.btn.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--water-line); }
.btn.link { background: none; color: var(--danger); font-weight: 400; padding: 8px; }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; }
.row > .btn { margin: 0; padding: 10px 6px; font-size: 14px; white-space: nowrap; }

.card {
  background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer;
}
.card .title { font-weight: 600; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--water); color: var(--ship); white-space: nowrap; }
.badge.go { background: var(--ok); color: #fff; }
.badge.win { background: #f2c94c; color: #3b2f00; }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; background: var(--card); }
.banner.go { background: var(--ok); color: #fff; }
.banner.win { background: #f2c94c; color: #3b2f00; }
.banner.lose { background: var(--danger); color: #fff; }
.banner .big { font-size: 18px; font-weight: 700; }
.banner.go { animation: pulse 1.6s ease-in-out 2; }
@keyframes pulse { 50% { transform: scale(1.03); box-shadow: 0 0 0 6px rgba(46, 158, 91, .25); } }

/* Plansza */
.board {
  display: grid; grid-template-columns: 18px repeat(10, 1fr); gap: 2px;
  width: 100%; user-select: none;
}
.board.small { max-width: 250px; margin: 0 auto; }
.board .lbl { font-size: 11px; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.cell {
  aspect-ratio: 1; background: var(--water); border-radius: 4px; position: relative;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}
.board.target.active .cell.free { cursor: crosshair; }
.board.target.active .cell.free:hover { outline: 2px solid var(--accent); }
.cell.ship { background: var(--ship); }
.cell.miss::after { content: ""; width: 22%; height: 22%; border-radius: 50%; background: var(--muted); }
.cell.near::after { content: ""; width: 14%; height: 14%; border-radius: 50%; background: var(--water-line); }
.cell.hit { background: var(--hit); }
.cell.hit::after { content: "✕"; color: #fff; }
.cell.sunk { background: var(--sunk); }
.cell.sunk::after { content: "✕"; color: #ffd2cc; }
.cell.ship.hit { background: var(--hit); }
.cell.reveal { background: var(--ship); opacity: .55; }
.cell.preview { background: var(--accent); opacity: .5; }
.cell.bad { background: var(--danger); opacity: .5; }
.cell.flash { animation: flash .5s; }
@keyframes flash { from { transform: scale(1.35); } to { transform: scale(1); } }

/* Ustawianie floty */
.tray { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  display: flex; gap: 2px; padding: 6px; border-radius: 8px; background: var(--card);
  border: 2px solid transparent; cursor: pointer;
}
.chip.sel { border-color: var(--accent); }
.chip i { width: 12px; height: 12px; border-radius: 2px; background: var(--ship); display: block; }
.chip.done { opacity: .25; cursor: default; }

.log { font-size: 13px; color: var(--muted); padding-left: 18px; margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin: 14px 0 6px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(20, 32, 46, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600;
  max-width: 90vw; text-align: center; z-index: 10;
}
