* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  min-height: 100vh;
  background: linear-gradient(135deg, #101018, #16213e, #0f3460);
  color: #f5f5f5;
  background-attachment: fixed; /* makes the gradient stick */
  background-size: cover;
  background-repeat: no-repeat;
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

header {
  background: linear-gradient(90deg, #02021f,#000000,#000000,#000000,#020820);
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
}
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 99vmin;
  margin: auto;
  padding: 16px 24px;
}
.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2563eb;
}
.nav-links {
  list-style: none;
  display: flex;
  gap: 24px;
}
.nav-links a {
  text-decoration: none;
  color: #a3a3a3;
  font-weight: 500;
  transition: color 0.2s ease;
}
.nav-links a:hover {
  color: #2563eb;
}

#main-container {
  display: flex;
  align-items: flex-start; 
  justify-content: flex-start;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  max-width: 100vw;
  box-sizing: border-box;
  flex: 1;
}

#top-row {
  display: flex;
  flex-direction: row;
  gap: 5px;
  align-items: flex-start;
  background: transparent;
}

#bottom-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  background: transparent;
}

#chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1 / 1; 
  width: 80vmin; 
  height: auto;
  border: none;
  border-radius: 12px;
  box-shadow: 0 12px 20px rgba(0,0,0,0.5);
}

.square {
  aspect-ratio: 1 / 1; 
  width: 100%; 
  height: auto;
  box-sizing: border-box;
  overflow: hidden; 
  position: relative;
}

.light {
  background-color: #dabe92;
}

.dark {
  background-color: #64472f;
}

.dark img:hover,
.light img:hover{
  transform: scale(1.2);
}

.square img {
  position: absolute;
  top: 1%;
  left: 1%;
  width: 98%;
  height: 98%;
  object-fit: contain;
  pointer-events: none; 
  z-index: 3;
}

.square:hover img{
  transform: scale(1.2);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.684));
  transform:translateY(-2px);
}

.square img.move-indicator {
  position: absolute;
  top: 5;
  left: 7;  
}

.square img.move-indicator.move-option{
  transform: scale(0.6);
  opacity: 0.40;
  z-index: 1; 
}

.square:hover img.move-indicator.move-option{
  transform: scale(0.7) translateY(-2px);
  opacity: 0.6;
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.684));
  z-index: 1; 
}

.square img.move-indicator.capture-option{
  transform: scale(0.4) translatey(-2px);
  opacity: 0.8;
  z-index: 4; 
}

.square:hover img.move-indicator.capture-option{
  transform: scale(0.6) translateY(-2px);
  opacity: 0.4;
  z-index: 4; 
}

.square.selected::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: none;
  border: 3px solid #facc15; /* gold */
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.7);
  border: 2px solid #ff0;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 2;
}

.square.move-option::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: none;
  border: 3px solid #22c55e; /* green */
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 2;
}

.square.capture-option::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: none;
  border: 3px solid #ef4444; /* red */
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.7);
  padding: 4px;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 2;
}

.square.last-move::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgb(166, 255, 0);
  opacity: 0.5;
  border: 2px #ffd000;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 1;
}

.square.promotion-option::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(235, 96, 16, 0.3);
  opacity: 0.8;
  border: 4px dashed #FFD700;
  box-sizing: border-box;
  pointer-events: none;
  padding: 4px;
  z-index: 2;
}

.square.promotion-option img {
  opacity: 0.9;
  filter: drop-shadow(0 0 8px rgba(255,215,0,0.8));
  width: 80%;
  height: 80%;
  top: 10%;
  left: 10%;
  transform: scale(1.1);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 4;
}

.square.promotion-option:hover img {
  opacity: 0.8;
  transform: scale(1.15);
}

#fen-box, #pgn-box {
  width: 75vmin;
  margin-top: 10px;
  gap: 4px;
  padding: 8px;
  background: rgba(31, 41, 55, 0.85); /* dark slate */
  color: #f9fafb;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

#fen-box h3, #pgn-box h3 {
  margin: 0 0 8px 0;
}

.fen-input-row {
  display: flex;
  gap: 8px;
}

#fen-box input[type="text"] {
  flex: 1;  
  max-width: 90vw; 
  padding: 6px;
  font-size: 16px;
  box-sizing: border-box;
  border: 1px solid #374151;
  border-radius: 8px;
  background: #111827;
  color: #f9fafb;
}

#fen-box button, #pgn-box button {
  padding: 5px 10px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: white;
  cursor: pointer;
  transition: background 0.2s ease;
}

#fen-box button:hover, #pgn-box button:hover {
  background: #1e40af;
}

.pgn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

/* PGN textarea */
#pgn-field {
  width: 100%;
  min-height: 120px;   /* adjust for how tall you want */
  font-size: 15px;
  padding: 6px;
  resize: vertical;    /* allow resizing by user */
  box-sizing: border-box;
  line-height: 1.4;
  white-space: pre-wrap; /* ensures long lines wrap */
  word-wrap: break-word;
}

#pgn-section {
  display: flex;
  flex-direction: column;
  align-items: center;   /* keeps nav buttons centered under the PGN box */
  margin-left: 5px;
}

#pgn-container {
  margin-left: 5px;
  width: 40vmin;
  max-height: 70vmin;
  height: 70vmin;
  overflow-y: auto;
  border: 1px solid #aaa;
  border-radius: 8px;
  padding: 12px;
  font-family: sans-serif;
  font-size: 14px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  background: #111827;
  color: #f9fafb;
}

#pgn-container h3 {
  margin: 0 0 10px;
  font-size: 30px;
  text-align: center;
  color: #bab9e9;
  padding-bottom: 7px;
  border-bottom: 3px solid #000000;
}

#move-list {
  flex: 1;
  overflow-y: auto; 
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.move-row {
  display: grid;
  grid-template-columns: 1.8em auto auto;
  gap: 12px;
  align-items: center;
  white-space: nowrap;
  font-size: 1.5rem; 
  padding: 4px 0;     
}

.move.highlight {
  background-color: #f7de0273;
  border-radius: 4px;
  padding: 2px 4px;
  transition: background-color 0.2s ease;
}

.move-heading {
  display: grid;
  grid-template-columns: 1.8em auto auto;
  gap: 12px;
  align-items: center;
  white-space: nowrap;
  font-size: 1.7rem; 
  padding: 4px 0;    
  color: #5a7be7; 
  font-weight: bold;
  text-decoration: underline;
}

.move-number {
  font-weight: bold;
  color: #ffffff;
  text-align: right;
  font-size: 1.6rem; 
}

.move {
  color: #ffffff;
  cursor: pointer;
}

.move.highlight {
  background-color: #ffd70073;
  border-radius: 4px;
  padding: 2px 4px;
}

#pgn-nav-buttons {
  margin-left: 20px;    
  margin-top: 8px;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

#pgn-nav-buttons button {
  padding: 6px 14px;
  font-size: 1.2rem;
  background-color: #ddd;
  border: 1px solid #888;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  touch-action: manipulation;
}

#pgn-nav-buttons button:hover {
  background-color: #bbb;
}

.move-row.variant {
  font-size: 1.2rem;
  opacity: 0.8;
  padding-left: 1em;
  margin-left: 1.5em;
  border-left: 2px dotted #aaa;
  color: #9ea8e4 !important;
}

.move-number.variant {
  font-weight: bold;
  color: #9ea8e4;
  text-align: right;
  font-size: 1.5rem; 
}

.variant-separator {
  border-top: 2px solid  #9ea8e4;
  margin: 2px 0;
  opacity: 0.6;
}

/* Background overlay */
.popup {
  display: none; /* Hidden by default */
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

/* Desktop-only adjustments */
@media (min-width: 801px) {
  #main-container {
    margin-left: 20vmin;  /* center children horizontally */
  }
}



@media (max-width: 800px) {
  body {
    padding-top: 0;
    justify-content: flex-start;
  }

  #main-container {
    flex-direction: column;   
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 0;
    box-sizing: border-box;
    margin-left: 0;
  }

  .logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2563eb;
  }
  .nav-links {
    list-style: none;
    display: flex;
    gap: 10px;
  }
  .nav-links a {
    font-size: 1rem;
    text-decoration: none;
    color: #a3a3a3;
    font-weight: 500;
    transition: color 0.2s ease;
  }

  #top-row {
    display: flex;
    flex-direction: column;
    width: 95vw;
    align-items: center;
    gap: 8px;
  }

  #bottom-row {
    display: flex;
    flex-direction: column;
    width: 95vw;
    align-items: center;
  }


  #chessboard {
    margin-top: 10px;
    width: 90vw;
    max-width: 90vw;
    aspect-ratio: 1 / 1;  
    height: auto;  
    flex-shrink: 0;             
  }

  .square {
    aspect-ratio: 1 / 1; 
    width: 100%; 
    height: auto;
    box-sizing: border-box;
    overflow: hidden; 
    position: relative;
  }

  #pgn-section {
    margin-top: 10px;
    margin-left: 0;
    width: 95vw;
  }

  #pgn-container {
    width: 90vw;
    max-height: 115px; 
    overflow-y: auto;
    font-size: 0.8em;
  }

  #pgn-nav-buttons {
    margin-top: 6px;
    width: 90vw;
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    flex-shrink: 0;  /* never shrink */
    margin-top: 4px;
  }

  #move-list {
    flex-direction: row;          
    flex-wrap: nowrap;            
    overflow-x: auto;             
    overflow-y: hidden;           
    gap: 1px;                     
    white-space: nowrap;          
    padding-bottom: 6px;          
  }

  .move-heading {
    display: none;
  }

  .move-row {
    flex: 0 0 auto;               
    display: flex;                
    align-items: center;
    gap: 2px;
    padding: 2px 2px;
  }

  .move,
  .move-number{
    padding: 1px;
    gap: 1px;
    font-size: 0.9rem;
  }
  .move-number.variant{
    padding: 2px 2px 2px;
    gap: 2px;
    font-size: 1.2em !important;
  }
  .move-row.variant {
    padding: 2px 2px 2px;
    gap: 2px;
    font-size: 0.7em !important;
  }

  .variant-separator {
    border-top: 0px solid #bbb;
    margin: 0px 0;
    opacity: 0.6;
    width: 0px;
    display: none;
  }

  #pgn-nav-buttons {
    margin-top: 8px;
    justify-content: space-around;
  }

  #fen-box {
    width: 95vw;
    max-width: 500px;
    margin-top: 16px;
  }

  #pgn-box {     
    width: 95vw;
    max-width: 500px;
    margin-top: 16px;
  }
}

