/* jack-game — схематичная первая версия. brand: none — личная игра для друзей, не материал PM Culture.
   Картинки клеток позже: .t-<вид> { background-image: url(/img/tiles/<вид>.png) } */

:root {
  --bg: #f6f3ea;
  --ink: #1f2a33;
  --muted: #6b7680;
  --card: #fffdf7;
  --line: #d9d2bf;
  --sea: #bfe0ee;
  --sea-line: #a7d0e2;
  --closed: #5f8a4a;
  --closed-line: #4f7a3c;
  --sand: #efe0b4;
  --coin: #e0a100;
  --target: #1b7f86;
  --target-carry: #c98a12;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.top h1 { font-size: 20px; margin: 0; letter-spacing: .5px; white-space: nowrap; }
.room-tag { color: var(--muted); font-size: 14px; white-space: nowrap; }
.top #helpBtn { margin-left: auto; }

main { padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; }
.narrow { max-width: 560px; margin: 24px auto; }
.card h2 { margin-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted); font-size: 14px; }

input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; flex: 1; }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--target); background: var(--target); color: #fff; cursor: pointer; }
button.ghost { background: transparent; color: var(--target); }
button:disabled { opacity: .4; cursor: default; }
button.on { outline: 3px solid var(--target-carry); outline-offset: 1px; }

.seats { display: grid; gap: 8px; margin-bottom: 14px; }
.seat { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.seat .chip, .player .chip { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.seat .who { flex: 1; }
.seat select { font: inherit; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); }
.invite { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 14px; }
.invite input { flex: 1 1 220px; }

/* ---------- партия ---------- */
.game { display: flex; gap: 16px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.board-wrap { flex: none; }
.board {
  --size: min(calc(100vw - 32px), calc(100vh - 100px), 760px);
  --cell: calc(var(--size) / 13);
  width: var(--size); height: var(--size);
  display: grid; grid-template-columns: repeat(13, 1fr); grid-template-rows: repeat(13, 1fr);
  gap: 1px; background: var(--sea-line); border-radius: 8px; overflow: hidden; user-select: none;
}
.cell { position: relative; background: var(--sea); display: flex; align-items: center; justify-content: center; font-size: calc(var(--cell) * .45); cursor: default; }
.cell.land { background: var(--closed); box-shadow: inset 0 0 0 1px var(--closed-line); }
.cell.land.closed::after { content: ''; width: 18%; height: 18%; border-radius: 50%; background: rgba(255, 255, 255, .18); }
.cell.open { background: var(--sand); box-shadow: none; }
.cell .sym { color: #4a3b1f; font-weight: 600; line-height: 1; pointer-events: none; }
.cell.dirs .sym { font-size: 1.2em; }

.t-chest { background: #f3d983 !important; }
.t-swamp { background: #b8c79b !important; }
.t-snare { background: #d8b58c !important; }
.t-idol { background: #cfa6a6 !important; }
.t-geyser { background: #acd6e3 !important; }
.t-fort { background: #cbc8bf !important; }
.t-eagle { background: #f3eab8 !important; }
.t-cave { background: #b9a88f !important; }
.t-parrot { background: #d6ecbf !important; }
.t-map { background: #eadfbe !important; }
.t-arrow, .t-fork, .t-vine { background: #e9d7a3 !important; }

.shipline { background: #b0d6e7; }
.ship { position: absolute; inset: 8% 4%; border-radius: 40% 40% 12% 12%; display: flex; align-items: center; justify-content: center; gap: 2px; flex-wrap: wrap; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.ship.mine { outline: 2px solid #fff; }

.coins { position: absolute; top: 4%; right: 4%; min-width: 38%; height: 38%; padding: 0 3px; border-radius: 999px; background: var(--coin); color: #3b2a00; font-weight: 700; font-size: calc(var(--cell) * .26); display: flex; align-items: center; justify-content: center; border: 1px solid #a87700; z-index: 2; }

.pirates { position: absolute; inset: 0; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: flex-start; padding: 4%; gap: 3%; pointer-events: none; z-index: 3; }
.ship .pirates { position: static; padding: 0; gap: 2px; justify-content: center; align-items: center; }
.pirate { width: calc(var(--cell) * .46); height: calc(var(--cell) * .46); border-radius: 50%; color: #fff; font-weight: 700; font-size: calc(var(--cell) * .28); display: flex; align-items: center; justify-content: center; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.pirates:has(.pirate:only-child) { align-items: center; justify-content: center; }
.pirates .pirate:only-child { width: calc(var(--cell) * .6); height: calc(var(--cell) * .6); font-size: calc(var(--cell) * .34); }
.ship .pirate, .ship .pirate:only-child { width: calc(var(--cell) * .28); height: calc(var(--cell) * .28); font-size: calc(var(--cell) * .19); border-width: 1px; box-shadow: none; }
.pirate.stuck { border-style: dashed; border-color: #222; }
.pirate.selected { outline: 3px solid #fff; box-shadow: 0 0 0 5px var(--ink); }

.cell.target { cursor: pointer; }
.cell.target::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--target); background: rgba(27, 127, 134, .18); z-index: 4; }
.cell.target.carry::before { box-shadow: inset 0 0 0 3px var(--target-carry); background: rgba(201, 138, 18, .22); }
.cell.pickable { cursor: pointer; }
.cell.choice::before { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px #b03a8a; background: rgba(176, 58, 138, .22); z-index: 4; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .6; } to { opacity: 1; } }
.cell.last { box-shadow: inset 0 0 0 2px rgba(31, 42, 51, .55); }

.side { width: min(360px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; }
.players { display: grid; gap: 6px; }
.player { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
.player.turn { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink) inset; }
.player .name { flex: 1; }
.player .score { font-weight: 700; }
.player .off { color: #b03a3a; font-size: 12px; }
.status { font-weight: 600; min-height: 1.4em; padding: 6px 10px; border-radius: 8px; }
.status.mine { background: var(--target); color: #fff; }
.controls { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.pirate-btns, .ship-btns { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.carry { font-size: 14px; }
.coins-info { font-size: 13px; color: var(--muted); }
.log { margin: 0; padding: 8px 10px 8px 34px; max-height: 260px; overflow: auto; font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.log li { margin: 2px 0; }
.host-tools { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 10; }

dialog { border: 1px solid var(--line); border-radius: 12px; max-width: 560px; width: calc(100vw - 32px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.rules li { margin: 4px 0; }
.legend { display: grid; grid-template-columns: 34px 1fr; gap: 6px 10px; align-items: center; font-size: 14px; margin-bottom: 12px; }
.legend .cell { width: 30px; height: 30px; font-size: 16px; border-radius: 4px; }
