body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #f4f6fb;
  color: #1f2933;
}

h1 {
  margin: 24px 0 16px;
  text-align: center;
  letter-spacing: 0.02em;
}

.app {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 20px;
  width: 100%;
  max-width: 1200px;
  padding: 0 24px 32px;
  box-sizing: border-box;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
  border: 1px solid #dce3f0;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

.sidebar-title {
  margin: 8px 0 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-weight: 600;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eff3fe;
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.07);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.hud-item[data-kind="cash"] {
  background: #e9f2ff;
}

.hud-item[data-kind="lives"] {
  background: #ffe4e6;
}

.hud-item.lost-life {
  animation: hud-life-flash 0.8s ease;
}

@keyframes hud-life-flash {
  0% {
    background: #ffe4e6;
    transform: scale(1);
  }
  50% {
    background: #fecdd3;
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(220, 38, 38, 0.35);
  }
  100% {
    background: #ffe4e6;
    transform: scale(1);
  }
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }
  
  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }

  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

.shake {
    animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.hud-icon {
  font-size: 20px;
}

.hud-label {
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 13px;
}

.hud-value {
  margin-left: 4px;
  font-weight: 700;
}

button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
}

button:active {
    transform: scale(0.95);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.4);
  opacity: 0.6;
}

button:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

#start-wave {
  width: 100%;
  margin-top: 4px;
}

.stage {
  position: relative;
  background: #ffffff;
  border: 1px solid #dce3f0;
  border-radius: 18px;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  overflow: hidden;
}

.stage::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: var(--background-image);
    background-size: cover;
    background-position: center;
    filter: blur(5px);
    opacity: 0.2;
    z-index: 0;
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  background: linear-gradient(180deg, #f8fbff 0%, #f0f4ff 100%);
  border: 1px solid #ccd6ed;
  border-radius: 16px;
  box-shadow: inset 0 2px 6px rgba(15, 23, 42, 0.06);
}

.tower-list {
  display: grid;
  gap: 10px;
}

.tower-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: #f6f9ff;
  border-radius: 12px;
  border: 2px solid transparent;
  padding: 12px 14px;
  color: #1f2933;
  font-size: 14px;
  text-align: left;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.tower-card-hero {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tower-card img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.12);
  background: #fff;
}

.tower-card-stats {
  font-size: 12px;
  color: #475569;
  margin-top: 4px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tower-card h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.tower-card p {
  margin: 0;
  font-weight: 600;
}

.tower-card:hover {
  transform: translateY(-1px);
  border-color: #8ab4f8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.18);
}

.tower-card.selected {
  border-color: #2563eb;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.3);
}

.tower-card.unaffordable {
  opacity: 0.6;
  filter: saturate(0.6);
  cursor: not-allowed;
}

.tower-card.unaffordable:hover {
  transform: none;
  box-shadow: none;
}

.tower-details {
  min-height: 180px;
  background: #f9fbff;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.highlight {
    outline: 3px solid #3498db;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.8);
}

.tutorial {
    background: #fff;
    border: 2px dashed #3498db;
    border-radius: 12px;
    padding: 12px;
    margin-top: 12px;
}

.tower-details button {
  width: 100%;
  margin-top: 10px;
}

.tower-details img {
  width: 120px;
  height: 120px;
  display: block;
  margin: 0 auto 12px;
}

.tower-stats {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}

.tower-stats li {
  display: flex;
  justify-content: space-between;
  background: rgba(37, 99, 235, 0.06);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
}

.tower-stats li span:first-child {
  color: #475569;
}

.level-tag {
  font-size: 13px;
  background: #facc15;
  color: #1f2933;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 6px;
}

.upgrade-hint,
.upgrade-desc,
.instructions-note {
  font-size: 13px;
  color: #475569;
  margin-top: 6px;
}

.instructions-note {
  font-style: italic;
}

.sidebar-toggle-btn {
    display: none;
}

@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 300px;
        height: 100%;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .sidebar-open .sidebar {
        left: 0;
    }

    .sidebar-toggle-btn {
        display: block;
    }
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    padding: 0 16px 24px;
  }

  .stage {
    order: -1;
  }
}
.is-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.map-selection-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.map-header {
  text-align: center;
  padding: 32px 24px 12px;
}

.map-subtitle {
  margin: 8px auto 0;
  max-width: 720px;
  color: #475569;
  font-size: 16px;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 24px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 32px;
  box-sizing: border-box;
}

.map-panel {
  background: #ffffff;
  border: 1px solid #dce3f0;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.map-switcher {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.map-switcher__btn {
  background: #e2e8f0;
  color: #1f2933;
  border: 1px solid #cbd5f5;
  box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.04);
}

.map-switcher__btn.is-active {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  border-color: transparent;
}

.difficulty-switcher {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.difficulty-switcher__btn {
  background: #e2e8f0;
  color: #1f2933;
  border: 1px solid #cbd5f5;
  box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.04);
}

.difficulty-switcher__btn.is-active {
  background: linear-gradient(135deg, #4caf50, #81c784);
  color: #ffffff;
  border-color: transparent;
}

.map-container {
  position: relative;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
  background: #f8fbff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  overflow: hidden;
}

.map-container.is-loading::after {
  content: 'Loading map...';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 251, 255, 0.82);
  color: #2563eb;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.map-container svg {
  width: 100%;
  height: auto;
}

.district {
  fill: #cbd5ff;
  stroke: #4c6ef5;
  stroke-width: 0.8;
  cursor: pointer;
  transition: fill 0.2s ease, stroke 0.2s ease, transform 0.2s ease;
}

.district:hover,
.district:focus-visible {
  fill: #93c5fd;
  stroke: #1d4ed8;
}

.district.is-selected {
  fill: #2563eb;
  stroke: #172554;
  transform: translateY(-1px);
}

.district-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #ffffff;
  border: 1px solid #dce3f0;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.12);
}

.district-placeholder {
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: #475569;
}

.placeholder-hint {
  font-size: 13px;
  color: #64748b;
  font-style: italic;
}

.district-chip {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0f172a;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.hero-list__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f8fbff;
  border: 1px solid rgba(37, 99, 235, 0.12);
  font-weight: 600;
  color: #1f2933;
}

.hero-list__item--empty {
  justify-content: center;
  color: #64748b;
  font-weight: 500;
}

.hero-list__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2563eb;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
}

.hero-list__name {
  flex: 1;
}

.hero-list__heading {
  margin: 18px 0 0;
  font-size: 16px;
  font-weight: 700;
}

.hero-list__hint {
  margin: 4px 0 12px;
  font-size: 13px;
  color: #64748b;
}

.district-roster {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.district-roster__header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.district-roster__header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.district-roster__timestamp {
  margin: 0;
  font-size: 12px;
  color: #64748b;
}

.district-roster__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.district-roster__card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: #f8fbff;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

.district-roster__avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(37, 99, 235, 0.16);
  background: #fff;
}

.district-roster__summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.district-roster__summary h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.district-roster__status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #e0f2fe;
  color: #0f172a;
}

.district-roster__status[data-role="challenger"] {
  background: #fef3c7;
  color: #92400e;
}

.district-roster__party {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.district-roster__bio {
  margin: 0;
  font-size: 13px;
  color: #334155;
}

.district-roster__policies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.district-roster__policy {
  padding: 4px 8px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.12);
  font-size: 12px;
  color: #1d4ed8;
  font-weight: 600;
}

.district-roster__empty {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: #8590a7;
}

.start-game-btn {
  width: 100%;
  margin-top: 12px;
}

.map-footer {
  margin: auto 0 24px;
  text-align: center;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: #2563eb;
  font-weight: 600;
  text-decoration: underline;
}

.link-button:hover {
  color: #1d4ed8;
}

.link-button:focus-visible {
  outline: 3px solid #bfdbfe;
  outline-offset: 2px;
}

.game-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  gap: 12px;
}

.game-header h1 {
  margin: 0;
}

.game-header .link-button {
  font-size: 15px;
}

@media (max-width: 1020px) {
  .map-layout {
    grid-template-columns: 1fr;
    padding-bottom: 24px;
  }

  .map-container {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .map-switcher {
    grid-template-columns: 1fr;
  }

  .map-header {
    padding-bottom: 0;
  }

  .map-subtitle {
    font-size: 15px;
  }
}
.game-header__titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-header__subtitle {
  margin: 0;
  color: #475569;
  font-size: 14px;
}

.wave-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  background: #eff3fe;
  border-radius: 10px;
  min-height: 40px;
}

.wave-preview__bloon {
    width: 30px;
    height: 40px;
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
  border: 8px solid #f3f3f3;
  border-top: 8px solid #3498db;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.share-status {
  min-height: 1.2em;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.85rem;
}

.guide-page {
  min-height: 100vh;
  margin: 0;
  color: #f8fafc;
  background:
    radial-gradient(circle at 15% 10%, rgba(251, 191, 36, 0.2), transparent 30rem),
    linear-gradient(145deg, #172554, #0f172a 55%, #020617);
}

.guide-shell {
  width: min(68rem, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3rem 0 4rem;
}

.guide-back,
.guide-family a {
  color: #fde68a;
  font-weight: 700;
}

.guide-kicker {
  margin: 3rem 0 0;
  color: #fbbf24;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.guide-shell > h1 {
  max-width: 15ch;
  margin: 0.7rem 0 0;
  font-size: clamp(2.5rem, 8vw, 5.8rem);
  line-height: 0.95;
}

.guide-lede {
  max-width: 44rem;
  margin: 1.5rem 0 0;
  color: #cbd5e1;
  font-size: 1.15rem;
  line-height: 1.75;
}

.guide-play {
  display: inline-flex;
  margin-top: 1.8rem;
  padding: 0.9rem 1.2rem;
  border-radius: 0.6rem;
  color: #172554;
  background: #fbbf24;
  font-weight: 800;
  text-decoration: none;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 3.5rem;
}

.guide-grid article,
.guide-note {
  padding: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.85rem;
  background: rgba(15, 23, 42, 0.72);
}

.guide-grid span {
  color: #fbbf24;
  font-size: 0.78rem;
  font-weight: 900;
}

.guide-grid h2,
.guide-note h2 {
  margin: 0.6rem 0 0;
}

.guide-grid p,
.guide-note p {
  margin-bottom: 0;
  color: #cbd5e1;
  line-height: 1.7;
}

.guide-note {
  margin-top: 1rem;
}

.guide-family {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-top: 2rem;
}

@media (max-width: 640px) {
  .guide-grid {
    grid-template-columns: 1fr;
  }
}



