:root{
  --bg:#06141d; --bg2:#0b2230; --panel:#0c2434; --line:#1f4a63; --text:#e6f3fa; --muted:#8fb0c4;
  --accent:#3ddc97; --accent2:#ffd166; --radius:14px;
  --bg-image: radial-gradient(1100px 500px at 50% -140px, #0f4560 0%, transparent 70%);
  --hit:#ff7a3d; --steel1:#a9bccb; --steel2:#6f8798; --sunk:#8a2433;
}
/* Shared arcade UI base (mobile-first). Game-specific theme + board styles follow. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-image, none);
  line-height: 1.4;
}
button, select, input { font: inherit; }
.app-header { text-align: center; padding: 14px 16px 6px; }
.logo { margin: 0; font-size: 26px; letter-spacing: .5px; color: var(--accent); }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.back-link { color: var(--accent2); text-decoration: none; font-size: 14px; }
.back-link:hover { text-decoration: underline; }
.help-btn { margin-top: 10px; }
.app-main { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 40px; max-width: 1040px; margin: 0 auto; }
.board-panel { width: 100%; min-width: 0; }
.side-panel { width: 100%; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
@media (min-width: 900px) {
  .app-main { flex-direction: row; align-items: flex-start; gap: 22px; }
  .board-panel { flex: 1 1 auto; }
  .side-panel { flex: 0 0 340px; width: 340px; }
}
.panel-title { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); }
.panel-title:first-child { margin-top: 0; }
.turn-indicator { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 28px; }
.turn-dot { width: 16px; height: 16px; border-radius: 50%; flex: 0 0 16px; }
.result { display: none; padding: 10px 12px; border-radius: 10px; font-weight: 700; background: rgba(255,184,77,.12); border: 1px solid var(--accent); color: var(--accent); margin: 8px 0; }
.result.show { display: block; }
.stat-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 6px 0; }
.stat-row b { color: var(--text); }
.controls { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.btn {
  appearance: none; border: 0; cursor: pointer; border-radius: 10px;
  background: var(--accent); color: #04170f; font-weight: 700;
  padding: 11px 16px; min-height: 44px; font-size: 15px;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn-sm { padding: 7px 12px; font-size: 14px; min-height: 40px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input[type=text] {
  width: 100%; min-height: 42px; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 15px;
}
.chk { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 14px; color: var(--text); cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 20px; }
.note { margin: 0; color: var(--muted); font-size: 12.5px; }
.ai-status { font-size: 13px; color: var(--accent); min-height: 18px; font-style: italic; }
.tn-entry { display: flex; gap: 6px; margin-bottom: 8px; }
.tn-actions { display: flex; gap: 6px; margin: 8px 0; }
.tn-actions .btn { flex: 1; }
#ol-name { margin-bottom: 4px; }
.tn-body { font-size: 13px; }
.tn-result { font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.tn-king { color: var(--accent2); font-weight: 600; margin-bottom: 8px; }
.tn-sub { color: var(--muted); margin: 6px 0 4px; font-size: 12px; }
.tn-hint { color: var(--muted); font-style: italic; font-size: 12px; }
.tn-queue { margin: 0 0 8px; padding-left: 22px; max-height: 140px; overflow-y: auto; }
.move-log { margin: 0; padding: 0; list-style: none; max-height: 150px; overflow-y: auto; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.move-log li { display: flex; align-items: center; gap: 4px; }
.mv-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.flash {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
  background: #1d2338; border: 1px solid var(--accent); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 70; max-width: 92vw; text-align: center;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.help-overlay { display: none; position: fixed; inset: 0; background: rgba(5,8,16,.78); z-index: 80; align-items: center; justify-content: center; padding: 12px; }
.help-overlay.open { display: flex; }
.help-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; padding: 20px 18px; }
.help-card h2 { color: var(--accent); margin: 0 36px 8px 0; font-size: 22px; }
.help-card h3 { color: var(--accent); font-size: 15px; margin: 18px 0 6px; }
.help-card p, .help-card li { font-size: 14px; line-height: 1.55; }
.help-card ul, .help-card ol { padding-left: 20px; margin: 6px 0; }
.help-card b { color: #fff; }
.help-close { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 28px; cursor: pointer; }
.help-close:hover { color: var(--accent); }
.help-actions { text-align: right; margin-top: 18px; }
.help-figs { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.help-figs figure { margin: 0; flex: 1 1 140px; min-width: 0; }
.help-figs svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.help-figs figcaption { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; transition-delay: 0s !important; } }

/* ---------- Sea Battle ---------- */
[hidden] { display: none !important; }
.sea-main { max-width: 1000px; margin: 0 auto; padding: 8px 16px 40px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; max-width: 620px; margin: 0 auto; }
#screen-battle { max-width: 1000px; }
.handover { text-align: center; padding: 40px 18px; }
.handover h2 { margin: 6px 0 8px; font-size: 24px; color: var(--accent2); }
.hand-icon { font-size: 54px; }
.handover .btn { margin-top: 18px; }

.sea {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px;
  width: 100%; max-width: 520px; aspect-ratio: 1 / 1; margin: 8px auto; padding: 5px;
  background: #05202c; border: 2px solid #245c78; border-radius: 12px;
  box-shadow: inset 0 0 30px rgba(0,0,0,.5);
}
.sea.small { max-width: 340px; }
.sea.place .cell { touch-action: none; }
.cell {
  position: relative; display: block; padding: 0; border: 0; border-radius: 4px; min-width: 0; min-height: 0; cursor: pointer;
  background: linear-gradient(160deg, #0f4a63 0%, #0a3448 100%);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.cell:focus-visible { outline: 3px solid var(--accent2); outline-offset: -3px; }
.cell.unk:hover { background: linear-gradient(160deg, #1b6f8f, #0f5470); box-shadow: inset 0 0 0 2px rgba(61,220,151,.7); }
.cell.ship { background: linear-gradient(170deg, var(--steel1), var(--steel2)); box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.cell.ship.h.s-start { border-radius: 40% 4px 4px 40%; } .cell.ship.h.s-end { border-radius: 4px 40% 40% 4px; }
.cell.ship.v.s-start { border-radius: 40% 40% 4px 4px; } .cell.ship.v.s-end { border-radius: 4px 4px 40% 40%; }
.cell.ship.h.s-start.s-end, .cell.ship.v.s-start.s-end { border-radius: 40%; }
.cell.ship.reveal { opacity: .55; }
.cell.ghost-ok { background: linear-gradient(170deg, #3ddc97, #1f9a68); }
.cell.ghost-bad { background: linear-gradient(170deg, #ff6b6b, #b02b3b); }
.cell.miss::after { content: ""; position: absolute; inset: 33%; border-radius: 50%; border: 2px solid #cfe9f5; opacity: .85; }
.cell.hit::after, .cell.sunk::after {
  content: "✕"; position: absolute; inset: 12%; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: radial-gradient(circle, #ffb15c 0%, var(--hit) 70%); color: #3b1204; font-weight: 900; font-size: 15px; line-height: 1;
  animation: pop .3s ease-out;
}
.cell.sunk { background: linear-gradient(170deg, #b5485a, var(--sunk)); }
.cell.sunk::after { background: radial-gradient(circle, #7a1f2d 0%, #4a0f19 75%); color: #ffb3bd; }
.cell.lastshot { box-shadow: inset 0 0 0 2px var(--accent2); }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tray { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip-ship {
  flex: 1 1 120px; min-width: 0; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; text-align: left;
  padding: 8px 10px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.chip-ship.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61,220,151,.2); }
.chip-ship.placed { opacity: .7; }
.cs-name { font-size: 13px; font-weight: 600; }
.cs-tick { font-size: 11px; color: var(--accent); }
.cs-pips { display: inline-flex; gap: 2px; }
.cs-pips i { width: 14px; height: 14px; border-radius: 3px; background: linear-gradient(170deg, var(--steel1), var(--steel2)); display: block; }
.drag-ghost { position: fixed; z-index: 90; pointer-events: none; transform: translate(-50%, -50%); opacity: .9; padding: 6px; background: rgba(6,20,29,.85); border: 2px solid var(--accent); border-radius: 10px; }
.drag-ghost.v .cs-pips { flex-direction: column; }
.drag-ghost .cs-pips i { width: 22px; height: 22px; }

.statusline { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.turn-line { font-weight: 700; font-size: 17px; color: var(--accent2); }
.chip-shots { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg2); font-size: 14px; color: var(--muted); }
.chip-shots b { color: var(--text); font-size: 17px; }
.msg { min-height: 24px; margin: 6px 0; font-weight: 600; }
.msg.hit { color: var(--hit); } .msg.sunk { color: #ff8ea0; } .msg.miss { color: var(--muted); }
.grids { display: flex; flex-direction: column; gap: 14px; }
.grid-title { margin: 6px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 1.3px; color: var(--muted); }
.fleetline { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; justify-content: center; max-width: 520px; margin: 0 auto; }
.fleetline .fl-head { color: var(--muted); width: 100%; text-align: center; }
.fl.gone { text-decoration: line-through; color: #ff8ea0; opacity: .8; } .fl.afloat { color: var(--text); }
@media (min-width: 900px) {
  .grids { flex-direction: row; align-items: flex-start; }
  .gridwrap { flex: 1 1 0; min-width: 0; }
  .gridwrap.mine { flex: 0 0 340px; }
}
