/* ============================================================
   RAVE CHESS — Mobile-first, black & silver design system
   ============================================================ */

.reconn-banner {
  background: rgba(251, 191, 36, 0.16);
  border-bottom: 1px solid rgba(251, 191, 36, 0.4);
  color: var(--amber);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 12px;
  flex-shrink: 0;
}

/* ---------- Mini-Lobby ---------- */
.chess-lobby {
  height: 100%;
  overflow-y: auto;
  display: grid;
  place-items: center;
  padding: 16px;
}

.lobby-card {
  width: min(100%, 460px);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lobby-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lobby-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #252525, #141414);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  font-size: 28px;
  flex-shrink: 0;
}

.lobby-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lobby-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--fg-2);
}

.lobby-seg {
  width: 100%;
  display: flex;
}

.lobby-seg button {
  flex: 1;
  padding: 8px 6px;
  font-size: 13px;
}

.lobby-join {
  gap: 8px;
}

.lobby-join .input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg-3);
  font-size: 12px;
}

.lobby-divider::before,
.lobby-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Game Stage Layout ---------- */
.chess-stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-b));
  gap: 6px;
  overflow: hidden;
  --board-size: min(calc(100vw - 16px), calc(100dvh - 285px));
}

.chess-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: var(--board-size);
}

/* ---------- Player Cards ---------- */
.player-card {
  width: 100%;
  padding: 7px 10px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--border-2);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.player-card.active-turn {
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.07);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.player-meta {
  min-width: 0;
  flex: 1;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
  animation: pulse 1.2s infinite;
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 16px;
  flex-wrap: wrap;
}

.cap-icon {
  width: 15px;
  height: 15px;
  object-fit: contain;
  opacity: 0.9;
}

.mat-adv {
  font-size: 11px;
  font-weight: 800;
  color: var(--silver-200);
  background: rgba(255, 255, 255, 0.08);
  padding: 0 5px;
  border-radius: 6px;
  margin-inline-start: 4px;
  direction: ltr;
}

/* ---------- Clocks ---------- */
.clock {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 17px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--fg-2);
  min-width: 72px;
  text-align: center;
  direction: ltr;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.clock.running {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.clock.clock-low {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.55);
  color: var(--red);
  animation: pulse 0.9s infinite;
}

/* ---------- Chess Board ---------- */
.board-area {
  position: relative;
  display: grid;
  place-items: center;
}

.board-wrap {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.65);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  direction: ltr;
  touch-action: none;
}

/* Themes */
.theme-silver {
  --sq-light: #d6dae0;
  --sq-dark: #5c6472;
  --coord-light: #4a515d;
  --coord-dark: #e2e5ea;
}

.theme-obsidian {
  --sq-light: #9ca3af;
  --sq-dark: #2c3038;
  --coord-light: #2c3038;
  --coord-dark: #b4bac4;
}

.theme-emerald {
  --sq-light: #dce3de;
  --sq-dark: #3b6b58;
  --coord-light: #2f5747;
  --coord-dark: #e8efe9;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
}

.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }

.sq.last-from::before,
.sq.last-to::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(251, 191, 36, 0.28);
  pointer-events: none;
}

.sq.selected::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(96, 165, 250, 0.42);
  pointer-events: none;
}

.sq.in-check::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(239, 68, 68, 0.85) 0%, rgba(239, 68, 68, 0.35) 60%, transparent 80%);
  pointer-events: none;
}

.sq.legal-dot::after {
  content: '';
  position: relative;
  z-index: 3;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(15, 15, 18, 0.34);
  pointer-events: none;
}

.sq.legal-cap::after {
  content: '';
  position: absolute;
  inset: 6%;
  z-index: 3;
  border-radius: 50%;
  border: 4px solid rgba(15, 15, 18, 0.36);
  pointer-events: none;
}

.sq.drag-over {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.75);
}

.coord-file,
.coord-rank {
  position: absolute;
  font-family: ui-monospace, monospace;
  font-size: clamp(9px, 1.5vw, 11px);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  opacity: 0.82;
}

.coord-file {
  bottom: 2px;
  right: 3px;
}

.coord-rank {
  top: 2px;
  left: 3px;
}

.sq.light .coord-file,
.sq.light .coord-rank { color: var(--coord-light); }
.sq.dark .coord-file,
.sq.dark .coord-rank { color: var(--coord-dark); }

.piece-img {
  width: 86%;
  height: 86%;
  object-fit: contain;
  position: relative;
  z-index: 2;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
  will-change: transform;
}

.sq.dragging-origin .piece-img {
  opacity: 0.22;
}

.drag-piece {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 950;
  pointer-events: none;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55));
  will-change: transform;
}

/* ---------- Waiting Overlay ---------- */
.waiting-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(9, 9, 9, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.waiting-box {
  padding: 20px 22px;
  text-align: center;
  max-width: 280px;
}

/* ---------- Mobile Move Ticker & Actions ---------- */
.moves-ticker {
  width: 100%;
  height: 34px;
  border-radius: 10px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  direction: ltr;
  scrollbar-width: none;
}

.moves-ticker::-webkit-scrollbar { display: none; }

.ticker-chip {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--fg-2);
  background: rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
}

.ticker-chip.active {
  background: #fff;
  color: #000;
}

.mobile-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

/* ---------- Side Panel (Desktop) / Sheet (Mobile) ---------- */
.chess-side {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--safe-b));
  z-index: 500;
  max-height: 70dvh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transform: translateY(120%);
  transition: transform 0.28s var(--ease);
}

.chess-side.open {
  transform: translateY(0);
}

.draw-banner {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.moves-nav {
  gap: 6px;
  direction: ltr;
}

.moves-nav button {
  flex: 1;
  min-height: 36px;
}

.moves-list {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  direction: ltr;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.move-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-items: center;
  gap: 4px;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.move-num {
  color: var(--fg-3);
  font-size: 12px;
  text-align: right;
  padding-right: 4px;
}

.move-cell {
  text-align: left;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--fg-2);
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.move-cell:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.move-cell.active {
  background: #fff;
  color: #000;
}

.side-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

/* ---------- Promotion Modal ---------- */
.promo-modal {
  max-width: 320px;
}

.promo-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.promo-btn {
  aspect-ratio: 1;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  padding: 8px;
  transition: transform 0.15s, background 0.15s;
}

.promo-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(1.06);
}

.promo-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- Desktop Layout (>= 860px) ---------- */
@media (min-width: 860px) {
  .chess-stage {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 12px 20px;
    --board-size: min(calc(100vw - 380px), calc(100dvh - 210px), 640px);
  }

  .chess-main {
    width: var(--board-size);
    gap: 8px;
  }

  .moves-ticker,
  .mobile-actions,
  .hide-desktop {
    display: none !important;
  }

  .chess-side {
    position: static;
    transform: none !important;
    width: 320px;
    height: calc(var(--board-size) + 116px);
    max-height: calc(100dvh - 80px);
    flex-shrink: 0;
  }
}
