/* ═══════════════════════════════════════════════════
   МОРСКОЙ БОЙ — style.css
   Дизайн: тёмная военно-морская тема, адаптив под TG
════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Inter:wght@400;500;600&display=swap');

/* ─── CSS ПЕРЕМЕННЫЕ ─────────────────────────────── */
:root {
  --bg:          var(--tg-theme-bg-color, #111111);
  --bg2:         var(--tg-theme-secondary-bg-color, #1e1e1e);
  --accent:      var(--tg-theme-button-color, #e0e0e0);
  --accent-text: var(--tg-theme-button-text-color, #111);
  --text:        var(--tg-theme-text-color, #e8e8e8);
  --hint:        var(--tg-theme-hint-color, #666666);
  --link:        var(--tg-theme-link-color, #aaaaaa);

  --cell-empty:    #1c1c1c;
  --cell-ship:     #3d3d3d;
  --cell-miss:     #252525;
  --cell-hover:    rgba(200,200,200,.15);
  --cell-preview:  rgba(200,200,200,.22);
  --cell-invalid:  rgba(220,60,60,.35);

  /* цвет попадания (штриховка) и потопления задаются через ::after */
  --cell-hit-bg:   #2a2a2a;
  --cell-sunk-bg:  #3a3a3a;

  --green:  #5cb85c;
  --red:    #d9534f;
  --yellow: #d4ac0d;
  --blue:   #aaaaaa;

  --radius:  10px;
  --gap:     8px;
  --font-ui: 'Inter', sans-serif;
  --font-hd: 'Orbitron', monospace;

  /* label column width = same as cell */
  --label-size: 20px;
  /* cell fills remaining width: (100vw - 2*12px padding - label col - 10 gaps of 2px) / 10 */
  --cell-size: calc((100vw - 24px - var(--label-size) - 20px) / 10);
}

/* ─── СБРОС И БАЗА ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ─── ЭКРАНЫ ─────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0) 0;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
  overflow-y: auto; overflow-x: hidden;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ─── ЗАГРУЗКА ───────────────────────────────────── */
#screen-loading {
  align-items: center; justify-content: center;
  background: var(--bg);
}
.loading-inner { text-align: center; }
.loading-grid {
  display: grid; grid-template-columns: repeat(3, 18px); gap: 6px;
  margin: 0 auto 20px;
  animation: grid-pulse 1.2s ease-in-out infinite;
}
.loading-grid span {
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 3px;
  opacity: .2;
  animation: cell-blink 1.2s ease-in-out infinite;
}
.loading-grid span:nth-child(1) { animation-delay: 0s }
.loading-grid span:nth-child(2) { animation-delay: .1s }
.loading-grid span:nth-child(3) { animation-delay: .2s }
.loading-grid span:nth-child(4) { animation-delay: .3s }
.loading-grid span:nth-child(5) { animation-delay: .15s }
.loading-grid span:nth-child(6) { animation-delay: .4s }
.loading-grid span:nth-child(7) { animation-delay: .5s }
.loading-grid span:nth-child(8) { animation-delay: .35s }
.loading-grid span:nth-child(9) { animation-delay: .6s }
@keyframes cell-blink {
  0%,100% { opacity: .15; transform: scale(.9); }
  50%      { opacity: 1;   transform: scale(1); }
}
.loading-text {
  font-family: var(--font-hd);
  font-size: 22px; letter-spacing: 6px;
  color: var(--accent);
  animation: text-pulse 1.5s ease-in-out infinite;
}
@keyframes text-pulse {
  0%,100% { opacity: .6 } 50% { opacity: 1 }
}

/* ─── ГЛАВНОЕ МЕНЮ ───────────────────────────────── */
.menu-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 0;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.btn-sound {
  background: var(--bg2); border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px; padding: 7px; cursor: pointer;
  color: var(--text); display: flex; align-items: center; justify-content: center;
  transition: color .2s, border-color .2s;
  flex-shrink: 0;
}
.btn-sound:active { transform: scale(.92); }
.btn-sound.muted { color: var(--hint); border-color: rgba(255,255,255,.05); }
.sound-mute-line { stroke: var(--hint); stroke-width: 2; stroke-linecap: round; }
.user-info { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
  border: 2px solid var(--accent);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.username { font-weight: 600; font-size: 15px; display: block; }
.user-tag { color: var(--hint); font-size: 12px; }
.stats-mini { display: flex; gap: 16px; }
.stat-item { text-align: center; }
.stat-val { display: block; font-family: var(--font-hd); font-size: 18px; color: var(--accent); }
.stat-lbl { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: 1px; }

.menu-hero {
  position: relative; flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 160px; overflow: hidden;
}
.hero-grid {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 2px; opacity: .15;
}
.hero-grid-cell {
  background: var(--cell-empty); border-radius: 2px;
  transition: background .3s, opacity .3s;
}
.hero-grid-cell.active { background: var(--accent); opacity: 1; }
.hero-grid-cell.hit    { background: var(--red); opacity: 1; }
.hero-title {
  font-family: var(--font-hd);
  font-size: clamp(26px, 8vw, 40px);
  font-weight: 900; letter-spacing: 4px;
  text-align: center; line-height: 1.15;
  color: var(--text);
  text-shadow: 0 0 30px var(--accent);
  position: relative; z-index: 1;
}

.menu-nav {
  padding: 0 16px 24px;
  display: flex; flex-direction: column; gap: 10px;
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ─── КНОПКИ ─────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border-radius: var(--radius);
  font-family: var(--font-ui); font-size: 15px; font-weight: 600;
  border: none; cursor: pointer;
  transition: transform .12s, opacity .12s, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.96); opacity: .9; }
.btn-primary {
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 4px 20px rgba(30,144,255,.35);
}
.btn-primary:hover { box-shadow: 0 4px 28px rgba(30,144,255,.55); }
.btn-secondary {
  background: var(--bg2); color: var(--text);
  border: 1px solid rgba(255,255,255,.1);
}
.btn-ghost {
  background: transparent; color: var(--hint);
  border: 1px solid rgba(255,255,255,.08);
}
.btn-danger { background: var(--red); color: #fff; }
.btn-large  { padding: 15px 20px; font-size: 16px; }
.btn-sm     { padding: 8px 14px; font-size: 13px; }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-icon { font-size: 18px; }

.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ─── ЗАГОЛОВОК СТРАНИЦ ──────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.page-header h2 {
  font-family: var(--font-hd); font-size: 16px;
  font-weight: 700; letter-spacing: 2px;
}
.btn-back {
  background: none; border: none; color: var(--hint);
  font-size: 14px; cursor: pointer; padding: 4px;
  font-family: var(--font-ui);
}

/* ─── РЕЖИМ ИГРЫ ─────────────────────────────────── */
.mode-list {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px;
}
.mode-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg2); border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: border-color .2s, transform .12s;
  text-align: left; color: var(--text);
}
.mode-card:active { transform: scale(.98); }
.mode-card:hover  { border-color: var(--accent); }
.mode-icon { font-size: 26px; flex-shrink: 0; }
.mode-info { flex: 1; }
.mode-info strong { display: block; font-size: 15px; }
.mode-info span   { color: var(--hint); font-size: 13px; }
.mode-badge {
  padding: 3px 9px; border-radius: 30px;
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  background: var(--bg); color: var(--hint);
}
.mode-badge.online  { background: rgba(38,166,91,.2); color: var(--green); }
.mode-badge.medium  { background: rgba(244,166,29,.2); color: var(--yellow); }
.mode-badge.hard    { background: rgba(230,57,70,.2); color: var(--red); }

/* ─── ПОЛЕ (ДОСКА) ───────────────────────────────── */
.board-wrap {
  width: 100%;
  padding: 6px 12px;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* Fix 5: outer wrapper — label col + board side by side */
.board-outer {
  display: flex;
  flex-direction: row;
  gap: 2px;
  width: 100%;
  align-items: flex-start;
}

/* Left labels col: empty corner space + row numbers */
.board-labels-col {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: var(--label-size);
  gap: 2px;
  /* Fix 5: push numbers down by the height of the col-labels row + its gap */
  padding-top: calc(var(--label-size) + 2px);
}

.board-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

/* Top row: A–J letters */
.board-labels-row {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
}

.board-label {
  height: var(--label-size);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--hint); font-family: var(--font-hd);
}

/* Row labels height = cell height */
.board-labels-col .board-label {
  width: 100%;
  height: var(--cell-size);
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, var(--cell-size));
  gap: 2px;
  width: 100%;
}

.cell {
  width: 100%; height: var(--cell-size);
  background: var(--cell-empty);
  border-radius: 3px;
  transition: background .1s;
  cursor: default;
  position: relative;
  overflow: hidden;
}
.cell.ship { background: var(--cell-ship); }

/* ПОПАДАНИЕ: штриховка поверх фона */
.cell.hit { background: var(--cell-hit-bg); }
.cell.hit::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    45deg,
    var(--red) 0px, var(--red) 2px,
    transparent 2px, transparent 6px
  );
  opacity: .85;
  pointer-events: none;
}

/* ПОТОПЛЕНИЕ: сплошная заливка */
.cell.sunk { background: var(--red); }
.cell.sunk::after { display: none; }

/* ПРОМАХ: маленькая точка */
.cell.miss { background: var(--cell-miss); }
.cell.miss::before {
  content: '';
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 4px; height: 4px; border-radius: 50%;
  background: #555;
  pointer-events: none;
}

.cell.preview { background: var(--cell-preview); }
.cell.invalid { background: var(--cell-invalid); }
/* Fix 4: pointer cursor, no scale */
.cell.hoverable { cursor: pointer; }
.cell.hoverable:hover { background: var(--cell-hover); }

/* ─── РАССТАНОВКА ────────────────────────────────── */
.placement-ships {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 12px 16px;
  min-height: 80px;
  align-content: flex-start;
}
.ship-piece {
  display: flex; gap: 3px;
  cursor: grab; touch-action: none;
  padding: 5px;
  border-radius: 5px;
  border: 2px solid transparent;
  transition: border-color .2s, opacity .2s, transform .15s;
  background: var(--bg2);
}
.ship-piece:active { cursor: grabbing; transform: scale(0.95); }
.ship-piece.selected { border-color: var(--accent); box-shadow: 0 0 8px rgba(200,200,200,.2); }
.ship-piece.placed { opacity: .25; pointer-events: none; }
.ship-piece.dragging { opacity: .5; }
.ship-cell {
  width: 28px; height: 28px;
  background: var(--cell-ship);
  border-radius: 3px;
}
.ship-piece.vertical { flex-direction: column; }
.placement-controls {
  display: flex; gap: 8px; padding: 0 16px 8px;
  flex-wrap: wrap;
}

/* ─── ОЖИДАНИЕ ───────────────────────────────────── */
#screen-waiting {
  align-items: center; justify-content: center;
}
.waiting-inner { text-align: center; padding: 24px; }
.waiting-inner h2 { margin: 20px 0 8px; font-family: var(--font-hd); font-size: 18px; }
.waiting-inner p  { color: var(--hint); font-size: 14px; }

.radar-anim {
  position: relative; width: 80px; height: 80px;
  margin: 0 auto;
}
.radar-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0;
  animation: radar-expand 2s ease-out infinite;
}
.radar-ring:nth-child(2) { animation-delay: .66s; }
.radar-ring:nth-child(3) { animation-delay: 1.33s; }
.radar-dot {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
@keyframes radar-expand {
  0%   { opacity: .8; transform: scale(.2); }
  100% { opacity: 0; transform: scale(1); }
}

.invite-block { margin-top: 24px; }
.invite-block.hidden { display: none; }
.invite-link-row {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg2); border-radius: var(--radius);
  padding: 10px 12px; margin-top: 8px;
}
.invite-link { flex: 1; font-size: 12px; color: var(--link); word-break: break-all; }

/* ─── ИГРОВОЙ ЭКРАН ──────────────────────────────── */
.game-topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px 6px;
}
.game-toggle {
  display: flex; background: var(--bg2); border-radius: 8px;
  overflow: hidden; flex-shrink: 0;
}
.toggle-btn {
  padding: 7px 12px; font-size: 13px; font-weight: 600;
  border: none; cursor: pointer;
  background: transparent; color: var(--hint);
  transition: background .2s, color .2s;
}
.toggle-btn.active { background: var(--accent); color: #fff; }
.game-status {
  flex: 1; text-align: center;
  font-family: var(--font-hd); font-size: 13px;
  letter-spacing: 1px;
  color: var(--accent);
}

/* ships-left hidden - removed per request */
.ships-left { display: none; }

.game-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.opponent-info { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.opp-avatar    { font-size: 22px; }

/* Fix 3: enemy remaining fleet panel */
.enemy-fleet {
  padding: 6px 12px 10px;
  flex-shrink: 0;
}
.enemy-fleet-label {
  font-size: 11px; color: var(--hint);
  text-transform: uppercase; letter-spacing: 1px;
  display: block; margin-bottom: 6px;
}
.enemy-fleet-ships {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end;
}
.fleet-ship {
  display: flex; gap: 2px;
  opacity: 1; transition: opacity .3s;
}
.fleet-ship.sunk { opacity: .2; }
.fleet-cell {
  width: 12px; height: 12px;
  background: var(--cell-ship);
  border-radius: 2px;
}
.fleet-ship.sunk .fleet-cell { background: var(--red); }

/* shot-feedback - hidden, kept for compat */
.shot-feedback { display: none !important; }

/* ─── КОНЕЦ ИГРЫ ─────────────────────────────────── */
#screen-gameover {
  align-items: center; justify-content: center;
  background: var(--bg);
}
.gameover-inner { text-align: center; padding: 24px; }
.gameover-icon  { font-size: 64px; animation: icon-bounce .6s ease; }
@keyframes icon-bounce {
  0%  { transform: scale(.3); opacity: 0; }
  60% { transform: scale(1.25); }
  100%{ transform: scale(1); opacity: 1; }
}
.gameover-title {
  font-family: var(--font-hd); font-size: clamp(28px, 8vw, 42px);
  margin: 12px 0 6px;
}
.gameover-sub { color: var(--hint); margin-bottom: 24px; }
.gameover-stats {
  display: flex; gap: 20px; justify-content: center;
  margin-bottom: 8px;
}
.go-stat { text-align: center; }
.go-stat span { display: block; font-family: var(--font-hd); font-size: 24px; }
.go-stat small { color: var(--hint); font-size: 12px; }

/* ─── ЛИДЕРБОРД ──────────────────────────────────── */
.leaderboard-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.lb-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border-radius: var(--radius);
  padding: 12px 14px;
}
.lb-rank {
  font-family: var(--font-hd); font-size: 16px; width: 28px;
  color: var(--hint); text-align: center;
}
.lb-rank.gold   { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }
.lb-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.lb-info   { flex: 1; }
.lb-info strong { display: block; font-size: 14px; }
.lb-info small  { color: var(--hint); font-size: 12px; }
.lb-wins   { font-family: var(--font-hd); color: var(--green); font-size: 16px; }

/* ─── СТАТИСТИКА ─────────────────────────────────── */
.stats-profile { display: flex; flex-direction: column; align-items: center; padding: 20px 0 12px; }
.stats-avatar { width: 60px; height: 60px; border-radius: 50%; background: var(--bg2); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; border: 3px solid var(--accent); margin-bottom: 10px; }
.stats-name { font-family: var(--font-hd); font-size: 16px; letter-spacing: 2px; }

.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; padding: 0 16px 16px;
}
.stat-card {
  background: var(--bg2); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
  border-left: 3px solid var(--hint);
}
.stat-card.green  { border-color: var(--green); }
.stat-card.red    { border-color: var(--red); }
.stat-card.yellow { border-color: var(--yellow); }
.stat-card.blue   { border-color: var(--blue); }
.stat-card span { display: block; font-family: var(--font-hd); font-size: 22px; }
.stat-card small { color: var(--hint); font-size: 11px; }

.section-title { padding: 4px 16px 10px; font-family: var(--font-hd); font-size: 13px; letter-spacing: 2px; color: var(--hint); }

.history-list { padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border-radius: var(--radius);
  padding: 10px 14px;
}
.history-icon { font-size: 18px; }
.history-info { flex: 1; font-size: 14px; }
.history-info span  { color: var(--hint); font-size: 12px; display: block; }
.history-time { font-size: 11px; color: var(--hint); }

/* ─── НАСТРОЙКИ ──────────────────────────────────── */
.settings-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.setting-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,.05);
  font-size: 15px;
}
.setting-input {
  background: var(--bg2); border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px; color: var(--text); padding: 6px 10px;
  font-size: 13px; width: 50%;
  outline: none;
}
.setting-input:focus { border-color: var(--accent); }

/* Тумблер */
.toggle-switch { position: relative; width: 44px; height: 24px; cursor: pointer; }
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--bg); border-radius: 30px;
  border: 1px solid rgba(255,255,255,.15);
  transition: background .25s;
}
.toggle-track::before {
  content: ''; position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--hint);
  transition: transform .25s, background .25s;
}
.toggle-switch input:checked + .toggle-track { background: rgba(30,144,255,.3); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(20px); background: var(--accent); }

/* ─── МОДАЛКА ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border-radius: 14px;
  padding: 24px; width: calc(100% - 48px); max-width: 320px;
  border: 1px solid rgba(255,255,255,.1);
  animation: modal-pop .2s ease;
}
@keyframes modal-pop {
  from { transform: scale(.85); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal h3 { font-family: var(--font-hd); font-size: 15px; letter-spacing: 2px; margin-bottom: 10px; }
.modal p  { color: var(--hint); font-size: 14px; line-height: 1.5; }
.modal-btns { display: flex; gap: 8px; margin-top: 18px; }
.modal-btns .btn { flex: 1; }

/* ─── УТИЛИТЫ ────────────────────────────────────── */
.empty-state { color: var(--hint); text-align: center; padding: 32px 16px; font-size: 14px; }
.hidden { display: none !important; }

/* ─── СКРОЛЛБАР ──────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }
