:root {
  --bg-color: #06111f;
  --panel-color: rgba(7, 17, 31, 0.88);
  --panel-strong: rgba(11, 24, 44, 0.96);
  --line-color: rgba(122, 237, 255, 0.24);
  --glow-color: #6ce3ff;
  --glow-strong: #b5f0ff;
  --accent-color: #ff8d57;
  --accent-soft: #ffd17b;
  --danger-color: #ff6778;
  --success-color: #87ffbf;
  --text-color: #eef7ff;
  --muted-color: #94aac8;
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.45);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(31, 104, 154, 0.35), transparent 36%),
    linear-gradient(180deg, #09192e 0%, #040910 100%);
  color: var(--text-color);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
}

body {
  min-height: 100dvh;
}

button {
  font: inherit;
}

.app-shell {
  width: min(calc(100vw - 24px), calc((100dvh - 28px) * 0.56), 620px);
  height: 100dvh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 8px 0 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
}

.hud-panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.top-panel {
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.status-cluster {
  position: relative;
  min-height: 48px;
  padding: 5px 8px 6px;
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(15, 34, 60, 0.92), rgba(7, 18, 34, 0.94));
  border: 1px solid rgba(118, 215, 255, 0.18);
  clip-path: polygon(0 12px, 12px 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 0 100%);
  box-shadow:
    inset 0 0 0 1px rgba(7, 25, 46, 0.7),
    0 10px 24px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.status-cluster::before,
.status-cluster::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.status-cluster::before {
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(118, 215, 255, 0.16), transparent);
  opacity: 0.65;
}

.status-cluster::after {
  left: 14px;
  right: 14px;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(118, 215, 255, 0.88), transparent 72%);
}

.commander-cluster::after {
  background: linear-gradient(90deg, rgba(111, 245, 214, 0.85), transparent 72%);
}

.wave-cluster::after {
  background: linear-gradient(90deg, rgba(136, 214, 255, 0.9), transparent 72%);
}

.hp-cluster::after {
  background: linear-gradient(90deg, rgba(255, 121, 124, 0.9), transparent 72%);
}

.energy-cluster::after {
  background: linear-gradient(90deg, rgba(122, 255, 189, 0.88), transparent 72%);
}

.record-cluster::after {
  background: linear-gradient(90deg, rgba(255, 196, 112, 0.9), transparent 72%);
}

.support-cluster::after {
  background: linear-gradient(90deg, rgba(174, 255, 143, 0.9), transparent 72%);
}

.status-cluster.wide {
  display: grid;
  gap: 4px;
}

.status-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.cluster-icon,
.skill-icon {
  position: relative;
  flex: 0 0 auto;
  display: inline-block;
  overflow: hidden;
}

.cluster-icon {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(124, 224, 255, 0.24);
  background: linear-gradient(180deg, rgba(14, 34, 58, 0.92), rgba(8, 18, 31, 0.96));
  clip-path: polygon(0 5px, 5px 0, calc(100% - 5px) 0, 100% 5px, 100% calc(100% - 5px), calc(100% - 5px) 100%, 5px 100%, 0 calc(100% - 5px));
  box-shadow:
    inset 0 0 12px rgba(108, 227, 255, 0.12),
    0 0 12px rgba(108, 227, 255, 0.12);
}

.cluster-icon::before,
.cluster-icon::after,
.skill-icon::before,
.skill-icon::after {
  content: "";
  position: absolute;
}

.commander-icon::before {
  left: 50%;
  top: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #94f7ff;
  transform: translateX(-50%);
}

.commander-icon::after {
  left: 4px;
  right: 4px;
  bottom: 3px;
  height: 6px;
  border-radius: 6px 6px 2px 2px;
  border: 1px solid rgba(148, 247, 255, 0.9);
  border-top: 0;
}

.wave-icon::before {
  inset: 4px 3px auto 3px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #8fefff 18%, transparent 36%, #8fefff 54%, transparent 72%, #8fefff 90%, transparent);
}

.wave-icon::after {
  left: 3px;
  right: 3px;
  bottom: 4px;
  height: 5px;
  border-top: 1px solid rgba(143, 239, 255, 0.85);
  border-bottom: 1px solid rgba(143, 239, 255, 0.4);
  transform: skewX(-28deg);
}

.hp-icon::before {
  left: 50%;
  top: 3px;
  width: 8px;
  height: 8px;
  background: linear-gradient(180deg, #ff8e93, #ff6d72);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px 2px 0 2px;
}

.hp-icon::after {
  left: 7px;
  top: 4px;
  width: 4px;
  height: 8px;
  background: linear-gradient(180deg, #ffb6b7, #ff7b80);
  border-radius: 3px;
}

.energy-icon::before {
  left: 7px;
  top: 2px;
  width: 4px;
  height: 12px;
  background: linear-gradient(180deg, #8cffdc, #54d9ff);
  transform: skewX(-18deg);
}

.energy-icon::after {
  left: 5px;
  top: 7px;
  width: 8px;
  height: 4px;
  background: linear-gradient(90deg, #54d9ff, #8cffdc);
  transform: skewX(-18deg);
}

.record-icon::before {
  inset: 3px;
  border: 1px solid rgba(255, 206, 131, 0.9);
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 69% 57%, 79% 92%, 50% 71%, 21% 92%, 31% 57%, 2% 35%, 39% 34%);
}

.record-icon::after {
  left: 7px;
  top: 5px;
  width: 4px;
  height: 8px;
  background: linear-gradient(180deg, #ffe596, #ffbf5e);
}

.support-icon::before {
  left: 4px;
  top: 4px;
  width: 10px;
  height: 3px;
  background: linear-gradient(90deg, #bcff94, #71e6ff);
  transform: rotate(45deg);
  border-radius: 999px;
}

.support-icon::after {
  left: 6px;
  top: 6px;
  width: 6px;
  height: 6px;
  border: 1px solid rgba(188, 255, 148, 0.92);
  border-radius: 50%;
  box-shadow:
    0 0 0 2px rgba(9, 22, 38, 0.9),
    0 0 0 3px rgba(113, 230, 255, 0.42);
}

.label,
.subtext,
.summary-label,
.skill-meta,
.eyebrow {
  color: var(--muted-color);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.58rem;
}

#playerTag,
#supportMeta,
#bestScoreMeta {
  display: none;
}

#waveState {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-cluster strong,
.modal-card h2,
.skill-name,
.restart-button {
  font-family: "Eurostile", "Orbitron", "Trebuchet MS", sans-serif;
  letter-spacing: 0.03em;
}

.status-cluster strong {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  line-height: 1.05;
  text-shadow: 0 0 18px rgba(124, 224, 255, 0.08);
}

.meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.meter {
  position: relative;
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(128, 212, 255, 0.08);
}

.commander-cluster,
.wave-cluster,
.support-cluster,
.record-cluster {
  display: grid;
  align-content: start;
  gap: 2px;
}

.hp-cluster strong,
.energy-cluster strong {
  margin-top: 0;
  font-size: 0.68rem;
}

.cluster-icon {
  width: 15px;
  height: 15px;
}

.status-cluster::after {
  left: 10px;
  right: 10px;
}

.meter-row .status-head {
  gap: 4px;
}

.meter-row .label {
  letter-spacing: 0.08em;
}

#supportLabel,
#bestScoreLabel,
#waveLabel,
#playerName {
  font-size: 0.66rem;
}

#hpLabel,
#expLabel {
  font-size: 0.64rem;
}

#waveState {
  font-size: 0.54rem;
}

.meter span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  transition: width 0.2s ease;
}

.hp-meter span {
  background: linear-gradient(90deg, #ff6868, #ff9b72);
}

.exp-meter span {
  background: linear-gradient(90deg, #63d8ff, #80ffbf);
}

.stage-panel {
  min-height: 0;
}

.stage-frame {
  position: relative;
  height: 100%;
  min-height: 0;
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(19, 70, 120, 0.42), transparent 30%),
    linear-gradient(180deg, rgba(4, 8, 18, 0.92), rgba(2, 5, 12, 0.98));
  border: 1px solid rgba(115, 209, 255, 0.15);
  box-shadow: var(--shadow-lg);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.stage-tip {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: min(560px, calc(100% - 36px));
  padding: 4px 8px;
  border-radius: 0;
  background: linear-gradient(180deg, rgba(4, 14, 25, 0.88), rgba(3, 10, 18, 0.94));
  border: 1px solid rgba(127, 229, 255, 0.24);
  backdrop-filter: blur(10px);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.05;
  clip-path: polygon(0 10px, 10px 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
}

.tutorial-card {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 3;
  width: min(380px, calc(100% - 36px));
  padding: 16px 16px 14px;
  background:
    linear-gradient(180deg, rgba(7, 21, 36, 0.94), rgba(4, 11, 20, 0.98));
  border: 1px solid rgba(129, 232, 255, 0.26);
  clip-path: polygon(0 14px, 14px 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
}

.tutorial-card.hidden {
  display: none;
}

.tutorial-card h2 {
  margin: 4px 0 0;
  font-size: clamp(1.05rem, 1.2vw + 0.8rem, 1.45rem);
}

.tutorial-step {
  margin: 0;
  color: #8df0ff;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.tutorial-body {
  margin: 10px 0 0;
  color: #d4e8ff;
  font-size: 0.94rem;
  line-height: 1.5;
}

.tutorial-dismiss {
  min-width: 0;
  margin-top: 14px;
  padding: 10px 14px;
}

.bottom-panel {
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
}

.skill-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.skill-button,
.upgrade-card,
.restart-button {
  border: 1px solid rgba(128, 222, 255, 0.18);
  color: var(--text-color);
  background:
    linear-gradient(180deg, rgba(24, 45, 76, 0.95), rgba(10, 20, 38, 0.95));
  border-radius: 0;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    opacity 0.2s ease;
  clip-path: polygon(0 12px, 12px 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
}

.skill-button {
  position: relative;
  min-height: 62px;
  padding: 12px 14px 12px 46px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  overflow: hidden;
}

.skill-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(108, 227, 255, 0.12), transparent 48%);
  pointer-events: none;
}

.skill-hotkey {
  position: absolute;
  top: 8px;
  right: 12px;
  color: rgba(163, 214, 236, 0.7);
  font-family: "Eurostile", "Orbitron", "Trebuchet MS", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
}

.skill-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translateY(-50%);
  border: 1px solid rgba(132, 222, 255, 0.26);
  background: linear-gradient(180deg, rgba(16, 37, 63, 0.94), rgba(9, 18, 32, 0.98));
  clip-path: polygon(0 6px, 6px 0, calc(100% - 6px) 0, 100% 6px, 100% calc(100% - 6px), calc(100% - 6px) 100%, 6px 100%, 0 calc(100% - 6px));
  box-shadow:
    inset 0 0 14px rgba(110, 236, 255, 0.14),
    0 0 14px rgba(110, 236, 255, 0.08);
}

.bombard-icon::before {
  left: 9px;
  top: 2px;
  width: 4px;
  height: 8px;
  background: linear-gradient(180deg, #ffd980, #ff9d61);
}

.bombard-icon::after {
  left: 5px;
  bottom: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 226, 137, 0.95) 0 24%, rgba(255, 166, 95, 0.92) 25% 56%, transparent 57%),
    radial-gradient(circle, transparent 0 52%, rgba(255, 145, 103, 0.9) 53% 70%, transparent 71%);
}

.freeze-icon::before {
  inset: 4px;
  background:
    linear-gradient(180deg, transparent 0 30%, #b4f6ff 30% 70%, transparent 70%),
    linear-gradient(90deg, transparent 0 30%, #b4f6ff 30% 70%, transparent 70%);
}

.freeze-icon::after {
  inset: 3px;
  border: 1px solid rgba(180, 246, 255, 0.8);
  transform: rotate(45deg);
}

.skill-button:hover:not(:disabled),
.upgrade-card:hover,
.restart-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(54, 176, 255, 0.18);
  border-color: rgba(138, 236, 255, 0.38);
}

.skill-button.locked,
.skill-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.compact-feed {
  position: relative;
  min-height: 0;
  padding: 8px 10px;
  border-radius: 0;
  background: linear-gradient(180deg, rgba(9, 21, 39, 0.95), rgba(5, 13, 24, 0.98));
  border: 1px solid rgba(129, 217, 255, 0.2);
  color: #c7f5ff;
  display: flex;
  align-items: center;
  font-size: 0.95rem;
  line-height: 1.35;
  clip-path: polygon(0 12px, 12px 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

.compact-feed::before {
  content: "COMBAT LOG";
  position: absolute;
  top: -1px;
  left: 14px;
  padding: 0 8px 0 0;
  background: linear-gradient(90deg, rgba(101, 229, 255, 0.24), transparent);
  color: rgba(123, 214, 255, 0.84);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: start center;
  padding: clamp(14px, 4dvh, 28px) 16px 18px;
  background: rgba(2, 6, 14, 0.78);
  backdrop-filter: blur(10px);
  z-index: 20;
  overflow-y: auto;
}

.overlay.hidden {
  display: none;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 44px);
  padding: 18px;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(10, 23, 40, 0.96), rgba(5, 11, 21, 0.98));
  border: 1px solid rgba(130, 222, 255, 0.18);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  margin: 0 0 8px;
}

.eyebrow.danger {
  color: #ff9dab;
}

.modal-card h2 {
  margin: 0;
  font-size: clamp(1.55rem, 1.4vw + 1rem, 2.35rem);
}

.levelup-modal,
.gameover-modal {
  display: grid;
  align-content: start;
  gap: 12px;
}

.levelup-modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 108px);
  padding: 14px;
  gap: 8px;
}

.levelup-toolbar {
  margin-top: 4px;
  display: grid;
  gap: 8px;
}

.levelup-token-status {
  width: 100%;
  padding: 8px 12px;
  border-radius: 16px;
  border: 1px solid rgba(128, 222, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: #d8eeff;
  font-weight: 600;
  font-size: 0.92rem;
}

.levelup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.upgrade-grid {
  margin-top: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.upgrade-card {
  min-height: 118px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}

.upgrade-card .icon {
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 1.35rem;
}

.upgrade-card h3 {
  margin: 0 0 6px;
  font-size: 0.96rem;
}

.upgrade-card p {
  margin: 0;
  color: var(--muted-color);
  font-size: 0.82rem;
  line-height: 1.25;
}

.tower-modal {
  width: min(520px, 100%);
}

.tower-summary {
  margin: 12px 0 0;
  color: #d0e6ff;
  line-height: 1.5;
}

.tower-stats {
  margin: 20px 0 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tower-stat {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(136, 221, 255, 0.12);
}

.tower-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 1.1rem;
  color: var(--text-color);
}

.tower-actions {
  margin-top: 22px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.action-button {
  min-width: 170px;
  padding: 14px 18px;
  border: 1px solid rgba(128, 222, 255, 0.18);
  color: var(--text-color);
  background:
    linear-gradient(180deg, rgba(24, 45, 76, 0.95), rgba(10, 20, 38, 0.95));
  border-radius: 0;
  cursor: pointer;
  clip-path: polygon(0 12px, 12px 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    opacity 0.2s ease;
}

.action-button.primary {
  background:
    linear-gradient(180deg, rgba(37, 82, 54, 0.98), rgba(13, 30, 22, 0.98));
  border-color: rgba(146, 255, 165, 0.24);
}

.action-button.danger {
  background:
    linear-gradient(180deg, rgba(84, 38, 46, 0.98), rgba(35, 12, 18, 0.98));
  border-color: rgba(255, 138, 150, 0.24);
}

.action-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(54, 176, 255, 0.18);
  border-color: rgba(138, 236, 255, 0.38);
}

.action-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.summary-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-grid > div {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(136, 221, 255, 0.12);
}

.summary-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
}

.restart-button {
  min-width: 0;
  width: min(220px, 100%);
  padding: 14px 18px;
  cursor: pointer;
  justify-self: start;
}

.leaderboard-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0;
}

.leaderboard-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(136, 221, 255, 0.12);
}

.leaderboard-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.3rem;
}

.leaderboard-note {
  margin: 10px 0 0;
  color: var(--muted-color);
  line-height: 1.5;
}

.leaderboard-list {
  margin: 14px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-color);
}

.leaderboard-list strong {
  margin-top: 0;
  font-size: 1rem;
  text-align: right;
}

.gameover-modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 96px);
  padding: 14px;
  gap: 8px;
}

.gameover-modal .summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gameover-modal .summary-grid > div,
.gameover-modal .leaderboard-card {
  padding: 10px 12px;
}

.gameover-modal .summary-grid strong {
  margin-top: 4px;
  font-size: 1rem;
}

.gameover-modal .leaderboard-card strong {
  margin-top: 5px;
  font-size: 1rem;
}

.gameover-modal .leaderboard-note,
.gameover-modal .leaderboard-list {
  margin-top: 6px;
}

.gameover-modal .leaderboard-list {
  gap: 5px;
}

.gameover-modal .leaderboard-list li {
  font-size: 0.88rem;
}

.gameover-modal .restart-button {
  width: min(160px, 100%);
  padding: 10px 12px;
}

.levelup-modal .eyebrow {
  margin-bottom: 4px;
  font-size: 0.68rem;
}

.levelup-modal h2 {
  font-size: clamp(1.12rem, 1vw + 0.9rem, 1.65rem);
  line-height: 1.05;
}

.levelup-modal .action-button {
  min-width: 0;
  padding: 10px 12px;
  font-size: 0.9rem;
}

@media (max-width: 920px) {
  .app-shell {
    width: min(calc(100vw - 16px), calc((100dvh - 18px) * 0.58), 620px);
    height: 100dvh;
    min-height: 100dvh;
    padding: 8px 0 10px;
    gap: 8px;
  }

  .top-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .upgrade-grid,
  .tower-stats {
    grid-template-columns: 1fr;
  }

  .levelup-toolbar {
    align-items: stretch;
  }

  .levelup-actions {
    width: 100%;
  }

  .levelup-actions .action-button {
    flex: 1 1 180px;
  }

  .gameover-modal .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .levelup-modal {
    max-height: calc(100dvh - 116px);
  }

  .status-cluster {
    min-width: 0;
    min-height: 48px;
    padding: 5px 8px 6px;
  }

  .stage-panel {
    min-height: 0;
  }

  .stage-frame {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .top-panel,
  .bottom-panel,
  .modal-card {
    padding: 12px;
  }

  .app-shell {
    gap: 6px;
  }

  .top-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0;
    gap: 4px;
  }

  .status-cluster {
    padding: 5px 8px 6px;
    min-height: 48px;
  }

  .cluster-icon {
    width: 15px;
    height: 15px;
  }

  .status-cluster strong {
    font-size: 0.72rem;
    line-height: 1.05;
  }

  .label,
  .subtext,
  .summary-label,
  .skill-meta,
  .eyebrow {
    font-size: 0.58rem;
  }

  .status-cluster.wide {
    gap: 4px;
  }

  .meter-row {
    gap: 4px;
  }

  .meter {
    height: 7px;
  }

  #playerTag,
  #supportMeta,
  #bestScoreMeta {
    display: none;
  }

  #waveState {
    display: block;
    line-height: 1.05;
    font-size: 0.54rem;
  }

  .stage-frame {
    min-height: 0;
    border-radius: 22px;
  }

  .skill-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .skill-button {
    min-height: 52px;
    padding: 8px 10px 8px 40px;
    gap: 3px;
  }

  .skill-hotkey {
    top: 7px;
    right: 10px;
    font-size: 0.64rem;
  }

  .skill-icon {
    left: 10px;
    width: 18px;
    height: 18px;
  }

  .skill-name {
    font-size: 0.88rem;
  }

  .skill-meta {
    font-size: 0.74rem;
  }

  .compact-feed {
    min-height: 0;
    padding: 8px 10px;
    font-size: 0.82rem;
    line-height: 1.3;
  }

  .stage-tip {
    right: 12px;
    left: 12px;
    bottom: 12px;
    border-radius: 18px;
    padding: 4px 8px;
    font-size: 0.62rem;
    font-weight: 600;
    line-height: 1.02;
  }

  .tutorial-card {
    top: 12px;
    left: 12px;
    width: min(360px, calc(100% - 24px));
    padding: 14px 14px 12px;
  }

  .tutorial-body {
    font-size: 0.88rem;
  }

  .upgrade-card {
    min-height: 0;
  }

  .levelup-token-status {
    width: 100%;
  }

  .levelup-actions,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .gameover-modal {
    max-height: calc(100dvh - 112px);
    padding: 12px;
  }

  .levelup-modal {
    max-height: calc(100dvh - 120px);
    padding: 12px;
  }

  .levelup-modal .levelup-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .levelup-modal .action-button {
    width: 100%;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  .levelup-modal .levelup-token-status {
    padding: 7px 10px;
    font-size: 0.82rem;
  }

  .levelup-modal .upgrade-card {
    min-height: 102px;
    padding: 10px 12px;
  }

  .levelup-modal .upgrade-card .icon {
    width: 36px;
    height: 36px;
    margin-bottom: 8px;
    font-size: 1.1rem;
  }

  .levelup-modal .upgrade-card h3 {
    font-size: 0.88rem;
  }

  .levelup-modal .upgrade-card p {
    font-size: 0.74rem;
    line-height: 1.18;
  }

  .gameover-modal .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .gameover-modal .summary-grid > div,
  .gameover-modal .leaderboard-card {
    padding: 9px 10px;
  }

  .gameover-modal .summary-grid strong,
  .gameover-modal .leaderboard-card strong {
    font-size: 0.94rem;
  }

  .gameover-modal .restart-button {
    width: min(150px, 100%);
  }

  .tower-actions {
    justify-content: stretch;
  }

  .action-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .top-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-cluster {
    padding: 6px 8px;
  }

  .status-cluster strong {
    font-size: 0.8rem;
  }

  .label,
  .subtext {
    font-size: 0.68rem;
  }

  .bottom-panel {
    grid-template-columns: 1fr;
  }

  .gameover-modal .summary-grid {
    grid-template-columns: 1fr;
  }
}

/* Force the top HUD to stay vertically compact across all breakpoints. */
.top-panel {
  padding: 0 !important;
  gap: 2px !important;
  align-items: start;
}

.top-panel .status-cluster {
  min-height: 0 !important;
  padding: 4px 7px 5px !important;
}

.top-panel .status-cluster.wide,
.top-panel .commander-cluster,
.top-panel .wave-cluster,
.top-panel .support-cluster,
.top-panel .record-cluster {
  gap: 2px !important;
}

.top-panel .status-head,
.top-panel .meter-row {
  gap: 4px !important;
}

.top-panel .cluster-icon {
  width: 13px !important;
  height: 13px !important;
}

.top-panel .label,
.top-panel .subtext {
  font-size: 0.5rem !important;
  letter-spacing: 0.06em !important;
  line-height: 1 !important;
}

.top-panel .status-cluster strong {
  margin-top: 0 !important;
  font-size: 0.56rem !important;
  line-height: 1 !important;
}

.top-panel #playerName,
.top-panel #waveLabel,
.top-panel #supportLabel,
.top-panel #bestScoreLabel {
  font-size: 0.54rem !important;
}

.top-panel #hpLabel,
.top-panel #expLabel,
.top-panel #levelLabel {
  font-size: 0.52rem !important;
}

.top-panel #waveState {
  font-size: 0.48rem !important;
  line-height: 1 !important;
}

.top-panel .meter {
  height: 5px !important;
}

/* Force the bottom HUD to stay vertically compact across all breakpoints. */
.bottom-panel {
  padding: 0 !important;
  gap: 4px !important;
}

.bottom-panel .skill-bar {
  gap: 6px !important;
}

.bottom-panel .skill-button {
  min-height: 42px !important;
  padding: 6px 10px 6px 34px !important;
  gap: 1px !important;
}

.bottom-panel .skill-hotkey {
  top: 5px !important;
  right: 8px !important;
  font-size: 0.56rem !important;
}

.bottom-panel .skill-icon {
  left: 9px !important;
  width: 16px !important;
  height: 16px !important;
}

.bottom-panel .skill-name {
  font-size: 0.82rem !important;
  line-height: 1 !important;
}

.bottom-panel .skill-meta {
  font-size: 0.62rem !important;
  line-height: 1 !important;
  letter-spacing: 0.06em !important;
}

.bottom-panel .compact-feed {
  min-height: 0 !important;
  padding: 6px 9px !important;
  font-size: 0.78rem !important;
  line-height: 1.15 !important;
}

.bottom-panel .compact-feed::before {
  left: 10px !important;
  font-size: 0.5rem !important;
}

/* Force the game over overlay to stay compact and keep restart visible. */
.gameover-modal {
  width: min(500px, 100%) !important;
  max-height: calc(100dvh - 132px) !important;
  padding: 12px !important;
  gap: 6px !important;
}

.gameover-modal .eyebrow {
  margin-bottom: 2px !important;
  font-size: 0.62rem !important;
}

.gameover-modal h2 {
  font-size: clamp(1.08rem, 0.95vw + 0.9rem, 1.55rem) !important;
  line-height: 1 !important;
}

.gameover-modal .summary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 6px !important;
}

.gameover-modal .summary-grid > div,
.gameover-modal .leaderboard-card {
  min-height: 0 !important;
  padding: 8px 10px !important;
}

.gameover-modal .summary-label {
  font-size: 0.52rem !important;
  letter-spacing: 0.06em !important;
}

.gameover-modal .summary-grid strong,
.gameover-modal .leaderboard-card strong {
  margin-top: 3px !important;
  font-size: 0.94rem !important;
  line-height: 1 !important;
}

.gameover-modal .leaderboard-note,
.gameover-modal .leaderboard-list {
  margin-top: 4px !important;
}

.gameover-modal .leaderboard-note,
.gameover-modal .leaderboard-list li {
  font-size: 0.76rem !important;
  line-height: 1.08 !important;
}

.gameover-modal .leaderboard-list {
  gap: 4px !important;
}

.gameover-modal .restart-button {
  position: sticky;
  bottom: 0;
  z-index: 2;
  width: min(150px, 100%) !important;
  min-width: 0 !important;
  padding: 9px 12px !important;
  font-size: 0.88rem !important;
  justify-self: start !important;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

@media (max-width: 640px) {
  .gameover-modal {
    max-height: calc(100dvh - 148px) !important;
    padding: 10px !important;
  }

  .gameover-modal .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .gameover-modal .summary-grid > div,
  .gameover-modal .leaderboard-card {
    padding: 7px 9px !important;
  }

  .gameover-modal .summary-grid strong,
  .gameover-modal .leaderboard-card strong {
    font-size: 0.88rem !important;
  }

  .gameover-modal .leaderboard-note,
  .gameover-modal .leaderboard-list li {
    font-size: 0.72rem !important;
  }
}
