/* === Global Reset === */
html, body {
  margin: 0;
  padding: 0;
  background: #111;
  color: #fff;
  font-family: monospace;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

button {
  font-family: monospace;
  font-size: 16px;
  background: #444;
  color: white;
  border: none;
  padding: 10px 12px;
  margin: 4px;
  border-radius: 6px;
  cursor: pointer;
}
button:hover {
  background: #666;
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Level Select Screen === */
#levelSelector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background:
    radial-gradient(circle at top, rgba(111, 255, 177, 0.14), transparent 32%),
    linear-gradient(180deg, #1d2124 0%, #111416 68%, #0a0d0f 100%);
}

.level-select-shell {
  width: min(100%, 980px);
  padding: 28px 18px 92px;
  box-sizing: border-box;
}

.level-select-copy {
  text-align: center;
  margin-bottom: 26px;
}

.level-select-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  color: #88f0bd;
  margin-bottom: 10px;
}

#levelSelector h1 {
  font-size: clamp(34px, 7vw, 58px);
  margin: 0;
  color: #f7f2db;
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}
#levelSelector button {
  width: auto;
}

#levelSelectStatus {
  margin: 12px auto 0;
  max-width: 520px;
  color: #b9c7cf;
  font-size: 14px;
  line-height: 1.45;
}

/* === Game Layout === */
#gameContainer {
  display: flex;
  flex-direction: row;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* === HUD Bar === */
#hudBar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 76px;
  background: #111;
  display: flex;
  justify-content: space-between;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  padding: 0 4px;
  box-sizing: border-box;
  z-index: 1000;
  font-size: 12px;
  gap: 4px;
}
#hudBar span,
#rankDisplay {
  flex: 1;
  text-align: center;
}
#rankDisplay {
  margin-top: 2px;
}
#wavePreviewDisplay {
  flex: 1 0 100%;
  text-align: center;
  font-size: 11px;
  color: #c4d7ff;
  margin-top: -6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px 2px;
  box-sizing: border-box;
}

.wave-planner {
  flex: 1 0 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 0 8px 6px;
  box-sizing: border-box;
}

.wave-planner__item {
  min-width: 0;
  padding: 6px 7px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
}

.wave-planner__item--active {
  background: rgba(122, 198, 255, 0.12);
  border-color: rgba(122, 198, 255, 0.35);
}

.wave-planner__item--upcoming {
  background: rgba(143, 211, 255, 0.08);
}

.wave-planner__step {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8fd3ff;
}

.wave-planner__title {
  margin-top: 2px;
  font-size: 11px;
  color: #fff5c2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wave-planner__special {
  margin-top: 3px;
  font-size: 10px;
  color: #ffde85;
}

.wave-planner__mix,
.wave-planner__advisory {
  margin-top: 3px;
  font-size: 10px;
  line-height: 1.3;
  color: #cfdae2;
}

.wave-planner__advisory {
  color: #9fd8ff;
}
#hudBar button {
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 5px;
  background: #333;
}

/* === Game Canvas === */
#gameCanvas {
  display: block;
  position: absolute;
  top: 76px;
  left: 0;
  width: 100%;
  height: calc(100dvh - 76px - 76px); /* HUD + tower panel */
  background: #000;
  z-index: 1;
  image-rendering: pixelated;
}

.tower-drawer {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 84px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(10, 14, 20, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  z-index: 1000;
}

.tower-drawer.is-open {
  display: flex;
}

.tower-drawer__summary {
  min-width: 0;
  flex: 1;
}

.tower-drawer__title {
  font-size: 16px;
  font-weight: bold;
  color: #fff4b0;
}

.tower-drawer__meta,
.tower-drawer__stats,
.tower-drawer__next {
  font-size: 12px;
  line-height: 1.35;
}

.tower-drawer__meta {
  color: #cfe2ff;
  margin-top: 2px;
}

.tower-drawer__stats {
  color: #ffffff;
  margin-top: 4px;
}

.tower-drawer__perks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tower-drawer__perk {
  display: inline-flex;
  align-items: center;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.03em;
  background: rgba(255,255,255,0.08);
  color: #eff7ff;
}

.tower-drawer__perk--next {
  background: rgba(114, 205, 255, 0.15);
  color: #9fe4ff;
}

.tower-drawer__next {
  color: #8fd3ff;
  margin-top: 4px;
}

.tower-drawer__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.tower-drawer__actions button {
  min-width: 116px;
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
}

/* === Tower Panel (Legacy) === */
.tower-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 72px;
  display: flex;
  justify-content: space-around;
  background: rgba(0, 0, 0, 0.85);
  padding: 6px 4px;
  z-index: 1000;
}

.tower-panel button {
  flex: 1;
  max-width: 70px;
  height: 100%;
  font-size: 12px;
  background: #333;
  color: white;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  margin: 0 2px;
  text-align: center;
}

#towerPanel button.selected {
    background-color: #666;
    box-shadow: 0 0 0 2px yellow;
}


/* === Paginated Tower Buttons (Modern Panel) === */
.tower-pages {
  display: flex;
  justify-content: center;
  flex: 1;
  gap: 6px;
  overflow: hidden;
  padding: 3px 0;
}

.tower-button img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  margin-top: 2px;
}

.tower-button small {
  font-size: 12px;
  color: gold;
  margin-bottom: 4px;
}

/* === Pagination Arrows === */
.page-arrow {
  width: 40px;
  height: 100%;
  background: #222;
  color: white;
  font-size: 20px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}
.page-arrow:hover {
  background: #444;
}

.lock-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 16px;
  color: orange;
  pointer-events: none;
}
.tower-button {
  position: relative; /* so lock-icon can be absolutely positioned */
}


/* === Tower Option UI (Right-click Panel) === */
.towerOption {
  width: 60px;
  height: 60px;
  background: #444;
  margin: 10px 0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  font-family: monospace;
  cursor: pointer;
  transition: transform 0.2s;
}
.towerOption:hover {
  transform: scale(1.05);
  background-color: #666;
}
.towerOption.selected {
  outline: 2px solid yellow;
}
.towerOption .icon {
  width: 100%;
  height: 60%;
  background: gray;
  margin-bottom: 4px;
}
.towerOption .label {
  font-size: 12px;
}
.towerOption .cost {
  font-size: 10px;
  color: gold;
}

/* === Overlay (Victory/Loss Message) === */
#overlayMessage {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  color: white;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 1000;
}
#overlayText {
  font-size: 20px;
  margin-bottom: 20px;
  max-width: min(92vw, 560px);
  text-align: center;
  line-height: 1.45;
  background: rgba(8, 10, 16, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 18px 22px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}

.overlay-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 12px;
}

.overlay-details {
  font-size: 15px;
  color: #d7e6ff;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.overlay-actions button {
  margin: 0;
  min-width: 138px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(18, 24, 31, 0.95);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 12px 26px rgba(0,0,0,0.24);
}

#restartBtn {
  background: linear-gradient(180deg, #1f6d4b 0%, #184f37 100%);
}

#mapSelectBtn {
  background: linear-gradient(180deg, #243443 0%, #1a2530 100%);
}

/* === Other Buttons === */
#restartBtn, #mapSelectBtn, #speedToggleBtn, #pauseToggleBtn {
  margin: 10px;
}
#startWaveBtn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  font-size: 18px;
  background: #000;
  border: none;
  cursor: pointer;
  display: none;
  z-index: 10;
}

@media (max-width: 700px) {
  .tower-drawer {
    left: 6px;
    right: 6px;
    bottom: 82px;
    padding: 10px 12px;
    gap: 10px;
  }

  .tower-drawer__title {
    font-size: 14px;
  }

  .tower-drawer__meta,
  .tower-drawer__stats,
  .tower-drawer__next,
  .tower-drawer__actions button {
    font-size: 11px;
  }

  .tower-drawer__perk {
    font-size: 9px;
  }

  .tower-drawer__actions button {
    min-width: 96px;
    padding: 7px 8px;
  }

  .overlay-actions {
    width: min(92vw, 320px);
    flex-direction: column;
  }

  .overlay-actions button {
    width: 100%;
    min-width: 0;
  }
}

/* === Dev Button === */
#darkOpsBtn {
  position: absolute;
  bottom: 10px;
  left: 10px;
  padding: 0;
  margin: 0;
  max-width: 120px;
}

/* level locking  */
#levelButtons{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  align-items: stretch;
}

#levelButtons button {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(14, 18, 22, 0.88);
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 16px 30px rgba(0,0,0,0.22);
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

#levelButtons button:hover {
  transform: translateY(-2px);
  border-color: rgba(136, 240, 189, 0.45);
  box-shadow: 0 20px 36px rgba(0,0,0,0.28);
}

.level-thumbnail {
  width: 100%;
  height: 96px;
  object-fit: cover;
  display: block;
}

.level-lock {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 18px;
  pointer-events: none;
  opacity: 0.95;
}

.level-card__body {
  padding: 10px 12px 12px;
  text-align: left;
}

.level-card__title {
  font-size: 15px;
  font-weight: bold;
  color: #fff1b4;
}

.level-card__desc {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.35;
  color: #c6d0d6;
  min-height: 32px;
}

.level-card__modifier {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.35;
  color: #9fe7c4;
}

.level-card__honors {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  color: #f6dda2;
}

.level-card__honors-label {
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.level-card__honors-icons {
  display: inline-flex;
  gap: 6px;
  font-size: 13px;
}

.level-card__honors-icons span {
  opacity: 0.28;
  filter: grayscale(0.9);
}

.level-card__honors-icons span.is-earned {
  opacity: 1;
  filter: none;
}

.level-card__record {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.35;
  color: #b8c7cf;
}

.level-card__meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 11px;
  color: #84d7ff;
}

.level-card__badge {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 3px 7px;
  font-size: 10px;
  border-radius: 999px;
  background: rgba(6, 8, 10, 0.72);
  color: #fff;
  letter-spacing: 0.08em;
}

.level-card--locked .level-thumbnail {
  filter: saturate(0.7) brightness(0.7);
}

.level-card--locked .level-card__title,
.level-card--locked .level-card__desc,
.level-card--locked .level-card__record {
  color: #a8b0b5;
}

.level-card--locked .level-card__meta {
  color: #d6ab73;
}

.level-card--locked .level-card__honors {
  color: #b8a98c;
}

@media (max-width: 700px) {
  .level-select-shell {
    padding: 22px 14px 88px;
  }

  #levelButtons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .level-thumbnail {
    height: 88px;
  }

  .level-card__body {
    padding: 9px 10px 11px;
  }

  .level-card__title {
    font-size: 14px;
  }

  .level-card__desc,
  .level-card__meta {
    font-size: 11px;
  }
}
