* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #2b2b36;
  background-image:
    linear-gradient(#33333f 2px, transparent 2px),
    linear-gradient(90deg, #33333f 2px, transparent 2px);
  background-size: 40px 40px;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  color: #f1f1f1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

#app {
  width: 820px;
  padding: 12px;
}

/* ---- Wood/stone panel look ---- */
#topbar, #toolbar, #modal {
  background: #8a5a34;
  border: 6px solid #5c3a1e;
  box-shadow:
    inset 4px 4px 0 #a97a4a,
    inset -4px -4px 0 #4a2e17;
  image-rendering: pixelated;
}

#topbar {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

#topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1px;
  color: #ffe08a;
  text-shadow: 3px 3px 0 #3a2410;
  text-align: center;
}

#stats {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 10px;
}

.stat {
  background: #4a2e17;
  border: 3px solid #2f1c0d;
  padding: 8px 9px;
  white-space: nowrap;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,0.08);
}

.stat b { color: #ffe08a; }

.stat.clickable {
  cursor: pointer;
}

.stat.clickable:hover {
  filter: brightness(1.25);
}

.lives-hint {
  color: #8fd18f;
  text-shadow: 0 0 4px rgba(143, 209, 143, 0.8);
}

.lives-hint.hidden {
  visibility: hidden;
}

#toolbar {
  padding: 10px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tower-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 10px;
  color: #f1f1f1;
  background: #7f7f7f;
  border: 3px solid #3f3f3f;
  box-shadow:
    inset 3px 3px 0 #b0b0b0,
    inset -3px -3px 0 #4a4a4a;
  padding: 10px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tool-btn:hover { filter: brightness(1.1); }
.tool-btn:active {
  box-shadow:
    inset -3px -3px 0 #b0b0b0,
    inset 3px 3px 0 #4a4a4a;
}

.tool-btn.selected {
  background: #4f8f2b;
  box-shadow:
    inset 3px 3px 0 #6fbf3f,
    inset -3px -3px 0 #2f5f17;
}

.tool-btn.primary {
  background: #3b6ea5;
  box-shadow:
    inset 3px 3px 0 #5f96d1,
    inset -3px -3px 0 #234a75;
}

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tool-btn .cost {
  background: rgba(0,0,0,0.35);
  padding: 2px 5px;
  font-size: 9px;
}

#hint {
  font-size: 9px;
  color: #ffe08a;
  margin-left: auto;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  border: 6px solid #5c3a1e;
  box-shadow:
    inset 4px 4px 0 rgba(255,255,255,0.08),
    inset -4px -4px 0 rgba(0,0,0,0.35);
  image-rendering: pixelated;
  cursor: crosshair;
}

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#overlay.hidden { display: none; }

#modal {
  width: 560px;
  max-width: 90vw;
  padding: 24px;
  text-align: center;
}

#modalContent h2 {
  font-size: 15px;
  color: #ffe08a;
  text-shadow: 2px 2px 0 #3a2410;
  margin-top: 0;
  line-height: 1.6;
}

#modalContent p.question {
  font-size: 13px;
  line-height: 1.9;
  color: #fff;
  background: #4a2e17;
  border: 3px solid #2f1c0d;
  padding: 14px;
  margin: 16px 0 10px;
}

#modalContent p.equation {
  font-size: 22px;
  letter-spacing: 2px;
  color: #ffe08a;
  text-shadow: 2px 2px 0 #3a2410;
  background: #2f1c0d;
  border: 3px solid #1a0f07;
  padding: 10px;
  margin: 0 0 16px;
}

.answers {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.answer-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 16px;
  color: #fff;
  background: #4f8f2b;
  border: 3px solid #2f5f17;
  box-shadow:
    inset 3px 3px 0 #6fbf3f,
    inset -3px -3px 0 #2f5f17;
  width: 90px;
  height: 60px;
  cursor: pointer;
}

.answer-btn:hover { filter: brightness(1.15); }
.answer-btn.wrong {
  background: #a5423b;
  box-shadow:
    inset 3px 3px 0 #d16f5f,
    inset -3px -3px 0 #6f2a24;
}
.answer-btn.correct {
  background: #ffd23f;
  box-shadow:
    inset 3px 3px 0 #fff0a0,
    inset -3px -3px 0 #b3901f;
  color: #3a2410;
}

.feedback {
  font-size: 11px;
  min-height: 22px;
  margin-top: 14px;
  color: #ffe08a;
}

.modal-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 11px;
  color: #fff;
  background: #3b6ea5;
  border: 3px solid #234a75;
  box-shadow:
    inset 3px 3px 0 #5f96d1,
    inset -3px -3px 0 #234a75;
  padding: 12px 18px;
  margin-top: 14px;
  cursor: pointer;
}

.modal-btn:hover { filter: brightness(1.1); }

@media (max-width: 860px) {
  #app { width: 100%; }
  #hint { margin-left: 0; }
}
