/* Biển xanh ngọc chấm lưới, tàu là các khúc bo tròn nhiều màu; trúng = đỏ, trượt = chấm đậm. */
:root {
  --bg: #e4f3f6;
  --panel: #fff;
  --line: #c6e2e8;
  --text: #17323a;
  --muted: #5f7f88;
  --accent: #d6336c;
  --sea: #bfe6e8;
  --sea-dot: #7cc4c6;
  --hit: #e0312f;
  --sunk: #5a6b78;
  --good: #2e9e5b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.4 "Be Vietnam Pro", "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; justify-content: center;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
input { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  width: min(380px, calc(100vw - 32px)); display: grid; gap: 12px; text-align: center; box-shadow: 0 12px 40px #17323a26;
}
.card h1, .card h2 { margin: 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.card h1 .logo { width: 40px; height: 40px; }
.card h1 .back { color: var(--muted); display: inline-flex; }
.card label { display: grid; gap: 4px; text-align: left; color: var(--muted); }
.sub, .muted { margin: 0; color: var(--muted); }
.muted { font-size: 12px; }
.join { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: 3px; text-align: center; }
#home { height: 100%; display: grid; place-items: center; padding: 16px; }

#room { position: relative; height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 6px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
header .grow { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--hit); flex: none; }
.dot.on { background: var(--good); }
@media (max-width: 480px) { header .lbl { display: none; } }

#vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 0 12px; }
.side { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 10px; border-radius: 12px; border: 2px solid transparent; background: #fff8; }
.side[data-seat="2"] { justify-content: flex-end; }
.side b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.side.turn { border-color: var(--accent); background: #fff; }
.side.me b::after { content: ' (bạn)'; font-weight: 400; color: var(--muted); }
html[lang="en"] .side.me b::after { content: ' (you)'; }
#clock { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
#clock.low { color: var(--hit); animation: blink .5s infinite alternate; }
@keyframes blink { to { opacity: .4; } }

#placeBar { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px 0; }
#placeText { color: var(--muted); font-size: 14px; text-align: center; flex-basis: 100%; }
/* Đang xếp tàu: tàu chạm vào được, tàu đang chọn có viền. */
.sea.edit .c { cursor: pointer; }
.c.ship.sel { box-shadow: 0 0 0 3px var(--accent); filter: brightness(1.08); }
/* Hàng tàu dưới mỗi biển: tàu đã chìm mờ + gạch ngang. */
.fleet { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; min-height: 10px; }
.fleet .pip { display: flex; gap: 2px; }
.fleet .pip i { width: 8px; height: 8px; border-radius: 3px; background: var(--ship); }
.fleet .pip.sunk { opacity: .35; } .fleet .pip.sunk i { background: var(--sunk); }
/* Điện thoại xoay ngang lúc xếp tàu: nút dồn thành cột bên trái, ẩn thanh cảm xúc để biển đủ to mà chạm. */
@media (orientation: landscape) and (max-height: 500px) {
  body.placing #placeBar { position: absolute; z-index: 4; left: 12px; top: 55%; translate: 0 -50%; width: 190px; flex-direction: column; align-items: stretch; padding: 0; }
  body.placing #emoBar { display: none; }
}

#wrap { position: relative; flex: 1; min-height: 0; margin: 8px; display: grid; place-items: center; }
/* Ngang / máy tính: 2 biển cạnh nhau. Dọc: biển của mình nhỏ ở trên, biển đối thủ (chỗ bắn) to ở dưới. */
#seas { display: flex; gap: 16px; align-items: center; justify-content: center; }
@media (max-aspect-ratio: 1/1) { #seas { flex-direction: column; gap: 6px; } }
.sea { margin: 0; display: grid; gap: 4px; justify-items: center; }
.sea figcaption { font-weight: 700; font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.sea.target figcaption { color: var(--accent); }
.grid {
  display: grid; grid-template-columns: repeat(10, var(--s, 32px)); grid-auto-rows: var(--s, 32px);
  background: var(--sea); border-radius: 12px; padding: 4px; box-shadow: 0 6px 18px #17323a22;
}
.sea.target .grid { outline: 3px solid var(--accent); outline-offset: 2px; }
.c { position: relative; display: grid; place-items: center; }
.c::before { content: ''; width: 16%; height: 16%; border-radius: 50%; background: var(--sea-dot); }
.sea.aim .c:not([data-v]):hover { background: #ffffff80; border-radius: 6px; cursor: crosshair; }
/* Khúc tàu: bo tròn từng khúc như hình trong sách tranh. */
.c.ship::before { content: none; }
.c.ship { background: var(--ship); border-radius: 30%; margin: 6%; }
.c.ship.hitme { background: color-mix(in srgb, var(--ship) 55%, #000); }
.c[data-v="1"]::before { width: 30%; height: 30%; background: #2f6f78; }
.c[data-v="2"]::before, .c.hitme::before { content: ''; width: 46%; height: 46%; background: var(--hit); box-shadow: 0 0 0 3px #fff8; }
.c[data-v="3"] { background: var(--sunk); border-radius: 30%; margin: 6%; }
.c[data-v="3"]::before { content: ''; width: 40%; height: 40%; background: var(--hit); }
.c.last { animation: splash .5s ease-out; }
@keyframes splash { from { transform: scale(1.5); filter: brightness(1.6); } }

#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #e4f3f666; z-index: 5; }
#btnResult { position: absolute; left: 50%; bottom: 8px; translate: -50% 0; z-index: 6; box-shadow: 0 6px 20px #17323a44; }

#emoBar { display: flex; justify-content: center; gap: 6px; padding: 6px 12px max(8px, env(safe-area-inset-bottom)); }
#emoBar button { padding: 4px 12px; font-size: 20px; }
.emo-fly { position: fixed; translate: -50% -100%; font-size: 34px; pointer-events: none; z-index: 20; animation: emo 1.6s ease-out forwards; }
.emo-fly .ic { filter: drop-shadow(0 2px 3px #0005); }
@keyframes emo { to { transform: translateY(-80px) scale(1.4); opacity: 0; } }
