@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&family=Outfit:wght@400;700;900&display=swap');

:root {
  --bg-color: #0f172a;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  --glass-bg: rgba(30, 41, 59, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --light-cell: #e2e8f0;
  --dark-cell: #334155;
  --ok: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: 'Outfit', sans-serif; }
h1 { margin: 0 0 4px; font-size: clamp(28px, 4vw, 42px); font-weight: 900; background: -webkit-linear-gradient(#fff, #cbd5e1); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
h2 { margin: 0 0 12px; font-size: 20px; font-weight: 700; }
p { margin: 0; color: var(--text-muted); line-height: 1.5; }

/* Glassmorphism utility */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 24px;
}

/* LOBBY */
.lobby-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lobby-card {
  padding: 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}

.lobby-card p {
  margin-bottom: 30px;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.input-group input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.2);
  color: #fff;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  transition: border-color 0.3s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.divider {
  color: var(--text-muted);
  font-size: 14px;
  position: relative;
  margin: 10px 0;
}
.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: rgba(255,255,255,0.1);
}
.divider::before { left: 0; }
.divider::after { right: 0; }

.btn-primary, .btn-secondary {
  border: none;
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-2px);
}

.lobby-message {
  margin-top: 20px;
  font-weight: 600;
  color: var(--warning);
  min-height: 24px;
}

/* APP LAYOUT */
.app { width: min(1300px, 96vw); margin: 0 auto; padding: 24px 0; animation: fadeIn 0.5s ease-out; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 24px 30px;
  margin-bottom: 20px;
}

.controls { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.controls label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
select {
  min-width: 200px;
  background: rgba(0,0,0,0.3);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  outline: none;
}
select:focus { border-color: var(--accent); }
select option { background: #1e293b; color: #fff; }
.controls button { width: auto; padding: 12px 20px; font-size: 14px; }

.connection-status {
  padding: 14px 24px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 600;
  border-radius: 12px;
  display: none; /* toggled via JS */
}
.connection-status.warning { color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3); background: rgba(245, 158, 11, 0.1); }
.connection-status.ok { color: var(--ok); border: 1px solid rgba(16, 185, 129, 0.3); background: rgba(16, 185, 129, 0.1); }
.connection-status.danger { color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.1); }

.game-layout {
  display: grid;
  grid-template-columns: 300px minmax(360px, 1fr) 280px;
  gap: 24px;
  align-items: start;
}

.panel { padding: 24px; }

.status {
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
  line-height: 1.5;
  font-size: 15px;
}
.scoreboard { display: grid; gap: 10px; margin-bottom: 24px; color: var(--text-muted); font-size: 15px; }
.dot { display: inline-block; width: 16px; height: 16px; border-radius: 50%; vertical-align: -3px; margin-right: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.white-dot { background: #f8fafc; border: 2px solid #cbd5e1; }
.black-dot { background: #111827; border: 2px solid #334155; }
.ok-dot { background: var(--ok); border: 2px solid #059669; }
.error-dot { background: var(--danger); border: 2px solid #b91c1c; }

.network-status { display: inline-block; font-size: 14px; font-weight: 600; padding: 6px 12px; background: rgba(0,0,0,0.2); border-radius: 20px; margin-bottom: 15px; }
.network-status-small { display: inline-block; font-weight: 600; }

.rules ul { padding-left: 20px; margin: 0; color: var(--text-muted); line-height: 1.6; font-size: 14px; }
.small { font-size: 13px; line-height: 1.6; margin-top: 10px; }

/* BOARD */
.board-wrap {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  border-radius: 28px;
  padding: 20px;
  box-shadow: inset 0 0 0 1px var(--glass-border), 0 30px 60px rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
}

.disabled-board {
  pointer-events: none;
  opacity: 0.6;
  filter: grayscale(0.5);
}

.board {
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1 / 1;
  display: grid;
  border: 12px solid #1e293b;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  background: #1e293b;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  user-select: none;
  transition: background 0.3s;
}
.cell.light { background: var(--light-cell); }
.cell.dark { background: var(--dark-cell); }
.cell.playable { cursor: pointer; }
.cell.playable:hover { filter: brightness(1.15); }
.cell.selected { 
  box-shadow: inset 0 0 0 4px var(--accent);
  background: #475569 !important;
}

.cell.hint::after {
  content: "";
  position: absolute;
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 15px var(--ok);
  opacity: 0.8;
  animation: pulse 1.5s infinite;
}
.cell.capture-hint::after { 
  content: "";
  position: absolute;
  width: 25%;
  height: 25%;
  border-radius: 50%;
  background: var(--danger); 
  box-shadow: 0 0 15px var(--danger);
  opacity: 0.8;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.6; }
  50% { transform: scale(1.1); opacity: 0.9; }
  100% { transform: scale(0.95); opacity: 0.6; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* PIECES */
.piece {
  width: 80%;
  height: 80%;
  border-radius: 50%;
  position: relative;
  display: grid;
  place-items: center;
  font-size: clamp(16px, 3vw, 28px);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}
.piece.white { 
  background: radial-gradient(circle at 30% 30%, #ffffff, #cbd5e1);
  box-shadow: -2px -2px 6px rgba(255,255,255,0.8), 4px 4px 10px rgba(0,0,0,0.3), inset -4px -4px 8px rgba(0,0,0,0.1);
  color: #1e293b; 
}
.piece.black { 
  background: radial-gradient(circle at 30% 30%, #475569, #0f172a);
  box-shadow: -2px -2px 6px rgba(255,255,255,0.1), 4px 4px 10px rgba(0,0,0,0.6), inset -4px -4px 8px rgba(0,0,0,0.5);
  color: #f8fafc; 
}
.piece:hover { transform: scale(1.08); z-index: 3; }
.piece.king::before { 
  content: "♛"; 
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

.coord {
  position: absolute;
  left: 6px;
  top: 4px;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.4;
  font-family: 'Inter', sans-serif;
  pointer-events: none;
}
.cell.dark .coord { color: #f8fafc; }
.cell.light .coord { color: #0f172a; }

.move-log { margin: 0; padding-left: 20px; color: var(--text-muted); max-height: 600px; overflow-y: auto; font-family: monospace; font-size: 14px; line-height: 1.8; }
.move-log li { margin-bottom: 6px; }

/* Custom Scrollbar for Move Log */
.move-log::-webkit-scrollbar { width: 6px; }
.move-log::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 4px; }
.move-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }
.move-log::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

.winner { color: var(--ok); font-weight: 900; font-size: 18px; display: block; margin-bottom: 5px; }
.warning-text { color: var(--warning); font-weight: 800; }

/* CHAT E INFO BAR */
.players-bar { display: flex; font-size: 16px; margin-top: 15px; }
.player-info { display: flex; align-items: center; gap: 10px; }
.score-badge { background: rgba(255,255,255,0.1); padding: 4px 10px; border-radius: 12px; font-size: 13px; font-weight: 600; }
.timer-badge { background: rgba(0,0,0,0.3); padding: 4px 10px; border-radius: 12px; font-size: 14px; font-weight: bold; font-family: monospace; color: var(--warning); }

.chat-box { display: flex; flex-direction: column; height: 250px; background: rgba(0,0,0,0.15); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.chat-msg { padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,0.05); width: fit-content; max-width: 90%; word-break: break-word; }
.chat-msg.me { background: rgba(59, 130, 246, 0.2); align-self: flex-end; }
.chat-msg.system { background: none; color: var(--text-muted); font-size: 12px; align-self: center; text-align: center; font-style: italic; }
.chat-input-row { display: flex; border-top: 1px solid rgba(255,255,255,0.05); }
.chat-input-row input { flex: 1; border: none; background: rgba(0,0,0,0.2); color: white; padding: 10px; font-size: 14px; outline: none; }
.chat-input-row button { background: var(--accent); color: white; border: none; padding: 0 15px; cursor: pointer; font-weight: bold; transition: 0.2s; }
.chat-input-row button:hover { background: var(--accent-hover); }

/* MODAL FIM DE JOGO E ACTIONS */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease-out;
}

.modal-card {
  padding: 40px;
  width: 90%;
  max-width: 400px;
  text-align: center;
}

.modal-card h2 {
  font-size: 28px;
  margin-bottom: 15px;
}

.modal-card p {
  font-size: 16px;
  margin-bottom: 30px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-actions button {
  width: 100%;
}

@media (max-width: 1024px) {
  .game-layout { grid-template-columns: 250px 1fr; }
  .move-log-panel { grid-column: span 2; }
}

@media (max-width: 768px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .game-layout { grid-template-columns: 1fr; }
  .move-log-panel { grid-column: 1; }
  .board-wrap { padding: 10px; }
  .board { border-width: 6px; }
}
