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

body, html {
  margin: 0;
  padding: 0;
  background: #222;
  height: 100%;
  width: 100%;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  overflow: hidden;
  color: #fff;
}

#gameContainer {
  position: relative;
  margin: 0 auto;
  display: block;
}

#gameCanvas {
  display: block;
  background: #333;
  touch-action: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  z-index: 1;
  max-width: 100vw;
  max-height: 100vh;
}

.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(34,34,34,0.95);
  z-index: 10;
  color: #fff;
  background-image: url('images/startscreen.png');
  background-size: cover;
  background-position: center;
  pointer-events: auto;
}

.screen h1 {
  font-size: clamp(16px, 3vh, 32px);
}
.screen p, .screen label {
  font-size: clamp(10px, 2vh, 18px);
}
.screen button {
  font-size: clamp(10px, 2vh, 18px);
  padding: clamp(6px, 1.5vh, 15px) clamp(12px, 3vh, 30px);
}

form label {
  margin: 0 8px 16px 0;
  font-size: 1.2em;
  color: #fff;
  display: inline-block;
}

button {
  margin-top: 16px;
  padding: 10px 24px;
  font-size: 1.1em;
  border: none;
  border-radius: 6px;
  background: #4caf50;
  color: white;
  cursor: pointer;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
}

button:active {
  background: #388e3c;
}

#quizScreen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('images/quiz_background.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  display: none;
  z-index: 10;
}

#quizScreen::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background-image: url('images/quiz_frame.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: -1;
}

#quizScreen input[type="number"] {
  font-size: 1.2em;
  margin: 10px 0;
  width: 80px;
  text-align: center;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
}

#tablesForm input[type="checkbox"] {
  display: none;
}

#tablesForm label {
  position: relative;
  padding-left: 1.8em;
  cursor: pointer;
  user-select: none;
  display: block;
  margin-bottom: 0.8em;
}

#tablesForm .custom-checkbox {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1.152em;
  height: 1.152em;
  background: url('images/checkbox_unchecked.png') no-repeat center center / contain;
  display: inline-block;
}

#tablesForm input[type="checkbox"]:checked + .custom-checkbox {
  background: url('images/checkbox_checked.png') no-repeat center center / contain;
}

.shop-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.shop-containers {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: calc(var(--tile-size, 32px) * 0.5);
  width: 90%;
  max-width: calc(var(--tile-size, 32px) * 9); /* 9 tiles wide */
}

.shop-container {
  background: rgba(0,0,0,0.8);
  border-radius: 8px;
  padding: calc(var(--tile-size, 32px) * 0.18) calc(var(--tile-size, 32px) * 0.32);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: calc(var(--tile-size, 32px) * 2.1);
  max-width: calc(var(--tile-size, 32px) * 2.7);
  min-height: calc(var(--tile-size, 32px) * 4.2);
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
  justify-content: flex-start;
  box-sizing: border-box;
  font-size: calc(var(--tile-size, 32px) * 0.38);
}

.shop-tower-img {
  width: calc(var(--tile-size, 32px) * 1.3);
  height: auto;
  margin: calc(var(--tile-size, 32px) * 0.18) 0 calc(var(--tile-size, 32px) * 0.32) 0;
}

.shop-stat {
  display: flex;
  align-items: center;
  margin-bottom: 0.3em;
  font-size: calc(var(--tile-size, 32px) * 0.36);
  color: #fff;
  font-family: inherit;
}
.shop-icon {
  width: 1.2em;
  height: 1.2em;
  margin-right: 0.4em;
}
.shop-buy, .shop-back {
  margin-top: 0.6em;
  margin-bottom: 0;
  padding: calc(var(--tile-size, 32px) * 0.18) calc(var(--tile-size, 32px) * 0.5);
  font-size: calc(var(--tile-size, 32px) * 0.22);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
  text-align: center;
  display: block;
  box-sizing: border-box;
  max-width: none;
  min-width: 0;
}
.shop-buy {
  background: #4caf50;
}
.shop-buy:active {
  background: #388e3c;
}
.shop-back {
  background: #e53935;
  margin-top: 1em;
  width: 100%;
  max-width: 220px;
  min-width: 120px;
  text-align: center;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.shop-back:active {
  background: #b71c1c;
}

@media (min-width: 600px) {
  .shop-bottom-bar {
    margin-left: calc(50% - 22vw * 1.5 - 2vw); /* 3 containers, gap 2vw, container max-width 22vw */
    width: auto;
  }
}

.start-wave-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: calc(0.38 * var(--tile-size, 32px));
  padding: 0.5em 1.5em;
  border: 2.5px solid #5a4632;
  border-radius: 10px;
  background: #f7e7c1;
  color: #3b2c1a;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  box-shadow: 0 1px 0 #d2b48c;
  cursor: pointer;
  outline: none;
  width: 70%;
  max-width: 20em;
  min-width: 8em;
  box-sizing: border-box;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 0 #fffbe6;
  transition: background 0.12s, box-shadow 0.12s, border 0.12s;
  margin: 0.1em 0;
}

#startWaveBtn {
  top: 50%;
  transform: translate(-50%, -50%);
}

#shopBtn {
  top: calc(50% + 15px);
  transform: translateX(-50%);
}

.start-wave-btn:active, .start-wave-btn:hover {
  background: #e6d3a3;
  border-color: #3b2c1a;
  box-shadow: inset 0 2px 6px #bfa76a;
}

#startWaveBtn:active, #startWaveBtn:hover {
  top: calc(50% + 2px);
  transform: translate(-50%, -50%);
}

#shopBtn:active, #shopBtn:hover {
  top: calc(50% + 15px + 2px);
  transform: translateX(-50%);
}

.shop-vertcol {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.shop-back {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin-top: 0.5em;
  box-sizing: border-box;
}

.quiz-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7em;
  width: 80%;
  max-width: 340px;
  margin: 0.5em auto 0 auto;
  justify-items: center;
}
.numpad-btn {
  font-size: 1.5em;
  padding: 0.7em 0;
  border: 2.5px solid #5a4632;
  border-radius: 10px;
  background: #f7e7c1;
  color: #3b2c1a;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  box-shadow: 0 1px 0 #d2b48c;
  cursor: pointer;
  width: 100%;
  transition: background 0.12s, box-shadow 0.12s, border 0.12s;
  user-select: none;
  outline: none;
  margin: 0.1em 0;
  text-shadow: 0 1px 0 #fffbe6;
}
.numpad-btn:active, .numpad-btn:hover {
  background: #e6d3a3;
  border-color: #3b2c1a;
  box-shadow: inset 0 2px 6px #bfa76a;
}

.level-text {
  position: absolute;
  left: 50%;
  top: calc(50% - 3.5em);
  transform: translate(-50%, -50%);
  z-index: 10;
  font-size: calc(0.38 * var(--tile-size, 32px));
  color: #fff;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}

.speed-buttons {
  position: absolute;
  right: calc(0.5 * var(--tile-size, 32px));
  top: calc(0.9 * var(--tile-size, 32px));
  z-index: 10;
  display: flex;
  gap: 0.27em;
  justify-content: center;
}

.speed-btn {
  font-size: calc(0.225 * var(--tile-size, 32px));
  padding: 0.27em 0.54em;
  border: 2px solid #5a4632;
  border-radius: 6px;
  background: #f7e7c1;
  color: #3b2c1a;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  box-shadow: 0 1px 0 #d2b48c;
  cursor: pointer;
  outline: none;
  text-shadow: 0 1px 0 #fffbe6;
  transition: background 0.12s, box-shadow 0.12s, border 0.12s;
  margin: 0;
  min-width: 2.25em;
  text-align: center;
}

.speed-btn:hover {
  background: #e6d3a3;
  border-color: #3b2c1a;
}

.speed-btn.active {
  background: #d4c196;
  border-color: #2d1f0f;
  box-shadow: inset 0 2px 4px #a68b5b;
  color: #2d1f0f;
}

/* Dialogue Overlay Styles */
.dialogue-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  /* Prevent text selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.dialogue-box {
  position: relative;
  width: 100%;
  max-width: calc(var(--tile-size, 32px) * 9);
  cursor: pointer;
  /* Prevent text selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.dialogue-background {
  width: 100%;
  height: auto;
  display: block;
  /* Prevent image dragging and selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
}

.dialogue-border {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: auto;
  z-index: 2;
  pointer-events: none;
  /* Prevent image dragging and selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
}

.dialogue-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  padding: calc(var(--tile-size, 32px) * 0.5);
  box-sizing: border-box;
  z-index: 1;
}

.dialogue-character {
  width: calc(var(--tile-size, 32px) * 3);
  height: auto;
  margin-right: calc(var(--tile-size, 32px) * 0.05);
  margin-left: 10px;
  margin-bottom: 2px;
  flex-shrink: 0;
  /* Prevent image dragging and selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.dialogue-text-container {
  flex: 1;
  height: calc(var(--tile-size, 32px) * 3);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding-right: 10px;
}

.dialogue-text {
  color: #352502;
  font-size: calc(var(--tile-size, 32px) * 0.22);
  line-height: 1.4;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  padding: calc(var(--tile-size, 32px) * 0.2);
  padding-top: 0;
  /* Prevent text selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.dialogue-image {
  max-width: calc(var(--tile-size, 32px) * 2);
  max-height: calc(var(--tile-size, 32px) * 2);
  margin-top: calc(var(--tile-size, 32px) * 0.3 - 15px);
  align-self: center;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  /* Prevent image dragging and selection */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.dialogue-text-small {
  font-size: calc(var(--tile-size, 32px) * 0.18);
}

.dialogue-text-italic {
  font-style: italic;
}

.dialogue-text-small-italic {
  font-size: calc(var(--tile-size, 32px) * 0.18);
  font-style: italic;
}

/* Cheat Menu Overlay */
.cheat-menu-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.cheat-menu-container {
  background: rgba(34, 34, 34, 0.95);
  border: 3px solid #4caf50;
  border-radius: 12px;
  padding: 2em;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.cheat-menu-container h2 {
  color: #4caf50;
  margin-top: 0;
  margin-bottom: 1em;
  font-size: 1.5em;
}

.cheat-menu-container p {
  color: #fff;
  margin-bottom: 1.5em;
  font-size: 1em;
}

.wave-selector {
  margin-bottom: 2em;
}

.wave-selector label {
  display: block;
  color: #fff;
  margin-bottom: 0.8em;
  font-size: 0.9em;
}

.wave-selector input {
  width: 80px;
  padding: 0.5em;
  font-size: 1em;
  text-align: center;
  border: 2px solid #4caf50;
  border-radius: 4px;
  background: #444;
  color: #fff;
  font-family: 'Press Start 2P', 'VT323', 'Pixelify Sans', monospace;
  margin-bottom: 1em;
}

.wave-selector input:focus {
  outline: none;
  border-color: #66bb6a;
  background: #555;
}

#skipToWaveBtn {
  background: #2196f3;
  margin-bottom: 0;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
}

#skipToWaveBtn:active {
  background: #1976d2;
}

#add10000GoldBtn {
  background: #ff9800;
  margin-bottom: 0.5em;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
}

#add10000GoldBtn:active {
  background: #f57c00;
}

#setGoldZeroBtn {
  background: #e91e63;
  margin-bottom: 0.5em;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
}

#setGoldZeroBtn:active {
  background: #c2185b;
}

#copyGameFieldBtn {
  background: #9c27b0;
  margin-bottom: 0.5em;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
}

#copyGameFieldBtn:active {
  background: #7b1fa2;
}

#loadPreset1Btn {
  background: #607d8b;
  margin-bottom: 0.5em;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
  min-width: 3em;
}

#loadPreset1Btn:active {
  background: #455a64;
}

#closeCheatMenuBtn {
  background: #f44336;
  padding: 0.6em 1.2em;
  font-size: 0.8em;
  margin-top: 0.5em;
}

#closeCheatMenuBtn:active {
  background: #d32f2f;
}