:root {
  --board-size: min(100vw, 100dvh);
  --piece-scale: 1.06;
  
  /* Modern Theme Color Variables */
  --glow-primary: rgba(180, 107, 255, 0.8);
  --glow-check: rgba(255, 75, 75, 0.85);
  --glow-legal: rgba(255, 255, 255, 0.65);
  --ui-glass-bg: rgba(18, 18, 22, 0.75);
  --ui-glass-border: rgba(255, 255, 255, 0.12);
}

* { 
  box-sizing: border-box; 
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  padding: 0;
  background-color: #08080a;
  background-image:
    radial-gradient(circle at 50% 50%, rgba(25, 25, 35, 0.5), rgba(5, 5, 8, 0.95)),
    url("./assets/BACKGROUND.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  overflow-x: hidden;
}

/* UPGRADE 1: Ambient Floating Aurora Mesh Background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(circle at 20% 20%, rgba(180, 107, 255, 0.12), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(0, 180, 255, 0.10), transparent 45%);
  pointer-events: none;
  z-index: 0;
  animation: ambientAurora 14s ease-in-out infinite alternate;
}

@keyframes ambientAurora {
  0% { transform: scale(1) translate(0, 0); }
  50% { transform: scale(1.08) translate(-1.5%, 1.5%); }
  100% { transform: scale(1) translate(1.5%, -1.5%); }
}

body {
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #ffffff;
}

button, select, textarea { font: inherit; }

/* Keep structural compatibility while ensuring smooth display */
.topbar,
.controls,
.side-column {
  display: none !important;
}

.app-shell,
.game-column {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  display: block;
}

.board-wrap {
  position: relative;
  width: 100%;
  height: 100dvh;
  height: 100svh;
  min-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  perspective: 1200px;
}

.banner {
  position: relative;
  width: 100%;
  height: 0;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
  pointer-events: none;
  background: transparent;
}

.banner img {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  max-width: none;
  max-height: none;
  display: block;
  object-fit: fill;
  object-position: center center;
  margin: 0;
  padding: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Premium Board Framing & Floating Shadow */
.board {
  position: relative;
  flex: 0 0 auto;

  /* One authoritative square. The grid and every piece inherit from this. */
  width: min(100vw, 100dvh);
  height: min(100vw, 100dvh);
  aspect-ratio: 1 / 1;

  max-width: 100vw;
  max-height: 100dvh;

  margin: 0 auto;
  padding: 0;
  border: 0;

  overflow: visible;
  box-sizing: border-box;

  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;

  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.75));
  transition: filter 0.4s ease, transform 0.4s ease;
}

/* UPGRADE 3: Reactive Board Alarm Glow when in Check (Zero JS needed) */
.board:has(.square.check) {
  filter: drop-shadow(0 20px 45px rgba(255, 40, 40, 0.45));
}

.board-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  object-fit: fill; 
  margin: 0;
  padding: 0;
}

.board-grid {
  position: absolute;
  inset: 0%; 
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  align-content: stretch;
  justify-content: stretch;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box;
  overflow: visible;
}

.square {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  background: transparent;
  cursor: pointer;
  overflow: visible;
  vertical-align: top;
  line-height: 0;
  font-size: 0;
  transition: background-color 0.2s ease, transform 0.1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* UPGRADE 4: Tactile App-Style Haptic Press Feedback */
.square:active {
  transform: scale(0.95);
}

/* Modernized Square Highlights & Dynamic Indicators */
.square.selected::after {
  content: "";
  position: absolute;
  inset: 4%;
  border: min(3px, .6vw) solid rgba(255, 255, 255, 0.95);
  border-radius: 12%;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.5), inset 0 0 10px rgba(255, 255, 255, 0.25);
  pointer-events: none;
  animation: pulseSelect 1.8s ease-in-out infinite;
}

.square.legal::before {
  content: "";
  position: absolute;
  width: 24%;
  height: 24%;
  left: 38%;
  top: 38%;
  border-radius: 50%;
  background: var(--glow-legal);
  box-shadow: 0 0 12px var(--glow-legal);
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.square.legal:hover::before {
  transform: scale(1.35);
  background: #ffffff;
  box-shadow: 0 0 16px #ffffff;
}

/* UPGRADE 5: Target Lock Radar Reticle for Captures */
.square.capture::before {
  content: "";
  position: absolute;
  inset: 6%;
  border: min(3px, .6vw) dashed rgba(255, 80, 80, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(255, 60, 60, 0.5);
  pointer-events: none;
  animation: rotateCapture 8s linear infinite;
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 80, 80, 0.25) 0%, transparent 70%);
  animation: pulseTarget 1.2s ease-in-out infinite;
  pointer-events: none;
}

.square.last-move {
  background-color: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 min(3px, .5vw) rgba(255, 255, 255, 0.25);
}

.square.check {
  background-color: rgba(255, 50, 50, 0.18);
  box-shadow: inset 0 0 0 min(4px, .7vw) var(--glow-check), 0 0 20px var(--glow-check);
  animation: pulseCheck 1.1s ease-in-out infinite alternate;
}

/* ============================================================
   PIECE ALIGNMENT SYSTEM
   ============================================================ */
.piece {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: block;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  transform-origin: center bottom;
  transform: scale(var(--piece-scale));
  overflow: visible;
  border: 0;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform, filter, opacity;
}

.square > .piece {
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

.piece.no-transition {
  transition: none !important;
}

.piece.state-moving { animation: pieceMoving 0.40s cubic-bezier(0.22, 1, 0.36, 1) both; }
.piece.state-attacking { animation: pieceAttacking 0.75s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
.piece.state-celebrate { animation: pieceCelebrate 5.00s ease-in-out both; }
.piece.state-defeated { animation: pieceDefeated 1.65s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.piece.state-secret { animation: pieceSecret 1.8s ease-in-out infinite; }

.capture-ghost {
  pointer-events: none;
  z-index: 3;
  opacity: 1;
  inset: auto;
  margin: 0;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
}

@keyframes pulseSelect {
  0%, 100% { opacity: 0.95; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.97); }
}

@keyframes rotateCapture {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulseTarget {
  0%, 100% { transform: scale(0.85); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

@keyframes pulseCheck {
  from { box-shadow: inset 0 0 0 min(3px, .5vw) rgba(255, 50, 50, 0.5), 0 0 10px rgba(255, 50, 50, 0.3); }
  to { box-shadow: inset 0 0 0 min(6px, 1vw) rgba(255, 80, 80, 0.95), 0 0 28px rgba(255, 50, 50, 0.75); }
}

@keyframes pieceMoving {
  0% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
  50% { transform: translate3d(0, -14%, 0) scale(calc(var(--piece-scale) * 1.14)) rotate(-2deg); filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.4)); }
  100% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
}

@keyframes pieceAttacking {
  0% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
  40% { transform: translate3d(0, -20%, 0) scale(calc(var(--piece-scale) * 1.24)) rotate(5deg); filter: drop-shadow(0 20px 26px rgba(255, 80, 80, 0.45)); }
  100% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
}

@keyframes pieceCelebrate {
  0% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
  25% { transform: translate3d(0, -15%, 0) scale(calc(var(--piece-scale) * 1.15)) rotate(-6deg); }
  50% { transform: translate3d(0, -5%, 0) scale(calc(var(--piece-scale) * 1.15)) rotate(6deg); }
  75% { transform: translate3d(0, -10%, 0) scale(calc(var(--piece-scale) * 1.05)) rotate(-3deg); }
  100% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); }
}

@keyframes pieceDefeated {
  0% { opacity: 1; transform: translate3d(0, 0, 0) scale(var(--piece-scale)) rotate(0); filter: brightness(1); }
  35% { opacity: 0.85; transform: translate3d(0, 0, 0) scale(calc(var(--piece-scale) * 1.12)) rotate(-10deg); filter: brightness(1.8) drop-shadow(0 0 18px rgba(255, 50, 50, 0.85)); }
  100% { opacity: 0; transform: translate3d(0, 0, 0) scale(calc(var(--piece-scale) * 0.35)) rotate(45deg); filter: brightness(0.1); }
}

@keyframes pieceSecret {
  0%, 100% { transform: translate3d(0, 0, 0) scale(var(--piece-scale)); filter: brightness(1) drop-shadow(0 4px 8px rgba(0,0,0,0.4)); }
  50% { transform: translate3d(0, 0, 0) scale(calc(var(--piece-scale) * 1.08)); filter: brightness(1.6) drop-shadow(0 0 22px var(--glow-primary)); }
}

/* Glassmorphism Pawn Promotion Modal */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 50;
  animation: fadeIn 0.25s ease-out;
}

.modal.hidden { display: none; }

.modal-card {
  background: var(--ui-glass-bg);
  border: 1px solid var(--ui-glass-border);
  border-radius: 24px;
  padding: 20px;
  min-width: 0;
  box-shadow: 0 28px 56px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.modal-card h2 { display: none; }

.promotion-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.promotion-choice {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 64px;
  min-height: 64px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
  transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@supports (height: 100dvh) {
  .board {
    width: min(100vw, 100dvh);
    height: min(100vw, 100dvh);
  }
}

/* UPGRADE 6: Dynamic Light Sheen Reflection on Hover */
.promotion-choice::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 45%,
    rgba(255, 255, 255, 0.25) 50%,
    transparent 55%
  );
  transform: translateX(-100%);
  transition: transform 0.6s ease;
  pointer-events: none;
}

.promotion-choice:hover::after { transform: translateX(100%); }
.promotion-choice:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45), 0 0 14px rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
}
.promotion-choice:active { 
  transform: translateY(0) scale(0.95); 
  background: rgba(255, 255, 255, 0.28);
}
.promotion-choice img { 
  width: 100%; 
  height: 100%; 
  object-fit: contain; 
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.35));
}

/* Glassmorphism Game Result Modal */
.game-result-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  animation: fadeIn 0.3s ease-out;
}

.game-result-modal.hidden { display: none; }

.game-result-card {
  width: min(88vw, 360px);
  padding: 30px 24px 26px;
  text-align: center;
  color: #ffffff;
  background: var(--ui-glass-bg);
  border: 1px solid var(--ui-glass-border);
  border-radius: 24px;
  box-shadow: 0 28px 56px rgba(0, 0, 0, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  transform: scale(1);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-result-title {
  font-size: clamp(22px, 5.5vw, 29px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #ffffff 0%, #b5b5c3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-result-message {
  margin-top: 10px;
  font-size: clamp(16px, 4vw, 20px);
  line-height: 1.3;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
}

.game-result-hint {
  margin-top: 14px;
  font-size: clamp(12px, 3.2vw, 14px);
  line-height: 1.4;
  color: rgba(255, 255, 255, 0.62);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.88) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Accessibility Support */
@media (prefers-reduced-motion: reduce) {
  .piece.state-moving,
  .piece.state-attacking,
  .piece.state-celebrate,
  .piece.state-defeated,
  .piece.state-secret,
  .square.selected::after,
  .square.capture::before,
  .square.capture::after,
  .square.check,
  .game-result-card,
  .modal,
  body::before {
    animation: none !important;
    transition: none !important;
  }
}


/* ============================================================
   SPEECH BUBBLE SYSTEM
   ============================================================ */
.speech-bubble {
  position: absolute;
  bottom: 85%;
  left: 50%;
  transform: translateX(-50%) translateY(10px) scale(0.8);
  
  /* Glassmorphism Styling */
  background: var(--ui-glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--ui-glass-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  
  /* Typography */
  color: #ffffff;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: clamp(12px, 3vw, 14px);
  font-weight: 600;
  white-space: nowrap;
  
  /* Behavior */
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  animation: bubblePop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  width: 10px;
  height: 10px;
  background: var(--ui-glass-bg);
  border-right: 1px solid var(--ui-glass-border);
  border-bottom: 1px solid var(--ui-glass-border);
  transform: translateX(-50%) rotate(45deg);
  z-index: -1;
}

.speech-bubble.fade-out {
  animation: bubbleFade 0.3s ease-in forwards;
}

@keyframes bubblePop {
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes bubbleFade {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(-5px) scale(0.9);
  }
}
