/* style.css — Premium Chess UI */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;0,700;1,400&family=DM+Sans:wght@400;500;600&display=swap');

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

:root {
  --bg-deep: #0c0a09;
  --bg-warm: #1c1917;
  --bg-surface: #292524;
  --gold: #c9a84c;
  --gold-light: #e8d48b;
  --gold-dim: #8b7635;
  --cream: #f5f0e8;
  --cream-dim: #d4c9b8;
  --text-primary: #e7e5e4;
  --text-muted: #a8a29e;
  --text-dim: #78716c;
  --board-light: #e8d5b5;
  --board-dark: #b08853;
  --board-light-accent: #f0dfc0;
  --board-dark-accent: #9a7544;
  --select-green: #6ab04c;
  --select-green-light: #82cc64;
  --danger: #dc4a4a;
  --danger-dim: #a83232;
  --border-subtle: rgba(201, 168, 76, 0.15);
  --border-gold: rgba(201, 168, 76, 0.35);
  --shadow-piece: drop-shadow(1px 2px 2px rgba(0,0,0,0.5));
  --shadow-piece-hover: drop-shadow(1px 3px 4px rgba(0,0,0,0.7));
  --transition-fast: 120ms ease;
  --transition-med: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

html { height: 100%; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-image:
    radial-gradient(ellipse 120% 80% at 50% 0%, rgba(201,168,76,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 80% 60% at 20% 100%, rgba(139,118,53,0.04) 0%, transparent 50%);
}

/* Subtle noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

/* ── App shell ─────────────────────────────────────────────────── */

.chess-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 540px;
  animation: fadeIn 600ms ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--gold);
  position: relative;
}

h1::after {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 6px auto 0;
}

/* ── Menu ──────────────────────────────────────────────────────── */

.menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 36px;
  width: 100%;
  max-width: 300px;
  animation: slideUp 500ms ease both 200ms;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.menu-divider {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin: 6px 0;
  letter-spacing: 3px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.menu-divider::before,
.menu-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-subtle), transparent);
}

.btn-large {
  width: 100%;
  padding: 16px 28px;
  font-size: 1rem;
  letter-spacing: 1.5px;
}

.btn-online {
  background: #2a4a3a;
  border: 1px solid rgba(106, 176, 76, 0.2);
}

.btn-online:hover {
  background: #1e3a2c;
  border-color: rgba(106, 176, 76, 0.4);
}

/* ── Waiting Screen ───────────────────────────────────────────── */

.waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 36px;
  animation: slideUp 500ms ease both 100ms;
}

.waiting-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.3rem;
  font-style: italic;
  color: var(--cream-dim);
  animation: pulse 2.5s ease-in-out infinite;
}

.waiting-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.room-code {
  font-family: 'DM Sans', sans-serif;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 10px;
  color: var(--gold);
  background: rgba(201, 168, 76, 0.06);
  padding: 14px 32px;
  border-radius: 4px;
  border: 1px solid var(--border-gold);
  user-select: all;
  cursor: pointer;
  transition: var(--transition-med);
}

.room-code:hover {
  background: rgba(201, 168, 76, 0.1);
  border-color: var(--gold);
}

.copy-feedback {
  font-size: 0.8rem;
  color: var(--select-green);
  min-height: 1.2em;
  letter-spacing: 1px;
}

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

/* ── Join Form ────────────────────────────────────────────────── */

.join-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 36px;
  animation: slideUp 500ms ease both 100ms;
}

.join-label {
  font-size: 0.95rem;
  color: var(--cream-dim);
  letter-spacing: 1px;
}

.join-input {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 8px;
  text-align: center;
  text-transform: uppercase;
  width: 220px;
  padding: 12px;
  border: 1px solid var(--border-gold);
  border-radius: 4px;
  background: rgba(201, 168, 76, 0.04);
  color: var(--gold-light);
  outline: none;
  transition: var(--transition-med);
}

.join-input:focus {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.08);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

.join-input::placeholder {
  color: var(--text-dim);
  letter-spacing: 6px;
}

.join-error {
  font-size: 0.85rem;
  color: var(--danger);
  min-height: 1.2em;
}

.join-buttons {
  display: flex;
  gap: 10px;
}

/* ── Room Info (in-game) ──────────────────────────────────────── */

.room-info {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ── Disconnect Banner ────────────────────────────────────────── */

.disconnect-banner {
  background: rgba(220, 74, 74, 0.1);
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 20px;
  border-radius: 4px;
  border: 1px solid rgba(220, 74, 74, 0.25);
  letter-spacing: 0.5px;
}

/* ── Status bar ────────────────────────────────────────────────── */

.status {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  min-height: 1.4em;
  color: var(--cream-dim);
  letter-spacing: 0.5px;
}

.status.game-over {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 1px;
}

.status.in-check-status {
  color: var(--danger);
  font-weight: 600;
}

/* ── Game area ─────────────────────────────────────────────────── */

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

/* ── Captured pieces ───────────────────────────────────────────── */

.captured {
  width: 100%;
  max-width: 500px;
  min-height: 28px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 2px 8px;
}

.captured svg {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.3));
  opacity: 0.7;
}

/* ── Board wrapper (rank labels + board) ───────────────────────── */

.board-wrap {
  display: flex;
  align-items: stretch;
  width: 100%;
  max-width: 500px;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  padding-right: 6px;
  user-select: none;
  width: 18px;
  flex-shrink: 0;
}

.rank-labels span {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.file-labels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  max-width: 500px;
  width: calc(100% - 18px);
  margin-left: 18px;
  user-select: none;
}

.file-labels span {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  text-align: center;
  padding-top: 4px;
}

/* ── Board grid ────────────────────────────────────────────────── */

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  flex: 1;
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(201, 168, 76, 0.3);
  border-radius: 2px;
  overflow: hidden;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.4),
    0 8px 32px rgba(0,0,0,0.3),
    inset 0 0 0 1px rgba(201,168,76,0.08);
}

/* ── Squares ───────────────────────────────────────────────────── */

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  transition: background-color var(--transition-fast);
}

/* Wood-textured light squares */
.cell.light {
  background:
    linear-gradient(135deg,
      rgba(255,255,255,0.06) 0%,
      transparent 50%,
      rgba(0,0,0,0.03) 100%),
    linear-gradient(45deg,
      rgba(200,170,120,0.08) 25%,
      transparent 25%,
      transparent 75%,
      rgba(200,170,120,0.05) 75%),
    var(--board-light);
}

/* Wood-textured dark squares */
.cell.dark {
  background:
    linear-gradient(135deg,
      rgba(255,255,255,0.04) 0%,
      transparent 50%,
      rgba(0,0,0,0.06) 100%),
    linear-gradient(45deg,
      rgba(120,80,30,0.1) 25%,
      transparent 25%,
      transparent 75%,
      rgba(120,80,30,0.06) 75%),
    var(--board-dark);
}

.cell:hover {
  filter: brightness(1.06);
}

/* Piece SVGs inside cells */
.cell svg {
  width: 80%;
  height: 80%;
  filter: var(--shadow-piece);
  transition: filter var(--transition-fast), transform var(--transition-fast);
  pointer-events: none;
}

.cell:hover svg {
  filter: var(--shadow-piece-hover);
  transform: scale(1.04);
}

/* Selection */
.cell.selected {
  background: var(--select-green) !important;
  box-shadow: inset 0 0 12px rgba(106,176,76,0.4);
}

.cell.selected svg {
  transform: scale(1.08);
  filter: var(--shadow-piece-hover);
}

/* Move target dot */
.cell.move-target::after {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
  transition: transform var(--transition-fast);
}

.cell.move-target:hover::after {
  transform: scale(1.3);
  background: rgba(0, 0, 0, 0.35);
}

/* Capture target */
.cell.capture-target {
  background: var(--danger) !important;
  box-shadow: inset 0 0 12px rgba(220,74,74,0.3);
}

.cell.capture-target::after {
  content: '';
  position: absolute;
  inset: 2px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 1px;
  pointer-events: none;
}

/* In-check king highlight */
.cell.in-check {
  background: var(--danger) !important;
  animation: checkPulse 1s ease-in-out infinite;
}

@keyframes checkPulse {
  0%, 100% { box-shadow: inset 0 0 8px rgba(220,74,74,0.4); }
  50% { box-shadow: inset 0 0 20px rgba(220,74,74,0.7); }
}

/* Last-move highlight */
.cell.last-move-from {
  background: rgba(201, 168, 76, 0.35) !important;
}

.cell.last-move-to {
  background: rgba(201, 168, 76, 0.45) !important;
}

/* Piece move animation */
.cell.piece-animating svg {
  animation: piecePlace 200ms ease-out;
}

@keyframes piecePlace {
  from { transform: scale(1.15); }
  to { transform: scale(1); }
}

/* ── Controls ──────────────────────────────────────────────────── */

.controls {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  font-family: 'DM Sans', sans-serif;
  padding: 10px 28px;
  background: var(--bg-surface);
  color: var(--cream-dim);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: var(--transition-med);
}

.btn:hover {
  background: #353130;
  border-color: var(--border-gold);
  color: var(--gold-light);
}

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

.btn-secondary {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-dim);
}

.btn-secondary:hover {
  background: rgba(201, 168, 76, 0.05);
  border-color: var(--border-gold);
  color: var(--cream-dim);
}

.btn-small {
  padding: 8px 18px;
  font-size: 0.8rem;
}

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

.promo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 200ms ease;
}

.promo-modal {
  background: var(--bg-warm);
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.promo-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 2px;
}

.promo-pieces {
  display: flex;
  gap: 8px;
}

.promo-piece {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition-med);
}

.promo-piece:hover {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.1);
  transform: scale(1.08);
}

.promo-piece svg {
  width: 40px;
  height: 40px;
  filter: var(--shadow-piece);
}

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

@media (max-width: 420px) {
  .chess-app { gap: 10px; }
  h1 { font-size: 1.6rem; letter-spacing: 4px; }
  .captured svg { width: 18px; height: 18px; }
  .room-code { font-size: 1.8rem; letter-spacing: 6px; }
  .rank-labels { font-size: 0.55rem; width: 14px; padding-right: 3px; }
  .file-labels span { font-size: 0.55rem; }
  .file-labels { margin-left: 14px; }
}
