/* FunWithWords: Sonar - Co-Located Feature Stylesheet (GEMINI.md Rule 24 §2.4)
   Strictly scoped under .fww-game-sonar with zero !important declarations. */

.fww-game-sonar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  box-sizing: border-box;
}

/* Over-Board Telemetry Bar (Canonical #board-top-stats) */
.panel-board.fww-game-sonar #board-top-stats,
.fww-game-sonar #board-top-stats,
#board-top-stats:has(.sonar-telemetry-bar) {
  min-height: 32px;
  padding: 0;
  width: var(--board-size, min(var(--board-desktop-size, 400px), 94vw));
  max-width: var(--board-size, min(var(--board-desktop-size, 400px), 94vw));
  margin: 0 auto 6px auto;
}

.sonar-telemetry-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 8px;
  padding: 5px 10px;
  gap: 8px;
  box-sizing: border-box;
  color: #f8fafc;
  font-size: 0.80rem;
}


.fww-game-sonar .sonar-telemetry-solo .sonar-telemetry-player,
.fww-game-sonar .sonar-telemetry-solo .sonar-telemetry-metrics {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.fww-game-sonar .sonar-player-badge {
  font-weight: 800;
  color: #e2e8f0;
  white-space: nowrap;
}

.fww-game-sonar .sonar-fleet-pips {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 6px;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: #38bdf8;
}

.fww-game-sonar .sonar-sub-pip.is-sunk {
  color: #10b981;
  text-decoration: underline;
}

.fww-game-sonar .sonar-pip-dot {
  color: #64748b;
}

.fww-game-sonar .sonar-miss-pill {
  color: #cbd5e1;
  font-size: 0.78rem;
}

.fww-game-sonar .sonar-miss-pill strong {
  color: #fb923c;
}

.fww-game-sonar .sonar-par-sub {
  color: #94a3b8;
  font-size: 0.72rem;
}

.fww-game-sonar .sonar-timer-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(14, 116, 144, 0.22);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* 1v1 Duel Telemetry: My Waters on Left under P1 Name, Enemy Waters on Right under P2 Name */
.fww-game-sonar .sonar-telemetry-duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.fww-game-sonar .sonar-duel-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fww-game-sonar .sonar-duel-left {
  align-items: flex-start;
}

.fww-game-sonar .sonar-duel-right {
  align-items: flex-end;
}

.fww-game-sonar .sonar-duel-player-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.fww-game-sonar .sonar-duel-col.is-turn-active .sonar-player-badge {
  color: #34d399;
}

.fww-game-sonar .sonar-duel-score {
  font-size: 0.76rem;
  font-weight: 700;
  color: #94a3b8;
}

.fww-game-sonar .sonar-miss-inline {
  color: #fb923c;
  font-weight: 600;
}

.fww-game-sonar .sonar-duel-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.fww-game-sonar .sonar-waters-tab {
  appearance: none;
  background: rgba(30, 41, 59, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #94a3b8;
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.fww-game-sonar .sonar-waters-tab:hover {
  border-color: rgba(56, 189, 248, 0.6);
  color: #e2e8f0;
}

.fww-game-sonar .sonar-waters-tab.is-active {
  background: rgba(14, 165, 233, 0.24);
  border-color: #38bdf8;
  color: #f8fafc;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.25);
}

.fww-game-sonar .sonar-final-salvo-badge {
  font-size: 0.68rem;
  font-weight: 800;
  color: #fef08a;
  background: rgba(234, 179, 8, 0.22);
  border: 1px solid rgba(250, 204, 21, 0.5);
  border-radius: 4px;
  padding: 1px 5px;
}

/* Ocean Grid Container (Canonical #board-grid matching XWord pattern) */
#board-grid.sonar-active,
.fww-game-sonar #board-grid {
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--sonar-grid-size, var(--grid-size, 7)), 1fr);
  grid-template-rows: repeat(var(--sonar-grid-size, var(--grid-size, 7)), 1fr);
  gap: 4px;
  padding: 6px;
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at 50% 35%, #0c243c 0%, #071526 100%);
  border: 2px solid rgba(56, 189, 248, 0.38);
  border-radius: 12px;
  box-sizing: border-box;
  box-shadow: inset 0 0 24px rgba(2, 6, 23, 0.8), 0 8px 22px rgba(2, 6, 23, 0.45);
  position: relative;
}


/* Individual Ocean Cell */
.fww-game-sonar .sonar-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 32, 56, 0.88);
  border: 1.5px solid rgba(56, 189, 248, 0.18);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: transform 0.08s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.fww-game-sonar .sonar-cell:hover {
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(22, 46, 78, 0.92);
}

/* Selected Target Cell Cursor */
.fww-game-sonar .sonar-cell.sonar-cell-selected {
  outline: 2px solid #38bdf8;
  outline-offset: -1px;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.45);
  z-index: 2;
}

/* Drag Hover States */
.fww-game-sonar .sonar-cell.drag-hover {
  background: rgba(14, 165, 233, 0.35);
  border-color: #38bdf8;
  transform: scale(1.03);
}

.fww-game-sonar .sonar-cell.drag-hover-illegal {
  background: rgba(239, 68, 68, 0.28);
  border-color: #ef4444;
}

/* State 1: Confirmed Direct Hit (Solid Green Square) */
.fww-game-sonar .sonar-cell.sonar-cell-hit {
  background: linear-gradient(145deg, #059669 0%, #047857 100%);
  border: 2px solid #34d399;
  color: #ecfdf5;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.25);
}

.fww-game-sonar .sonar-cell.sonar-cell-hit.sonar-cell-sunk {
  background: linear-gradient(145deg, #10b981 0%, #059669 100%);
  border-color: #6ee7b7;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
}

/* State 2: Submarine Hull Hit with Wrong Letter (Solid/Tinted Orange Square, NO Directional Edges) */
.fww-game-sonar .sonar-cell.sonar-cell-hull {
  background: linear-gradient(145deg, rgba(234, 88, 12, 0.82) 0%, rgba(194, 65, 12, 0.88) 100%);
  border: 2px solid #fb923c;
  color: #ffedd5;
}

/* State 3: Probed Empty Water Square + Shared-Edge Echo Indicators */
.fww-game-sonar .sonar-cell.sonar-cell-water {
  background: rgba(7, 17, 32, 0.94);
  border: 1.5px solid rgba(51, 65, 85, 0.55);
  color: #94a3b8;
}

/* Solid Green (Exact Letter Match on Adjacent Unrevealed Submarine) & Solid Orange (Easy Mode Adjacent Hull) Shared Edges */
.fww-game-sonar .sonar-cell.sonar-edge-n-green {
  border-top: 4px solid #10b981;
}
.fww-game-sonar .sonar-cell.sonar-edge-s-green {
  border-bottom: 4px solid #10b981;
}
.fww-game-sonar .sonar-cell.sonar-edge-e-green {
  border-right: 4px solid #10b981;
}
.fww-game-sonar .sonar-cell.sonar-edge-w-green {
  border-left: 4px solid #10b981;
}

.fww-game-sonar .sonar-cell.sonar-edge-n-orange {
  border-top: 4px solid #fb923c;
}
.fww-game-sonar .sonar-cell.sonar-edge-s-orange {
  border-bottom: 4px solid #fb923c;
}
.fww-game-sonar .sonar-cell.sonar-edge-e-orange {
  border-right: 4px solid #fb923c;
}
.fww-game-sonar .sonar-cell.sonar-edge-w-orange {
  border-left: 4px solid #fb923c;
}

/* State 4: Staged Draft Tile awaiting Enter ↵ */
.fww-game-sonar .sonar-cell.sonar-cell-draft {
  background: linear-gradient(145deg, rgba(14, 165, 233, 0.42) 0%, rgba(2, 132, 199, 0.52) 100%);
  border: 2px dashed #38bdf8;
  color: #f0f9ff;
}

/* Friendly Submarine Hull on My Waters in 1v1 mode */
.fww-game-sonar .sonar-cell.sonar-cell-friendly-sub {
  background: rgba(30, 58, 138, 0.55);
  border: 1.5px solid rgba(96, 165, 250, 0.55);
  color: #bfdbfe;
}

/* Top-Left Tried Letters History Badge (Orange Hull & Dark Water cells) */
.fww-game-sonar .sonar-cell-tried {
  position: absolute;
  top: 2px;
  left: 4px;
  right: 2px;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.05;
  color: #fed7aa;
  letter-spacing: 0.02em;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.fww-game-sonar .sonar-cell.sonar-cell-water .sonar-cell-tried {
  color: #94a3b8;
}

/* Center Character (Confirmed Hit or Staged Draft) */
.fww-game-sonar .sonar-cell-char {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.fww-game-sonar .sonar-orient-indicator {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.62rem;
  font-weight: 800;
  color: #38bdf8;
  pointer-events: none;
}

/* Outcome Banner Overlay */
.fww-game-sonar .sonar-outcome-banner,
#board-grid.sonar-active .sonar-outcome-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  max-width: 320px;
  padding: 12px 16px;
  border-radius: 10px;
  text-align: center;
  box-sizing: border-box;
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}


.fww-game-sonar .sonar-outcome-banner.is-victory {
  background: rgba(6, 95, 70, 0.45);
  border: 1px solid #10b981;
  color: #ecfdf5;
}

.fww-game-sonar .sonar-outcome-banner.is-defeat {
  background: rgba(127, 29, 29, 0.45);
  border: 1px solid #f87171;
  color: #fef2f2;
}

.fww-game-sonar .sonar-outcome-title {
  font-weight: 800;
  font-size: 0.92rem;
}

.fww-game-sonar .sonar-outcome-sub {
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-top: 2px;
}
