:root {
  --bg:         #0d1b2a;
  --panel:      #1a3a5c;
  --sea:        #1e6091;
  --sea-hover:  #2471a3;
  --hdr-cell:   #0f2744;
  --ship:       #2c3e50;
  --ship-lit:   #374957;
  --hit:        #c0392b;
  --miss-bg:    rgba(255,255,255,0.07);
  --miss-dot:   #7f8c8d;
  --text:       #ecf0f1;
  --muted:      #95a5a6;
  --accent:     #2980b9;
  --green:      #27ae60;
  --border:     rgba(255,255,255,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow-x: hidden;
}

/* ── PHASES ─────────────────────────────────────────────── */
#phase-setup,
#phase-battle,
#phase-end {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 20px;
  gap: 8px;
}

.hidden { display: none !important; }

/* ── HEADER ──────────────────────────────────────────────── */
header { text-align: center; padding: 4px 0 2px; }
header h1 { font-size: 22px; font-weight: 700; }
.subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  padding: 11px 14px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 15px;
  font-size: 16px;
}

.btn-outline {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline.danger { color: #e74c3c; }

/* ── SETUP CONTROLS ──────────────────────────────────────── */
.setup-controls {
  display: flex;
  gap: 8px;
}
.setup-controls .btn { flex: 1; font-size: 12px; padding: 9px 6px; }

/* ── SHIP LIST ───────────────────────────────────────────── */
.ship-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ship-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-radius: 10px;
  border: 2px solid transparent;
  transition: border-color .2s, background .2s;
}

.ship-row.active {
  border-color: var(--accent);
  background: rgba(41,128,185,.18);
}

.ship-row.done { opacity: .5; }

.ship-graphic { display: flex; gap: 2px; }

.ship-block {
  width: 20px;
  height: 20px;
  background: var(--ship-lit);
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.15);
}

.ship-row.active .ship-block { background: var(--accent); }
.ship-row.done .ship-block { background: var(--green); }

.ship-label { flex: 1; font-size: 13px; color: var(--muted); }
.ship-counter { font-size: 13px; font-weight: 700; }
.ship-row.done .ship-counter { color: var(--green); }

/* ── GRID ────────────────────────────────────────────────── */
.grid-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid {
  display: grid;
  grid-template-columns: 24px repeat(10, 1fr);
  gap: 2px;
  width: 100%;
  max-width: 376px;
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background .1s;
  line-height: 1;
}

.cell.hdr {
  background: var(--hdr-cell);
  color: var(--muted);
  cursor: default;
  font-size: 9px;
}

.cell.water {
  background: var(--sea);
}
.cell.water:active { background: var(--sea-hover); }

.cell.ship { background: var(--ship); }

/* my-grid battle states */
.cell.incoming-miss {
  background: var(--miss-bg);
  color: var(--miss-dot);
  font-size: 16px;
}
.cell.incoming-hit {
  background: var(--hit);
  color: #fff;
  font-size: 14px;
}

/* enemy-grid states */
.cell.shot-miss {
  background: var(--miss-bg);
  color: var(--miss-dot);
  font-size: 16px;
}
.cell.shot-hit {
  background: var(--hit);
  color: #fff;
  font-size: 14px;
}

/* flash on invalid placement */
@keyframes flash-red {
  0%,100% { background: var(--sea); }
  40%      { background: #922b21; }
}
.cell.flash { animation: flash-red .35s ease; }

/* ── SETUP BOTTOM ────────────────────────────────────────── */
.setup-bottom { margin-top: 2px; }

/* ── TABS ────────────────────────────────────────────────── */
.tabs { display: flex; gap: 8px; }

.tab {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.tab.tab-active { background: var(--accent); color: #fff; }

/* ── HINT ────────────────────────────────────────────────── */
.hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 0 8px;
  line-height: 1.4;
}

/* ── STATS ───────────────────────────────────────────────── */
.battle-stats {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

/* ── END SCREEN ──────────────────────────────────────────── */
#phase-end {
  justify-content: center;
  align-items: center;
}

.end-screen {
  text-align: center;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.end-icon { font-size: 88px; line-height: 1; }

.end-screen h1 { font-size: 36px; }
.end-screen p { color: var(--muted); font-size: 16px; }
.end-screen .btn { max-width: 280px; margin-top: 16px; }

/* ── TOAST ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,20,35,.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 999;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .3s;
}
.toast.hidden { opacity: 0; }
