/* ═══════════════════════════════════════════════════════════════
   NJORDFEL FUTURES — Viking Battleship CSS
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─────────────────────────────────────────── */
:root {
  --gold:        #c9a84c;
  --gold-light:  #e8c87a;
  --gold-dark:   #8a6a1f;
  --dark-wood:   #3d2b1f;
  --deep-water:  #0a1628;
  --mid-water:   #122244;
  --light-water: #1a3a6c;
  --hit:         #e84b1a;
  --hit-light:   #ff6a3d;
  --miss:        #4a6fa5;
  --miss-light:  #6a8fc5;
  --ship-color:  #5c3d1e;
  --ship-light:  #7a5530;
  --grid-line:   #1a3a5c;
  --text-primary:#e8d5a3;
  --text-dim:    #8a7a5a;
  --danger:      #8b1a1a;
  --success:     #1a6b2a;
  --cell-size:   40px;
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background-color: var(--deep-water);
  color: var(--text-primary);
  font-family: 'Cinzel', 'Georgia', serif;
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(18, 34, 68, 0.8) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(26, 58, 108, 0.4) 0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23122244' fill-opacity='0.3'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  min-height: 100vh;
}

/* ─── Screen Management ─────────────────────────────────────── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ─── Typography ────────────────────────────────────────────── */
h1, h2, h3, h4 { font-family: 'Cinzel', serif; letter-spacing: 0.05em; }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  letter-spacing: 0.08em;
  border: none;
  cursor: pointer;
  padding: 12px 24px;
  border-radius: 4px;
  transition: all 0.2s ease;
  text-transform: uppercase;
  font-size: 0.85rem;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.05);
  opacity: 0;
  transition: opacity 0.2s;
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled::after { display: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-dark) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  color: #1a0e00;
  border: 1px solid var(--gold-light);
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 0 30px rgba(201, 168, 76, 0.5), inset 0 1px 0 rgba(255,255,255,0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: linear-gradient(135deg, #1a2a4a 0%, #2a3a6a 100%);
  color: var(--gold);
  border: 1px solid var(--grid-line);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(201, 168, 76, 0.2);
}

.btn-danger {
  background: linear-gradient(135deg, #4a1010 0%, #6b1e1e 100%);
  color: #ffaaaa;
  border: 1px solid #8b3030;
}
.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, #6b1e1e 0%, #8b2020 100%);
}

.btn-sm { padding: 8px 16px; font-size: 0.75rem; }

/* ─── Lobby Screen ──────────────────────────────────────────── */
#lobby-screen {
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.lobby-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.logo-area {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.ship-illustration {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 16px rgba(201,168,76,0.3));
}

.game-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow:
    0 0 40px rgba(201, 168, 76, 0.6),
    0 0 80px rgba(201, 168, 76, 0.3),
    2px 2px 0 rgba(0,0,0,0.8);
  line-height: 1.1;
  letter-spacing: 0.1em;
}

.title-sub {
  font-size: 0.55em;
  color: var(--gold-light);
  letter-spacing: 0.3em;
}

.game-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.rune-border {
  width: 200px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  position: relative;
}
.rune-border::before, .rune-border::after {
  content: '✦';
  position: absolute;
  color: var(--gold);
  top: -8px;
  font-size: 10px;
}
.rune-border::before { left: 30%; }
.rune-border::after { right: 30%; }

.lobby-card {
  width: 100%;
  background: rgba(10, 22, 40, 0.8);
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  padding: 32px;
  box-shadow:
    0 0 40px rgba(0,0,0,0.6),
    inset 0 1px 0 rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.form-group label {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-transform: uppercase;
}
.form-group input {
  background: rgba(18, 34, 68, 0.8);
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Cinzel', serif;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(201, 168, 76, 0.2);
}
.form-group input::placeholder { color: var(--text-dim); }

#room-code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 1.4rem;
  text-align: center;
}

.lobby-actions { display: flex; flex-direction: column; gap: 16px; }
.lobby-actions .btn { width: 100%; }

.divider {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
}

.join-section { display: flex; flex-direction: column; gap: 12px; }

.lobby-message {
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 0.85rem;
  text-align: center;
}
.lobby-message.error {
  background: rgba(139, 26, 26, 0.3);
  border: 1px solid var(--danger);
  color: #ffaaaa;
}
.lobby-message.info {
  background: rgba(26, 107, 42, 0.3);
  border: 1px solid var(--success);
  color: #aaffcc;
}

.waiting-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border: 1px dashed var(--gold-dark);
  border-radius: 4px;
  background: rgba(201, 168, 76, 0.05);
}
.waiting-panel p { color: var(--text-dim); font-size: 0.85rem; }
.waiting-text { color: var(--gold) !important; animation: pulse 2s ease-in-out infinite; }

.room-code-display {
  font-size: 1.8rem;
  color: var(--gold);
  letter-spacing: 0.3em;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.5);
}

.waiting-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--grid-line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ─── Placement Screen ──────────────────────────────────────── */
#placement-screen {
  padding: 16px;
  align-items: stretch;
  gap: 16px;
}

.placement-header {
  text-align: center;
  padding: 16px;
  border-bottom: 1px solid var(--grid-line);
}
.placement-header h2 {
  color: var(--gold);
  font-size: 1.5rem;
}
.placement-status {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 6px;
  letter-spacing: 0.1em;
}
.opponent-label {
  color: var(--miss);
  font-size: 0.8rem;
  margin-top: 4px;
}

.placement-layout {
  display: flex;
  flex: 1;
  gap: 24px;
  padding: 16px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

/* Ship Tray */
.ship-tray {
  background: rgba(10, 22, 40, 0.6);
  border: 1px solid var(--grid-line);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 200px;
  max-width: 240px;
}
.ship-tray h3 {
  color: var(--gold);
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  border-bottom: 1px solid var(--grid-line);
  padding-bottom: 10px;
}

.ship-list { display: flex; flex-direction: column; gap: 10px; }

.ship-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  background: rgba(18, 34, 68, 0.5);
}
.ship-item:hover:not(.placed) {
  border-color: var(--gold-dark);
  background: rgba(201, 168, 76, 0.08);
}
.ship-item.selected {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.15);
  box-shadow: 0 0 15px rgba(201, 168, 76, 0.2);
}
.ship-item.placed {
  opacity: 0.4;
  cursor: not-allowed;
}
.ship-item-name {
  font-size: 0.75rem;
  color: var(--gold);
  letter-spacing: 0.1em;
}
.ship-item-size {
  font-size: 0.65rem;
  color: var(--text-dim);
}
.ship-visual {
  display: flex;
  gap: 2px;
}
.ship-cell-preview {
  width: 18px;
  height: 18px;
  background: var(--ship-color);
  border-radius: 2px;
  border: 1px solid var(--ship-light);
}
.ship-item.selected .ship-cell-preview {
  background: var(--gold-dark);
  border-color: var(--gold);
}
.ship-item.placed .ship-cell-preview {
  background: #2a2a2a;
  border-color: #444;
}

.placement-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-ready {
  margin-top: 8px;
  font-size: 0.85rem !important;
  padding: 14px 20px !important;
}

.placement-waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 10px;
  border: 1px dashed var(--grid-line);
  border-radius: 4px;
}
.placement-waiting .waiting-spinner {
  width: 20px;
  height: 20px;
  border-width: 2px;
  flex-shrink: 0;
}

.placement-board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.board-label {
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-transform: uppercase;
}
.placement-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  max-width: 420px;
  line-height: 1.5;
}

/* ─── Boards (shared) ───────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  grid-template-rows: repeat(10, var(--cell-size));
  gap: 1px;
  background: var(--grid-line);
  border: 2px solid var(--grid-line);
  border-radius: 2px;
  box-shadow:
    0 0 30px rgba(0, 0, 0, 0.5),
    inset 0 0 20px rgba(10, 22, 40, 0.5);
  user-select: none;
  position: relative;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--mid-water);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s;
  font-size: 14px;
}

/* ── Ship overlay illustrations ── */
.ship-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  line-height: 0;
}

/* ── Placement board cells ── */
.placement-board .cell { cursor: crosshair; }
.placement-board .cell:hover { background: rgba(201, 168, 76, 0.15); }
.placement-board .cell.ship {
  background: transparent;
  border: none;
}
.placement-board .cell.preview-valid {
  background: rgba(92, 61, 30, 0.5);
  border: 1px dashed var(--gold);
}
.placement-board .cell.preview-invalid {
  background: rgba(232, 75, 26, 0.25);
  border: 1px dashed var(--hit);
}

/* ── Home board cells (battle) ── */
#home-board .cell {
  cursor: default;
}
#home-board .cell.ship {
  background: transparent;
  border: none;
}
#home-board .cell.ship.hit {
  background: var(--hit);
  position: relative;
  z-index: 3;
  animation: hitFlare 0.6s ease-out;
}
#home-board .cell.ship.sunk {
  background: rgba(60,60,60,0.85);
  position: relative;
  z-index: 3;
}
#home-board .cell.miss {
  background: var(--miss);
  position: relative;
  z-index: 3;
}

/* ── Enemy board cells (battle) ── */
#enemy-board .cell {
  cursor: crosshair;
}
#enemy-board .cell.my-turn:hover {
  background: rgba(201, 168, 76, 0.25);
  box-shadow: inset 0 0 8px rgba(201, 168, 76, 0.3);
}
#enemy-board .cell.hit {
  background: var(--hit);
  animation: hitFlare 0.6s ease-out;
}
#enemy-board .cell.miss {
  background: var(--miss);
}
#enemy-board .cell.sunk {
  background: #555;
}
#enemy-board .cell.hit::after,
#enemy-board .cell.sunk::after {
  content: '✕';
  font-size: 18px;
  color: rgba(255,255,255,0.9);
  font-weight: bold;
}
#enemy-board .cell.miss::after {
  content: '·';
  font-size: 24px;
  color: rgba(255,255,255,0.6);
}
#home-board .cell.ship.hit::after {
  content: '✕';
  font-size: 18px;
  color: rgba(255,255,255,0.9);
  font-weight: bold;
}
#home-board .cell.miss::after {
  content: '·';
  font-size: 24px;
  color: rgba(255,255,255,0.6);
}

/* ─── Game Screen ───────────────────────────────────────────── */
#game-screen {
  padding: 0;
  gap: 0;
}

.turn-banner {
  padding: 14px 24px;
  text-align: center;
  background: rgba(10, 22, 40, 0.9);
  border-bottom: 2px solid var(--grid-line);
  font-size: 1rem;
  letter-spacing: 0.15em;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s;
}
.turn-banner.my-turn {
  background: rgba(201, 168, 76, 0.12);
  border-bottom-color: var(--gold);
  color: var(--gold);
  animation: turnPulse 2s ease-in-out infinite;
}
.turn-banner.enemy-turn {
  background: rgba(74, 111, 165, 0.12);
  border-bottom-color: var(--miss);
  color: var(--miss-light);
}

.boards-container {
  display: flex;
  gap: 32px;
  padding: 20px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  flex: 1;
}

.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.board-header {
  text-align: center;
}
.board-header h2 {
  color: var(--gold);
  font-size: 1rem;
  letter-spacing: 0.15em;
}
.board-desc {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 2px;
}

.ship-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--text-dim);
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--ship-color);
  border: 1px solid var(--ship-light);
  flex-shrink: 0;
}
.legend-dot.sunk { background: #444; border-color: #666; }

.sunk-ships-log {
  background: rgba(10, 22, 40, 0.5);
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  padding: 12px;
  width: 100%;
}
.sunk-ships-log h4 {
  color: var(--gold);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--grid-line);
  padding-bottom: 6px;
}
.sunk-list { display: flex; flex-direction: column; gap: 4px; }
.no-sunk {
  color: var(--text-dim);
  font-size: 0.75rem;
}
.sunk-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: #aaa;
  animation: fadeIn 0.4s ease-out;
}
.sunk-item::before { content: '⚓'; }

/* ─── Message Log ───────────────────────────────────────────── */
.message-log {
  background: rgba(10, 22, 40, 0.8);
  border-top: 1px solid var(--grid-line);
  padding: 12px 20px;
  max-height: 140px;
  overflow-y: auto;
}
.messages { display: flex; flex-direction: column; gap: 4px; }
.msg {
  font-size: 0.8rem;
  padding: 4px 8px;
  border-left: 3px solid transparent;
  animation: fadeIn 0.3s ease-out;
  line-height: 1.4;
}
.msg.hit-msg   { border-color: var(--hit); color: #ff9977; }
.msg.miss-msg  { border-color: var(--miss); color: var(--miss-light); }
.msg.sunk-msg  { border-color: var(--gold); color: var(--gold); }
.msg.info-msg  { border-color: var(--grid-line); color: var(--text-dim); }
.msg.turn-msg  { border-color: var(--gold-dark); color: var(--gold-light); }

/* ─── Victory Screen ────────────────────────────────────────── */
#victory-screen {
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at center, rgba(201, 168, 76, 0.15) 0%, transparent 70%);
}

.victory-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px;
  max-width: 500px;
}

.victory-runes {
  font-size: 3rem;
  animation: float 3s ease-in-out infinite;
}
.victory-runes::before { content: '⚔'; }

.victory-title {
  font-size: clamp(2.5rem, 10vw, 5rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow:
    0 0 40px rgba(201, 168, 76, 0.8),
    0 0 80px rgba(201, 168, 76, 0.4);
  animation: victoryGlow 2s ease-in-out infinite alternate;
}

.victory-subtitle {
  font-size: 1.1rem;
  color: var(--text-primary);
  letter-spacing: 0.1em;
}

.victory-divider {
  color: var(--gold-dark);
  letter-spacing: 0.5em;
}

.victory-container .btn { width: 200px; }

/* ─── Animations ────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes turnPulse {
  0%, 100% { box-shadow: 0 2px 20px rgba(201, 168, 76, 0.2); }
  50% { box-shadow: 0 2px 40px rgba(201, 168, 76, 0.5); }
}

@keyframes hitFlare {
  0%   { background: #fff; transform: scale(1.1); }
  30%  { background: var(--hit-light); transform: scale(1.05); }
  100% { background: var(--hit); transform: scale(1); }
}

@keyframes ripple {
  0%   { box-shadow: 0 0 0 0 rgba(74, 111, 165, 0.8); }
  100% { box-shadow: 0 0 0 10px rgba(74, 111, 165, 0); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes victoryGlow {
  from { text-shadow: 0 0 40px rgba(201, 168, 76, 0.6), 0 0 80px rgba(201, 168, 76, 0.3); }
  to   { text-shadow: 0 0 60px rgba(201, 168, 76, 1.0), 0 0 120px rgba(201, 168, 76, 0.6); }
}

@keyframes sunkShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.cell.sunk-anim { animation: sunkShake 0.5s ease-in-out; }

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--deep-water); }
::-webkit-scrollbar-thumb {
  background: var(--grid-line);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --cell-size: 34px; }

  .boards-container {
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 12px;
  }

  .placement-layout {
    flex-direction: column;
    align-items: center;
  }
  .ship-tray {
    width: 100%;
    max-width: 100%;
  }
  .ship-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .ship-item {
    flex: 1;
    min-width: 120px;
  }
  .placement-controls {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  :root { --cell-size: 30px; }

  .lobby-card { padding: 20px; }
  .game-title { font-size: 2rem; }

  .turn-banner { font-size: 0.85rem; padding: 10px; }
}
