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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #08080d;
  color: #f3f1dd;
  min-height: 100vh;
  overflow-x: hidden;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.card {
  background: #10101a;
  border-radius: 20px;
  padding: 48px 40px;
  text-align: center;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.brand-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: rgba(231, 199, 90, 0.12);
  padding: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.card h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  color: #f7f3d0;
}

.subtitle {
  color: #d9d4aa;
  margin-bottom: 32px;
}

.actions {
  margin-bottom: 8px;
}

.btn {
  display: inline-block;
  padding: 14px 28px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-primary {
  background: #e7c75a;
  color: #0f0b10;
  width: 100%;
}

.btn-primary:hover {
  background: #d4b458;
}

.btn-secondary {
  background: #141424;
  color: #f3f1dd;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: #1f1f34;
}

.divider {
  margin: 24px 0;
  display: flex;
  align-items: center;
  color: #9a8f5a;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(156, 139, 84, 0.25);
}

.divider span {
  padding: 0 16px;
}

#joinForm {
  text-align: left;
}

#joinForm label,
#createForm label {
  display: block;
  margin-bottom: 8px;
  color: #d8cf9c;
  font-size: 0.9rem;
}

.input-full {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #1c1c2a;
  border-radius: 10px;
  background: #0f0f1b;
  color: #f3f1dd;
  font-size: 1rem;
  margin-bottom: 12px;
}

.input-full:focus {
  outline: none;
  border-color: #e7c75a;
}

.input-group {
  display: flex;
  gap: 8px;
}

.input-group input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #1c1c2a;
  border-radius: 10px;
  background: #0f0f1b;
  color: #f3f1dd;
  font-size: 1rem;
  font-family: monospace;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.input-group input:focus {
  outline: none;
  border-color: #e7c75a;
}

/* ── Top Bar ─────────────────────── */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.top-bar > div:last-child {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(231, 199, 90, 0.14);
  padding: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.brand-name {
  font-weight: 700;
  color: #f7f3d0;
  letter-spacing: 0.04em;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.game-info .label {
  color: #888;
}

.game-info .code {
  font-family: monospace;
  font-weight: 700;
  font-size: 1.1rem;
  color: #e7c75a;
  letter-spacing: 2px;
  margin-right: 12px;
}

.badge {
  background: #1c1c30;
  padding: 2px 12px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  color: #f3f1dd;
}

.turn-indicator {
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  background: #0f3460;
}

.turn-counter {
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: #f3f1dd;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.turn-indicator.waiting {
  background: #333;
  color: #aaa;
}

.turn-indicator.voting {
  background: #e7c75a;
  color: #0f0b10;
  animation: pulse 1s infinite;
}

.turn-indicator.game-over {
  background: #2ecc71;
  color: #fff;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ── Theme: premium board colors ──── */

#board {
  display: block;
  width: min(560px, 100%);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45);
  margin: 0 auto;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

#board .board-b72b1,
#board .chessboard-63f37 {
  touch-action: none;
  overscroll-behavior: none;
}

#board .square-55d63,
#board .piece-417db {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

#board .piece-417db {
  cursor: grab;
}

#board .square-55d63 {
  cursor: pointer;
}

#board .board-b72b1 {
  border-radius: 4px;
  border-color: #2c2c3a;
}

/* Override square colors to chess.com premium style */
#board .white-1e1d7 {
  background-color: #ebecd0 !important;
}

#board .black-3c85d {
  background-color: #779556 !important;
}

/* Piece styling for better visibility */
#board .piece-417db {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2));
  cursor: pointer;
}

.side-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-section {
  background: #10101a;
  border-radius: 16px;
  padding: 18px;
}

.panel-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 12px;
}

/* ── Connection Status Dot ──────── */

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-left: 8px;
}

.status-dot.connected {
  background: #2ecc71;
  box-shadow: 0 0 6px #2ecc71;
}

.status-dot.disconnected {
  background: #e94560;
  box-shadow: 0 0 6px #e94560;
}

/* ── Timer Bar ───────────────────── */

.timer-bar {
  margin-top: 12px;
  background: rgba(22, 25, 40, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.timer-bar.hidden {
  display: none;
}

.timer-bar.warning {
  border-color: #ff7a44;
}

.timer-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #f5f5f7;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.timer-label {
  color: #a6a6b8;
}

.timer-text {
  font-weight: 700;
  font-size: 1.15rem;
}

.timer-progress {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #3cbfff, #6a5cff);
  border-radius: 999px;
  transition: width 1s linear, background-color 0.3s ease;
}

.timer-bar.warning .timer-fill {
  background: linear-gradient(90deg, #ff6b6b, #ff9b4a);
}

/* ── Move List ───────────────────── */

.move-list {
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.move-entry {
  padding: 4px 0;
  border-bottom: 1px solid #1a1a2e;
  display: flex;
  gap: 8px;
}

.move-turn {
  color: #666;
  font-family: monospace;
}

.move-player {
  color: #e0e0e0;
}

.move-uci {
  color: #e94560;
  font-family: monospace;
  font-weight: 600;
  margin-left: auto;
}

/* ── Vote Display ────────────────── */

.vote-result {
  font-size: 0.85rem;
}

.vote-summary {
  margin-bottom: 8px;
  color: #ccc;
}

.vote-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vote-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vote-bar-row.winner {
  font-weight: 700;
}

.vote-move {
  width: 40px;
  font-family: monospace;
  text-align: right;
  flex-shrink: 0;
}

.vote-bar-bg {
  flex: 1;
  height: 16px;
  background: #1a1a2e;
  border-radius: 4px;
  overflow: hidden;
}

.vote-bar-fill {
  height: 100%;
  background: #e7c75a;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.vote-bar-row.winner .vote-bar-fill {
  background: #2ecc71;
}

.vote-count {
  width: 60px;
  flex-shrink: 0;
  text-align: right;
  font-family: monospace;
  font-size: 0.8rem;
  color: #aaa;
}

/* ── My Vote ─────────────────────── */

.my-vote {
  font-size: 0.9rem;
}

.vote-confirmed {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-mark {
  color: #2ecc71;
  font-size: 1.2rem;
}

.hidden {
  display: none !important;
}

/* ── Play Again ──────────────────── */

.play-again {
  margin-top: 8px;
}

/* ── Modal ───────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: #10101a;
  border-radius: 20px;
  padding: 32px;
  width: 90%;
  max-width: 430px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(231, 199, 90, 0.2);
}

.modal-card h2 {
  font-size: 1.4rem;
  color: #f7f3d0;
  margin-bottom: 20px;
}

.modal-card label {
  display: block;
  margin-bottom: 8px;
  color: #a0a0b8;
  font-size: 0.9rem;
}

.color-choice {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.color-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 2px solid #1c1c2a;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: #f3f1dd;
  background: #0f0f1b;
}

.color-option:has(input:checked) {
  border-color: #e7c75a;
  background: rgba(231, 199, 90, 0.14);
}

.color-option input {
  display: none;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.modal-actions .btn {
  flex: 1;
}

/* ── Square Highlights ───────────── */

.sq-selected,
.sq-legal,
.sq-voted {
  position: relative !important;
  overflow: visible !important;
}

.sq-selected {
  box-shadow: inset 0 0 0 3px #1a1a2e, inset 0 0 12px 4px #ffd700 !important;
}

.sq-legal {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.6), inset 0 0 8px 2px #2ecc71 !important;
}

.sq-voted {
  box-shadow: inset 0 0 0 3px #1a1a2e, inset 0 0 8px 2px #3498db !important;
}

.sq-selected::after,
.sq-legal::after,
.sq-voted::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 24%;
  height: 24%;
  border-radius: 50%;
  z-index: 2;
  pointer-events: none;
}

.sq-legal::after {
  background: #22c55e;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(34, 197, 84, 0.25), 0 0 8px rgba(34, 197, 84, 0.45);
}

.sq-selected::after {
  background: #fbbf24;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.25), 0 0 8px rgba(251, 191, 36, 0.45);
}

.sq-voted::after {
  background: #3b82f6;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25), 0 0 8px rgba(59, 130, 246, 0.45);
}

/* ── Ad Banner ───────────────────── */

.ad-banner {
  margin-top: 16px;
  text-align: center;
  min-height: 60px;
}

/* ── Layout ──────────────────────── */

.main-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.board-section {
  flex-shrink: 0;
  width: 100%;
  max-width: 480px;
}

/* ── Panel Toggle ────────────────── */

.panel-toggle,
.btn-copy {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s, color 0.2s;
}

.panel-toggle:hover,
.btn-copy:hover {
  background: #16213e;
  color: #fff;
  border-color: #e94560;
}

.side-panel.collapsed {
  display: none;
}

/* ── Responsive ──────────────────── */

@media (max-width: 860px) {
  .container {
    padding: 12px;
  }

  .main-layout {
    gap: 12px;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-bar > div:last-child {
    justify-content: space-between;
  }

  .game-info {
    flex-wrap: wrap;
  }

  .main-layout {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  #board {
    width: min(100%, min(92vw, 560px));
    max-width: 100%;
  }

  .side-panel {
    width: 100%;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 8px;
  }

  .top-bar {
    gap: 8px;
    margin-bottom: 12px;
  }

  .brand-block {
    justify-content: space-between;
    width: 100%;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .game-info {
    font-size: 0.8rem;
    gap: 6px;
    align-items: center;
  }

  .game-info .code {
    margin-right: 0;
    font-size: 0.95rem;
  }

  .top-bar > div:last-child {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .panel-toggle,
  .btn-copy {
    padding: 5px 10px;
    font-size: 0.75rem;
  }

  .turn-indicator {
    width: 100%;
    text-align: center;
    padding: 7px 12px;
    font-size: 0.8rem;
  }

  .panel-section {
    padding: 12px;
  }

  .panel-section h3 {
    margin-bottom: 8px;
    font-size: 0.72rem;
  }

  .move-list {
    max-height: 140px;
  }

  .move-entry {
    flex-wrap: wrap;
    gap: 4px;
  }

  .move-uci {
    margin-left: 0;
    width: 100%;
  }

  .vote-move {
    width: 30px;
    font-size: 0.72rem;
  }

  .vote-count {
    width: 46px;
    font-size: 0.68rem;
  }

  #board {
    width: min(100%, calc(100vw - 12px));
    max-width: calc(100vw - 12px);
  }

  .ad-banner {
    margin-top: 10px;
    min-height: 0;
  }
}
