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

:root {
  --bg-dark: #1a1114;
  --bg-parchment: #2a1f1a;
  --gold: #c9a84c;
  --gold-bright: #f0d060;
  --silver: #b8c0cc;
  --silver-bright: #dce3ed;
  --square-light: #f0ead6;
  --square-dark: #4a7c59;
  --square-highlight: rgba(201, 168, 76, 0.45);
  --square-selected: rgba(240, 208, 96, 0.6);
  --square-move: rgba(100, 200, 100, 0.4);
  --square-capture: rgba(220, 60, 60, 0.5);
  --text-light: #e8dcc8;
  --text-dim: #9a8b78;
  --danger: #c0392b;
  --font-title: 'MedievalSharp', cursive;
  --font-body: 'Cinzel', serif;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(ellipse 120% 60% at 50% 0%, rgba(201, 168, 76, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 80% 50% at 20% 80%, rgba(160, 90, 20, 0.10) 0%, transparent 50%),
    radial-gradient(ellipse 80% 50% at 80% 80%, rgba(160, 90, 20, 0.10) 0%, transparent 50%),
    radial-gradient(circle at 10% 15%, rgba(255, 180, 40, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 90% 15%, rgba(255, 180, 40, 0.06) 0%, transparent 40%),
    linear-gradient(180deg, #1a1114 0%, #201418 30%, #2a1a14 60%, #1a1114 100%);
  color: var(--text-light);
  font-family: var(--font-body);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 40px,
      rgba(201, 168, 76, 0.015) 40px,
      rgba(201, 168, 76, 0.015) 41px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 40px,
      rgba(201, 168, 76, 0.015) 40px,
      rgba(201, 168, 76, 0.015) 41px
    );
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(180, 120, 30, 0.08) 0%, transparent 100%),
    radial-gradient(circle at 50% 50%, transparent 30%, rgba(0, 0, 0, 0.4) 100%);
  pointer-events: none;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

/* ===== Screens ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ===== Menu Screen ===== */
.menu-container {
  text-align: center;
  position: relative;
  padding: 3em 2em;
}

.menu-container::before {
  content: '⚔ ✦ ⚔';
  display: block;
  font-size: 1.5rem;
  color: var(--gold);
  opacity: 0.35;
  letter-spacing: 12px;
  margin-bottom: 1em;
  text-shadow: 0 0 12px rgba(201, 168, 76, 0.3);
}

.menu-container::after {
  content: '✦ ◆ ✦';
  display: block;
  font-size: 1rem;
  color: var(--gold);
  opacity: 0.25;
  letter-spacing: 10px;
  margin-top: 2em;
  text-shadow: 0 0 10px rgba(201, 168, 76, 0.2);
}

.game-title {
  font-family: var(--font-title);
  font-size: 4.5rem;
  color: var(--gold);
  text-shadow:
    0 0 40px rgba(201, 168, 76, 0.5),
    0 0 80px rgba(201, 168, 76, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 4px;
  margin-bottom: 0.2em;
}

.game-subtitle {
  font-family: var(--font-body);
  font-size: 1.1rem;
  color: var(--text-dim);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-bottom: 3em;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1em;
  align-items: center;
}

.menu-btn {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.8em 2.5em;
  border: 2px solid var(--gold);
  background: linear-gradient(180deg, rgba(201, 168, 76, 0.08) 0%, transparent 100%);
  color: var(--gold);
  cursor: pointer;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: all 0.25s ease;
  min-width: 240px;
}

.menu-btn:hover {
  background: linear-gradient(180deg, var(--gold) 0%, #a88a3a 100%);
  color: var(--bg-dark);
  box-shadow: 0 0 25px rgba(201, 168, 76, 0.4), 0 0 8px rgba(201, 168, 76, 0.2);
}

.menu-btn.secondary {
  border-color: var(--text-dim);
  color: var(--text-dim);
}

.menu-btn.secondary:hover {
  background: var(--text-dim);
  color: var(--bg-dark);
  box-shadow: 0 0 20px rgba(154, 139, 120, 0.3);
}

/* ===== Difficulty Select ===== */
.difficulty-select {
  margin-top: 2em;
  text-align: center;
  animation: fadeSlideIn 0.3s ease-out;
}

.difficulty-select.hidden {
  display: none;
}

.difficulty-label {
  font-family: var(--font-title);
  font-size: 1.2rem;
  color: var(--text-dim);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 1em;
}

.difficulty-buttons {
  display: flex;
  gap: 0.8em;
  justify-content: center;
}

.diff-btn {
  min-width: 120px;
  padding: 0.6em 1.5em;
  font-size: 0.9rem;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Game Screen ===== */
#game-screen.active {
  display: flex;
  flex-direction: column;
}

.game-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6em 1.5em;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.25) 100%);
  border-bottom: 1px solid rgba(201, 168, 76, 0.3);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.back-btn {
  font-family: var(--font-body);
  font-size: 0.8rem;
  background: none;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  padding: 0.4em 1em;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s;
}

.back-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.turn-indicator {
  font-family: var(--font-title);
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 0 0 15px rgba(201, 168, 76, 0.3);
  transition: color 0.3s;
}

.turn-indicator.black-turn {
  color: var(--silver-bright);
  text-shadow: 0 0 15px rgba(184, 192, 204, 0.3);
}

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

/* ===== Game Body ===== */
.game-body {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  gap: 1.5em;
  padding: 1em;
}

/* ===== Captured Pieces Panels ===== */
.captured-panel {
  width: 140px;
  min-height: 200px;
  text-align: center;
}

.captured-panel h3 {
  font-family: var(--font-title);
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.8em;
  letter-spacing: 1px;
}

.captured-pieces {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  font-size: 1.5rem;
}

/* ===== Board ===== */
.board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-frame {
  display: grid;
  grid-template-columns: 24px 1fr 24px;
  grid-template-rows: 1fr 24px;
  gap: 0;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: var(--font-body);
}

.file-labels {
  grid-column: 2;
  display: flex;
  justify-content: space-around;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: var(--font-body);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(70vmin, 560px);
  height: min(70vmin, 560px);
  border: 4px solid var(--gold);
  box-shadow:
    0 0 50px rgba(0, 0, 0, 0.7),
    0 0 20px rgba(201, 168, 76, 0.2),
    inset 0 0 30px rgba(0, 0, 0, 0.15);
  outline: 1px solid rgba(201, 168, 76, 0.15);
  outline-offset: 4px;
}

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

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

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

.square.selected {
  background-color: var(--square-selected) !important;
}

.square.move-target::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--square-move);
}

.square.capture-target {
  background-color: var(--square-capture) !important;
}

.square.in-check {
  box-shadow: inset 0 0 18px 4px rgba(220, 40, 40, 0.7);
}

.square:hover {
  filter: brightness(1.15);
}

/* ===== Pieces ===== */
.piece {
  pointer-events: none;
  transition: transform 0.15s ease;
}

.piece-img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.5));
}

/* ===== Captured Piece Icons ===== */
.captured-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
  opacity: 0.85;
}

/* ===== Animations ===== */
@keyframes pieceAppear {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.piece-appear {
  animation: pieceAppear 0.2s ease-out;
}

@keyframes squarePulse {
  0%, 100% { box-shadow: inset 0 0 8px rgba(201, 168, 76, 0.3); }
  50% { box-shadow: inset 0 0 16px rgba(201, 168, 76, 0.6); }
}

.square.last-move {
  animation: squarePulse 2s ease-in-out 1;
}

/* ===== Game Over Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0.85) 100%);
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: linear-gradient(170deg, #2f2319 0%, var(--bg-parchment) 40%, #241a14 100%);
  border: 2px solid var(--gold);
  padding: 2.5em 3em;
  text-align: center;
  box-shadow:
    0 0 80px rgba(201, 168, 76, 0.15),
    0 0 30px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(201, 168, 76, 0.1);
  max-width: 400px;
  border-radius: 4px;
}

.modal h2 {
  font-family: var(--font-title);
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 0.5em;
}

.modal p {
  color: var(--text-light);
  margin-bottom: 1.5em;
  font-size: 1rem;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  align-items: center;
}

/* ===== Know Modal ===== */
.know-modal {
  max-width: 440px;
}

.know-modal p {
  font-size: 1.05rem;
  line-height: 1.6;
}

/* ===== Tutorial Side Panel ===== */
.tutorial-panel {
  display: none;
  width: 320px;
  flex-shrink: 0;
  align-self: center;
}

.tutorial-panel.active {
  display: block;
  animation: tutFadeIn 0.35s ease-out;
}

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

.game-body.tutorial-active .captured-panel {
  display: none;
}

.tutorial-card {
  background: var(--bg-parchment);
  border: 2px solid var(--gold);
  padding: 1.4em 1.3em 1.2em;
  text-align: center;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.4), 0 0 12px rgba(201, 168, 76, 0.12);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}

.tutorial-piece-preview {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 0.4em;
  min-height: 40px;
  align-items: center;
}

.tutorial-piece-preview img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.5));
}

.tutorial-title {
  font-family: var(--font-title);
  font-size: 1.3rem;
  color: var(--gold);
  margin-bottom: 0.3em;
}

.tutorial-text {
  color: var(--text-light);
  font-size: 0.85rem;
  line-height: 1.55;
  margin-bottom: 1em;
}

.tutorial-speak-btn {
  position: absolute;
  top: 0.8em;
  right: 0.8em;
  background: none;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  font-size: 1rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.tutorial-speak-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 10px rgba(201, 168, 76, 0.2);
}

.tutorial-speak-btn.speaking {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
  animation: speakPulse 1s ease-in-out infinite;
}

@keyframes speakPulse {
  0%, 100% { box-shadow: 0 0 4px rgba(201, 168, 76, 0.2); }
  50% { box-shadow: 0 0 14px rgba(201, 168, 76, 0.5); }
}

.tutorial-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
}

.tutorial-nav-btn {
  min-width: 80px;
  padding: 0.4em 0.8em;
  font-size: 0.78rem;
}

.tutorial-step-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.4;
  transition: all 0.25s;
}

.tutorial-dot.active {
  background: var(--gold);
  opacity: 1;
  transform: scale(1.3);
}

/* ===== Tutorial Board Highlight ===== */
@keyframes tutorialGlow {
  0%, 100% { box-shadow: inset 0 0 10px 2px rgba(201, 168, 76, 0.4); }
  50% { box-shadow: inset 0 0 20px 5px rgba(240, 208, 96, 0.7); }
}

.square.tutorial-highlight {
  animation: tutorialGlow 1.5s ease-in-out infinite;
  z-index: 2;
}

.square.tutorial-move::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(100, 200, 100, 0.55);
  pointer-events: none;
}

.square.tutorial-capture {
  box-shadow: inset 0 0 12px 3px rgba(220, 60, 60, 0.5);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .game-body {
    flex-direction: column;
    gap: 0.5em;
  }

  .captured-panel {
    width: 100%;
    min-height: auto;
    display: flex;
    align-items: center;
    gap: 0.5em;
  }

  .captured-panel h3 {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .board {
    width: min(85vmin, 480px);
    height: min(85vmin, 480px);
  }

  .tutorial-panel {
    width: 100%;
    order: 10;
  }

  .tutorial-card {
    max-width: 480px;
    margin: 0 auto;
  }

  .game-body.tutorial-active {
    overflow-y: auto;
  }
}

@media (max-width: 500px) {
  .game-title {
    font-size: 2.8rem;
  }

  .board {
    width: min(92vmin, 360px);
    height: min(92vmin, 360px);
  }

  .captured-panel {
    width: 100%;
  }

  .tutorial-card {
    padding: 1em 1.2em 1em;
  }

  .tutorial-title {
    font-size: 1.2rem;
  }

  .tutorial-text {
    font-size: 0.85rem;
  }

  .tutorial-nav-btn {
    min-width: 80px;
    font-size: 0.8rem;
  }
}

/* ===== AI Thinking Indicator ===== */
.ai-thinking {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-title);
  font-size: 1rem;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.3s;
}

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

@keyframes thinkingDots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}
