/* =========================================
         === GLOBAL RESET & BASE STYLES ===
         ========================================= */
* {
  font-size: 16px;
  background: #f2e8cf;
  box-sizing: border-box;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* =========================================
         === TYPOGRAPHY & BASIC ELEMENTS ===
         ========================================= */
h1 {
  font-size: 1.5rem;
  text-align: center;
}
legend {
  font-size: 1.25rem;
  background: #d6c7a0;
}
label {
  background: #d6c7a0;
  font-weight: 100;
}
button {
  font-size: 1.5rem;
  margin: 2px;
  width: 100px;
  cursor: pointer;
  border-radius: 5px;
  border: 1px solid rgba(21, 21, 197, 0);
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
}
button:hover {
  background-color: #e0d5ba;
  transform: translateY(-2px) scale(1.1);
}
button:active {
  transform: translateY(0px);
}
fieldset {
  border-radius: 5px;
  border: 1px solid black;
  font-weight: bold;
}

/* =========================================
         === HEADER BANNER & MENU ICON ===
         ========================================= */
.banner {
  display: flex;
  height: 8vh;
  width: 100vw;
  margin-bottom: 2px;
  justify-content: space-between;
  align-items: center;
  background: #386641;
  padding: 0 20px;
  z-index: 500;
}
.burger-menu {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 5px;
  z-index: 1001;
}
.burger-menu svg {
  background: transparent;
}
.burger-menu rect {
  transition: all 0.3s ease;
}
.banner h1 {
  background: #386641;
  font-size: 2rem;
  color: #f2e8cf;
  margin: 0;
}
.player-name,
.score {
  font-size: 1.5rem;
  font-weight: bold;
  padding: 8px;
  border-radius: 8px;
  background: rgba(214, 199, 160, 0.15);
  color: #f2e8cf;
}

/* =========================================
         === MAIN LAYOUT & CONTROL PANEL ===
         ========================================= */
.game-board {
  display: flex;
  justify-content: center;
  width: 100vw;
  height: 92vh;
  padding: 0;
  position: relative;
}

.controls {
  position: fixed;
  top: 8vh;
  left: -100%;
  width: 85vw;
  max-width: 320px;
  height: 92vh;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  background: #d6c7a0;
  border-radius: 0 15px 15px 0;
  padding: 15px;
  box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
  transition: left 0.3s ease-in-out;
  z-index: 1000;
  overflow-y: auto;
}

.controls.active {
  left: 0;
}

.buttons {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  background: #d6c7a0;
}
.themes-btn {
  width: 175px;
  height: 50px;
  align-self: center;
  margin: 0 auto;
}
.controls h1 {
  background: #a7c957;
  padding: 12px;
  border-radius: 10px;
  border: 3px solid black;
}

/* =========================================
         === GAME CANVAS & OVERLAYS ===
         ========================================= */
.game {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
}

.grids {
  width: 80%;
  min-width: 300px;
  max-width: 600px;
  aspect-ratio: 1/1;
  margin: 0 auto;
  background-color: rgb(244, 244, 250);
  display: flex;
  border-radius: 5px;
  overflow: hidden;
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
}

#easy-grid {
  background-color: #d6c7a0;
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}

canvas {
  background: #a7c957;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  border: solid 1px black;
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
}

.state-block {
  width: 100%;
  height: 100%;
  background-color: rgba(242, 232, 207, 0.9);
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border-radius: 5px;
}
.state-block h2 {
  background: transparent;
  font-size: 3rem;
  text-align: center;
}
#restart {
  width: 200px;
  height: 50px;
}
.add-new-player {
  width: 200px;
  height: 50px;
  align-self: center;
}

/* =========================================
         === LEADERBOARD ===
         ========================================= */
.leaderboard {
  display: flex;
  flex-direction: column;
  min-height: 250px;
  background: #d6c7a0;
}
.leader-title {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #d6c7a0;
}
.leader-title h1 {
  background: #a7c957;
  margin-top: 0;
  padding: 10px;
  border: solid 3px black;
}
.first-part {
  display: flex;
  justify-content: space-around;
  align-items: start;
  background: #d6c7a0;
}
.sec-part {
  display: flex;
  flex-direction: column;
  justify-content: start;
  background: #d6c7a0;
  width: 32%;
}
.sec-part h3 {
  text-align: center;
  background: #c3b48b;
  margin: 0 0 10px 0;
  border-radius: 3px;
}
.player-names div,
.high-scores div,
.leaderboard-speeds div {
  background: #d6c7a0;
  text-align: center;
  padding: 3px 0;
  font-weight: bold;
  border-bottom: 1px solid #c3b48b;
}
.speed,
.sound {
  border: rgba(0, 0, 0, 0.9) 1px solid;
  background: #d6c7a0;
}
#slow {
  background: #d6c7a0;
}

/* =========================================
         === MODAL WINDOWS (NEW PLAYER & THEME) ===
         ========================================= */
.new-player-class {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: #87a575;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.new-player-class h1 {
  background: rgba(0, 0, 0, 0);
  font-size: 5rem;
  color: #f2e8cf;
  margin-bottom: 20px;
}
.instructions,
.instructions h3,
.instructions ul,
.instructions li,
.intro {
  background: rgba(0, 0, 0, 0);
  color: #f2e8cf;
}
.instructions h3 {
  text-align: center;
  font-size: 2rem;
}
.instructions li {
  font-size: 1.5rem;
  margin-bottom: 10px;
}
#player-name {
  width: 250px;
  height: 40px;
  font-size: 1.25rem;
  padding: 5px;
  text-align: center;
  background: #f2e8cf;
  color: #333;
  border: none;
  border-radius: 5px;
}
#player-name::placeholder {
  color: #666;
}
.intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  margin-top: 30px;
}
#submit {
  width: 120px;
  height: 40px;
  font-size: 1.25rem;
  background: #f2e8cf;
  border: none;
}

.theme-window {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: #87a575;
  z-index: 5000;
  display: none;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  overflow-y: auto;
}
.theme-window h1 {
  font-size: 2.5rem;
  background: #87a575;
  color: #f2e8cf;
  margin: 20px 0 0 0;
}
.theme-window h3 {
  font-size: 1.5rem;
  background: #87a575;
  color: #f2e8cf;
  margin: 10px 0;
}
.sub {
  background: #87a575;
  width: 90vw;
  max-width: 800px;
  display: flex;
  justify-content: center;
}
.sub button {
  contain: content;
  width: 15vw;
  height: 15vw;
  max-width: 120px;
  max-height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px;
  transition: border 0.3s;
}
.sub button:hover {
  background-color: #f2e8cf;
}
img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}
#back {
  margin: 20px;
  width: 150px;
  height: 50px;
}
.theme-title {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: transparent;
  width: 90vw;
  max-width: 800px;
}
.theme-title p {
  width: 15vw;
  max-width: 140px;
  background-color: transparent;
  color: #f2e8cf;
  text-align: center;
  margin: 0 10px;
  font-size: 1.25rem;
}
.theme-selected {
  border: 5px solid #df0505 !important;
  background-color: #f2e8cf !important;
  box-shadow: 5px 5px 15px rgba(221, 7, 7, 0.897) !important;
}

/* =========================================
         === MOBILE CONTROLS & MEDIA QUERIES ===
         ========================================= */
.mobile-controls {
  display: none;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px;
  gap: 15px;
  margin-top: 30px;
  justify-content: center;
  background: transparent;
}

.d-btn {
  background: #a7c957;
  border: 2px solid #386641;
  border-radius: 12px;
  font-size: 28px;
  color: #386641;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.d-btn:active {
  background: #87a575;
  transform: translateY(2px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.d-up {
  grid-column: 2;
  grid-row: 1;
}
.d-left {
  grid-column: 1;
  grid-row: 2;
}
.d-down {
  grid-column: 2;
  grid-row: 2;
}
.d-right {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 768px) {
  .mobile-controls {
    display: grid;
  }
  .grids {
    width: 95vw;
    min-width: 280px;
  }
  .banner h1 {
    display: none;
  }
  .player-name,
  .score {
    font-size: 1rem;
    padding: 6px;
  }
  .new-player-class h1 {
    font-size: 3.5rem;
    text-align: center;
  }
}
