/* =========================================================
   МОРСКОЙ БОЙ — общие стили
   ========================================================= */

:root {
  --deep-1: #051a30;
  --deep-2: #0a2a4a;
  --deep-3: #0f3d63;
  --accent: #21d4c8;
  --accent-2: #ffb648;
  --danger: #ff5470;
  --success: #35e08a;
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.16);
  --text-main: #eaf4ff;
  --text-muted: #9ab4cf;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow-soft: 0 20px 60px rgba(0, 0, 0, 0.35);
  font-size: 16px;
}

* { box-sizing: border-box; }

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

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color: var(--text-main);
  background: linear-gradient(160deg, var(--deep-1) 0%, var(--deep-2) 45%, var(--deep-3) 100%);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

a { color: inherit; text-decoration: none; }
ul { padding-left: 1.2em; margin: .5em 0; }
li { margin-bottom: .4em; line-height: 1.5; }

.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; letter-spacing: .08em; }
.muted { color: var(--text-muted); }
.muted.small { font-size: .78em; font-weight: 400; }

/* ---------- Фоновые волны ---------- */
.ocean-bg {
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
}
.ocean-bg.subtle { opacity: .5; }
.ocean-bg::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(33,212,200,.10), transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(255,182,72,.08), transparent 45%);
}
.wave {
  position: absolute; left: -10%; width: 120%; height: 200px;
  background: radial-gradient(ellipse at center, rgba(33,212,200,.10) 0%, transparent 70%);
  border-radius: 45%;
  animation: waveMove 18s ease-in-out infinite;
}
.wave1 { top: 10%; animation-duration: 22s; }
.wave2 { top: 45%; animation-duration: 28s; animation-direction: reverse; opacity: .7; }
.wave3 { top: 75%; animation-duration: 34s; opacity: .5; }
@keyframes waveMove {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  50% { transform: translateX(4%) rotate(2deg); }
}

/* ---------- Стеклянные карточки ---------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-soft);
  padding: 28px;
  position: relative;
  z-index: 1;
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer;
  font-size: 1rem; font-weight: 600;
  padding: 13px 22px;
  border-radius: var(--radius-md);
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease, filter .15s ease;
  font-family: inherit;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0fb8ac);
  color: #04241f;
  box-shadow: 0 8px 24px rgba(33, 212, 200, .35);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 10px 28px rgba(33,212,200,.45); }
.btn-secondary {
  background: linear-gradient(135deg, var(--accent-2), #ff8a3d);
  color: #341800;
  box-shadow: 0 8px 24px rgba(255, 182, 72, .3);
}
.btn-secondary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-outline {
  background: rgba(255,255,255,.06);
  color: var(--text-main);
  border: 1px solid var(--glass-border);
}
.btn-outline:hover { background: rgba(255,255,255,.12); }
.btn-small { padding: 9px 14px; font-size: .85rem; }
.btn-wide { width: 100%; margin-top: 14px; }
.btn-label { display: inline-block; }
.btn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.25); border-top-color: rgba(0,0,0,.75);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Формы ---------- */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.field input {
  background: rgba(6, 22, 40, .55);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(33,212,200,.18); }
.form-error {
  color: var(--danger); font-size: .85rem; min-height: 1.2em; margin: 0;
}

/* =========================================================
   ГЛАВНАЯ СТРАНИЦА
   ========================================================= */
.home-wrap {
  position: relative; z-index: 1;
  max-width: 980px; margin: 0 auto;
  padding: 48px 20px 60px;
}
.home-header { text-align: center; margin-bottom: 36px; }
.logo {
  font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em;
  display: inline-flex; align-items: center; gap: 10px;
}
.logo.small { font-size: 1.15rem; }
.tagline { color: var(--text-muted); margin-top: 10px; font-size: 1.02rem; }

.cards-row {
  display: grid; grid-template-columns: 1fr auto 1fr;
  gap: 20px; align-items: stretch; margin-bottom: 28px;
}
.cards-row .glass-card { text-align: center; }
.divider { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-weight: 700; }
.divider span {
  background: rgba(255,255,255,.06); border-radius: 50%; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center; border: 1px solid var(--glass-border);
}
.card-icon { font-size: 2.4rem; margin-bottom: 6px; }
.card-desc { color: var(--text-muted); font-size: .92rem; margin: 6px 0 0; }

.rules-card { margin-top: 8px; }
.rules-card h3 { margin-top: 0; }

.home-footer {
  text-align: center; color: var(--text-muted); font-size: .82rem; margin-top: 36px;
}

@media (max-width: 760px) {
  .cards-row { grid-template-columns: 1fr; }
  .divider { display: none; }
}

/* =========================================================
   СТРАНИЦА КОМНАТЫ
   ========================================================= */
.room-header {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; flex-wrap: wrap; gap: 12px;
}
.room-code-badge {
  background: rgba(255,255,255,.07); border: 1px solid var(--glass-border);
  border-radius: 999px; padding: 8px 16px; font-size: .9rem;
  display: flex; align-items: center; gap: 8px;
}
.icon-btn {
  background: none; border: none; color: var(--text-main); cursor: pointer;
  font-size: 1rem; opacity: .8; padding: 0 2px;
}
.icon-btn:hover { opacity: 1; }

.room-main {
  position: relative; z-index: 1;
  max-width: 1100px; margin: 0 auto; padding: 10px 20px 60px;
}
.loading-hint { text-align: center; color: var(--text-muted); padding: 60px 0; }

.center-card { max-width: 560px; margin: 40px auto; text-align: center; }
.pulse-icon { font-size: 2.6rem; animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .6; transform: scale(1); } 50% { opacity: 1; transform: scale(1.12); } }

.share-box { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.share-row { display: flex; align-items: center; gap: 8px; }
.share-label { width: 60px; text-align: left; font-size: .82rem; color: var(--text-muted); flex-shrink: 0; }
.share-input {
  flex: 1; background: rgba(6,22,40,.55); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); color: var(--text-main); padding: 10px 12px; font-size: .92rem;
  min-width: 0;
}

/* ---------- Модалка имени ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 12, 24, .72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay[hidden] { display: none; }
.modal-card { max-width: 420px; width: 100%; text-align: center; }

/* ---------- Расстановка кораблей ---------- */
.placing-grid {
  display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start;
}
@media (max-width: 860px) {
  .placing-grid { grid-template-columns: 1fr; }
}

.board-wrap { display: flex; justify-content: center; margin-top: 14px; }
.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: min(440px, 100%);
  aspect-ratio: 1 / 1;
  gap: 2px;
  background: rgba(4, 16, 30, .5);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 6px;
}
.cell {
  background: rgba(255,255,255,.045);
  border-radius: 4px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  user-select: none;
  transition: background .12s ease, transform .1s ease;
}
.target-board .cell { cursor: pointer; }
.target-board .cell:hover:not(.shot-miss):not(.shot-hit):not(.disabled) {
  background: rgba(33,212,200,.28);
  transform: scale(1.04);
}
.target-board.disabled .cell { cursor: not-allowed; }

.cell.ship { background: rgba(160, 190, 220, .32); }
.cell.ship.sunk { background: rgba(255, 84, 112, .38); }
.cell.preview-ok { background: rgba(53, 224, 138, .35) !important; }
.cell.preview-bad { background: rgba(255, 84, 112, .35) !important; }
.cell.shot-miss::after { content: "•"; color: rgba(234,244,255,.55); font-size: 1.4rem; }
.cell.shot-hit { background: rgba(255, 84, 112, .5); }
.cell.shot-hit::after { content: "✦"; color: #fff; }
.cell.sunk-mark { background: rgba(255, 84, 112, .55) !important; }
.cell.just-hit { animation: hitPop .5s ease; }
@keyframes hitPop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }
.cell.just-miss { animation: missPop .5s ease; }
@keyframes missPop { 0% { transform: scale(0.4); opacity: 0;} 100% { transform: scale(1); opacity: 1;} }

/* ---------- Панель флота ---------- */
.fleet-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.fleet-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04); border: 1px solid transparent;
  cursor: pointer; transition: all .15s ease;
}
.fleet-item.active { border-color: var(--accent); background: rgba(33,212,200,.12); }
.fleet-item.done { opacity: .35; text-decoration: line-through; cursor: default; }
.fleet-dots { display: flex; gap: 3px; }
.fleet-dot { width: 12px; height: 12px; border-radius: 3px; background: rgba(255,255,255,.5); }
.fleet-count { margin-left: auto; font-size: .82rem; color: var(--text-muted); }

.placing-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.placing-controls .btn { flex: 1; min-width: 120px; }
.opponent-status { text-align: center; color: var(--text-muted); font-size: .85rem; margin-top: 14px; margin-bottom: 0; }

/* ---------- Игровая фаза ---------- */
.turn-banner {
  text-align: center; font-weight: 700; font-size: 1.15rem;
  padding: 14px 18px; border-radius: var(--radius-md);
  margin-bottom: 18px; border: 1px solid var(--glass-border);
  background: rgba(255,255,255,.05);
  transition: background .3s ease, border-color .3s ease;
}
.turn-banner.my-turn { background: rgba(53,224,138,.14); border-color: rgba(53,224,138,.4); color: #b9ffdc; }
.turn-banner.enemy-turn { background: rgba(255,182,72,.10); border-color: rgba(255,182,72,.35); color: #ffdca8; }

.boards-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 860px) {
  .boards-row { grid-template-columns: 1fr; }
}
.board-card h3 { margin-top: 0; text-align: center; }

.board-mini-wrap h4 { text-align: center; margin: 0 0 6px; color: var(--text-muted); font-weight: 600; }

/* ---------- Финал ---------- */
.result-icon { font-size: 3rem; }
.phase-finished .boards-row { margin-top: 18px; }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(10, 30, 50, .92); border: 1px solid var(--glass-border);
  color: var(--text-main); padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow-soft);
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px);} to { opacity: 1; transform: translateY(0);} }
.toast.error { border-color: rgba(255,84,112,.5); }
.toast.success { border-color: rgba(53,224,138,.5); }

/* ---------- Responsive tweaks ---------- */
@media (max-width: 480px) {
  .glass-card { padding: 18px; }
  .cell { font-size: .85rem; }
  .share-row { flex-wrap: wrap; }
  .share-label { width: 100%; }
}
