/* ============================================================================
   Paw & Crown — Cute 2D Multiplayer Chess Stylesheet
   Cozy Kawaii Pastel & Storybook Wood Aesthetic
   ============================================================================ */

:root {
  --bg-cream: #fffbf0;
  --bg-pattern: #fef3c7;
  --card-bg: #ffffff;
  --border-warm: #fde68a;
  --border-cocoa: #d97706;
  --text-dark: #451a03;
  --text-muted: #92400e;
  --sq-light: #fef9e7;
  --sq-dark: #a7d7c5;
  --sq-dark-border: #74b49b;
  --accent-gold: #f59e0b;
  --accent-mint: #10b981;
  --accent-coral: #f43f5e;
  --accent-indigo: #6366f1;
  --shadow-soft: 0 10px 28px rgba(120, 53, 15, 0.08);
  --shadow-tactile: 0 4px 0 #d97706;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-cream);
  background-image: radial-gradient(var(--bg-pattern) 1.5px, transparent 1.5px);
  background-size: 24px 24px;
  color: var(--text-dark);
  font-family: 'Quicksand', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
}

h1, h2, h3, strong, .btn, .status-badge, .role-badge, .turn-pill {
  font-family: 'Fredoka', 'Quicksand', sans-serif;
}

.chess-app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 20px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Top Header ─────────────────────────────────────────────────────────── */

.chess-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--card-bg);
  border: 3px solid var(--border-warm);
  border-radius: 22px;
  padding: 14px 22px;
  box-shadow: var(--shadow-soft);
}

.brand-box {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  font-size: 2.2rem;
  background: #fef3c7;
  border: 2px solid #fde68a;
  border-radius: 16px;
  padding: 6px 10px;
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  color: #78350f;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-badge, .role-badge {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  border: 2px solid transparent;
}

.status-waiting {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}

.status-playing {
  background: #d1fae5;
  color: #065f46;
  border-color: #6ee7b7;
}

.status-checkmate {
  background: #ffe4e6;
  color: #be123c;
  border-color: #fda4af;
}

.status-stalemate, .status-resigned {
  background: #e0e7ff;
  color: #3730a3;
  border-color: #a5b4fc;
}

.role-badge {
  background: #f3e8ff;
  color: #6b21a8;
  border-color: #d8b4fe;
}

/* ── Lobby / Join / Waiting / Spectator / Checkmate Cards ──────────────── */

.lobby-card {
  background: var(--card-bg);
  border: 3px solid var(--border-warm);
  border-radius: 22px;
  padding: 18px 24px;
  box-shadow: var(--shadow-soft);
  transition: all 0.2s ease;
}

.join-card {
  background: linear-gradient(135deg, #fffbeb 0%, #ffffff 100%);
  border-color: #fbbf24;
}

.lobby-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  border: 2px solid #fde68a;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.lobby-title {
  margin: 0 0 4px;
  font-size: 1.25rem;
  color: #78350f;
}

.lobby-desc {
  margin: 0 0 12px;
  font-size: 0.92rem;
  color: #92400e;
  font-weight: 600;
}

.join-form-row, .local-p2-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cute-input {
  flex: 1;
  min-width: 210px;
  max-width: 340px;
  padding: 10px 16px;
  font-size: 0.98rem;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  color: var(--text-dark);
  background: #ffffff;
  border: 2.5px solid #fcd34d;
  border-radius: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cute-input:focus {
  border-color: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
}

.input-sm {
  padding: 8px 14px;
  font-size: 0.9rem;
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: 14px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
}

.btn:active {
  transform: translateY(2px);
}

.btn-join {
  background: #f59e0b;
  color: #ffffff;
  border: 2px solid #d97706;
  box-shadow: 0 3px 0 #b45309;
}

.btn-join:hover {
  background: #d97706;
}

.btn-secondary {
  background: #10b981;
  color: #ffffff;
  border: 2px solid #059669;
  box-shadow: 0 3px 0 #047857;
}

.btn-secondary:hover {
  background: #059669;
}

.btn-outline {
  background: #fffbeb;
  color: #78350f;
  border: 2px solid #fcd34d;
  padding: 8px 14px;
  font-size: 0.86rem;
}

.btn-outline:hover {
  background: #fef3c7;
}

.btn-danger-soft {
  background: #ffe4e6;
  color: #be123c;
  border: 2px solid #fda4af;
  padding: 8px 14px;
  font-size: 0.86rem;
}

.btn-danger-soft:hover {
  background: #fecdd3;
}

.waiting-card {
  background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
  border-color: #6ee7b7;
}

.waiting-Header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.08rem;
  color: #065f46;
  margin-bottom: 6px;
}

.pulse-dot {
  width: 12px;
  height: 12px;
  background: #10b981;
  border-radius: 50%;
  display: inline-block;
  animation: pulseGlow 1.4s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.55; }
}

.spectator-card {
  background: linear-gradient(135deg, #f5f3ff 0%, #ffffff 100%);
  border-color: #c4b5fd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.spectator-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #4c1d95;
}

.spec-icon {
  font-size: 1.8rem;
}

.spec-registered {
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid #ddd6fe;
}

.gameover-card {
  background: linear-gradient(135deg, #fff1f2 0%, #fffbeb 100%);
  border-color: #fb7185;
  text-align: center;
  padding: 22px;
}

.trophy-icon {
  font-size: 2.6rem;
  margin-bottom: 6px;
}

.gameover-title {
  margin: 0 0 6px;
  font-size: 1.6rem;
  color: #be123c;
}

.gameover-reason {
  margin: 0 0 16px;
  font-size: 1.02rem;
  font-weight: 700;
  color: #881337;
}

.gameover-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Feedback / Impossible Move / Check Toast Banner ────────────────────── */

.feedback-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 0.95rem;
  border: 2.5px solid transparent;
  animation: popIn 0.18s ease-out;
}

@keyframes popIn {
  from { transform: translateY(-4px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.fb-error {
  background: #ffe4e6;
  color: #be123c;
  border-color: #fb7185;
}

.fb-warn {
  background: #fef3c7;
  color: #b45309;
  border-color: #fbbf24;
}

.fb-info {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #7dd3fc;
}

.fb-check {
  background: #ffe4e6;
  color: #be123c;
  border-color: #f43f5e;
  box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.15);
}

.fb-close {
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 800;
  font-size: 1rem;
  color: inherit;
  opacity: 0.7;
}

.fb-close:hover {
  opacity: 1;
}

/* ── Main 2-Column Workspace ────────────────────────────────────────────── */

.chess-workspace {
  display: grid;
  grid-template-columns: minmax(340px, 560px) 1fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 880px) {
  .chess-workspace {
    grid-template-columns: 1fr;
  }
}

.board-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Player Bars (Top & Bottom of Board) ────────────────────────────────── */

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 3px solid var(--border-warm);
  border-radius: 18px;
  padding: 10px 16px;
  box-shadow: var(--shadow-soft);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-bar.active-turn {
  border-color: #10b981;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.14);
}

.player-bar.in-check-bar {
  border-color: #f43f5e;
  background: #fff1f2;
  box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.2);
}

.player-bar.winner-bar {
  border-color: #f59e0b;
  background: #fffbeb;
}

.player-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fde68a;
  background: #fef3c7;
}

.avatar-b {
  background: #ede9fe;
  border-color: #c4b5fd;
}

.avatar-svg {
  width: 36px;
  height: 36px;
}

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

.player-name {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-dark);
}

.color-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.pill-w {
  background: #fef3c7;
  color: #92400e;
  border: 1.5px solid #fcd34d;
}

.pill-b {
  background: #3b3054;
  color: #fef3c7;
  border: 1.5px solid #1e1b2e;
}

.you-badge {
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
}

.captured-pieces {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 3px;
}

.mini-captured-piece {
  width: 22px;
  height: 22px;
}

.mini-piece-svg {
  width: 22px;
  height: 22px;
}

.no-captures {
  font-size: 0.76rem;
  color: #a16207;
  opacity: 0.7;
}

.turn-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.thinking-pill {
  background: #d1fae5;
  color: #065f46;
  border: 1.5px solid #34d399;
}

.check-pill {
  background: #f43f5e;
  color: #ffffff;
  animation: pulseGlow 1s infinite;
}

.winner-pill {
  background: #fbbf24;
  color: #78350f;
}

.waiting-pill, .idle-pill {
  background: #f5f5f4;
  color: #78716c;
}

/* ── Cute 2D Chessboard Frame & Squares ─────────────────────────────────── */

.board-frame {
  background: #d97706;
  background: linear-gradient(145deg, #f59e0b, #b45309);
  padding: 14px;
  border-radius: 26px;
  box-shadow: 0 14px 32px rgba(120, 53, 15, 0.22), inset 0 2px 4px rgba(255, 255, 255, 0.35);
  border: 4px solid #92400e;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 3px solid #78350f;
  background: var(--sq-light);
}

.chess-sq {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.14s ease, transform 0.1s ease;
}

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

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

.chess-sq:hover {
  filter: brightness(1.04);
}

/* Last move subtle golden highlight */
.sq-last-move.sq-light {
  background-color: #fde68a;
}

.sq-last-move.sq-dark {
  background-color: #86efac;
}

/* Selected piece square */
.sq-selected {
  background-color: #fcd34d !important;
  box-shadow: inset 0 0 0 3.5px #d97706;
}

/* Checked or Checkmated King square */
.sq-king-check {
  background: radial-gradient(circle, #fda4af 15%, #f43f5e 90%) !important;
  box-shadow: inset 0 0 0 3px #be123c;
}

/* Impossible move clicked square flash */
.sq-invalid {
  background-color: #fecdd3 !important;
  box-shadow: inset 0 0 0 3.5px #e11d48;
  animation: invalidShake 0.32s ease-in-out;
}

@keyframes invalidShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Coordinate Labels */
.coord-rank {
  position: absolute;
  top: 4px;
  left: 5px;
  font-size: 0.68rem;
  font-weight: 800;
  font-family: 'Fredoka', sans-serif;
  opacity: 0.72;
  pointer-events: none;
}

.coord-file {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 0.68rem;
  font-weight: 800;
  font-family: 'Fredoka', sans-serif;
  opacity: 0.72;
  pointer-events: none;
}

.sq-light .coord-rank, .sq-light .coord-file {
  color: #52947c;
}

.sq-dark .coord-rank, .sq-dark .coord-file {
  color: #315e4d;
}

/* Piece SVG Holder */
.piece-holder {
  width: 86%;
  height: 86%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sq-selected .piece-holder {
  transform: translateY(-4px) scale(1.07);
}

.piece-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ── Possible Move Highlights (Empty Dot & Capture Target Ring) ─────────── */

.legal-move-dot {
  position: absolute;
  width: 32%;
  height: 32%;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.85);
  border: 2.5px solid #ffffff;
  box-shadow: 0 2px 6px rgba(6, 95, 70, 0.35);
  z-index: 3;
  pointer-events: none;
  animation: dotPop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.castle-dot {
  width: 44%;
  height: 44%;
  background: rgba(99, 102, 241, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}

.castle-tag {
  font-size: 0.72rem;
}

.legal-capture-ring {
  position: absolute;
  inset: 4px;
  border-radius: 12px;
  border: 3.5px dashed #f43f5e;
  background: rgba(244, 63, 94, 0.14);
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 2px;
}

.capture-badge {
  font-size: 0.72rem;
  background: #f43f5e;
  color: #ffffff;
  border-radius: 999px;
  padding: 1px 4px;
  line-height: 1;
}

@keyframes dotPop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ── Right Sidebar (Move Helper, Promotion, History, Spectators) ────────── */

.chess-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-card {
  background: var(--card-bg);
  border: 3px solid var(--border-warm);
  border-radius: 20px;
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
}

.side-card-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #78350f;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.selected-piece-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fffbeb;
  border: 2px solid #fde68a;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.sel-preview {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.sel-piece-svg {
  width: 44px;
  height: 44px;
}

.sel-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sel-moves-count {
  font-size: 0.82rem;
  font-weight: 700;
  color: #059669;
}

.sel-empty-hint {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 14px;
  padding: 12px;
  font-size: 0.86rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 12px;
}

.promo-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.promo-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

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

.promo-btn {
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 10px;
  border: 2px solid #fde68a;
  background: #fffbeb;
  color: #78350f;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
}

.promo-btn.active {
  background: #f59e0b;
  color: #ffffff;
  border-color: #d97706;
}

/* Move History List */
.move-count-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 0.76rem;
  padding: 2px 9px;
  border-radius: 999px;
}

.history-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 4px;
}

.history-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  align-items: center;
  padding: 5px 10px;
  border-radius: 10px;
  background: #fffbeb;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
}

.turn-num {
  color: #b45309;
  font-weight: 600;
}

.ply-move {
  font-weight: 600;
  color: #451a03;
}

.ply-check {
  color: #d97706;
  font-weight: 700;
}

.ply-mate {
  color: #e11d48;
  font-weight: 800;
}

.empty-history, .empty-specs {
  font-size: 0.85rem;
  color: #92400e;
  opacity: 0.8;
  padding: 6px 0;
}

.spec-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.spec-pill {
  background: #f3e8ff;
  color: #6b21a8;
  border: 1.5px solid #d8b4fe;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed #fde68a;
}
