/* ═══════════════════════════════════════════════════════
   QuickChess — Global Styles
   Maroon (#800000) / White (#FFFFFF) / Dark (#1a1a1a) theme
   ═══════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ───────────────────────────── */
:root {
  --color-primary: #800000;
  --color-primary-dark: #5c0000;
  --color-primary-light: #a33;
  --color-accent: #ffffff;
  --color-bg: #121212;
  --color-bg-card: #1e1e1e;
  --color-bg-card-hover: #2a2a2a;
  --color-bg-elevated: #252525;
  --color-text: #f0f0f0;
  --color-text-muted: #999;
  --color-text-dim: #666;
  --color-success: #4caf50;
  --color-danger: #e53935;
  --color-warning: #ff9800;
  --color-border: #333;
  --color-border-light: #444;

  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(128, 0, 0, 0.3);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* ── Reset & Base ────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Subtle animated background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(128, 0, 0, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(128, 0, 0, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(128, 0, 0, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

a {
  color: var(--color-primary-light);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent);
}

/* ── Branding ────────────────────────────────────────── */
.app-logo {
  height: 80px;
  width: auto;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 10px rgba(128, 0, 0, 0.4));
  transition: transform var(--transition-normal);
}

.app-logo:hover {
  transform: scale(1.05) rotate(2deg);
}

/* ── Selection & Hints ───────────────────────────── */
.square-selected {
  box-shadow: inset 0 0 10px 5px rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.2) !important;
}

.legal-move-hint {
  position: relative;
  cursor: pointer;
}

.legal-move-hint::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  pointer-events: none;
}

.legal-move-hint.has-piece::after {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: 4px solid rgba(0, 0, 0, 0.1);
  background: transparent;
}

.highlight-last-move {
  box-shadow: inset 0 0 5px 3px rgba(255, 255, 0, 0.3);
}

.highlight-check {
  background: radial-gradient(circle, rgba(255, 0, 0, 0.8) 0%, transparent 70%) !important;
  animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.app-logo-small {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 8px;
  padding: 8px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.app-logo-small img {
  height: 32px;
  width: auto;
}

.app-logo-small span {
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 0.9rem;
  color: var(--color-accent);
}

.logo-text-small {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  align-items: flex-start;
}

.logo-text-small .quick {
  font-family: 'Chewy', system-ui;
  color: var(--color-primary);
  font-size: 1.1rem;
}

.logo-text-small .chess {
  font-family: 'Blocksmith', sans-serif;
  color: var(--color-accent);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
}

.credits {
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.credits a {
  color: var(--color-primary-light);
  font-weight: 600;
  border-bottom: 1px solid transparent;
}

.credits a:hover {
  color: var(--color-accent);
  border-bottom-color: var(--color-primary);
}

/* ── Typography ──────────────────────────────────────── */
h1, h2, h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h1 {
  font-size: 2.5rem;
}

h2 {
  font-size: 1.5rem;
}

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: var(--font-main);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-accent);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg-card-hover);
  border-color: var(--color-border-light);
}

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

.btn-success:hover {
  background: #388e3c;
}

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

.btn-danger:hover {
  background: #c62828;
}

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-outline:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-primary);
  color: var(--color-accent);
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1.05rem;
}

.btn-icon {
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
}

/* ── Inputs ──────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(128, 0, 0, 0.2);
}

input[type="text"]::placeholder {
  color: var(--color-text-dim);
  text-transform: none;
  letter-spacing: normal;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

/* ── Pill Buttons (Time Control) ─────────────────────── */
.pill-group {
  display: flex;
  gap: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.pill {
  padding: 10px 18px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex: 1;
  text-align: center;
}

.pill:not(:last-child) {
  border-right: 1px solid var(--color-border);
}

.pill:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text);
}

.pill.active {
  background: var(--color-primary);
  color: var(--color-accent);
}

/* ── Timer ───────────────────────────────────────────── */
.timer {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  padding: 8px 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  min-width: 100px;
  text-align: center;
  transition: all var(--transition-fast);
}

.timer-warning {
  color: var(--color-danger) !important;
  border-color: var(--color-danger) !important;
  animation: timerPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timerPulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}

/* ── Status Messages ─────────────────────────────────── */
.status-message {
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-info {
  color: var(--color-text);
  background: var(--color-bg-elevated);
}

.status-warning {
  color: var(--color-warning);
  background: rgba(255, 152, 0, 0.1);
}

.status-success {
  color: var(--color-success);
  background: rgba(76, 175, 80, 0.1);
}

.status-error {
  color: var(--color-danger);
  background: rgba(229, 57, 53, 0.1);
}

/* ── Captured Pieces ─────────────────────────────────── */
.captured-pieces {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  font-size: 1.2rem;
  padding: 4px 8px;
  flex-wrap: wrap;
}

/* ── Move History ────────────────────────────────────── */
.move-list {
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.move-list::-webkit-scrollbar {
  width: 6px;
}

.move-list::-webkit-scrollbar-track {
  background: transparent;
}

.move-list::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.move-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 2px;
  transition: background var(--transition-fast);
}

.move-row:hover {
  background: var(--color-bg-elevated);
}

.move-num {
  color: var(--color-text-dim);
}

.move-white,
.move-black {
  color: var(--color-text);
}

/* ── Game Over Overlay ───────────────────────────────── */
#game-over-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

#game-over-overlay.visible {
  display: flex;
}

.game-over-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 48px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease-out;
}

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

.game-over-title {
  font-size: 2rem;
  margin-bottom: 8px;
}

.game-over-reason {
  color: var(--color-text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.game-over-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-over-actions .btn {
  width: 100%;
}

/* ── Draw Offer ──────────────────────────────────────── */
#draw-offer-container {
  display: none;
}

#draw-offer-container.visible {
  display: block;
}

.draw-offer-popup {
  background: var(--color-bg-card);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  animation: slideUp 0.2s ease-out;
}

.draw-offer-popup p {
  margin-bottom: 12px;
  font-weight: 600;
}

.draw-offer-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Toast Notifications ─────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--color-bg-card);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: all 0.3s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(0);
}

/* ── Spinner ─────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Promotion Modal ─────────────────────────────────── */
#promotion-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

#promotion-modal.visible {
  display: flex;
}

.promotion-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
}

.promotion-card h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.promotion-pieces {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.promotion-piece {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.promotion-piece:hover {
  border-color: var(--color-primary);
  background: var(--color-primary);
  transform: scale(1.1);
}

/* ── Utility ─────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  h1 {
    font-size: 1.8rem;
  }

  .card {
    padding: 20px;
  }

  .btn-lg {
    padding: 12px 24px;
    font-size: 1rem;
  }

  .timer {
    font-size: 1.3rem;
    padding: 6px 12px;
  }

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

  #toast-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }

  .card {
    padding: 16px;
    border-radius: var(--radius-md);
  }
}
