/* ###########################################################################
################# styles.css for chessJS - © jh-concepts.at ##################
########################################################################### */
/* ================= GLOBAL RESETS & VARS ================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #1e1e1e; 
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 15px;
  background-color: #252526;
  border-bottom: 1px solid #333333;
  display: flex;
  justify-content: center;
  align-items: center;
}

header h1 {
  color: #00bcd4;
  font-size: 1.5rem;
  text-align: center;
}

footer {
  text-align: center;
  padding: 15px;
  margin-top: auto;
  font-size: 0.8rem;
  background-color: #252526;
  border-top: 1px solid #333333;
  color: #888888;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ================= MAIN CONTAINER (RESPONSIVE GRID) ================= */
.game-container {
  display: grid;
  grid-template-columns: 1fr; /* Mobil: Alles sauber untereinander */
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 15px;
}

/* Landscape / Desktop Monitors (Right column for controls and info */
@media (min-width: 850px) and (orientation: landscape) {
  .game-container {
    grid-template-columns: 1.2fr 1fr; /* left side: board, right side: sidebar  */
    grid-template-rows: auto auto auto 1fr;
    align-items: start;
  }

  .board-wrapper {
    grid-column: 1;
    grid-row: 1 / 5; /* Board uses the full height */
  }

  .top-bar, 
  .game-info, 
  .captured-pieces, 
  .move-history {
    grid-column: 2; /* Info-Boxes to the right side */
  }
}

/* ================= DARK BOX-DESIGNS (COMMON STYLES) ================= */
.top-bar, 
.game-info, 
.captured-pieces, 
.move-history {
  background-color: #252526;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #333333;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 600px;
  margin: auto;
}

/* ================= TOPBAR & CONTROLS ================= */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons and Dropdowns */
.controls select, 
.controls button {
  padding: 8px 14px;
  font-size: 1.1rem;
  border: 1px solid #444444;
  border-radius: 6px;
  background-color: #333333;
  color: #ffffff !important;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.controls select:focus, 
.controls button:hover {
    background-color: #444444;
    border-color: #555555;
}

#fs-off-btn {
  display: none;
}

#restart-btn {
  padding: 8px 14px;
  font-size: 1.3rem;
  border: 1px solid #444444;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

#new-game-btn, 
#restart-btn {
    background-color: #00bcd4 !important;
    color: #fff !important;
}

#new-game-btn:hover, 
#restart-btn:hover {
    background-color: #0097a7 !important;
}

/* ================= GAME INFO & STATUS ================= */
.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  font-size: 1.05rem;
  width: 100%;
  max-width: 600px;
  margin: auto;
}

/* State coloea from the JS-Logic */
.player-mode {
  color: #4caf50; 
}

.ai-mode {
  color: #f44336; 
}

.hidden {
  display: none !important;
}

/* ================= CHESSBOARD AND PIECES ================= */
.board-wrapper {
  width: 100%;
  max-width: 600px; 
  margin: 0 auto;
}

#chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1; 
  border: 6px solid #111111;
  border-radius: 4px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  transition: transform 0.5s ease;
}

/* Board-Rotation with the Flip-Button */
#chessboard.flipped {
  transform: rotate(180deg);
}

#chessboard.flipped .piece {
  transform: rotate(180deg); /* prevents the pieces from being upside down */
}

/* Fields of chess board */
.square {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(1.8rem, 7vw, 3.4rem); /* scale of the chess pieces (they are text) */
  user-select: none;
  cursor: pointer;
  transition: background-color 0.5s ease, box-shadow 0.5s ease; 
}

/* Board colors */
.light-square {
  background-color: #f0d9b5; 
  color: #222222; 
}

.dark-square {
  background-color: #b58863;
  color: #ffffff; 
}

/* Colors of pieces controlled by JS */
.white-piece {
  color: #ffffff !important;
  text-shadow: 0 0 4px rgba(0,0,0,0.6);
  filter: drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.6)) drop-shadow(0px 0px 1px rgba(0,0,0,0.8));
}

.black-piece {
  color: #000000 !important;
  text-shadow: 0 0 4px rgba(255,255,255,0.2);
  filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.9)) drop-shadow(0px 0px 1px rgba(255,255,255,0.4));
}

/* Selection- and Check-States */
.selected {
  outline: 4px solid #3a86ff !important;
  outline-offset: -4px;
}

/* Warning-red if king is in check */
.check-king {
  background-color: #cc3333 !important; 
}

.piece {
  transition: transform 0.35s ease-out;
}

/* ================= AI LAST MOVE HIGHLIGHT ================= */
/* manual with ?-button, automatical after every AI move */
.ai-last-move-highlight,
.square.last-move-from,
.square.last-move-to {
  outline: 4px solid #4caf50 !important;
  outline-offset: -4px;
  transition: outline 0.2s ease;
}

/* Marking of legal/possible mobes for human */
.selected-target {
  box-shadow: inset 0 0 0 2px #00f !important;
  cursor: pointer;
}

/* ================= CAPTURED PIECES ================= */
.captured-pieces h2, 
.move-history h2 {
  font-size: 1.1rem;
  margin-bottom: 10px;
  color: #aaaaaa;
  border-bottom: 1px solid #333333;
  padding-bottom: 5px;
}

#white-captured, 
#black-captured {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 35px;
  font-size: 1.6rem;
}

#white-captured {
  background-color: #222;
  border-radius: 5px;
  margin-bottom: 5px;
}

#black-captured {
  color: #000;
  background-color: #444;
  border-radius: 5px;
  font-size: 1.8rem; /* The black pieces otherwise appear smaller than the white ones. */
}

.captured-item {
  display: inline-block;
  line-height: 1;
}

/* ================= MOVE HISTORY ================= */
#move-list {
  max-height: 160px;
  overflow-y: auto;
  padding-right: 5px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95rem;
}

/* Scrollbar-Styling */
#move-list::-webkit-scrollbar {
  width: 6px;
}
#move-list::-webkit-scrollbar-track {
  background: #1e1e1e;
}
#move-list::-webkit-scrollbar-thumb {
  background: #444444;
  border-radius: 3px;
}

.move-row {
  display: grid;
  grid-template-columns: 0.6fr 1fr 1fr;
  padding: 5px 0;
  border-bottom: 1px solid #2d2d30;
}

.move-number {
  color: #666666;
}

.move-text {
  color: #e0e0e0;
}

/* ================= OVERLAYS - MODAL (GAME OVER) ================= */
#game-over-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.overlay-content {
  background: #252526;
  border: 1px solid #444444;
  padding: 30px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

#game-message {
  font-size: 1.4rem;
  font-weight: bold;
  margin-bottom: 20px;
  color: #ffffff;
}

/* Modal at pawn promotion */
#promotion-modal {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex; justify-content: center; align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

#promotion-modal.hidden {
  display: none;
}

.promotion-content {
  background-color: #2b2b2b;
  color: white;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.promotion-choices {
  display: flex; gap: 10px; margin-top: 15px;
}

.promotion-choices button {
  background-color: #444;
  color: white;
  border: none; padding: 10px 15px;
  font-size: 1.5rem; border-radius: 4px;
  cursor: pointer; transition: background 0.2s;
}

.promotion-choices button:hover {
  background-color: #ffeb3b; color: black;
}

/* ==========================================================================
  SMARTPHONE LANDSCAPE GRID
  ========================================================================== */
@media screen and (max-height: 520px) and (max-width: 950px) and (orientation: landscape) {

  /* Hauptcontainer: Definiert 4 Zeilen in der rechten Spalte */
  .game-container {
    display: grid !important;
    grid-template-columns: auto 1fr !important; /* Links Brett, rechts Steuerung */
    grid-template-rows: auto auto auto 1fr !important; /* 4 Zeilen: Zeile 4 (History) füllt den Restplatz */
    gap: 8px !important;                          /* Kompakter Abstand für mobile Bildschirme */
    padding: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;                     /* Nutzt die exakte Displayhöhe aus */
    align-items: start !important;                /* Richtet den gesamten Inhalt oben aus */
    box-sizing: border-box !important;
  }

  /* Das Schachbrett besetzt die linke Spalte und erstreckt sich über ALLE 4 Zeilen */
  .board-wrapper {
    grid-column: 1 !important;
    grid-row: 1 / 5 !important;                   /* Geht von Zeile 1 bis Zeile 5 (deckt alle 4 Zeilen ab) */
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  #chessboard {
    height: 100% !important;
    width: auto !important;
    aspect-ratio: 1 / 1 !important;               /* Bleibt mathematisch perfekt quadratisch */
    border: 4px solid #111111 !important;
  }

  .square {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(.8rem, 3vw, 1.1rem) !important;
    user-select: none;
    cursor: pointer;
    transition: background-color 0.5s ease, box-shadow 0.5s ease; 
  }

  /* Zeile 1 rechts: Die Menüleiste mit den Buttons */
  .top-bar {
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: block !important;
    width: 100% !important;
    background-color: #252526;
    padding: 6px 10px !important;
    border-radius: 6px;
    border: 1px solid #333333;
    margin: 0 !important;
    max-width: 100% !important;
  }

  /* Zeile 2 rechts: Die Info-Leiste (Turn/Status) direkt darunter */
  .game-info {
    grid-column: 2 !important;
    grid-row: 2 !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    width: 100% !important;
    background-color: #252526;
    padding: 6px 12px !important;
    border-radius: 6px;
    border: 1px solid #333333;
    margin: 0 !important;
    font-size: 0.9rem !important;
    max-width: 100% !important;
  }

  /* Zeile 3 rechts: Die geschlagenen Figuren */
  .captured-pieces {
    grid-column: 2 !important;
    grid-row: 3 !important;
    display: block !important;                   /* Macht die geschlagenen Figuren wieder sichtbar */
    width: 100% !important;
    background-color: #252526;
    padding: 6px 12px !important;
    border-radius: 6px;
    border: 1px solid #333333;
    margin: 0 !important;
    max-width: 100% !important;
  }

  /* Zeile 4 rechts: Die Zug-Historie füllt den verbleibenden Platz komplett aus */
  .move-history {
    grid-column: 2 !important;
    grid-row: 4 !important;
    display: flex !important;                    /* Macht die Historie wieder sichtbar */
    flex-direction: column !important;
    width: 100% !important;
    background-color: #252526;
    padding: 6px 12px !important;
    border-radius: 6px;
    border: 1px solid #333333;
    margin: 0 !important;
    max-width: 100% !important;
    height: 100% !important;                     /* Streckt die Box bis zum unteren Rand */
    overflow-y: auto !important;                 /* Erlaubt scrollen innerhalb der Historie */
  }

  /* Knöpfe kompakt halten */
  .controls {
    display: flex !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }

  .controls select, 
  .controls button {
    padding: 4px 8px !important;
    font-size: 0.95rem !important;
  }

  /* Header und Footer komplett ausblenden für maximalen Fokus */
  header, footer {
    display: none !important;
  }
}

/* ==========================================================================
  ORIENTATION: PORTRAIT
  ========================================================================== */
@media (orientation: portrait) {

}