:root {
  --bg: #0c0e12;
  --panel: #141820;
  --line: #252d38;
  --ink: #e7e9ee;
  --muted: #8b93a3;
  --accent: #f5a623;
  --danger: #ff5d58;
  --sea: #111722;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.shell { width: min(1040px, 100%); margin: 0 auto; padding: 18px 12px 28px; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0; }
.muted { color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.topbar p { margin: 4px 0 0; font-size: .92rem; }

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171d27;
  color: var(--ink);
  font: inherit;
}
.actions { display: flex; gap: 8px; }
#undo, #reset { min-height: 40px; padding: 0 14px; white-space: nowrap; }
button:disabled { opacity: .45; }

.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}
.board-wrap {
  width: 100%;
  overflow: hidden;
}
.board {
  display: grid;
  grid-template-columns: 24px repeat(10, minmax(0, 1fr)) 24px;
  gap: 3px;
  width: min(100%, 650px);
  margin: 0 auto;
  user-select: none;
}
.cell {
  aspect-ratio: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  line-height: 1;
  letter-spacing: 0;
}
.axis, .corner {
  color: var(--muted);
  font-size: .78rem;
}
.sea {
  position: relative;
  padding: 0;
  border-color: #253244;
  background:
    linear-gradient(rgba(245, 166, 35, calc(var(--heat) * .5)), rgba(245, 166, 35, calc(var(--heat) * .18))),
    var(--sea);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.025);
  color: var(--ink);
  font-size: clamp(.8rem, 4vw, 1.05rem);
  font-weight: 800;
  touch-action: none;
}
.sea.recommended {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245,166,35,.26), inset 0 0 0 1px rgba(255,255,255,.04);
}
.sea.miss {
  background: #10141b;
  color: #697386;
}
.sea.hit {
  background: rgba(255, 93, 88, .18);
  border-color: var(--danger);
  color: #ffd0cd;
}
.sea.sunk {
  background: #2b1517;
  border-color: #8e3330;
  color: #ffb6b2;
}

.readout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.readout > :not(.metric) { grid-column: 1 / -1; min-width: 0; }
.metric {
  min-width: 0;
  padding: 10px;
  border-radius: 6px;
  background: #10151d;
}
.metric span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
}
.metric strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
}
.outcome {
  grid-column: 1 / -1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151d;
}
.outcome-q { font-size: .9rem; margin-bottom: 8px; }
.outcome-q strong { color: var(--accent); }
.outcome-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.outcome-btns button {
  min-height: 48px;
  font-weight: 700;
  border-radius: 8px;
}
.o-miss { border-color: #2b3645; }
.o-hit { border-color: var(--danger); color: #ffd0cd; }
.o-sunk { border-color: #8e3330; color: #ffb6b2; background: #2b1517; }
.outcome-btns button:active:not(:disabled) { transform: scale(0.97); }

.result {
  grid-column: 1 / -1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151d;
}
.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-btns button { min-height: 46px; font-weight: 700; border-radius: 8px; }
.o-win { border-color: #2f7d4f; color: #b7f0cd; background: #15241b; }
.o-loss { border-color: #2b3645; }
.result-btns button:active { transform: scale(0.97); }

.train {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
#trainBtn { min-height: 40px; padding: 0 12px; }

.toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.toggle input { accent-color: var(--accent); }
.hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
}

@media (min-width: 820px) {
  .shell { padding-top: 28px; }
  .panel { grid-template-columns: minmax(0, 680px) 280px; align-items: start; }
  .readout { grid-template-columns: 1fr; }
}

/* IQ движка */
.iqbox {
  margin: 12px 0;
  padding: 12px 14px;
  background: #10151d;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.iq-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.iq-label { color: var(--muted); font-size: 13px; }
.iq-value { font-size: 22px; font-variant-numeric: tabular-nums; color: var(--accent); }
.iq-bar {
  height: 7px;
  border-radius: 4px;
  background: #1c2430;
  overflow: hidden;
}
.iq-fill {
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, #3d7d4f, var(--accent));
  transition: width .5s cubic-bezier(.23,1,.32,1);
}
.iqbox .muted { display: block; margin-top: 8px; font-size: 12px; line-height: 1.45; }
@media (prefers-reduced-motion: reduce) { .iq-fill { transition: none; } }

/* --- Моя расстановка ------------------------------------------------- */
/* Тот же язык, что и у основной панели: та же линия, тот же радиус,
   тот же акцент. Новой эстетики блок не вводит намеренно. */
.fleet { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.fleet h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.fleet p { margin: 4px 0 0; font-size: .9rem; }
.fleet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
#fleetBtn { min-height: 40px; padding: 0 16px; white-space: nowrap; }
.fleet-body { display: grid; gap: 14px; margin-top: 14px; }
.mini-board {
  display: grid;
  grid-template-columns: 18px repeat(10, minmax(0, 1fr));
  gap: 2px;
  width: min(100%, 420px);
  user-select: text;
}
.mini-board .mh {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  color: var(--muted);
}
.mini-board .mc {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--sea);
}
.mini-board .mc.ship {
  background: color-mix(in srgb, var(--accent) 72%, #2a2016);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}
.fleet-stats { font-size: .9rem; color: var(--muted); }
.fleet-stats strong { color: var(--ink); }
.fleet-stats ul { margin: 8px 0 0; padding-left: 18px; }
.fleet-stats li { margin: 2px 0; }
@media (min-width: 900px) {
  .fleet-body { grid-template-columns: 420px minmax(0, 1fr); align-items: start; }
}

[hidden] { display: none !important; }
.settings, .own-controls { display:flex; flex-wrap:wrap; gap:12px; align-items:end; margin:14px 0; }
.settings label { display:flex; gap:6px; flex-direction:column; font-size:.88rem; }
select, input { font:inherit; color:var(--ink); accent-color:var(--accent); }
select, input:not([type=checkbox]) { background:var(--sea); border:1px solid var(--line); border-radius:6px; padding:8px; max-width:100%; }
button, select { cursor:pointer; }
button:disabled { cursor:default; }
button:focus-visible, select:focus-visible, input:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.own-controls button, #retrySave { min-height:44px; padding:8px 12px; }
.fleet { display:block; }
.fleet-body { margin-top:12px; }
.mini-board .mc { padding:0; font-size:1.1rem; color:var(--ink); }
.mini-board .mc.own-shot { opacity:1; background:#2b1517; color:#ffb6b2; }
#setupHint { margin:12px 0; }
dialog { background:var(--panel); color:var(--ink); border:1px solid var(--line); border-radius:10px; max-width:min(480px,90vw); }
dialog::backdrop { background:rgb(0 0 0 / .7); }
#sinkOptions { display:grid; gap:8px; margin:16px 0; }
#sinkOptions button, #cancelSink { padding:12px; }
@media(max-width:480px) { .topbar{align-items:start;flex-wrap:wrap;} .settings>label{max-width:100%;} }


/* Match the opponent board's 10x10 footprint and keep the fleet directly below it. */
.mini-board {
  grid-template-columns: 24px repeat(10, minmax(0, 1fr)) 24px;
  gap: 3px;
  width: min(100%, 650px);
  margin: 0 auto;
}
.fleet-body { display: block; }

.fleet { margin-top: 20px; }
.fleet > h2 { width: min(100%, 650px); margin: 0 auto 12px; }
.mini-board .mh { aspect-ratio: 1; font-size: .78rem; }
.mini-board .mc { min-width: 0; }
.fleet-controls { border-top: 1px solid var(--line); padding-top: 14px; }
.fleet-controls h2 { margin: 0; }
.fleet-controls .own-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.fleet-controls .own-controls label { display: grid; gap: 6px; }
.fleet-controls .own-controls button, .fleet-controls select { width: 100%; }
.fleet-stats p { margin: 4px 0; }
.fleet-stats .eval-head { color: var(--ink); }
.fleet-controls .saved-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#opponentModel { flex-basis: 100%; font-size: .85rem; }
