.tower-layout {
  display: grid;
  gap: 2.5rem;
  margin-top: 2.5rem;
}

@media (min-width: 960px) {
  .tower-layout {
    grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr);
    align-items: start;
  }
}

.tower-stage {
  display: grid;
  gap: 1.25rem;
  position: relative;
}

.tower-grid {
  display: grid;
  grid-template-columns: repeat(var(--tower-grid-size, 7), minmax(0, 1fr));
  gap: 0.65rem;
  padding: 1.5rem;
  border-radius: 1.75rem;
  background: rgba(22, 30, 64, 0.5);
  box-shadow: inset 0 0 0 1px rgba(129, 161, 255, 0.18);
  backdrop-filter: blur(18px);
}

.tower-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 600;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.tower-cell[data-entity='hero'] {
  background: linear-gradient(145deg, rgba(64, 156, 255, 0.9), rgba(120, 93, 255, 0.78));
  box-shadow: 0 16px 32px rgba(64, 156, 255, 0.35);
}

.tower-cell[data-entity='wall'] {
  background: linear-gradient(145deg, rgba(28, 35, 74, 0.9), rgba(15, 18, 32, 0.92));
  border-color: rgba(90, 105, 180, 0.32);
}

.tower-cell[data-entity='monster'] {
  background: linear-gradient(145deg, rgba(255, 111, 145, 0.92), rgba(255, 88, 88, 0.78));
  box-shadow: 0 12px 28px rgba(255, 105, 135, 0.3);
}

.tower-cell[data-entity='door'] {
  background: linear-gradient(145deg, rgba(255, 196, 81, 0.92), rgba(255, 149, 0, 0.74));
  box-shadow: 0 14px 28px rgba(255, 182, 73, 0.32);
}

.tower-cell[data-entity='key'] {
  background: linear-gradient(145deg, rgba(255, 214, 94, 0.88), rgba(255, 191, 41, 0.72));
  color: #3a2b00;
}

.tower-cell[data-entity='potion'] {
  background: linear-gradient(145deg, rgba(126, 255, 210, 0.88), rgba(84, 213, 255, 0.76));
  color: rgba(10, 65, 80, 0.92);
}

.tower-cell[data-entity='attack'] {
  background: linear-gradient(145deg, rgba(255, 163, 145, 0.9), rgba(255, 103, 103, 0.74));
}

.tower-cell[data-entity='defense'] {
  background: linear-gradient(145deg, rgba(122, 197, 255, 0.88), rgba(66, 125, 255, 0.72));
}

.tower-cell[data-entity='coin'] {
  background: linear-gradient(145deg, rgba(255, 226, 140, 0.9), rgba(255, 196, 0, 0.76));
  color: rgba(80, 56, 0, 0.95);
}

.tower-cell[data-entity='empty'] {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
}

.tower-cell[data-entity='stairs'],
.tower-cell[data-entity='stairsUp'],
.tower-cell[data-entity='stairsDown'] {
  background: linear-gradient(145deg, rgba(173, 255, 223, 0.92), rgba(64, 255, 193, 0.72));
  color: rgba(0, 90, 70, 0.92);
}

.tower-cell[data-entity='shop'] {
  background: linear-gradient(145deg, rgba(255, 240, 179, 0.92), rgba(255, 207, 114, 0.78));
  color: rgba(88, 52, 0, 0.85);
  box-shadow: 0 12px 26px rgba(255, 195, 67, 0.3);
}

.tower-cell[data-entity='goal'] {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(175, 211, 255, 0.85));
  color: rgba(48, 70, 130, 0.92);
  box-shadow: 0 16px 30px rgba(140, 196, 255, 0.4);
}

.tower-cell:focus-visible {
  outline: 3px solid rgba(118, 196, 255, 0.85);
  outline-offset: 4px;
}

.tower-cell:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.3);
}

.tower-status {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.78);
  min-height: 1.5em;
}

.tower-controls {
  display: grid;
  justify-content: center;
  gap: 0.75rem;
}

.tower-control-middle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.tower-control {
  width: 60px;
  height: 60px;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: 0 8px 18px rgba(20, 40, 120, 0.32);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  text-align: center;
}

.tower-control:active {
  transform: scale(0.95);
  box-shadow: 0 4px 12px rgba(20, 40, 120, 0.4);
}

.tower-control-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.tower-control-label {
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.tower-sidebar {
  display: grid;
  gap: 1.75rem;
}

.tower-scorecard,
.tower-log-card,
.tower-equipment-card {
  padding: 1.75rem;
  border-radius: 1.5rem;
  background: rgba(15, 32, 96, 0.45);
  backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px rgba(124, 168, 255, 0.2);
  display: grid;
  gap: 1rem;
}

.tower-equipment {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
  font-size: 0.95rem;
}

.tower-equipment li {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tower-equipment li span:first-child {
  color: rgba(255, 255, 255, 0.7);
}

.equipment-value {
  color: #fff;
  font-weight: 600;
}

.stats-grid {
  display: grid;
  gap: 0.75rem;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.98rem;
}

.stat-row dt {
  color: rgba(255, 255, 255, 0.78);
}

.stat-row dd {
  margin: 0;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.tower-log {
  display: grid;
  gap: 0.6rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.8);
}

.tower-log li {
  line-height: 1.5;
}

.npc-lines {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
}

.tower-restart {
  justify-self: start;
}

.tower-dialog-backdrop {
  position: absolute;
  inset: 0;
  border-radius: 1.75rem;
  background: rgba(5, 10, 28, 0.65);
  backdrop-filter: blur(6px);
  transition: opacity 0.2s ease;
  z-index: 10;
}

.tower-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 90vw);
  padding: 1.75rem;
  border-radius: 1.5rem;
  background: rgba(16, 28, 66, 0.96);
  box-shadow: 0 28px 60px rgba(10, 14, 40, 0.55);
  backdrop-filter: blur(18px);
  display: grid;
  gap: 1.25rem;
  z-index: 20;
}

.tower-dialog.hidden,
.tower-dialog-backdrop.hidden {
  display: none;
}

.tower-dialog-header {
  display: grid;
  gap: 0.4rem;
}

.tower-dialog-sub {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.75);
}

.tower-dialog-body {
  display: grid;
  gap: 1rem;
}

.combat-side {
  padding: 1rem;
  border-radius: 1.25rem;
  background: rgba(20, 40, 98, 0.6);
  box-shadow: inset 0 0 0 1px rgba(118, 166, 255, 0.22);
  display: grid;
  gap: 0.6rem;
}

.combat-side h4 {
  margin: 0;
  font-size: 1rem;
}

.stat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.85);
}

.stat-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.combat-outcome {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
}

.tower-dialog-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.tower-dialog .button {
  min-width: 120px;
}

.shop-coins {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.78);
}

.shop-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.shop-item {
  padding: 1rem;
  border-radius: 1.2rem;
  background: rgba(24, 46, 108, 0.6);
  box-shadow: inset 0 0 0 1px rgba(126, 176, 255, 0.24);
  display: grid;
  gap: 0.5rem;
}

.shop-item-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.shop-item-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.shop-item-cost {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
}

.shop-item-desc {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.shop-item button {
  justify-self: end;
  min-width: 120px;
}

body.tower-dialog-open {
  overflow: hidden;
}

body.tower-dialog-open .tower-grid,
body.tower-dialog-open .tower-controls,
body.tower-dialog-open .tower-restart {
  pointer-events: none;
  user-select: none;
}

.tower-rules {
  margin-top: 3rem;
  padding: 2rem;
  border-radius: 1.75rem;
  background: rgba(24, 48, 112, 0.45);
  box-shadow: inset 0 0 0 1px rgba(130, 170, 255, 0.22);
  backdrop-filter: blur(24px);
  display: grid;
  gap: 1rem;
}

.tower-rules ul {
  display: grid;
  gap: 0.75rem;
  font-size: 0.98rem;
  color: rgba(255, 255, 255, 0.84);
  line-height: 1.6;
  padding-left: 1.2rem;
}

@media (max-width: 720px) {
  .tower-grid {
    padding: 1.1rem;
    gap: 0.5rem;
    border-radius: 1.4rem;
  }

  .tower-control {
    width: 52px;
    height: 52px;
  }
}
