@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

html,
body {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  font-family: 'VT323', monospace;
  background: #000;
  min-height: 100vh;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.03) 0px,
    rgba(255, 255, 255, 0.03) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  z-index: 9999;
  opacity: 0.5;
}

body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.6) 100%);
  pointer-events: none;
  z-index: 9998;
}

#game-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  gap: 30px;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

#board-container {
  flex: 0 0 auto;
  position: relative;
}

#game {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: #111;
  padding: 24px;
  position: relative;
}

#board-wrapper {
  display: grid;
  grid-template-columns: 40px repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr) 40px;
  gap: 2px;
  width: 100%;
  aspect-ratio: 1;
  max-width: 512px;
  margin: 0 auto;
  background: #000;
  padding: 4px;
}

.cellprefix {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', cursive;
  font-weight: bold;
  color: #fff;
  font-size: 11px;
  height: 40px;
  width: 40px;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

.rank-8 { grid-row: 1; grid-column: 1; }
.rank-7 { grid-row: 2; grid-column: 1; }
.rank-6 { grid-row: 3; grid-column: 1; }
.rank-5 { grid-row: 4; grid-column: 1; }
.rank-4 { grid-row: 5; grid-column: 1; }
.rank-3 { grid-row: 6; grid-column: 1; }
.rank-2 { grid-row: 7; grid-column: 1; }
.rank-1 { grid-row: 8; grid-column: 1; }

.file-a { grid-row: 9; grid-column: 2; }
.file-b { grid-row: 9; grid-column: 3; }
.file-c { grid-row: 9; grid-column: 4; }
.file-d { grid-row: 9; grid-column: 5; }
.file-e { grid-row: 9; grid-column: 6; }
.file-f { grid-row: 9; grid-column: 7; }
.file-g { grid-row: 9; grid-column: 8; }
.file-h { grid-row: 9; grid-column: 9; }
.file-empty { grid-row: 9; grid-column: 1; }

.gamecell {
  border: 2px solid #333;
  font-family: 'VT323', monospace;
  font-size: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  background: #fff;
  color: #000;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

.gamecell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.05) 2px,
    rgba(0, 0, 0, 0.05) 4px
  );
  pointer-events: none;
}

.gamecell:hover {
  background: #ddd;
  z-index: 2;
  transform: scale(1.02);
  box-shadow: 
    0 0 15px rgba(255, 255, 255, 0.4),
    inset 0 0 10px rgba(0, 0, 0, 0.3);
  border-color: #fff;
}

.gamecell.grey {
  background: #333 !important;
  color: #fff;
}

.gamecell.grey:hover {
  background: #555 !important;
}

.gamecell.green {
  background: #555 !important;
  box-shadow: 
    inset 0 0 20px rgba(255, 255, 255, 0.3),
    0 0 15px rgba(255, 255, 255, 0.5) !important;
  transform: scale(1.02);
  border-color: #fff;
  animation: pulseWhite 1s ease-in-out infinite;
}

@keyframes pulseWhite {
  0%, 100% { box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.3), 0 0 15px rgba(255, 255, 255, 0.5); }
  50% { box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.5), 0 0 25px rgba(255, 255, 255, 0.8); }
}

#game-controls {
  margin-top: 20px;
  text-align: center;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

#game-controls button {
  font-family: 'Press Start 2P', cursive;
  padding: 12px 24px;
  font-size: 10px;
  font-weight: bold;
  border: 4px solid #fff;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.1s ease;
  box-shadow: 
    4px 4px 0 #333,
    8px 8px 0 rgba(51, 51, 51, 0.5);
  min-width: 160px;
  background: #000;
  color: #fff;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
  position: relative;
  overflow: hidden;
}

#game-controls button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.3s ease;
}

#game-controls button:hover {
  background: #222;
  color: #fff;
  transform: translate(-2px, -2px);
  box-shadow: 
    6px 6px 0 #333,
    12px 12px 0 rgba(51, 51, 51, 0.5);
  text-shadow: 0 0 10px #fff, 0 0 20px #fff;
}

#game-controls button:hover::before {
  left: 100%;
}

#game-controls button:active {
  transform: translate(2px, 2px);
  box-shadow: 
    2px 2px 0 #333,
    4px 4px 0 rgba(51, 51, 51, 0.5);
}

#restart-btn {
  border-color: #fff;
  color: #fff;
}

#restart-btn:hover {
  background: #222;
  border-color: #fff;
  box-shadow: 
    6px 6px 0 #333,
    12px 12px 0 rgba(51, 51, 51, 0.5);
}

#draw-btn {
  border-color: #fff;
  color: #fff;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

#draw-btn:hover {
  background: #222;
  border-color: #fff;
  box-shadow: 
    6px 6px 0 #333,
    12px 12px 0 rgba(51, 51, 51, 0.5);
  text-shadow: 0 0 10px #fff, 0 0 20px #fff;
}

#resign-btn {
  border-color: #fff;
  color: #fff;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

#resign-btn:hover {
  background: #222;
  border-color: #fff;
  box-shadow: 
    6px 6px 0 #333,
    12px 12px 0 rgba(51, 51, 51, 0.5);
  text-shadow: 0 0 10px #fff, 0 0 20px #fff;
}

#move-list-container {
  flex: 1;
  max-width: 380px;
  background: #111;
  padding: 20px;
  height: fit-content;
  max-height: 600px;
  overflow-y: auto;
  position: relative;
}

#move-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 4px solid #333;
  position: relative;
}

#move-list-header::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #fff, transparent);
}

#move-list-header h3 {
  margin: 0;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-size: 14px;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
  letter-spacing: 1px;
}

#clear-moves {
  font-family: 'Press Start 2P', cursive;
  padding: 6px 12px;
  font-size: 8px;
  font-weight: bold;
  border: 3px solid #fff;
  border-radius: 0;
  cursor: pointer;
  background: #111;
  color: #fff;
  text-shadow: 0 0 5px #fff;
  transition: all 0.1s ease;
  box-shadow: 3px 3px 0 #333;
}

#clear-moves:hover {
  background: #333;
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 #333;
  text-shadow: 0 0 10px #fff, 0 0 20px #fff;
}

#turn-display {
  max-width: 100%;
  max-height: 50px;
  width: 100%;
  height: 100%;
  position: relative;
  border: 4px solid #333;
  border-radius: 0;
  text-align: center;
  padding: 12px 0;
  background: #111;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-weight: bold;
  font-size: 11px;
  transition: all 0.1s ease;
  box-shadow: 
    inset 0 0 20px rgba(0, 0, 0, 0.5),
    0 0 10px rgba(255, 255, 255, 0.2);
  margin-bottom: 12px;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
  letter-spacing: 1px;
}

#turn-display.turnhighlight {
  background: #222 !important;
  border-color: #fff !important;
  color: #fff !important;
  box-shadow: 
    inset 0 0 30px rgba(255, 255, 255, 0.2),
    0 0 20px rgba(255, 255, 255, 0.5);
  animation: turnPulse 0.5s ease-in-out infinite;
}

@keyframes turnPulse {
  0%, 100% { text-shadow: 0 0 5px #fff, 0 0 10px #fff; }
  50% { text-shadow: 0 0 15px #fff, 0 0 30px #fff, 0 0 45px #fff; }
}

#status-display {
  max-width: 100%;
  max-height: 50px;
  width: 100%;
  height: 100%;
  position: relative;
  border: 4px solid #333;
  border-radius: 0;
  text-align: center;
  padding: 12px 0;
  background: #111;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  font-weight: bold;
  font-size: 11px;
  transition: all 0.1s ease;
  box-shadow: 
    inset 0 0 20px rgba(0, 0, 0, 0.5),
    0 0 10px rgba(255, 255, 255, 0.2);
  margin-bottom: 15px;
  min-height: 55px;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
  letter-spacing: 1px;
}

#status-display.check {
  background: #222;
  border-color: #fff;
  color: #fff;
  box-shadow: 
    inset 0 0 30px rgba(255, 255, 255, 0.2),
    0 0 20px rgba(255, 255, 255, 0.5);
  animation: checkPulse 0.5s ease-in-out infinite;
}

@keyframes checkPulse {
  0%, 100% { text-shadow: 0 0 5px #fff, 0 0 10px #fff; }
  50% { text-shadow: 0 0 15px #fff, 0 0 30px #fff, 0 0 45px #fff; }
}

#status-display.checkmate {
  background: #222;
  border-color: #fff;
  color: #fff;
  box-shadow: 
    inset 0 0 30px rgba(255, 255, 255, 0.2),
    0 0 20px rgba(255, 255, 255, 0.5);
  animation: checkmatePulse 0.3s ease-in-out infinite;
}

@keyframes checkmatePulse {
  0%, 100% { text-shadow: 0 0 5px #fff, 0 0 10px #fff; transform: scale(1); }
  50% { text-shadow: 0 0 15px #fff, 0 0 30px #fff, 0 0 45px #fff; transform: scale(1.02); }
}

#status-display.stalemate {
  background: #222;
  border-color: #fff;
  color: #fff;
  box-shadow: 
    inset 0 0 30px rgba(255, 255, 255, 0.2),
    0 0 20px rgba(255, 255, 255, 0.5);
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

#status-display.draw {
  background: #222;
  border-color: #fff;
  color: #fff;
  box-shadow: 
    inset 0 0 30px rgba(255, 255, 255, 0.2),
    0 0 20px rgba(255, 255, 255, 0.5);
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

#move-list {
  font-family: 'VT323', monospace;
  font-size: 18px;
  line-height: 1.8;
  color: #fff;
  text-shadow: 0 0 3px #fff;
}

.move-entry {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 0;
  transition: background 0.1s ease;
  border-bottom: 1px dashed #333;
}

.move-entry:hover {
  background: #222;
  box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.1);
}

.move-number {
  font-family: 'Press Start 2P', cursive;
  font-weight: bold;
  color: #fff;
  min-width: 45px;
  text-shadow: 0 0 5px #fff;
}

.move-white {
  color: #fff;
  text-shadow: 0 0 3px #fff;
}

.move-black {
  color: #ccc;
  text-shadow: 0 0 3px #ccc;
}

.move-capture {
  color: #fff;
  font-weight: bold;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

.move-check {
  color: #fff;
  font-weight: bold;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

.move-checkmate {
  color: #fff;
  font-weight: bold;
  text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}

#move-list-container::-webkit-scrollbar {
  width: 12px;
}

#move-list-container::-webkit-scrollbar-track {
  background: #111;
  border: 2px solid #333;
}

#move-list-container::-webkit-scrollbar-thumb {
  background: #fff;
  border: 2px solid #111;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
}

#move-list-container::-webkit-scrollbar-thumb:hover {
  background: #ddd;
}

#move-list-container::-webkit-scrollbar-corner {
  background: #111;
}

::selection {
  background: rgba(255, 255, 255, 0.3);
  color: #000;
}

button:focus,
.gamecell:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.gamecell {
  font-variant-emoji: text;
  line-height: 1;
}

@keyframes crtFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.98; }
}

.gamecell:not(.grey):not(.green) {
  animation: crtFlicker 4s ease-in-out infinite;
}