/* ============================================================
   Xadrez Aguiar - Estilos Globais
   ============================================================ */
:root {
  --bg:        #1a1a2e;
  --bg2:       #16213e;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --success:   #16a34a;
  --gold:      #d97706;
  --light-sq:  #f0d9b5;
  --dark-sq:   #b58863;
  --select:    rgba(20,155,50,.65);
  --legal:     rgba(20,155,50,.45);
  --check-sq:  rgba(220,30,30,.7);
  --hint-from: rgba(255,215,0,.6);
  --hint-to:   rgba(255,215,0,.35);
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --border:    rgba(255,255,255,.1);
  --card-bg:   rgba(255,255,255,.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: 6px; border: none;
  font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }

.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-outline  { background: transparent; color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { background: var(--card-bg); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* ============================================================
   Auth Pages (Login / Register)
   ============================================================ */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 20% 50%, rgba(37,99,235,.15) 0%, transparent 60%),
    radial-gradient(circle at 80% 50%, rgba(217,119,6,.1) 0%, transparent 60%);
}

.auth-container {
  width: 100%; max-width: 400px;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  margin: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-king { font-size: 56px; line-height: 1; margin-bottom: 10px; }

.auth-logo h1 {
  font-size: 24px; font-weight: 700;
  color: var(--text);
  letter-spacing: .5px;
}
.logo-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-group input {
  padding: 10px 14px; border-radius: 6px;
  border: 1.5px solid var(--border);
  background: rgba(255,255,255,.06);
  color: var(--text); font-size: 15px;
  outline: none; transition: border-color .15s;
}
.form-group input:focus { border-color: var(--primary); }

.auth-link { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-muted); }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: 12px 16px; border-radius: 6px;
  font-size: 14px; margin-bottom: 16px;
}
.alert-error   { background: rgba(220,38,38,.15); border: 1px solid rgba(220,38,38,.4); color: #fca5a5; }
.alert-success { background: rgba(22,163,74,.15);  border: 1px solid rgba(22,163,74,.4);  color: #86efac; }

/* ============================================================
   Site Header
   ============================================================ */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg2);
  border-bottom: 1.5px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; }
.header-center { font-size: 16px; font-weight: 700; color: var(--text); }
.header-logo { font-size: 22px; }
.header-title { font-size: 18px; font-weight: 700; }
.header-user  { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   Lobby
   ============================================================ */
.lobby-page { background: var(--bg); min-height: 100vh; }
.lobby-main { display: flex; justify-content: center; padding: 32px 16px; }

.lobby-card {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  width: 100%; max-width: 560px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}

.lobby-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.lobby-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

.lobby-status-bar {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  padding: 8px 0; border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

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

.player-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s;
}
.player-row:hover { border-color: rgba(255,255,255,.2); }

.player-info { display: flex; align-items: center; gap: 10px; }

.player-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
  flex-shrink: 0;
}

.player-name { font-weight: 600; font-size: 15px; }

.badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px;
}
.badge-online  { background: rgba(22,163,74,.2);  color: #4ade80; }
.badge-playing { background: rgba(217,119,6,.2);  color: #fbbf24; }

.no-players, .loading-msg {
  text-align: center; padding: 32px 0;
  color: var(--text-muted); font-size: 14px; line-height: 1.8;
}

/* Online/offline dots */
.dot-online, .dot-offline {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0;
}
.dot-online  { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
.dot-offline { background: #f87171; }

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%; max-width: 380px;
  margin: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.modal-box h3 { font-size: 18px; margin-bottom: 10px; }
.modal-box p  { color: var(--text-muted); margin-bottom: 18px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.invite-time-select p { color: var(--text); margin-bottom: 12px; font-size: 14px; }
.time-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(30,41,59,.95);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 24px;
  font-size: 14px; color: var(--text);
  z-index: 500;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { opacity:0; transform: translateX(-50%) translateY(10px); } }

/* ============================================================
   Spinner
   ============================================================ */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Game Page
   ============================================================ */
.game-page { min-height: 100vh; }
.game-main { padding: 16px; display: flex; justify-content: center; }

#game-container {
  display: flex; gap: 20px;
  align-items: flex-start; flex-wrap: wrap;
  justify-content: center;
}

#board-col {
  display: flex; flex-direction: column;
  gap: 8px; align-items: stretch;
}

/* Clock bars */
.clock-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-radius: 8px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  transition: border-color .3s, background .3s;
}
.clock-bar.active {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.35);
  box-shadow: 0 0 12px rgba(255,255,255,.1);
}
.clock-bar.low {
  border-color: var(--danger) !important;
  background: rgba(220,38,38,.12) !important;
  animation: pulse-clock .8s ease-in-out infinite;
}
@keyframes pulse-clock {
  0%,100% { box-shadow: 0 0 6px rgba(220,38,38,.4); }
  50%      { box-shadow: 0 0 20px rgba(220,38,38,.9); }
}
.clock-who { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.clock-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); flex-shrink: 0; }
.clock-dot.w { background: #f5f0e8; }
.clock-dot.b { background: #1a1a2e; border-color: rgba(220,38,38,.7); }
.clock-time {
  font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--text); letter-spacing: 1px; min-width: 5ch; text-align: right;
}
.clock-bar.low .clock-time { color: #f87171; }

/* Captured pieces bar */
.caps-bar {
  display: flex; flex-wrap: wrap; gap: 2px;
  min-height: 28px; padding: 2px 0;
}
.cap-piece { font-size: 22px; line-height: 1; opacity: .7; }

/* Board */
#board-wrapper { position: relative; }
#board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows:    repeat(8, var(--sq));
  --sq: 68px;
  border: 5px solid #8b6914;
  border-radius: 3px;
  box-shadow: 0 0 40px rgba(0,0,0,.5);
  user-select: none;
}

.sq {
  width: var(--sq); height: var(--sq);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
  transition: filter .08s;
}
.sq:hover  { filter: brightness(1.12); }
.sq.light  { background: var(--light-sq); }
.sq.dark   { background: var(--dark-sq); }
.sq.sel    { background: var(--select) !important; }
.sq.chk    { background: var(--check-sq) !important; }

.sq.lm::after {
  content: ''; position: absolute;
  width: 30%; height: 30%; border-radius: 50%;
  background: var(--legal); pointer-events: none;
}
.sq.lc::after {
  content: ''; position: absolute; inset: 0;
  border: 5px solid var(--legal);
  pointer-events: none; border-radius: 2px;
}
.sq.hint-from { background: var(--hint-from) !important; }
.sq.hint-to   { background: var(--hint-to)   !important; }

/* Coordinate labels */
.lbl-rank { position: absolute; top: 2px; left: 3px; font-size: 10px; font-weight: 700; opacity: .6; pointer-events: none; }
.lbl-file { position: absolute; bottom: 2px; right: 3px; font-size: 10px; font-weight: 700; opacity: .6; pointer-events: none; }
.sq.light .lbl-rank, .sq.light .lbl-file { color: var(--dark-sq); }
.sq.dark  .lbl-rank, .sq.dark  .lbl-file { color: var(--light-sq); }

/* Chess piece rendering */
.piece {
  width: calc(var(--sq) - 6px);
  height: calc(var(--sq) - 6px);
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--sq) - 12px);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.4));
  transition: transform .1s;
}
.sq:hover .piece { transform: scale(1.08); }

/* Game over overlay */
#game-over-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.78); border-radius: 2px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; z-index: 10;
}
#game-over-overlay.hidden { display: none; }
#go-txt {
  font-size: 22px; font-weight: 700; color: #fff;
  text-align: center; line-height: 1.7;
  text-shadow: 2px 2px 4px #000;
}

/* Side panel */
#side { width: 220px; display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 8px; padding: 14px;
}
.card-title {
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  color: var(--text-muted); text-transform: uppercase; margin-bottom: 10px;
}

#turn-row { display: flex; align-items: center; gap: 8px; }
#turn-dot  { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); flex-shrink: 0; }
#turn-dot.w { background: #f5f0e8; }
#turn-dot.b { background: #1a1a2e; border-color: rgba(220,38,38,.7); }
#status-txt { font-size: 13px; font-weight: 600; line-height: 1.5; }

#hist { max-height: 200px; overflow-y: auto; font-size: 13px; line-height: 1.9; }
#hist::-webkit-scrollbar { width: 3px; }
#hist::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }
.move-pair { display: flex; gap: 6px; }
.move-num  { color: var(--text-muted); min-width: 24px; }
.move-san  { color: var(--text); }

#conn-status { font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--text-muted); }

/* Promotion */
.promo-pieces {
  display: flex; gap: 12px; justify-content: center; padding: 8px 0;
}
.promo-opt {
  width: 68px; height: 68px;
  background: var(--card-bg); border: 2px solid var(--border);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 48px; line-height: 1;
  transition: all .15s;
}
.promo-opt:hover { background: rgba(37,99,235,.3); border-color: var(--primary); transform: scale(1.08); }

/* Responsive */
@media (max-width: 700px) {
  #board { --sq: 44px; }
  .clock-time { font-size: 18px; }
  .piece { font-size: calc(var(--sq) - 8px); }
}
@media (max-width: 460px) {
  #board { --sq: 36px; border-width: 3px; }
  #side { width: 100%; max-width: 320px; }
  .clock-time { font-size: 16px; }
}
