@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;700;900&family=DM+Mono:wght@400;500&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --font-display: 'Cinzel', serif;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', monospace;

  --bg-deep: #07080a;
  --bg-surface: #0e1117;
  --bg-surface-elevated: #161a22;
  --bg-card: #1c212c;

  --gold-primary: #d4af37;
  --gold-glow: #e6c86e;
  --gold-dim: #8c7328;
  --gold-surface: rgba(212, 175, 55, 0.08);

  --text-main: #f0ede6;
  --text-muted: #8e95a5;
  --text-dim: #5c6270;

  --border-subtle: #252b38;
  --border-strong: #363e50;

  --sq-light: #ded8cb;
  --sq-light-hover: #ece7dc;
  --sq-dark: #464c58;
  --sq-dark-hover: #535a68;

  --sq-selected: #d4af37;
  --sq-last-move: rgba(212, 175, 55, 0.35);
  --sq-check: rgba(230, 57, 70, 0.65);
  --sq-check-glow: rgba(230, 57, 70, 0.4);

  --danger-color: #e63946;
  --success-color: #2a9d8f;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(circle at 50% 15%, #181d26 0%, #0c0e13 45%, var(--bg-deep) 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* --- APP SHELL --- */
.shell {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px 18px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- HEADER --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 24px;
}

.brand .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--gold-primary);
  display: block;
  margin-bottom: 4px;
}

.brand-title {
  font-family: var(--font-display);
  font-size: clamp(26px, 3.2vw, 38px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  line-height: 1.1;
}

.brand-accent {
  color: var(--gold-primary);
  font-weight: 900;
  text-shadow: 0 0 16px rgba(212, 175, 55, 0.4);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.mode-badge .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success-color);
  box-shadow: 0 0 8px var(--success-color);
  animation: pulse 2s infinite ease-in-out;
}

.mode-badge.online-badge .pulse-dot {
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.status-chip {
  padding: 8px 16px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  text-transform: uppercase;
}

.status-chip.white-turn {
  border-color: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.status-chip.black-turn {
  border-color: var(--gold-dim);
  background: #11141b;
}

.status-chip.check-chip {
  background: rgba(230, 57, 70, 0.15);
  border-color: var(--danger-color);
  color: #ff6b6b;
  animation: checkPulse 1.2s infinite alternate;
}

.status-chip.result-chip {
  background: var(--gold-surface);
  border-color: var(--gold-primary);
  color: var(--gold-glow);
}

@keyframes checkPulse {
  0% { box-shadow: 0 0 6px rgba(230, 57, 70, 0.3); }
  100% { box-shadow: 0 0 16px rgba(230, 57, 70, 0.8); }
}

/* --- STAGE LAYOUT --- */
.stage {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 340px;
  gap: 32px;
  align-items: start;
}

/* --- BOARD COLUMN --- */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 660px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.top-bar {
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.bottom-bar {
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-avatar {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid #777;
}

.white-avatar { background: #f5f1e6; }
.black-avatar { background: #1c1f24; border-color: #555; }

.player-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.captured-tray {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
  min-height: 24px;
}

.captured-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.captured-icon svg {
  width: 100%;
  height: 100%;
}

.material-advantage {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-glow);
  min-width: 24px;
  text-align: right;
}

/* --- BOARD FRAME & CHESS BOARD --- */
.board-frame {
  width: 100%;
  max-width: 660px;
  aspect-ratio: 1;
  padding: 14px;
  background: #14171d;
  border: 2px solid #282f3d;
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.65),
    inset 0 0 0 1px rgba(212, 175, 55, 0.15);
  transition: transform 0.4s ease;
  perspective: 1000px;
}

.board-frame.perspective-3d {
  transform: rotateX(24deg) rotateZ(0deg) scale(0.96);
  transform-style: preserve-3d;
  box-shadow:
    0 40px 80px rgba(0, 0, 0, 0.8),
    0 20px 40px rgba(0, 0, 0, 0.5);
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 1px solid #1c202a;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}

/* SQUARES */
.chess-sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background-color 0.15s, filter 0.15s;
}

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

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

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

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

/* HIGHLIGHTS */
.chess-sq.sq-selected {
  box-shadow: inset 0 0 0 4px var(--gold-primary);
}

.chess-sq.sq-last-move {
  background-color: #8c7328 !important;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.chess-sq.sq-in-check {
  background: radial-gradient(circle, #e63946 25%, #800f2f 90%) !important;
  animation: checkSquarePulse 1s infinite alternate;
}

@keyframes checkSquarePulse {
  0% { box-shadow: inset 0 0 8px 3px rgba(255, 0, 0, 0.7); }
  100% { box-shadow: inset 0 0 16px 6px rgba(255, 0, 0, 0.95); }
}

/* LEGAL MOVE INDICATORS */
.chess-sq.sq-legal-move::after {
  content: '';
  position: absolute;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.45);
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.2);
  pointer-events: none;
  z-index: 5;
}

.chess-sq.sq-legal-capture::after {
  content: '';
  position: absolute;
  inset: 8%;
  border: 4px solid rgba(212, 175, 55, 0.85);
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
  animation: captureRing 1.5s infinite ease-in-out;
}

@keyframes captureRing {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.05); opacity: 1; }
}

/* PIECES */
.piece-wrapper {
  position: relative;
  width: 86%;
  height: 86%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: transform 0.16s ease;
}

.chess-sq:hover .piece-wrapper {
  transform: translateY(-2px);
}

.svg-piece {
  width: 100%;
  height: 100%;
  display: block;
}

/* COORDINATE LABELS */
.coord-label {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

.file-coord {
  bottom: 2px;
  right: 4px;
}

.rank-coord {
  top: 3px;
  left: 4px;
}

.sq-light .coord-label { color: #646a78; }
.sq-dark .coord-label { color: #d0c8b6; }

/* --- SIDEBAR PANEL --- */
.game-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 16px;
  min-height: 580px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 12px;
}

.panel-tab {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold-primary);
}

.text-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  transition: color 0.15s;
}

.text-btn strong {
  color: #38bdf8;
}

.text-btn:hover {
  color: #fff;
}

/* MOVE HISTORY TABLE */
.history-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 240px;
  max-height: 380px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 16px;
}

.history-table-header {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  background: #11141b;
  border-bottom: 1px solid var(--border-subtle);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-main);
}

.history-row {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.history-row:hover {
  background: rgba(212, 175, 55, 0.04);
}

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

.col-white, .col-black {
  font-weight: 500;
  letter-spacing: 0.04em;
}

.col-white { color: #e5e7eb; }
.col-black { color: #cbd5e1; }

/* TOOLBAR BUTTONS */
.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 6px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
  min-height: 48px;
}

.action-btn:hover:not(:disabled) {
  background: #252c3b;
  border-color: var(--border-strong);
  color: #fff;
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-btn.active-btn {
  border-color: var(--gold-primary);
  background: var(--gold-surface);
  color: var(--gold-glow);
}

.action-btn.primary-btn {
  background: var(--gold-surface);
  border-color: var(--gold-dim);
  color: var(--gold-primary);
}

.action-btn.can-claim {
  background: rgba(212, 175, 55, 0.18);
  border-color: var(--gold-primary);
  color: var(--gold-glow);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
  animation: pulse 1.5s infinite;
  cursor: pointer;
}

.action-btn.primary-btn:hover {
  background: rgba(212, 175, 55, 0.16);
  border-color: var(--gold-primary);
  color: #fff;
}

.action-btn.danger-btn {
  color: #f87171;
}

.action-btn.danger-btn:hover {
  background: rgba(230, 57, 70, 0.12);
  border-color: var(--danger-color);
}

.btn-icon {
  font-size: 15px;
  margin-bottom: 2px;
}

/* EXPORT BUTTONS */
.export-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-btn {
  padding: 9px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.export-btn:hover {
  color: #fff;
  border-color: var(--border-strong);
  background: var(--bg-card);
}

/* ERROR BANNER */
.error-banner {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(230, 57, 70, 0.15);
  border: 1px solid var(--danger-color);
  border-radius: 6px;
  color: #fca5a5;
  font-size: 12px;
  line-height: 1.4;
}

/* --- PROMOTION MODAL --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-surface);
  border: 2px solid var(--gold-primary);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9), 0 0 24px rgba(212, 175, 55, 0.2);
  text-align: center;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold-primary);
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.promo-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.promo-piece-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.promo-piece-btn:hover {
  background: var(--gold-surface);
  border-color: var(--gold-primary);
  transform: translateY(-2px);
}

.promo-piece-btn svg {
  width: 44px;
  height: 44px;
  margin-bottom: 6px;
}

.promo-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-cancel-btn {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 16px;
}

.modal-cancel-btn:hover {
  color: #fff;
}

/* --- TOAST NOTIFICATION --- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e2430;
  border: 1px solid var(--gold-dim);
  color: var(--gold-glow);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 6px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
  z-index: 1001;
  animation: slideUp 0.25s ease-out;
}

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

/* --- FOOTER --- */
.app-footer {
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 24px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  border-top: 1px solid var(--border-subtle);
}

.hidden {
  display: none !important;
}

/* --- RESPONSIVE MEDIA QUERIES --- */
@media (max-width: 900px) {
  .shell {
    padding: 16px 14px;
  }

  .stage {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .board-frame {
    max-width: 100%;
    padding: 8px;
  }

  .game-panel {
    min-height: auto;
  }

  .history-container {
    max-height: 200px;
  }

  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
