/* ============================================================
   SHARED BASE — Roblox-inspired: chunky borders, punchy plastic
   colors, bold rounded type, springy motion.
   ============================================================ */

:root {
  --bg-deep: #14162b;
  --bg-panel: #1f2242;
  --bg-panel-2: #262a4f;
  --ink: #ffffff;
  --ink-dim: #a9adcf;
  --accent-red: #ff5c5c;
  --accent-green: #4be38a;
  --accent-yellow: #ffcf4d;
  --accent-blue: #4d9bff;
  --accent-purple: #b57bff;
  --accent-orange: #ff9d4d;
  --border-dark: #0c0d1c;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-chunk: 0 6px 0 var(--border-dark), 0 10px 24px rgba(0,0,0,0.35);
  --shadow-chunk-sm: 0 4px 0 var(--border-dark), 0 6px 14px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; background: var(--bg-deep); color: var(--ink);
  font-family: "Nunito", sans-serif; overflow-x: hidden;
}
h1, h2, h3, .brand, .btn, .round-pill, .timer-pill, .winner-name {
  font-family: "Baloo 2", "Nunito", sans-serif;
}

#bg-blobs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.35; }
.blob-a { width: 420px; height: 420px; background: var(--accent-purple); top: -120px; left: -100px; }
.blob-b { width: 380px; height: 380px; background: var(--accent-blue); bottom: -140px; right: -80px; }
.blob-c { width: 300px; height: 300px; background: var(--accent-green); bottom: 10%; left: 40%; opacity: 0.2; }

.screen {
  position: relative; z-index: 1; display: none; min-height: 100vh;
  padding: 24px 16px; align-items: center; justify-content: center; flex-direction: column;
}
.screen.active { display: flex; animation: screenIn 0.35s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.brand { text-align: center; margin-bottom: 20px; }
.brand-badge { font-size: 40px; display: inline-block; animation: wiggle 2.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(8deg); } }
.brand h1 {
  font-size: 44px; font-weight: 800; margin: 6px 0 0; color: var(--accent-yellow);
  text-shadow: 3px 3px 0 var(--border-dark); letter-spacing: 1px;
}
.tagline { color: var(--ink-dim); font-weight: 700; margin: 4px 0 0; }

.card {
  background: var(--bg-panel); border: 4px solid var(--border-dark);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-chunk); padding: 26px;
}
.panel { width: 100%; max-width: 380px; }
.panel-wide { max-width: 480px; }
.panel-narrow { max-width: 420px; text-align: center; }
.section-heading { font-size: 22px; font-weight: 700; margin: 0 0 14px; color: var(--ink); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-weight: 800; font-size: 13px; color: var(--ink-dim);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
input[type="text"], select {
  width: 100%; padding: 12px 14px; font-size: 16px; font-weight: 700;
  background: var(--bg-panel-2); color: var(--ink);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm);
  font-family: "Nunito", sans-serif; outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--accent-blue); }
input[type="text"]::placeholder { color: #6b7099; }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 10px; cursor: pointer; border: 3px solid var(--border-dark); transition: transform 0.15s ease; }
.swatch:hover { transform: translateY(-2px) scale(1.05); }
.swatch.selected { outline: 3px solid var(--ink); outline-offset: 2px; transform: translateY(-2px) scale(1.08); }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 10px; font-weight: 800; font-size: 14px;
  background: var(--bg-panel-2); color: var(--ink-dim);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm); cursor: pointer;
}
.tab-btn.active { background: var(--accent-blue); color: #fff; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.btn {
  display: inline-block; text-align: center; cursor: pointer;
  font-weight: 800; font-size: 16px; letter-spacing: 0.3px;
  padding: 13px 20px; border-radius: var(--radius-md);
  border: 3px solid var(--border-dark); box-shadow: var(--shadow-chunk-sm);
  transition: transform 0.08s ease, box-shadow 0.08s ease; user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--border-dark); }
.btn-block { display: block; width: 100%; margin-top: 10px; }
.btn-small { padding: 10px 16px; font-size: 14px; margin-top: 0; }
.btn-primary { background: var(--accent-green); color: #06331c; }
.btn-secondary { background: var(--accent-blue); color: #041a3d; }
.btn-ghost { background: var(--bg-panel-2); color: var(--ink-dim); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-text { color: var(--accent-red); font-weight: 700; font-size: 14px; min-height: 18px; margin-top: 10px; text-align: center; }
.hint-text { color: var(--ink-dim); font-weight: 700; font-size: 13px; text-align: center; margin: 10px 0; }

.room-code-header { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; }
.room-code-header > span { font-weight: 800; color: var(--ink-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.chip-code {
  display: flex; align-items: center; gap: 10px; background: var(--accent-yellow); color: #3a2a00;
  border: 3px solid var(--border-dark); border-radius: var(--radius-md); padding: 10px 18px;
  font-size: 26px; font-weight: 800; letter-spacing: 4px; cursor: pointer;
  box-shadow: var(--shadow-chunk-sm); font-family: "Baloo 2", sans-serif;
}
.chip-code:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--border-dark); }
.copy-icon { font-size: 18px; }

.player-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 10px; background: var(--bg-panel-2);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm); padding: 10px 12px; font-weight: 700;
}
.player-avatar { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--border-dark); flex-shrink: 0; }
.player-list .you-tag { margin-left: auto; font-size: 11px; background: var(--accent-purple); color: #fff; padding: 3px 8px; border-radius: 20px; font-weight: 800; }
.player-list .score-tag { margin-left: auto; font-weight: 800; color: var(--accent-yellow); }

.pulse-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-orange); margin: 0 auto 16px; animation: pulseDot 1.1s ease-in-out infinite; }
@keyframes pulseDot { 0%, 100% { transform: scale(0.8); opacity: 0.7; } 50% { transform: scale(1.25); opacity: 1; } }
.hidden { display: none !important; }

.trophy { font-size: 60px; animation: bounceLite 1s ease-in-out infinite; }
@keyframes bounceLite { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.winner-name { font-size: 30px; font-weight: 800; color: var(--accent-yellow); text-shadow: 2px 2px 0 var(--border-dark); margin: 6px 0 18px; }
#confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 16px; opacity: 0.9; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel-2); border: 3px solid var(--border-dark); border-radius: var(--radius-md);
  padding: 10px 18px; font-weight: 700; box-shadow: var(--shadow-chunk-sm); z-index: 50;
}
.toast.hidden { display: none; }

/* ---------- loading screen (progress bar + skeleton) ---------- */
.loading-card { text-align: center; }
.progress-track {
  width: 100%; height: 10px; background: var(--bg-panel-2);
  border: 2px solid var(--border-dark); border-radius: 999px; overflow: hidden; margin-bottom: 16px;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent-green); border-radius: 999px; transition: width 0.3s ease; }
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }
.skeleton-block {
  height: 16px; border-radius: 8px; margin: 10px 0;
  background: linear-gradient(90deg, var(--bg-panel-2) 25%, #ffffff 37%, var(--bg-panel-2) 63%);
  background-size: 400px 100%; animation: shimmer 1.4s ease infinite;
}
.skeleton-chip { height: 34px; width: 60%; margin: 0 auto 16px; border-radius: 20px; }
.skeleton-line.short { width: 70%; }

/* ---------- offline mode divider ---------- */
.offline-divider {
  display: flex; align-items: center; gap: 10px; margin: 18px 0 12px;
  color: var(--ink-dim); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 1px;
}
.offline-divider::before, .offline-divider::after { content: ""; flex: 1; height: 2px; background: var(--bg-panel-2); }

/* ---------- acting-as toggle (local pass & play) ---------- */
.acting-as-toggle { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
.acting-chip {
  padding: 8px 14px; border-radius: 20px; border: 3px solid var(--border-dark);
  background: var(--bg-panel-2); font-weight: 800; font-size: 13px; cursor: pointer;
}
.acting-chip.active { background: #f1e9fe; }
.acting-chip.done { opacity: 0.55; }

/* ---------- placement screen ---------- */
.placement-card { max-width: 460px; text-align: center; }
.ship-tray { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.ship-chip {
  padding: 8px 12px; border-radius: var(--radius-sm); border: 3px solid var(--border-dark);
  background: var(--bg-panel-2); font-weight: 800; font-size: 12px; cursor: pointer;
  font-family: "Nunito", sans-serif; color: var(--ink);
}
.ship-chip.selected { background: var(--accent-purple); color: #fff; }
.ship-chip.placed { background: #eafbf1; border-color: var(--accent-green); opacity: 0.85; }
#btn-rotate { margin: 6px 0 14px; }

/* ---------- battle grids ---------- */
.battle-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px;
  background: var(--bg-panel-2); border: 3px solid var(--border-dark); border-radius: var(--radius-md);
  padding: 6px; max-width: 340px; margin: 0 auto; aspect-ratio: 1/1;
}
.grid-cell {
  background: #eef0f8; border: 1px solid rgba(44,22,80,0.12); border-radius: 3px;
  cursor: pointer; padding: 0; aspect-ratio: 1/1;
}
.grid-cell.ship { background: var(--accent-purple); opacity: 0.55; }
.grid-cell.hit { background: var(--accent-red); opacity: 1; }
.grid-cell.miss { background: #c7ceda; }
.grid-cell.miss::after { content: "•"; }
.grid-cell.sunk { background: #7a1f1f; }
.battle-grid.enemy .grid-cell:not(.hit):not(.miss):hover { background: #dfe4f2; }
.battle-grid.own .grid-cell { cursor: default; }

/* ---------- battle layout ---------- */
.battle-layout { width: 100%; max-width: 760px; margin: 0 auto; }
.turn-banner {
  text-align: center; font-weight: 800; font-size: 15px; padding: 10px; margin-bottom: 14px;
  background: var(--bg-panel-2); border: 3px solid var(--border-dark); border-radius: var(--radius-md);
  color: var(--ink-dim);
}
.turn-banner.your-turn { background: #eafbf1; color: #0d5c33; border-color: var(--accent-green); }
.grids-wrap { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.grid-block { flex: 1; min-width: 260px; max-width: 360px; }
.grid-title { text-align: center; font-size: 14px; margin: 0 0 8px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.5px; }

@media (max-width: 700px) {
  .grids-wrap { flex-direction: column; align-items: center; }
  .grid-block { width: 100%; max-width: 340px; }
}

/* ---------- in-game chat (Roblox-style floating overlay) ---------- */
.chat-toggle-btn {
  position: fixed; bottom: 18px; left: 18px; z-index: 40;
  width: 46px; height: 46px; border-radius: 50%; padding: 0; margin: 0;
  background: rgba(20,20,30,0.75); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.chat-toggle-btn:hover { background: rgba(20,20,30,0.9); }
.chat-toggle-btn:active { transform: scale(0.94); }
.chat-panel {
  position: fixed; bottom: 74px; left: 18px; z-index: 40;
  width: 300px; max-width: calc(100vw - 36px);
  background: rgba(15,15,20,0.72); border: none; border-radius: 10px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.chat-feed {
  max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  padding-right: 2px; scrollbar-width: thin;
}
.chat-msg {
  font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-weight: 400;
  padding: 3px 8px; border-radius: 4px; background: rgba(0,0,0,0.32); color: #f2f2f2;
  line-height: 1.4; word-break: break-word;
}
.chat-msg .c-name { font-weight: 700; margin-right: 3px; }
.chat-msg.own { background: rgba(0,0,0,0.48); }
.chat-form { display: flex; gap: 6px; }
.chat-form input {
  flex: 1; padding: 7px 10px; font-size: 13px; font-weight: 400;
  font-family: Arial, Helvetica, sans-serif;
  background: rgba(255,255,255,0.14); color: #fff; border: none;
  border-radius: 4px; outline: none; min-width: 0;
}
.chat-form input::placeholder { color: rgba(255,255,255,0.55); }
.chat-form .btn {
  padding: 7px 12px; font-size: 12px; font-weight: 700; border-radius: 4px;
  background: rgba(255,255,255,0.18); color: #fff; border: none; cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
}
.chat-form .btn:hover { background: rgba(255,255,255,0.28); }

@media (max-width: 480px) {
  .chat-panel { left: 10px; bottom: 68px; width: calc(100vw - 20px); }
  .chat-toggle-btn { left: 10px; }
}

/* ---------- winner / round-end shared bits ---------- */
.trophy { font-size: 60px; animation: bounceLite 1s ease-in-out infinite; }
@keyframes bounceLite { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.winner-name { font-size: 26px; font-weight: 800; color: var(--accent-yellow); text-shadow: 2px 2px 0 var(--border-dark); margin: 6px 0 18px; }
#confetti-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 1; }
.confetti-piece { position: absolute; top: -20px; width: 10px; height: 16px; opacity: 0.9; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; } }
