/* Royal Gambit — Chess UI Styles */

:root {
  --bg-deep: #0f0e17;
  --bg-card: rgba(22, 21, 35, 0.85);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --accent-gold: #e8c547;
  --accent-gold-dim: #b8942e;
  --accent-emerald: #3ecf8e;
  --accent-ruby: #e85d75;
  --text-primary: #f0eef8;
  --text-muted: #8b8798;
  --square-light: #e8dcc8;
  --square-dark: #7a9e6a;
  --square-light-highlight: #f5ecd8;
  --square-dark-highlight: #8fb87a;
  --shadow-board: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --radius: 14px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

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

html { font-size: 16px; }

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

.bg-pattern {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(232, 197, 71, 0.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(62, 207, 142, 0.06) 0%, transparent 55%),
    repeating-conic-gradient(rgba(255,255,255,0.015) 0% 25%, transparent 0% 50%) 0 0 / 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header-links {
  display: flex;
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header-link {
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
}

.header-link:hover {
  color: var(--accent-gold);
  border-color: rgba(232, 197, 71, 0.35);
  background: rgba(232, 197, 71, 0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2.5rem;
  filter: drop-shadow(0 0 12px rgba(232, 197, 71, 0.5));
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-gold), #fff8dc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.mode-switcher {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: 999px;
  padding: 4px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-btn:hover { color: var(--text-primary); }

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent-gold-dim), var(--accent-gold));
  color: #1a1508;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(232, 197, 71, 0.35);
}

.mode-icon { font-size: 1rem; }

/* Layout */
.game-layout {
  display: grid;
  grid-template-columns: 240px 1fr 240px;
  gap: 1.25rem;
  flex: 1;
  align-items: start;
}

.panel { display: flex; flex-direction: column; gap: 1rem; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  backdrop-filter: blur(12px);
}

.card h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.hidden { display: none !important; }

/* Status */
.status-message {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 0.6rem;
  transition: color 0.3s;
}

.status-message.check { color: var(--accent-ruby); }
.status-message.game-over {
  color: var(--accent-gold);
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.turn-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.turn-badge {
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.turn-badge.w { background: rgba(255,255,255,0.15); color: #fff; }
.turn-badge.b { background: rgba(0,0,0,0.4); color: #ccc; border: 1px solid rgba(255,255,255,0.1); }

.ai-thinking {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  min-height: 1.35rem;
  font-size: 0.8rem;
  color: var(--accent-gold);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ai-thinking.visible {
  opacity: 1;
  visibility: visible;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-gold);
  animation: bounce 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Form controls */
.select-label, .range-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.select-label:last-child, .range-label:last-child { margin-bottom: 0; }

select, input[type="range"] {
  font-family: var(--font-body);
}

select {
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--bg-card-border);
  background: rgba(0,0,0,0.3);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-gold);
}

/* Evaluation bar */
.eval-track {
  height: 8px;
  background: linear-gradient(to right, #333 50%, #eee 50%);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.eval-bar {
  height: 100%;
  width: 50%;
  background: linear-gradient(to right, #555, #ddd);
  border-radius: 999px;
  transition: width 0.5s ease;
  position: relative;
}

.eval-score {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

/* Board area */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.board-wrapper {
  position: relative;
  width: min(72vw, 72vh, 560px);
  aspect-ratio: 1;
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow-board);
  position: relative;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

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

.square.selected {
  background: var(--accent-gold) !important;
  box-shadow: inset 0 0 0 3px rgba(0,0,0,0.2);
}

.square.last-move {
  background: rgba(232, 197, 71, 0.45) !important;
}

.square.check {
  background: radial-gradient(circle, rgba(232, 93, 117, 0.7) 30%, transparent 70%) !important;
  animation: pulse-check 1.5s ease-in-out infinite;
}

@keyframes pulse-check {
  0%, 100% { box-shadow: inset 0 0 20px rgba(232, 93, 117, 0.3); }
  50% { box-shadow: inset 0 0 30px rgba(232, 93, 117, 0.6); }
}

.square.legal::after {
  content: '';
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

.square.capture::after {
  content: '';
  width: 85%;
  height: 85%;
  border-radius: 50%;
  border: 4px solid rgba(200, 50, 50, 0.55);
  background: transparent;
  pointer-events: none;
}

.square .coord {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 0.55rem;
  font-weight: 600;
  opacity: 0.45;
  pointer-events: none;
}

.square .coord-file {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.55rem;
  font-weight: 600;
  opacity: 0.45;
  pointer-events: none;
}

.piece {
  font-size: clamp(2rem, 7vw, 3.5rem);
  line-height: 1;
  z-index: 2;
  transition: transform 0.12s ease, opacity 0.12s;
  cursor: grab;
  filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.35));
}

.piece.white-piece {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8), 0 0 1px #000;
}

.piece.black-piece {
  color: #1a1a1a;
  text-shadow: 0 0 2px rgba(255,255,255,0.3);
}

.square:hover .piece { transform: scale(1.06); }

.piece.ghost {
  position: absolute;
  z-index: 100;
  pointer-events: none;
  transition: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.non-interactive .square { cursor: default; }
.non-interactive .square:hover .piece { transform: none; }

/* Promotion overlay */
.promotion-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  z-index: 200;
}

.promotion-overlay.hidden {
  display: none !important;
}

.promotion-picker {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-card);
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--bg-card-border);
}

.promotion-btn {
  font-size: 2.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  cursor: pointer;
  transition: all 0.2s;
}

.promotion-btn:hover {
  border-color: var(--accent-gold);
  background: rgba(232, 197, 71, 0.15);
  transform: scale(1.1);
}

/* Captured pieces */
.captured-bar {
  width: min(72vw, 72vh, 560px);
  min-height: 1.5rem;
  padding: 0 0.25rem;
}

.captured-pieces {
  font-size: 1.1rem;
  opacity: 0.7;
  letter-spacing: 2px;
}

.captured-top { text-align: left; }
.captured-bottom { text-align: left; }

/* Board controls */
.board-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ctrl-btn {
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.ctrl-btn:hover {
  border-color: rgba(232, 197, 71, 0.4);
  background: rgba(232, 197, 71, 0.08);
}

.ctrl-btn.primary {
  background: linear-gradient(135deg, var(--accent-gold-dim), var(--accent-gold));
  color: #1a1508;
  border-color: transparent;
  font-weight: 600;
}

.ctrl-btn.primary:hover {
  box-shadow: 0 4px 16px rgba(232, 197, 71, 0.35);
  transform: translateY(-1px);
}

.ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.sound-btn {
  min-width: 2.75rem;
  font-size: 1rem;
  padding: 0.5rem 0.65rem;
}

.sound-btn.muted {
  opacity: 0.55;
}

/* Sound settings */
.sound-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  margin-bottom: 0.75rem;
  user-select: none;
}

.sound-toggle-label input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.sound-toggle-ui {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--bg-card-border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.sound-toggle-ui::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.2s, background 0.2s;
}

.sound-toggle-label input:checked + .sound-toggle-ui {
  background: rgba(232, 197, 71, 0.25);
  border-color: rgba(232, 197, 71, 0.45);
}

.sound-toggle-label input:checked + .sound-toggle-ui::after {
  transform: translateX(18px);
  background: var(--accent-gold);
}

/* Move history */
.move-history-card { flex: 1; min-height: 200px; display: flex; flex-direction: column; }

.move-list {
  flex: 1;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.move-list::-webkit-scrollbar { width: 4px; }
.move-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.move-row {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr;
  gap: 0.25rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.move-num { color: var(--text-muted); }
.move-san { cursor: default; }
.move-san.white { color: #ddd; }
.move-san.black { color: var(--text-muted); }

/* Rules */
.rules-list {
  list-style: none;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.rules-list li {
  padding-left: 1rem;
  position: relative;
  margin-bottom: 0.3rem;
}

.rules-list li::before {
  content: '♟';
  position: absolute;
  left: 0;
  font-size: 0.6rem;
  color: var(--accent-gold);
  opacity: 0.7;
}

.inline-help-link {
  color: var(--accent-gold);
  text-decoration: none;
  font-size: 0.78rem;
}

.inline-help-link:hover {
  text-decoration: underline;
}

/* Footer */
.footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-link {
  color: var(--accent-gold);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-link:hover {
  color: #fff8dc;
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 1100px) {
  .game-layout {
    grid-template-columns: 1fr;
    max-width: 560px;
    margin: 0 auto;
  }

  .panel-left, .panel-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .move-history-card { grid-column: 1 / -1; }
  .rules-card { display: none; }
}

@media (max-width: 520px) {
  .panel-left, .panel-right { grid-template-columns: 1fr; }
  .header { flex-direction: column; align-items: flex-start; }
  .mode-switcher { width: 100%; }
  .mode-btn { flex: 1; justify-content: center; font-size: 0.78rem; padding: 0.5rem; }
}
