#ui-root {
  --pf-panel: #11151c;
  --pf-box: #151a22;
  --pf-card: #1c222c;
  --pf-card-hover: #20262f;
  --pf-border: #242a34;
  --pf-line: #1d222b;
  --pf-text: #e6e9ef;
  --pf-muted: #8b93a1;
  --pf-cyan: #5fcfe4;
  --pf-gold: #f2c867;
  --pf-green: #6fdca5;
  --pf-red: #f38a9a;
  --pf-radius: 2px;
  color: var(--pf-text);
  font-size: 13px;
  touch-action: pan-y;
}

#ui-root [hidden] {
  display: none !important;
}

#ui-root :where(button, select) {
  font: inherit;
  color: inherit;
  background: var(--pf-card);
  border: 1px solid transparent;
  border-radius: var(--pf-radius);
}

#ui-root button {
  cursor: pointer;
  transition: border-color 140ms, background-color 140ms, box-shadow 140ms, opacity 140ms;
}

#ui-root button:hover:not(:disabled),
#ui-root select:hover {
  background: var(--pf-card-hover);
}

#ui-root :focus-visible {
  outline: 2px solid var(--pf-cyan);
  outline-offset: 2px;
}

#ui-root button:disabled {
  cursor: default;
  opacity: 0.55;
}

#ui-root button[aria-pressed="true"] {
  border-color: transparent;
  background: color-mix(in srgb, var(--pf-cyan) 16%, var(--pf-card));
  color: var(--pf-cyan);
}

#ui-root button.pf-primary {
  color: #0b1a20;
  border-color: transparent;
  background: var(--pf-cyan);
  font-weight: 700;
}

#ui-root button.pf-primary:hover:not(:disabled) {
  background: #7ddbec;
}

#ui-root kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border: 1px solid #3c4c65;
  border-radius: 2px;
  background: var(--pf-panel);
  color: #c2cfe3;
  font: 600 10px/16px system-ui, sans-serif;
  text-align: center;
}

.pf-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  vertical-align: middle;
}

.pf-coin {
  display: inline-block;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border: 0;
  border-radius: 1px;
  background: var(--pf-gold);
}

.pf-logo {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  aspect-ratio: 1;
  transform: rotate(45deg);
  border: 1px solid #a6edff;
  border-radius: 2px;
  background: var(--pf-cyan);
}

.pf-logo::after {
  position: absolute;
  inset: 22%;
  border: 0;
  border-radius: 1px;
  content: "";
}

#pf-hud {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.5vw, 22px);
  height: var(--top-h);
  padding: var(--safe-top) max(12px, var(--safe-right)) 0 max(12px, var(--safe-left));
  border-bottom: 1px solid var(--pf-line);
  background: var(--pf-panel);
}

.pf-wordmark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #e5f4ff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.pf-resources,
.pf-controls {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 7px;
  white-space: nowrap;
}

.pf-resources {
  gap: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pf-coins,
.pf-lives,
.pf-price {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pf-coins,
.pf-price {
  color: var(--pf-gold);
}

.pf-lives {
  color: var(--pf-red);
}

.pf-lives .pf-icon {
  width: 14px;
  height: 14px;
}

.pf-wave-stat {
  color: #e3eaff;
}

.pf-wave-preview {
  flex: 0 1 auto;
  min-width: 0;
  margin-right: auto;
  overflow: hidden;
  color: var(--pf-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  padding: 0 5px;
  min-height: 34px;
}

#ui-root button.pf-wave-preview { background: transparent; border-color: transparent; }
#pf-wave-summary, #pf-menu-wave { display: none; }

.pf-controls button,
.pf-secondary-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 34px;
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
}

#ui-root #pf-next-wave.is-early {
  color: var(--pf-gold);
  border-color: transparent;
  color: #1a1408;
  background: var(--pf-gold);
}

#ui-root #pf-next-wave.is-early:hover {
  background: #f6d688;
}

#pf-panel {
  position: fixed;
  z-index: 9;
  inset: var(--top-h) 0 var(--safe-bottom) auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: var(--panel-w);
  min-width: 0;
  padding: 9px max(9px, var(--safe-right)) 9px 9px;
  border-left: 1px solid var(--pf-line);
  background: var(--pf-panel);
}

.pf-section {
  min-height: 0;
  padding: 9px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-box);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #394e6c var(--pf-panel);
}

.pf-section[data-section="build"],
.pf-section[data-section="gems"] {
  flex-shrink: 0;
}

.pf-section[data-section="build"] { order: -2; }
.pf-section[data-section="gems"] { order: 1; }

.pf-section h2 {
  margin: 0 0 6px;
  color: var(--pf-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pf-tabs {
  order: -1;
  display: flex;
  gap: 5px;
}

.pf-tabs button {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  min-height: 34px;
  padding: 0 4px;
  color: #bdcee8;
  font-weight: 700;
}

#ui-root .pf-tabs button[aria-expanded="true"] {
  border-color: transparent;
  background: color-mix(in srgb, var(--pf-cyan) 16%, var(--pf-card));
  color: var(--pf-cyan);
}

.pf-build-options,
.pf-shop-levels,
.pf-inventory {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.pf-shop-levels {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.pf-build-card,
.pf-shop-card {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  min-width: 0;
  padding: 7px 2px;
}

.pf-build-card {
  min-height: 57px;
  font-size: 12px;
}

.pf-build-card.is-unaffordable:not(:disabled) {
  opacity: 0.7;
}

.pf-build-card .pf-icon {
  width: 19px;
  height: 19px;
  color: #9dd5f2;
}

.pf-build-card > kbd {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 13px;
  padding: 0 2px;
  font-size: 9px;
  line-height: 12px;
}

.pf-price {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pf-price .pf-coin {
  width: 6px;
  height: 6px;
}

.pf-type-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 5px;
}

#ui-root button.pf-type-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 32px;
  padding: 0 4px;
  border-radius: 2px;
  font-size: 12px;
  font-weight: 700;
}

.pf-type-choice .pf-icon {
  width: 20px;
  height: 20px;
  color: var(--gem-color, var(--pf-cyan));
}

.pf-shop-type {
  margin: 0 0 6px;
  color: var(--pf-muted);
  font-size: 12px;
}

.pf-shop-card canvas {
  display: block;
  width: 36px;
  height: 36px;
}

.pf-shop-card.is-locked {
  filter: grayscale(0.78);
}

.pf-shop-card.is-locked .pf-price {
  color: #c3cee0;
}

.pf-shop-card.is-locked .pf-coin {
  display: none;
}

#ui-root .pf-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  height: 39px;
  padding: 0;
  border-radius: 2px;
  background: var(--pf-card);
}

.pf-slot::before {
  position: absolute;
  inset: 5px;
  border: 0;
  border-radius: 2px;
  content: "";
  pointer-events: none;
}

#ui-root .pf-slot.has-gem {
  touch-action: none;
  background: color-mix(in srgb, var(--gem-color) 14%, var(--pf-card));
}

.pf-slot canvas {
  position: relative;
  width: 39px;
  max-width: 100%;
  aspect-ratio: 1;
  pointer-events: none;
}

.pf-level-badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: grid;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  place-items: center;
  border: 1px solid #61809e;
  border-radius: 2px;
  background: var(--pf-panel);
  color: #deecff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

#ui-root .pf-slot.is-source {
  opacity: 0.36;
}

#ui-root .pf-slot.is-merge-target {
  border-color: #68da9e;
  box-shadow: none;
}

#ui-root .pf-slot.is-empty-target {
  border-color: var(--pf-muted);
  background: var(--pf-card-hover);
}

.pf-slot.is-merged::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #97f8cb;
  animation: pf-merge-flash 420ms ease-out both;
  content: "";
  pointer-events: none;
}

.pf-slot.is-merged canvas {
  animation: pf-gem-pop 420ms ease-out;
}

@keyframes pf-merge-flash {
  from { opacity: 0.65; }
  to { opacity: 0; }
}

@keyframes pf-gem-pop {
  0%, 100% { scale: 1; }
  35% { scale: 1.24; }
}

.pf-inventory-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.pf-inventory-actions button,
.pf-trash {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 3px 5px;
  font-size: 12px;
  font-weight: 650;
}

.pf-trash {
  border: 1px dashed var(--pf-border);
  border-radius: var(--pf-radius);
  color: var(--pf-muted);
}

.pf-trash .pf-icon {
  width: 14px;
  height: 14px;
}

.pf-trash.is-ready {
  border-color: #9c7655;
  background: #34231d;
  color: var(--pf-gold);
}

.pf-trash.is-over {
  border-color: var(--pf-gold);
  box-shadow: none;
}

#pf-info h3 {
  margin: 0 0 6px;
  color: #e2ecfd;
  font-size: 14px;
  line-height: 1.3;
}

#pf-info .pf-info-action + h3 {
  margin-top: 8px;
}

.pf-structure-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

#pf-info .pf-structure-header h3, .pf-structure-header .pf-meter { margin: 0; }

.pf-info-note,
.pf-ability {
  margin: 4px 0 0;
  color: var(--pf-muted);
  font-size: 12px;
  line-height: 1.45;
}

.pf-meter {
  --pf-meter-color: var(--pf-cyan);
  display: grid;
  gap: 4px;
  margin-top: 5px;
}

.pf-meter-health { --pf-meter-color: var(--pf-green); }
.pf-meter-charge { --pf-meter-color: var(--pf-gold); }

.pf-meter-caption {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--pf-meter-color);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pf-meter progress {
  appearance: none;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 1px solid var(--pf-border);
  border-radius: 2px;
  background: var(--pf-panel);
}

.pf-meter progress::-webkit-progress-bar {
  background: var(--pf-panel);
}

.pf-meter progress::-webkit-progress-value {
  background: var(--pf-meter-color);
}

.pf-meter progress::-moz-progress-bar {
  background: var(--pf-meter-color);
}

.pf-ritual-warning { color: var(--pf-gold); }

.pf-ritual-defense {
  color: var(--pf-red);
  font-weight: 700;
  animation: pf-ritual-pulse 1.4s ease-in-out infinite;
}

@keyframes pf-ritual-pulse {
  50% { opacity: 0.65; }
}

.pf-ability strong {
  display: block;
  margin-bottom: 1px;
  color: var(--pf-text);
}

.pf-gem-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 7px;
  padding: 0;
  list-style: none;
}

.pf-gem-stats li {
  padding: 3px 6px;
  border: 0;
  border-radius: 2px;
  background: var(--pf-card);
  font-size: 11px;
}

.pf-target-mode,
.pf-info-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.pf-target-mode {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.pf-target-mode button {
  min-height: 30px;
  padding: 0 4px;
}

.pf-sell-action { margin-top: 12px; }

.pf-info-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  gap: 8px;
  margin-top: 10px;
}

.pf-info-footer > .pf-sell-action { margin-top: 0; }
.pf-info-footer:has(details[open]) { grid-template-columns: 1fr; }

.pf-abilities summary {
  width: fit-content;
  padding: 5px 0;
  color: var(--pf-cyan);
  cursor: pointer;
}

.pf-info-action {
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
}

.pf-info-action.pf-primary {
  justify-content: center;
}

#pf-map-ui {
  position: fixed;
  z-index: 8;
  inset: var(--top-h) var(--panel-w) var(--dock-h) 0;
  pointer-events: none;
}

#pf-map-ui button,
#minimap {
  pointer-events: auto;
}

#pf-map-tools {
  position: absolute;
  right: max(10px, var(--safe-right));
  bottom: max(10px, var(--safe-bottom));
  display: flex;
  align-items: end;
  gap: 7px;
}

#pf-center,
#pf-cancel-build {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  background: var(--pf-panel);
}

#pf-cancel-build {
  position: absolute;
  top: 8px;
  right: max(10px, var(--safe-right));
}

#minimap {
  display: block;
  width: 128px;
  height: 128px;
  border-radius: 2px;
  outline: 1px solid var(--pf-border);
  background: var(--pf-panel);
  background: var(--pf-panel);
  cursor: crosshair;
  touch-action: none;
}

#pf-coach {
  position: absolute;
  bottom: max(10px, var(--safe-bottom));
  left: max(10px, var(--safe-left));
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(390px, calc(100% - 195px));
  padding: 5px 5px 5px 10px;
  border: 1px solid var(--pf-border);
  border-radius: 2px;
  background: var(--pf-panel);
  background: var(--pf-panel);
}

#pf-coach p { margin: 0; }
#pf-coach strong {
  display: block;
  margin-bottom: 2px;
  color: var(--pf-cyan);
  font-size: 12px;
}

#pf-coach button {
  min-width: 40px;
  min-height: 32px;
  margin-left: auto;
}

#pf-toasts {
  position: fixed;
  z-index: 8;
  inset: calc(var(--top-h) + 8px) var(--panel-w) auto 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: 4px;
  padding-inline: max(8px, var(--safe-left)) max(8px, var(--safe-right));
  pointer-events: none;
}

.pf-toast {
  --toast-color: var(--pf-cyan);
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: fit-content;
  max-width: min(100%, 320px);
  padding: 5px 9px;
  border: 0;
  border-left: 3px solid var(--toast-color);
  border-radius: 2px;
  background: var(--pf-card);
  color: var(--pf-text);
  font-size: 12px;
  font-weight: 600;
  animation: pf-toast 2500ms both;
}

.pf-toast span {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.pf-toast strong {
  flex: none;
  color: var(--toast-color);
}

.pf-toast-good { --toast-color: var(--pf-green); }
.pf-toast-warn { --toast-color: var(--pf-gold); }
.pf-toast-bad { --toast-color: var(--pf-red); }

@keyframes pf-toast {
  0% { opacity: 0; translate: 0 -7px; }
  7%, 90% { opacity: 1; translate: 0 0; }
  100% { opacity: 0; translate: 0 -4px; }
}

.pf-drag-ghost {
  position: fixed;
  z-index: 40;
  width: 56px;
  height: 56px;
  translate: -50% -50%;
  scale: 1.12;
  filter: drop-shadow(0 0 9px var(--gem-color));
  pointer-events: none;
  animation: pf-pickup 120ms ease-out;
}

.pf-drag-ghost.is-touch { translate: -50% calc(-50% - 42px); }

.pf-drag-ghost canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.pf-drag-hint {
  position: absolute;
  bottom: 100%;
  left: 50%;
  translate: -50%;
  padding: 2px 6px;
  border: 1px solid #967041;
  border-radius: 2px;
  background: var(--pf-card);
  color: var(--pf-gold);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

@keyframes pf-pickup {
  from { scale: 0.85; }
  to { scale: 1.12; }
}

#pf-overlay {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: safe center;
  padding: max(12px, var(--safe-top)) max(12px, var(--safe-right))
    max(12px, var(--safe-bottom)) max(12px, var(--safe-left));
  overflow: auto;
  overscroll-behavior: contain;
  background: #0c0f14e6;
}

.pf-dialog {
  width: min(100%, 490px);
  padding: clamp(15px, 4vw, 30px);
  border: 1px solid var(--pf-border);
  border-radius: 2px;
  background: var(--pf-panel);
  text-align: center;
}

.pf-dialog > .pf-logo {
  width: 32px;
  margin: 3px auto 8px;
}

.pf-dialog h1 {
  margin: 0 0 10px;
  color: #e0f5ff;
  font-size: clamp(25px, 6vw, 42px);
  font-weight: 850;
  line-height: 1.08;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pf-pitch {
  margin: 0 auto 15px;
  color: #c3cfe3;
  line-height: 1.55;
}

.pf-help {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-card);
  color: #bdcbe0;
  font-size: 12px;
  list-style: none;
  text-align: left;
}

.pf-help li {
  display: grid;
  grid-template-columns: minmax(80px, 102px) 1fr;
  align-items: center;
  gap: 8px;
}

.pf-overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.pf-overlay-actions button {
  min-width: 106px;
  min-height: 44px;
  padding: 7px 12px;
  font-weight: 700;
}

.pf-gameover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 15px 0 0;
}

.pf-gameover-stats > div {
  padding: 9px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-card);
}

.pf-gameover-stats dt {
  color: var(--pf-muted);
}

.pf-gameover-stats dd {
  margin: 3px 0 0;
  color: var(--pf-cyan);
  font-size: 24px;
  font-weight: 750;
}

.pf-essentials {
  margin: 14px 0 5px;
  color: var(--pf-muted);
  font-size: 12px;
}

.pf-controls-help summary {
  width: fit-content;
  margin: 0 auto;
  padding: 6px;
  color: var(--pf-cyan);
  cursor: pointer;
}

.pf-controls-help h2 {
  margin: 10px 0 6px;
  font-size: 13px;
  text-align: left;
}

.pf-hud-popover,
.pf-secondary-controls {
  position: absolute;
  top: calc(100% + 6px);
  right: max(8px, var(--safe-right));
  width: min(280px, calc(100% - 16px));
  padding: 8px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-panel);
}

.pf-hud-popover { line-height: 1.4; }

.pf-secondary-controls {
  display: grid;
  gap: 5px;
}

.pf-secondary-controls button {
  justify-content: start;
  gap: 8px;
}

.pf-secondary-controls .pf-price { margin-left: auto; }

@media (orientation: portrait) and (max-width: 1024px), (max-width: 699px) {
  #pf-panel {
    inset: auto 0 0;
    width: auto;
    max-height: min(52dvh, 440px);
    padding: 6px max(8px, var(--safe-right)) calc(6px + var(--safe-bottom)) max(8px, var(--safe-left));
    border-top: 1px solid var(--pf-line);
    border-left: 0;
    gap: 5px;
  }

  #pf-panel .pf-section { order: 0; flex-shrink: 1; }
  #pf-panel .pf-tabs { order: 1; flex-shrink: 0; }
  #pf-panel .pf-section h2 { display: none; }
  #pf-panel .pf-section { padding: 4px; }
  #pf-build-pane.pf-section { border: 0; padding: 0; background: none; }
  #pf-gems-pane.pf-section { border: 0; background: none; }
  #pf-info { padding: 4px 5px; }
  #pf-map-tools { bottom: 8px; }
  #pf-coach { bottom: 8px; }
}

@media (min-width: 600px) and (max-width: 1024px) and (orientation: portrait) {
  #pf-panel .pf-inventory { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  #pf-shop-pane, #pf-info { width: min(100%, 610px); margin-inline: auto; }
}

@media (max-width: 699px) {
  #pf-hud {
    display: grid;
    grid-template: 32px 44px / auto minmax(0, 1fr);
    gap: 0 8px;
    padding: var(--safe-top) max(8px, var(--safe-right)) 3px max(8px, var(--safe-left));
  }

  .pf-wordmark { display: none; }
  .pf-resources { gap: 9px; }
  #pf-wave-preview { display: none; }
  #pf-wave-summary { display: block; min-height: 0; }
  #pf-menu-wave { display: block; margin: 0 0 4px; color: var(--pf-muted); }
  .pf-controls { grid-column: 1 / -1; gap: 5px; }
  .pf-controls button { min-width: 44px; min-height: 44px; padding: 0 6px; }
  #pf-next-wave { flex: 1; }
  #pf-toasts { padding-right: max(8px, var(--safe-right)); }
  .pf-toast { max-width: min(100%, 260px); }
  #minimap { width: 72px; height: 72px; }
  #pf-coach { max-width: calc(100% - 146px); font-size: 12px; }
  #pf-cancel-build { top: auto; bottom: 86px; }
}

@media (max-width: 499px) {
  #pf-hud { gap: 0 4px; }
  #ui-root .pf-wave-preview { padding-left: 3px; }
  .pf-build-card { min-height: 57px; padding-block: 3px; gap: 1px; }
  .pf-build-card .pf-icon { width: 17px; height: 17px; }
  .pf-shop-levels { gap: 4px; }
  #pf-info .pf-gem-stats { gap: 3px; }
  #pf-info .pf-gem-stats li { padding: 2px 4px; }
  .pf-overlay-help { font-size: 12px; }
}

@media (min-width: 700px) and (max-height: 499px) and (orientation: landscape) {
  #pf-panel { gap: 5px; padding-block: 5px; }
  #pf-panel .pf-section { order: 0; flex-shrink: 1; }
  #pf-panel .pf-section h2 { display: none; }
  #pf-panel .pf-tabs { flex-shrink: 0; }
  #pf-panel .pf-section { padding: 5px; }
  #minimap { width: 80px; height: 80px; }
  #pf-coach { max-width: calc(100% - 156px); }
  .pf-wordmark { display: none; }
}

@media (pointer: coarse) {
  #ui-root button,
  #ui-root summary {
    min-width: 44px;
    min-height: 44px;
  }

  #ui-root button.pf-wave-preview { min-width: 44px; min-height: 44px; }
  #ui-root .pf-type-choice,
  #ui-root .pf-slot { height: 44px; }

  #ui-root .pf-build-card > kbd,
  #ui-root .pf-inventory-actions kbd { display: none; }
  .pf-price,
  .pf-meter-caption,
  .pf-gem-stats li,
  .pf-level-badge,
  #ui-root kbd { font-size: 12px; }
  .pf-trash { min-height: 44px; }

  #ui-root summary {
    padding-block: 0;
    align-content: center;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (min-height: 500px) and (min-width: 700px) {
  #pf-panel .pf-inventory { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (pointer: fine) and (min-width: 1025px) and (max-height: 760px) {
  #pf-panel .pf-inventory { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  #ui-root button {
    transition: none;
  }

  .pf-drag-ghost,
  .pf-ritual-defense,
  .pf-toast,
  .pf-slot.is-merged canvas {
    animation: none;
  }
}

.pf-next-unlock {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--pf-muted);
  text-align: center;
}

.pf-smaller-levels {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--pf-muted);
}
.pf-smaller-levels:empty { display: none; }
.pf-level-chip {
  min-width: 30px;
  padding: 3px 7px;
  border-radius: 2px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.7);
  color: #cbd5e1;
  font: 600 12px/1.2 system-ui, sans-serif;
  cursor: pointer;
}
.pf-level-chip:hover:not(:disabled) { border-color: rgba(103, 232, 249, 0.6); color: #ecfeff; }
.pf-level-chip:disabled { opacity: 0.4; cursor: not-allowed; }

/* Tap-to-place: picked gem */
#ui-root .pf-slot.is-picked {
  outline: 2px solid var(--gem-color, var(--pf-gold));
  outline-offset: 1px;
}
@keyframes pf-picked-pulse { from { transform: translateY(0); } to { transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { #ui-root .pf-slot.is-picked { animation: none; } }
#pf-pick-hint {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 24px);
  padding: 4px 4px 4px 12px;
  border: 1px solid #f4cd7699;
  border-radius: 2px;
  background: var(--pf-panel);
  color: var(--pf-text);
  font-size: 12px;
  pointer-events: auto;
}
#pf-pick-hint[hidden] { display: none; }
#pf-pick-hint button { min-width: 36px; min-height: 36px; padding: 0; display: inline-grid; place-items: center; }
.pf-arm-action { border-color: #86edb7aa !important; }

/* Selected-structure chip: quick action without leaving the Shop or Gems */
#pf-sel-chip {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 20px);
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--pf-border);
  border-radius: 2px;
  background: var(--pf-panel);
  color: var(--pf-text);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: auto;
}
#pf-sel-chip[hidden], #pf-sel-chip [hidden] { display: none; }
#pf-sel-chip .pf-sel-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
#pf-sel-chip button { min-height: 36px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px; }
#pf-sel-chip .pf-sel-action { border-color: #86edb7aa; }
#pf-sel-chip .pf-sel-close { min-width: 36px; padding: 0; justify-content: center; }

/* Floating Repair All above the centre button */
.pf-map-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
#pf-quick-repair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px;
  border-color: #86edb7aa;
  background: var(--pf-panel);
  white-space: nowrap;
}
#pf-quick-repair[hidden] { display: none; }
#pf-quick-repair svg { color: var(--pf-green); }
#pf-quick-repair.is-urgent:not(:disabled) { border-color: #ff9aab; animation: pf-repair-pulse 1s ease-in-out infinite alternate; }
#pf-quick-repair.is-urgent svg { color: var(--pf-red); }
@keyframes pf-repair-pulse { from { opacity: 1; } to { opacity: 0.7; } }
@media (prefers-reduced-motion: reduce) { #pf-quick-repair.is-urgent { animation: none; } }
@media (max-width: 499px) { #pf-quick-repair .pf-quick-all { display: none; } }

/* Boxed groupings: flat 1px frames that separate areas without depth */
.pf-resources > span {
  padding: 4px 9px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-box);
}
.pf-resources { gap: 6px; }
#pf-wave-preview, #pf-wave-summary {
  padding: 4px 9px;
  border: 1px solid var(--pf-border);
  border-radius: var(--pf-radius);
  background: var(--pf-box);
}
.pf-structure-header {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--pf-border);
  margin-bottom: 8px;
}
.pf-inventory-actions {
  padding-top: 8px;
  border-top: 1px solid var(--pf-border);
}
.pf-section h2 {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--pf-border);
  margin-bottom: 8px;
}
#pf-coach, #pf-sel-chip, #pf-pick-hint, .pf-toast { border: 1px solid var(--pf-border); }
.pf-toast { border-left: 3px solid var(--toast-color); }
/* Mid-size screens: keep the logo mark, drop the wordmark text so the HUD fits */
@media (max-width: 1100px) {
  .pf-wordmark { font-size: 0; gap: 0; }
}

/* Keep notifications clear of the selection bar / picked-gem hint at the top of the map */
#ui-root.has-chip #pf-toasts { top: calc(var(--top-h) + 60px); }

/* Phone HUD: the wave summary truncates instead of running off-screen */
#pf-wave-summary { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
