/* ============================================================
   Морской бой — стили
   ============================================================ */
:root {
  --bg: #06121f;
  --bg-2: #0b1f33;
  --panel: rgba(13, 35, 56, .82);
  --panel-2: rgba(9, 26, 43, .9);
  --line: #1e4062;
  --line-soft: #16324e;
  --text: #e6f2ff;
  --muted: #8badcb;
  --accent: #38d6ff;
  --accent-2: #2b8cff;
  --hit: #ff4d5e;
  --hit-soft: #7d1c27;
  --miss: #9fb3c6;
  --ship: #63a4ff;
  --ship-deck: #1c3d63;
  --ok: #34d399;
  --warn: #fbbf24;
  --cell: 34px;
  --radius: 14px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любые display-правила (важно для оверлея,
   у которого display: flex — иначе пустая карточка видна сразу после входа). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 15% -10%, #14405f 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #10304a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.screen { padding: 18px clamp(12px, 3vw, 34px) 40px; }

/* ---------- общие блоки ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
  padding: 18px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #14395b, #0e2a44);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #2fc3ff, #1f7ae0);
  border-color: #63d8ff;
  color: #04121f;
}
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 12px; font-size: 13px; }

.error {
  color: #ffb4bc;
  background: rgba(255, 77, 94, .12);
  border: 1px solid rgba(255, 77, 94, .4);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 10px 0 0;
  font-size: 14px;
}
.hint { color: var(--muted); font-size: 13px; }

/* ---------- экран входа ---------- */
#screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card { width: min(430px, 100%); text-align: center; }
.logo {
  margin: 0 0 4px;
  font-size: 34px;
  letter-spacing: .5px;
  background: linear-gradient(90deg, #7ef0ff, #2b8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.field { display: block; text-align: left; margin-bottom: 16px; }
.field span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.field input {
  width: 100%;
  padding: 12px 14px;
  font-size: 17px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 214, 255, .18); }
.login-card .btn { width: 100%; }
.login-card .hint { margin-top: 14px; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.topbar__title { display: flex; align-items: center; gap: 10px; }
.anchor { font-size: 26px; }
.topbar__game { font-weight: 700; font-size: 18px; }
.topbar__id { color: var(--muted); font-size: 12px; font-family: ui-monospace, Consolas, monospace; }

.players { display: flex; align-items: center; gap: 14px; }
.player {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
}
.player__role { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.player__name { font-weight: 700; }
.player--me { border-color: rgba(56, 214, 255, .55); }
.player--foe { border-color: rgba(255, 77, 94, .35); }
.vs { color: var(--muted); font-weight: 700; font-size: 12px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #6b7d8f; display: inline-block;
}
.dot--on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot--off { background: #66788a; }

.topbar__right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 4px 10px;
}
.badge--on { color: var(--ok); border-color: rgba(52, 211, 153, .5); }
.badge--off { color: #ffb4bc; border-color: rgba(255, 77, 94, .5); }

/* ---------- индикатор хода ---------- */
.turn {
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-radius: 12px;
  padding: 12px 18px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(28, 61, 99, .9), rgba(11, 31, 51, .6));
}
.turn--me { border-color: var(--ok); background: linear-gradient(90deg, rgba(20, 92, 74, .85), rgba(11, 31, 51, .6)); }
.turn--foe { border-color: rgba(255, 77, 94, .55); }
.turn--win { border-color: var(--warn); background: linear-gradient(90deg, rgba(120, 90, 10, .8), rgba(11, 31, 51, .6)); }
.turn__text { font-size: 17px; font-weight: 700; }
.turn__sub { color: var(--muted); font-size: 13px; }

/* ---------- панель расстановки ---------- */
.stage-panel { margin-bottom: 16px; }
.stage-panel__head h2 { margin: 0 0 4px; font-size: 18px; }
.stage-panel__head p { margin: 0; color: var(--muted); font-size: 13px; }

.fleet {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 16px 0;
}
.fleet__group { display: flex; flex-direction: column; gap: 6px; }
.fleet__label { font-size: 12px; color: var(--muted); }

.ship {
  display: flex;
  gap: 3px;
  padding: 5px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  background: rgba(255, 255, 255, .03);
  transition: background .15s ease, border-color .15s ease;
}
.ship:hover { background: rgba(56, 214, 255, .12); }
.ship--active { border-color: var(--accent); background: rgba(56, 214, 255, .18); }
.ship--done { opacity: .35; cursor: default; filter: grayscale(.7); }
.ship__cell {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: linear-gradient(180deg, #7db4ff, #3f7fd6);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25);
}

.stage-panel__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- поля ---------- */
.boards {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  align-items: flex-start;
}
.board-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .3);
}
.board-card__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.board-card__head h3 { margin: 0; font-size: 16px; }
.board-card__meta { font-size: 12px; color: var(--muted); }
.board-card--foe { border-color: rgba(255, 77, 94, .38); }

.board {
  display: grid;
  grid-template-columns: 26px repeat(10, var(--cell));
  grid-auto-rows: var(--cell);
  gap: 2px;
  touch-action: manipulation;
}
.axis {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}
.axis--corner { font-size: 10px; }

.cell {
  position: relative;
  border-radius: 4px;
  border: 1px solid #12324c;
  background: #0a2338;
  cursor: default;
  padding: 0;
  transition: background .12s ease, transform .08s ease;
}
.board--mine .cell { border-color: #16395a; background: #0b2941; }
.board--foe .cell--live { cursor: pointer; }
.board--foe .cell--live:hover { background: #1b4a6d; transform: scale(1.06); }

/* свои корабли */
.cell--ship { background: linear-gradient(180deg, #5a9bff, #2f6dbf); border-color: #7cb6ff; }
.cell--ship::after {
  content: "";
  position: absolute; inset: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .35);
}
/* попадания */
.cell--hit { background: linear-gradient(180deg, #ff6a78, #c0263a); border-color: #ff9aa4; }
.cell--hit::before, .cell--hit::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 68%; height: 3px; border-radius: 2px;
  background: #fff2f4;
}
.cell--hit::before { transform: translate(-50%, -50%) rotate(45deg); }
.cell--hit::after { transform: translate(-50%, -50%) rotate(-45deg); }

/* промахи */
.cell--miss { background: #0d2b43; border-color: #2a557a; }
.cell--miss::after {
  content: "";
  position: absolute; left: 50%; top: 50%;
  width: 8px; height: 8px; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid #8fa9c0;
  background: rgba(143, 169, 192, .25);
}
/* потопленный корабль целиком */
.cell--sunk { box-shadow: inset 0 0 0 2px rgba(255, 190, 120, .65); }
/* последний выстрел */
.cell--last { animation: pulse .8s ease-out 2; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(56, 214, 255, .9); }
  100% { box-shadow: 0 0 0 10px rgba(56, 214, 255, 0); }
}

/* подсказка при расстановке (превью корабля) */
.cell--preview-ok { background: rgba(52, 211, 153, .45); }
.cell--preview-bad { background: rgba(255, 77, 94, .45); }

.footnote { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* ---------- оверлей результата ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 10, 18, .78);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 40;
}
.overlay__card {
  width: min(460px, 100%);
  text-align: center;
  padding: 28px 24px;
  animation: pop .25s ease-out;
}
@keyframes pop {
  from { transform: scale(.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.overlay__emoji { font-size: 54px; line-height: 1; margin-bottom: 8px; }
.overlay__card h2 { margin: 0 0 8px; font-size: 28px; }
.overlay__card p { color: var(--muted); margin: 0 0 20px; }
#result-overlay.is-win h2 { color: var(--warn); }
#result-overlay.is-lose h2 { color: #ff9aa4; }
.overlay__actions { display: flex; justify-content: center; gap: 10px; }

/* ---------- всплывающее уведомление ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  max-width: min(560px, 92vw);
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(9, 30, 48, .96);
  border: 1px solid var(--line);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .45);
  font-size: 14px;
  z-index: 50;
  animation: rise .2s ease-out;
}
@keyframes rise {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.toast--hit { border-color: rgba(255, 77, 94, .7); }
.toast--miss { border-color: rgba(159, 179, 198, .7); }
.toast--win { border-color: var(--warn); color: #ffe9a8; }
.toast--start, .toast--reset { border-color: rgba(56, 214, 255, .7); }

/* ---------- адаптив ---------- */
@media (max-width: 900px) {
  :root { --cell: 30px; }
}
@media (max-width: 620px) {
  :root { --cell: 27px; }
  .boards { gap: 14px; }
  .player__role { display: none; }
  .turn { flex-direction: column; gap: 2px; }
}
@media (max-width: 420px) {
  :root { --cell: 23px; }
  .board { grid-template-columns: 20px repeat(10, var(--cell)); }
}
