/* Battleships — English Room Games */
:root {
  --deep: #071a30;
  --deep-2: #0b2440;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.1);
  --ink: #eaf3ff;
  --muted: #9fb6d1;
  --muted-2: #6f88a6;
  --gold: #ffc93c;
  --gold-dark: #c99a1c;
  --hit: #ff5a3c;
  --ok: #4fd18b;
  --sea-1: #0e3d6b;
  --sea-2: #145189;
  --display: 'Fredoka', 'Sarabun', sans-serif;
  --body: 'Sarabun', sans-serif;
  --cell: 40px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: radial-gradient(1200px 700px at 25% 0%, #12345a 0%, var(--deep) 55%, #050f1d 100%) fixed;
  background-color: var(--deep);
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.th { font-family: var(--body); color: var(--muted); font-weight: 400; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, #0c223c, #081a2f);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 201, 60, 0.2);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .mark svg { width: 28px; height: 28px; fill: var(--gold); display: block; }
.brand h1 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 23px; white-space: nowrap; }
.brand .site {
  font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted-2); text-decoration: none; white-space: nowrap;
}
.brand .site:hover { color: var(--gold); }
.spacer { flex: 1; }
.turn {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 14px 6px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255, 255, 255, .04); white-space: nowrap; font-weight: 600;
}
.turn .disc { width: 12px; height: 12px; border-radius: 50%; background: var(--muted-2); }
.turn.go .disc { background: var(--ok); box-shadow: 0 0 0 4px rgba(79, 209, 139, .2); animation: pulse 1.4s infinite; }
.turn.wait .disc { background: var(--gold); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(79, 209, 139, 0); } }
.iconbtn {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255, 255, 255, .04); color: var(--muted);
  cursor: pointer; text-decoration: none;
  transition: color .15s, border-color .15s, background .15s;
}
.iconbtn:hover { color: var(--ink); border-color: rgba(255, 201, 60, .5); background: rgba(255, 201, 60, .08); }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn[aria-pressed="false"] { color: var(--muted-2); }
.iconbtn[aria-pressed="false"] .wave { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .06);
  border-radius: 12px; padding: 9px 14px; min-height: 42px;
  font-weight: 700; cursor: pointer; transition: background .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .11); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn kbd { font: 600 11px var(--body); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; color: var(--muted); }
.btn.primary {
  background: var(--gold); color: #1d2452; border-color: transparent;
  box-shadow: 0 4px 0 var(--gold-dark); font-family: var(--display); font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: #ffd35e; }
.btn.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.big { font-size: 1.15rem; padding: 12px 22px; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--gold); font-weight: 700; cursor: pointer; margin-top: 12px; }

/* ---------- panels ---------- */
.panel {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 14px 16px;
}
.panel-head h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 1.25rem; }
.panel-head h2 .th { font-size: .9rem; margin-left: 6px; }
.panel-head.row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head .hint { margin: 6px 0 14px; color: var(--ink); line-height: 1.5; }
.mini-title { margin: 0 0 8px; font-family: var(--display); font-weight: 600; font-size: 1rem; }
.mini-title .th { font-size: .85rem; margin-left: 4px; }
.mini-title .count { float: right; color: var(--gold); }
.panel.turn-on { border-color: rgba(255, 201, 60, .55); box-shadow: 0 0 0 3px rgba(255, 201, 60, .12), 0 0 30px rgba(255, 201, 60, .08); }

/* ---------- board ---------- */
.board {
  --lab: calc(var(--cell) * .62);
  position: relative;
  display: inline-grid;
  grid-template-columns: var(--lab) repeat(10, var(--cell));
  grid-template-rows: var(--lab) repeat(10, var(--cell));
  padding: 8px 10px 10px 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, #0a2038, #071628);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06), 0 14px 30px rgba(0, 0, 0, .35);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.board .water {
  position: absolute;
  left: calc(8px + var(--lab)); top: calc(8px + var(--lab));
  width: calc(var(--cell) * 10); height: calc(var(--cell) * 10);
  border-radius: 6px; overflow: hidden;
  background:
    radial-gradient(120% 80% at 30% 20%, rgba(255, 255, 255, .08), transparent 60%),
    linear-gradient(160deg, var(--sea-2), var(--sea-1));
}
.board .water::before {   /* gentle moving waves */
  content: ''; position: absolute; inset: -50%;
  background:
    repeating-radial-gradient(ellipse 40px 12px at 50% 50%, rgba(255, 255, 255, .05) 0 2px, transparent 3px 22px);
  background-size: 120px 60px;
  animation: waves 18s linear infinite;
  opacity: .9;
}
@keyframes waves { to { transform: translate(120px, 60px); } }
.board .sonar {
  position: absolute; inset: -40%;
  background: conic-gradient(from 0deg, transparent 0deg 290deg, rgba(120, 230, 255, .13) 360deg);
  animation: sweep 6s linear infinite;
  pointer-events: none;
}
@keyframes sweep { to { transform: rotate(360deg); } }
.lab {
  display: flex; align-items: center; justify-content: center;
  font: 600 calc(var(--cell) * .36) var(--display);
  color: #7ea2c9; z-index: 1; transition: color .1s, transform .1s;
}
.lab.hl { color: var(--gold); transform: scale(1.25); }
.cell {
  position: relative; z-index: 1;
  border-right: 1px solid rgba(255, 255, 255, .07);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.cell.c0 { border-left: 1px solid rgba(255, 255, 255, .07); }
.cell.r0 { border-top: 1px solid rgba(255, 255, 255, .07); }
.cell.open { cursor: crosshair; }
.cell.open:hover::before, .cell.aim::before {
  content: ''; position: absolute; inset: 10%; z-index: 4; border-radius: 50%;
  border: 2px solid var(--gold);
  background:
    linear-gradient(var(--gold), var(--gold)) center / 2px 60% no-repeat,
    linear-gradient(var(--gold), var(--gold)) center / 60% 2px no-repeat;
  box-shadow: 0 0 10px rgba(255, 201, 60, .6);
}
.board.locked .cell { cursor: default; }
.board.locked .cell.open:hover::before { display: none; }

/* ship hulls */
.hull {
  position: absolute; z-index: 1;
  background: linear-gradient(180deg, #dbe3ec 0%, #9fadbd 55%, #7d8b9c 100%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25), 0 3px 5px rgba(0, 0, 0, .35);
}
.hull.h { top: 20%; bottom: 20%; left: -1px; right: -1px; }
.hull.h.bow { left: 8%; border-radius: 999px 0 0 999px; }
.hull.h.stern { right: 8%; border-radius: 0 35% 35% 0; }
.hull.v { left: 20%; right: 20%; top: -1px; bottom: -1px; background: linear-gradient(90deg, #dbe3ec 0%, #9fadbd 55%, #7d8b9c 100%); }
.hull.v.bow { top: 8%; border-radius: 999px 999px 0 0; }
.hull.v.stern { bottom: 8%; border-radius: 0 0 35% 35%; }
.hull.mid::after {
  content: ''; position: absolute; inset: 26% 30%; border-radius: 40%;
  background: #6b7a8d; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3);
}
.hull.wreck { background: linear-gradient(180deg, #8a5550, #4d2b2b); }
.hull.v.wreck { background: linear-gradient(90deg, #8a5550, #4d2b2b); }
.hull.wreck.mid::after { background: #3a2020; }
.hull.ghost { opacity: .5; }

/* shot markers */
.peg { position: absolute; z-index: 3; border-radius: 50%; pointer-events: none; }
.miss .peg { inset: 37%; background: #e9f2fc; box-shadow: 0 0 0 3px rgba(255, 255, 255, .14); }
.hit .peg {
  inset: 24%;
  background: radial-gradient(circle at 42% 38%, #fff4b8 0%, #ff9a3c 40%, #e2321e 75%);
  box-shadow: 0 0 12px 3px rgba(255, 90, 40, .55);
  animation: flicker 1.1s ease-in-out infinite alternate;
}
@keyframes flicker { from { transform: scale(.92); } to { transform: scale(1.06); box-shadow: 0 0 16px 5px rgba(255, 110, 40, .65); } }
.fresh::after { content: ''; position: absolute; z-index: 5; pointer-events: none; border-radius: 50%; }
.fresh.hit::after {
  inset: -60%;
  background: radial-gradient(circle, rgba(255, 240, 160, .95) 0%, rgba(255, 120, 40, .8) 30%, rgba(220, 40, 20, .35) 55%, transparent 70%);
  animation: boom .7s ease-out forwards;
}
@keyframes boom { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }
.fresh.miss::after { inset: 10%; border: 3px solid rgba(255, 255, 255, .85); animation: ripple .8s ease-out forwards; }
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(2.1); opacity: 0; } }
.fresh.hit { animation: shake .35s; }
@keyframes shake { 25% { transform: translate(2px, -1px); } 50% { transform: translate(-2px, 1px); } 75% { transform: translate(1px, 1px); } }

/* placement preview */
.cell.pv-ok { background: rgba(79, 209, 139, .38); }
.cell.pv-bad { background: rgba(255, 80, 80, .42); }
.cell.has-ship { cursor: grab; }

/* ---------- callout ---------- */
.callout {
  position: absolute; left: 50%; top: 46%; z-index: 30;
  transform: translate(-50%, -50%) scale(.6); opacity: 0;
  pointer-events: none; text-align: center;
  padding: 14px 28px; border-radius: 20px; min-width: 200px;
  background: rgba(5, 15, 30, .9); border: 2px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  transition: opacity .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.callout.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.callout .c-who { font-size: .85rem; color: var(--muted); }
.callout .c-coord { font: 700 1.5rem var(--display); color: var(--ink); letter-spacing: .05em; }
.callout .c-res { font: 700 2.6rem/1.1 var(--display); }
.callout .c-th { font-size: 1.1rem; color: var(--ink); }
.callout.hit { border-color: rgba(255, 90, 60, .7); }
.callout.hit .c-res { color: var(--hit); }
.callout.miss .c-res { color: #9fd3ff; }
.callout.sunk { border-color: var(--gold); }
.callout.sunk .c-res { color: var(--gold); font-size: 1.7rem; }
.callout.small { min-width: 150px; padding: 10px 18px; }
.callout.small .c-res { font-size: 1.8rem; }
.callout.small.sunk .c-res { font-size: 1.25rem; }

/* ---------- setup screen ---------- */
.setup { padding: 18px; display: flex; justify-content: center; }
.setup-panel { max-width: 980px; width: 100%; }
.setup-body { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.setup .board { --cell: clamp(28px, min(calc((100vh - 290px) / 10.8), 4.4vw), 46px); }
.dock { flex: 1; min-width: 260px; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.dock-list { display: flex; flex-direction: column; gap: 8px; }
.dock-item {
  display: flex; align-items: center; gap: 10px; text-align: left;
  border: 2px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .04);
  padding: 9px 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.dock-item:hover { background: rgba(255, 255, 255, .08); }
.dock-item.sel { border-color: var(--gold); background: rgba(255, 201, 60, .1); }
.dock-item.placed { opacity: .55; }
.dock-item .nm { flex: 1; font-weight: 700; line-height: 1.2; }
.dock-item .nm small { display: block; font-weight: 400; color: var(--muted); }
.dock-item .tick { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #062; font-weight: 700; font-size: 13px; }
.dock-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dock-actions .btn { flex: 1; white-space: nowrap; }

/* little segment strips used in fleet lists */
.segs { display: inline-flex; gap: 3px; }
.segs i { width: 14px; height: 14px; border-radius: 4px; background: linear-gradient(180deg, #dbe3ec, #8b99aa); }
.segs i.x { background: radial-gradient(circle, #ff9a3c, #c7301c); }

/* ---------- battle screen ---------- */
.battle {
  display: grid;
  grid-template-columns: auto minmax(300px, 400px);
  gap: 18px; padding: 18px;
  justify-content: center; align-items: start;
}
.battle .enemy .board { --cell: clamp(26px, min(calc((100vh - 300px) / 10.8), 4.2vw), 48px); }
.board-holder { display: flex; justify-content: center; }
.board.small { --cell: clamp(18px, min(calc((100vh - 560px) / 10.8), 2.4vw), 28px); padding: 6px 8px 8px 6px; border-radius: 12px; }
.board.small .water { left: calc(6px + var(--lab)); top: calc(6px + var(--lab)); }
.board.small .hull.mid::after { display: none; }
.side { display: flex; flex-direction: column; gap: 14px; }
.target { font: 600 1rem var(--display); color: var(--gold); }
.type-form { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.type-form label { font-weight: 700; }
.type-form label .th { font-size: .85rem; }
.type-form input {
  width: 100px; text-transform: uppercase; text-align: center;
  font: 700 1.25rem var(--display); letter-spacing: .06em;
  color: var(--ink); background: #061426; border: 2px solid var(--line); border-radius: 12px; padding: 6px 8px;
}
.type-form input:focus { outline: none; border-color: var(--gold); }
.type-form input::placeholder { text-transform: none; color: var(--muted-2); letter-spacing: 0; font-weight: 500; }
.type-msg { margin: 6px 0 0; min-height: 1.4em; color: var(--muted); }
.type-msg.bad { color: #ff9b8a; }

.fleet { display: grid; gap: 6px; }
.fleet .fs { display: flex; align-items: center; gap: 10px; }
.fleet .fs .nm { flex: 1; font-weight: 600; }
.fleet .fs .nm small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.fleet .fs.sunk .nm { text-decoration: line-through; color: var(--muted-2); }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 150px; overflow: auto; font-size: .95rem; }
.log li { display: flex; gap: 8px; align-items: baseline; }
.log li b { font-family: var(--display); font-weight: 600; min-width: 34px; }
.log li .r-hit { color: var(--hit); font-weight: 700; }
.log li .r-miss { color: #9fd3ff; }
.log li .r-sunk { color: var(--gold); font-weight: 700; }
.log li .who { color: var(--muted); min-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
.log .empty { color: var(--muted-2); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3, 10, 20, .72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto;
}
.overlay.solid { background: radial-gradient(circle at 50% 30%, #12345a, #050f1d); backdrop-filter: none; }
.card {
  width: min(540px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: linear-gradient(180deg, #0f2a48, #0a1d33);
  border: 1px solid var(--line); border-radius: 22px; padding: 24px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6);
}
.card.center { text-align: center; }
.card h2 { margin: 0 0 6px; font-family: var(--display); font-weight: 700; font-size: 2rem; }
.card h2 .th { font-size: 1rem; }
.kicker { font: 600 .8rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px; }
.kicker a { color: inherit; text-decoration: none; }
.kicker a:hover { text-decoration: underline; }
.lede { margin: 0 0 18px; color: var(--ink); line-height: 1.5; }
.lede .th { display: block; font-size: .95rem; margin-top: 2px; }
.field { margin-bottom: 16px; }
.field > label { display: block; font: 600 .8rem var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.field input {
  width: 100%; font: 600 1rem var(--body); color: var(--ink);
  background: #061426; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.field input:focus { outline: none; border-color: var(--gold); }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice button {
  text-align: left; padding: 12px 14px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--line); background: #061426;
}
.choice button[aria-pressed="true"] { border-color: var(--gold); background: rgba(255, 201, 60, .1); }
.choice .t { display: block; font-weight: 700; font-size: 1.05rem; }
.choice .d { display: block; color: var(--muted); font-size: .88rem; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #061426; padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg.two { grid-template-columns: 1fr 1fr; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--gold); color: #1d2452; }
.note { margin: 7px 0 0; color: var(--muted); font-size: .92rem; }
.handoff-ship svg { width: 110px; fill: var(--gold); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.medal { font: 700 3.4rem/1 var(--display); margin-bottom: 6px; }
.medal svg { width: 90px; height: 90px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 18px; }
.stats div { background: rgba(255, 255, 255, .05); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; }
.stats b { display: block; font: 700 1.6rem var(--display); color: var(--gold); }
.stats span { color: var(--muted); font-size: .85rem; }
.stats .who { grid-column: 1 / -1; text-align: left; background: none; border: 0; padding: 0; font-weight: 700; }
.actions.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rules { padding-left: 20px; line-height: 1.5; margin: 6px 0 16px; }
.rules li { margin-bottom: 9px; }
.rules .th { display: block; font-size: .93rem; }
.phrases { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 5px; }
.phrases .th { margin-left: 8px; }
#help .fleet { margin-bottom: 16px; }

/* ---------- smaller screens ---------- */
@media (max-width: 900px) {
  .brand .site { display: none; }
  .battle { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
  .battle .enemy .board { --cell: min(calc((100vw - 70px) / 10.8), 44px); }
  .board.small { --cell: min(calc((100vw - 90px) / 10.8 * .72), 30px); }
  .setup { padding: 12px; }
  .setup .board { --cell: min(calc((100vw - 70px) / 10.8), 44px); }
  .dock { max-width: none; }
}
@media (max-width: 560px) {
  .topbar { padding-inline: 10px; gap: 7px; }
  .brand .mark { display: none; }
  .brand h1 { font-size: 18px; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .turn { order: 10; flex-basis: 100%; justify-content: center; padding: 5px 12px; }
  .type-form label { flex-basis: 100%; }
  .iconbtn { width: 33px; height: 33px; }
  .iconbtn svg { width: 17px; height: 17px; }
  .panel { padding: 12px; border-radius: 16px; }
  .battle .enemy .board { --cell: calc((100vw - 52px) / 10.7); }
  .setup .board { --cell: calc((100vw - 52px) / 10.7); }
  .board { padding: 6px 8px 8px 6px; }
  .board .water { left: calc(6px + var(--lab)); top: calc(6px + var(--lab)); }
  .card { padding: 18px; }
  .card h2 { font-size: 1.6rem; }
  .callout { min-width: 170px; padding: 10px 18px; }
  .callout .c-res { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
