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

:root {
  --bg-deep: #f3eefc;
  --bg-panel: #ffffff;
  --bg-panel-2: #ece1fa;
  --ink: #2c1650;
  --ink-dim: #8577a8;
  --accent-red: #ff5c5c;
  --accent-green: #7c3aed;
  --accent-yellow: #a78bfa;
  --accent-blue: #4d9bff;
  --accent-purple: #9d4edd;
  --accent-orange: #ff9d4d;
  --border-dark: #2c1650;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-chunk: 0 6px 0 var(--border-dark), 0 10px 24px rgba(124,58,237,0.18);
  --shadow-chunk-sm: 0 4px 0 var(--border-dark), 0 6px 14px rgba(124,58,237,0.15);
}

* { 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.16; }
.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.12; }

.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: #ffffff; }
.btn-secondary { background: #c4b5fd; color: #2c1650; }
.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: #ffffff;
  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; }

/* ---------- Tic-Tac-Toe specific ---------- */
.ttt-scorebar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 18px;
}
.ttt-score-chip {
  display: flex; align-items: center; gap: 6px; background: var(--bg-panel-2);
  border: 3px solid var(--border-dark); border-radius: var(--radius-sm); padding: 6px 10px;
  font-weight: 800; font-size: 13px;
}
.ttt-symbol {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent-blue);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.ttt-name { color: var(--ink-dim); }
.ttt-pts { color: var(--accent-yellow); }
.ttt-turn-indicator {
  font-weight: 800; font-size: 14px; color: var(--accent-yellow);
  background: var(--bg-panel-2); border: 3px solid var(--border-dark);
  border-radius: 20px; padding: 6px 14px; white-space: nowrap;
}

.ttt-board {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  aspect-ratio: 1/1; margin: 0 auto 16px; max-width: 320px;
}
.ttt-cell {
  background: var(--bg-panel-2); border: 3px solid var(--border-dark);
  border-radius: var(--radius-sm); font-size: 42px; font-weight: 800;
  font-family: "Baloo 2", sans-serif; color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 var(--border-dark);
  transition: transform 0.1s ease;
}
.ttt-cell.x { color: var(--accent-red); }
.ttt-cell.o { color: var(--accent-blue); }
.ttt-cell:not(:disabled):hover { background: #313663; }
.ttt-cell:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--border-dark); }
.ttt-cell:disabled { cursor: not-allowed; }
.ttt-cell.win-cell { background: var(--accent-green); color: #ffffff; animation: popIn 0.3s ease; }
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- 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);
}

/* ---------- 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%; }

/* ---------- 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; }
}
