@font-face {
  font-family: "Cinzel";
  src: url("assets/fonts/Cinzel-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "CinzelBold";
  src: url("assets/fonts/Cinzel-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "CinzelSemiBold";
  src: url("assets/fonts/Cinzel-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
}

@font-face {
  font-family: "CinzelDecorative";
  src: url("assets/fonts/CinzelDecorative-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
}

@font-face {
  font-family: "CrimsonText";
  src: url("assets/fonts/CrimsonText-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "CrimsonTextSemiBold";
  src: url("assets/fonts/CrimsonText-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
}

@font-face {
  font-family: "CrimsonTextItalic";
  src: url("assets/fonts/CrimsonText-Italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
}

@font-face {
  font-family: "ChessMerida";
  src: url("assets/fonts/ChessMeridaUnicode.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "ChessCuernavaca";
  src: url("assets/fonts/ChessCuernavaca.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "ChessJiutepec";
  src: url("assets/fonts/ChessJiutepec.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "ChessTepoztlan";
  src: url("assets/fonts/ChessTepoztlan.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

@font-face {
  font-family: "ChessFairy";
  src: url("assets/fonts/OpenChessFontFairy.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
}

:root {
  --baroque-gold: #d4af37;
  --baroque-cream: #faf6f0;
  --baroque-burgundy: #722f37;
  --baroque-navy: #1b3a57;
  --baroque-sage: #7a8b7f;
  --baroque-pearl: #f8f4e6;
  --baroque-charcoal: #2c2c2c;
  --baroque-copper: #b87333;
  --baroque-rose: #c9a0a7;
  --baroque-gradient: linear-gradient(135deg, #faf6f0 0%, #f8f4e6 100%);
  --baroque-card-gradient: linear-gradient(180deg, #ffffff 0%, #faf6f0 100%);
  --baroque-gold-gradient: linear-gradient(135deg, #d4af37 0%, #f4e4bc 50%, #d4af37 100%);
  --baroque-navy-gradient: linear-gradient(135deg, #1b3a57 0%, #2c5282 100%);
  --baroque-cream-gradient: linear-gradient(180deg, #faf6f0 0%, #f8f4e6 100%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "CrimsonText", Georgia, serif;
  background: var(--baroque-gradient);
  color: var(--baroque-charcoal);
  min-height: 100vh;
}

body.theme-dark {
  background: #0f172a;
  color: #f8f4e6;
}

#app {
  min-height: 100vh;
}

.justaddai-link {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 50;
  font-family: "Open Sans", sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #fdf6e3;
  background: rgba(27, 41, 63, 0.92);
  border: 1px solid rgba(212, 175, 55, 0.8);
  border-radius: 999px;
  padding: 8px 14px;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.justaddai-link:hover {
  transform: translateY(-1px);
  background: rgba(27, 41, 63, 1);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

@media (max-width: 720px) {
  .justaddai-link {
    top: auto;
    right: 12px;
    bottom: 14px;
    font-size: 11px;
    padding: 7px 12px;
  }
}

.page {
  min-height: 100vh;
  display: none;
  padding: 24px 20px 32px;
}

.page.active {
  display: block;
}

.page.hidden {
  display: none;
}

.page-scroll {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-header {
  text-align: center;
  padding: 20px 0 10px;
}

.page-header h1 {
  font-family: "CinzelDecorative", serif;
  color: var(--baroque-burgundy);
  margin: 10px 0 0;
  font-size: 32px;
}

.app-mark {
  font-size: 56px;
  color: var(--baroque-gold);
}

.card {
  background: var(--baroque-card-gradient);
  border: 2px solid var(--baroque-gold);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.card.subtle-card {
  opacity: 0.85;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header-row h2,
.card-header-row h3 {
  margin: 0;
  font-family: "CinzelSemiBold", serif;
  color: var(--baroque-navy);
}

.card-icon {
  font-size: 28px;
}

.card-actions {
  margin-top: 14px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-eyebrow {
  font-family: "CinzelSemiBold", serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--baroque-navy);
  text-transform: uppercase;
}

.card h2 {
  margin: 0;
}

.btn {
  border: none;
  cursor: pointer;
  padding: 12px 20px;
  border-radius: 14px;
  font-family: "CinzelSemiBold", serif;
  font-size: 14px;
  letter-spacing: 0.5px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.btn:active {
  transform: translateY(0);
}

.btn-navy {
  background: var(--baroque-navy-gradient);
  color: #fff;
}

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

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

.btn-gold {
  background: var(--baroque-gold-gradient);
  color: var(--baroque-navy);
}

.btn-circle {
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 12px;
}

.toggle-group {
  display: flex;
  gap: 10px;
}

.piece-toggle {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  font-size: 26px;
  border: 3px solid transparent;
  background: #fff;
  color: var(--baroque-charcoal);
}

.piece-toggle.dark {
  background: var(--baroque-charcoal);
  color: #fff;
}

.piece-toggle.active {
  border-color: var(--baroque-gold);
}

.select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid var(--baroque-gold);
  font-family: "CrimsonText", serif;
  font-size: 14px;
  background: #fff;
}

.small-note {
  font-size: 12px;
  color: var(--baroque-sage);
  margin-top: 8px;
}

.note-pill {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--baroque-sage);
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.subtle {
  color: var(--baroque-sage);
  font-size: 13px;
}

.center-title {
  font-family: "CinzelSemiBold", serif;
  text-align: center;
  color: var(--baroque-navy);
}

.center-subtitle {
  text-align: center;
  font-size: 12px;
  color: var(--baroque-charcoal);
}

.page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.page-topbar h2 {
  margin: 0;
  font-family: "CinzelSemiBold", serif;
  color: var(--baroque-burgundy);
}

.loading-content {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}

.loading-crown {
  font-size: 120px;
  color: var(--baroque-gold);
  opacity: 0;
  transform: scale(0.9);
}

.loading-title h1 {
  font-family: "CinzelDecorative", serif;
  font-size: 32px;
  color: var(--baroque-burgundy);
  margin: 0;
  opacity: 0;
}

.loading-title p {
  font-family: "CrimsonTextItalic", serif;
  color: var(--baroque-sage);
  margin: 8px 0 0;
  opacity: 0;
}

.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(212, 175, 55, 0.2);
  border-top-color: var(--baroque-gold);
  animation: spin 1s linear infinite;
}

.loading-features {
  opacity: 0;
  display: grid;
  gap: 8px;
  font-size: 14px;
}

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

.game-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 30px;
}

.board-frame {
  position: relative;
  width: min(94vw, 78vh, 760px);
  height: min(94vw, 78vh, 760px);
  aspect-ratio: 1;
  border: 3px solid var(--baroque-gold);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  background: var(--baroque-pearl);
}

.puzzle-frame {
  margin: 10px auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  --square-light: #eeeed2;
  --square-dark: #769656;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-family: "ChessMerida", "Cinzel", serif;
  cursor: pointer;
  user-select: none;
  border: none;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

body.reduced-motion .square,
body.animations-off .square {
  transition: none;
}

.square.last-move {
  animation: pulse-gold 1.2s ease-in-out infinite;
}

body.reduced-motion .square.last-move,
body.animations-off .square.last-move {
  animation: none;
}

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

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

.square.last-move {
  box-shadow: inset 0 0 0 3px var(--baroque-gold);
}

.square.selected {
  box-shadow: inset 0 0 0 4px var(--baroque-burgundy);
  background: #ffe4e9;
}

.square.valid {
  box-shadow: inset 0 0 0 3px var(--baroque-gold);
}

.square.capture::after {
  content: "";
  width: 40%;
  height: 40%;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.2);
  position: absolute;
}

.square.keyboard-focus {
  outline: 2px dashed rgba(30, 58, 87, 0.8);
  outline-offset: -4px;
}

@keyframes pulse-gold {
  0% { box-shadow: inset 0 0 0 3px var(--baroque-gold); }
  50% { box-shadow: inset 0 0 0 6px rgba(212, 175, 55, 0.8); }
  100% { box-shadow: inset 0 0 0 3px var(--baroque-gold); }
}

.board-coordinates {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: "CinzelSemiBold", serif;
  color: rgba(30, 41, 59, 0.7);
  font-size: 12px;
}

body.theme-dark .board-coordinates {
  color: rgba(248, 244, 230, 0.7);
}

.coord-file,
.coord-rank {
  position: absolute;
}

.coord-file {
  bottom: 4px;
  transform: translateX(-50%);
}

.coord-rank {
  left: 6px;
  transform: translateY(-50%);
}

.check-indicator {
  padding: 10px 18px;
  border-radius: 18px;
  border: 2px solid #dc2626;
  background: var(--baroque-card-gradient);
  color: #dc2626;
  font-family: "CinzelSemiBold", serif;
  font-size: 14px;
  margin-top: 10px;
}

.ai-progress {
  width: min(90vw, 520px);
  height: 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.ai-progress-bar {
  height: 100%;
  width: 0;
  background: var(--baroque-gold);
  transition: width 0.1s linear;
}

.game-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(94vw, 720px);
  justify-content: space-between;
}

.game-panel {
  width: min(94vw, 720px);
}

.inline-actions {
  display: flex;
  gap: 8px;
}

.move-list {
  display: grid;
  gap: 8px;
  max-height: 200px;
  overflow: auto;
  padding-right: 6px;
  font-family: "CrimsonText", serif;
}

.move-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 12px;
  align-items: center;
}

.move-number {
  font-family: "CinzelSemiBold", serif;
  color: var(--baroque-burgundy);
}

.move-san {
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(212, 175, 55, 0.15);
  border: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.move-san.active {
  background: rgba(114, 47, 55, 0.2);
  box-shadow: inset 0 0 0 2px rgba(114, 47, 55, 0.5);
}

.divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.08);
  margin: 12px 0;
}

.pgn-dialog {
  width: min(92vw, 520px);
}

.pgn-textarea {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 12px;
  font-family: "CrimsonText", serif;
  font-size: 14px;
  min-height: 180px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.9);
}

.opening-trends {
  display: grid;
  gap: 8px;
  font-family: "CrimsonText", serif;
}

.opening-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(212, 175, 55, 0.12);
  border-radius: 12px;
}

.status-pill {
  padding: 12px 24px;
  border-radius: 22px;
  background: var(--baroque-card-gradient);
  border: 2px solid var(--baroque-gold);
  font-family: "CinzelSemiBold", serif;
  color: var(--baroque-navy);
  font-size: 15px;
  flex: 1;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.overlay.hidden {
  display: none;
}

.dialog {
  background: var(--baroque-card-gradient);
  border: 3px solid var(--baroque-gold);
  border-radius: 24px;
  padding: 28px;
  width: min(90vw, 420px);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.dialog h2 {
  font-family: "CinzelBold", serif;
  margin: 10px 0;
  color: var(--baroque-burgundy);
}

.dialog-icon {
  font-size: 64px;
}

.promotion-dialog {
  background: #1e293b;
  color: #f1f5f9;
  border-color: #3b82f6;
}

.promotion-dialog h2 {
  color: #f1f5f9;
}

.promotion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.promotion-btn {
  background: #334155;
  border: 2px solid #3b82f6;
  color: #fbbf24;
  font-size: 54px;
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
}

.reset-dialog .dialog-icon {
  color: var(--baroque-burgundy);
}

.reset-body {
  background: rgba(0, 0, 0, 0.1);
  padding: 16px;
  border-radius: 16px;
  text-align: left;
  display: grid;
  gap: 8px;
  color: var(--baroque-charcoal);
}

.split-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.puzzle-meta {
  text-align: center;
  font-family: "CinzelSemiBold", serif;
}

.rating-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rating-info {
  flex: 1;
}

.tier-icon {
  font-size: 32px;
}

.progress {
  height: 6px;
  background: #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  width: 40%;
  background: var(--baroque-gold);
}

.streak {
  font-size: 16px;
  color: var(--baroque-copper);
}

.medals {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 18px;
}

.board-preview {
  width: 80px;
  height: 80px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0;
  margin: 10px auto;
  border: 2px solid var(--baroque-gold);
}

.preview-square {
  background: #eee;
}

.piece-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 42px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 30px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d1d5db;
  border-radius: 999px;
  transition: 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--baroque-gold);
}

.switch input:checked + .slider::before {
  transform: translateX(24px);
}

.tier-row {
  display: flex;
  gap: 16px;
  align-items: center;
}

.tier-title {
  font-family: "CinzelBold", serif;
  color: var(--baroque-navy);
  font-size: 20px;
}

.triple-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.small-card {
  text-align: center;
}

.stat-number {
  font-family: "CinzelBold", serif;
  font-size: 20px;
  color: var(--baroque-burgundy);
}

.stat-label {
  font-size: 12px;
  color: var(--baroque-charcoal);
}

.stat-icon {
  font-size: 22px;
}

.recent-summary {
  display: flex;
  align-items: center;
  gap: 16px;
}

.recent-icons {
  display: flex;
  gap: 6px;
}

.recent-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: "CinzelBold", serif;
  font-size: 14px;
}

.recent-games {
  display: grid;
  gap: 10px;
}

.recent-game {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--baroque-gold);
  background: #fffef9;
}

.recent-game-icon {
  font-size: 24px;
  text-align: center;
}

.hidden {
  display: none;
}

@media (max-width: 768px) {
  .page {
    padding: 20px 16px 28px;
  }

  .status-pill {
    font-size: 13px;
  }

  .btn-circle {
    width: 52px;
    height: 52px;
  }
}

@media (min-width: 900px) {
  #home-page .page-scroll {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    align-items: start;
  }

  #home-page .page-header {
    grid-column: 1 / -1;
  }

  #home-page .card {
    height: 100%;
  }

  .game-shell {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) minmax(320px, 420px);
    grid-template-rows: repeat(4, auto);
    grid-template-areas:
      "check panel"
      "board panel"
      "progress panel"
      "controls panel";
    align-items: start;
    justify-items: stretch;
    gap: 22px 26px;
    width: min(1200px, 100%);
    margin: 0 auto;
  }

  #check-indicator {
    grid-area: check;
    justify-self: start;
  }

  .game-shell .board-frame {
    grid-area: board;
    width: min(52vw, 78vh, 720px);
    height: min(52vw, 78vh, 720px);
    justify-self: center;
  }

  #ai-progress {
    grid-area: progress;
    justify-self: center;
    width: min(52vw, 520px);
  }

  .game-shell .game-controls {
    grid-area: controls;
    justify-self: center;
    width: min(52vw, 520px);
  }

  .game-shell .game-panel {
    grid-area: panel;
    width: 100%;
    align-self: start;
    position: sticky;
    top: 24px;
  }

  .game-shell .move-list {
    max-height: min(60vh, 520px);
  }
}
