:root {
  --bg: #9dd7f4;
  --panel: rgba(13, 32, 31, 0.82);
  --panel-2: rgba(30, 58, 52, 0.9);
  --border: rgba(214, 244, 221, 0.18);
  --text: #f2f6ef;
  --muted: #b8c8bb;
  --accent: #f2c84b;
  --good: #93d977;
  --bad: #d27b70;
  --shadow: rgba(0, 0, 0, 0.22);
  --font: "Trebuchet MS", "Segoe UI", sans-serif;

  /* Safe-area insets for notch / home-bar devices */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body,
#app {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.3), transparent 28%),
    linear-gradient(180deg, #bbe7ff 0%, #98d0eb 45%, #7ab0c8 100%);
  font-family: var(--font);
  color: var(--text);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#hud-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  box-shadow: 0 12px 28px var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ── Top Strip ─────────────────────────────────────────────── */

.top-strip {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  z-index: 10;
}

.resource-bar,
.progress-panel {
  pointer-events: auto;
  border-radius: 14px;
  padding: 8px 10px;
  min-height: 48px;
}

.resource-bar {
  min-width: min(420px, 56vw);
}

.progress-panel {
  min-width: min(300px, 42vw);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  flex-wrap: wrap;
}

.resource-grid,
.progress-grid {
  display: grid;
  gap: 6px;
}

.resource-grid {
  grid-template-columns: repeat(8, minmax(34px, 1fr));
}

.progress-grid {
  grid-template-columns: 1fr;
}

.resource-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 5px 6px;
  font-weight: 700;
  min-width: 0;
}

.resource-pill.full {
  background: rgba(242, 200, 75, 0.18);
  outline: 1px solid rgba(242, 200, 75, 0.45);
}

.resource-pill span:first-child {
  font-size: 0.9rem;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  gap: 12px;
  font-size: 0.86rem;
}

.xp-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 5px;
}

.xp-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f2c84b, #ffe490);
  transition: width 180ms ease;
}

/* ── Tool Panel (desktop left rail) ───────────────────────── */

.tool-panel {
  position: absolute;
  left: calc(10px + var(--safe-left));
  top: 82px;
  width: 150px;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  gap: 7px;
  pointer-events: auto;
}

.tool-panel h2,
.build-panel h2,
.info-rail h2,
.status-panel h2,
.inspector-panel h2,
.objective-panel h2 {
  margin: 0 0 4px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

.tool-button,
.build-card {
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.tool-button {
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  text-align: left;
  font-weight: 700;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 6px;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.tool-button:hover {
  transform: translateX(2px);
  border-color: rgba(255, 255, 255, 0.18);
}

.tool-button.active {
  background: rgba(242, 200, 75, 0.2);
  border-color: rgba(242, 200, 75, 0.55);
}

.tool-button em {
  color: var(--accent);
  font-style: normal;
  font-size: 0.74rem;
}

.upgrade-button,
.trade-button,
.reset-button,
.reset-confirm-button,
.reset-cancel-button {
  border: 1px solid rgba(242, 200, 75, 0.32);
  background: rgba(242, 200, 75, 0.16);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  min-height: 44px;
}

.upgrade-button {
  grid-column: 1 / -1;
  border-radius: 8px;
}

/* ── Info Rail (right sidebar) ─────────────────────────────── */

.info-rail {
  position: absolute;
  right: calc(10px + var(--safe-right));
  top: 130px;
  width: 210px;
  border-radius: 12px;
  padding: 8px;
  pointer-events: auto;
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 170px - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.status-panel,
.inspector-panel,
.objective-panel {
  min-width: 0;
}

.status-panel,
.inspector-panel,
.objective-panel {
  border-bottom: 1px solid rgba(214, 244, 221, 0.14);
  padding-bottom: 8px;
}

.status-grid,
.objective-list {
  display: grid;
  gap: 5px;
}

.mini-meter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 8px;
  font-size: 0.72rem;
}

.mini-meter div {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
}

.mini-meter i {
  display: block;
  height: 100%;
  background: #84d37a;
}

.mini-meter.hunger i {
  background: #f2c84b;
}

.mini-meter.temp i {
  background: #44aa88;
}

.upgrade-building-btn {
  border: 1px solid rgba(242, 200, 75, 0.32);
  background: rgba(242, 200, 75, 0.16);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
  padding: 5px 8px;
  margin-top: 4px;
  font-size: 0.72rem;
  min-height: 44px;
}

.status-row,
.objective-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
}

.objective-item {
  justify-content: flex-start;
  align-items: flex-start;
}

.objective-item p,
.inspector-panel p {
  margin: 0;
}

.objective-item.complete {
  color: var(--muted);
  text-decoration: line-through;
}

.objective-item.objective-more span {
  color: var(--muted);
  font-size: 0.68rem;
  font-style: italic;
}

.objective-panel h2 {
  display: flex;
  justify-content: space-between;
}

.objective-panel h2 span {
  color: var(--accent);
}

.inspector-panel {
  display: grid;
  gap: 3px;
  font-size: 0.74rem;
}

.inspector-panel p {
  color: var(--text);
  line-height: 1.25;
}

.crafting-panel {
  display: grid;
  gap: 6px;
}

.craft-list,
.automation-list {
  display: grid;
  gap: 5px;
}

.craft-button {
  border: 1px solid rgba(214, 244, 221, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  display: grid;
  gap: 2px;
  padding: 8px 6px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  min-height: 44px;
}

.craft-button strong {
  font-size: 0.72rem;
}

.craft-button span,
.automation-list p {
  margin: 0;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.15;
}

.craft-button.disabled {
  opacity: 0.42;
  cursor: default;
}

/* ── Build Panel (bottom) ──────────────────────────────────── */

.build-panel {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100% - 360px));
  border-radius: 14px;
  padding: 8px;
  pointer-events: auto;
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 7px;
}

.build-card {
  min-height: 70px;
  padding: 7px;
  text-align: left;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.build-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.18);
}

.build-card.active {
  border-color: rgba(147, 217, 119, 0.7);
  background: rgba(147, 217, 119, 0.16);
}

.build-card.locked,
.build-card.disabled {
  opacity: 0.45;
  cursor: default;
}

.build-card h3,
.build-card p {
  margin: 0;
}

.build-card h3 {
  font-size: 0.82rem;
  margin-bottom: 3px;
}

.cost-row {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.build-card small {
  display: none;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.18;
}

.build-card:hover small,
.build-card.active small {
  display: block;
}

.trade-button {
  width: 100%;
  margin-top: 8px;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.78rem;
}

.left-rail .reset-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

/* ── Map / Help hint buttons ───────────────────────────────── */

.map-hint-button {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
  user-select: none;
  white-space: nowrap;
  min-height: 44px;
}

.map-hint-button:hover {
  color: var(--text);
  border-color: rgba(242, 200, 75, 0.45);
}

.map-hint-button kbd {
  background: rgba(242, 200, 75, 0.18);
  border: 1px solid rgba(242, 200, 75, 0.4);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--accent);
}

.reset-button,
.reset-confirm-button,
.reset-cancel-button {
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

.reset-confirm-button {
  background: rgba(147, 217, 119, 0.18);
  border-color: rgba(147, 217, 119, 0.45);
}

.reset-cancel-button {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
}

/* ── Overlays ──────────────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 12, 16, 0.6);
  pointer-events: auto;
  padding: 16px;
}

.overlay-card {
  width: min(520px, calc(100% - 32px));
  padding: 28px;
  border-radius: 28px;
  text-align: center;
  background:
    radial-gradient(circle at top, rgba(255, 228, 144, 0.16), transparent 36%),
    linear-gradient(180deg, rgba(31, 58, 54, 0.96), rgba(17, 31, 28, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.3);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.overlay-card h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 5vw, 3rem);
}

.overlay-card p {
  color: var(--muted);
  line-height: 1.5;
}

.overlay-button,
.overlay-card button {
  margin-top: 16px;
  padding: 14px 20px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(90deg, #f2c84b, #ffe490);
  color: #243229;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
}

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

.overlay-actions .overlay-button {
  margin-top: 0;
}

.overlay-button.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

/* ── Action Bar ────────────────────────────────────────────── */

.action-bar {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  width: 120px;
  pointer-events: none;
  z-index: 15;
}

.action-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.action-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f2c84b, #ffe490);
  transition: width 50ms linear;
}

/* ── Region Transition ─────────────────────────────────────── */

.region-transition {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(127, 143, 154, 0.1), rgba(25, 39, 49, 0.9));
  opacity: 0;
  transition: opacity 260ms ease;
}

.region-transition.active {
  opacity: 1;
}

/* ── Map Overlay ─────────────────────────────────────────────── */

.map-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 12, 16, 0.72);
  pointer-events: auto;
  z-index: 50;
  padding: 16px;
}

.map-card {
  width: min(600px, 100%);
  max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom));
  padding: 24px 28px;
  border-radius: 20px;
  background:
    radial-gradient(circle at top, rgba(147, 217, 119, 0.10), transparent 36%),
    linear-gradient(180deg, rgba(17, 36, 32, 0.97), rgba(9, 20, 17, 0.99));
  border: 1px solid rgba(147, 217, 119, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  overscroll-behavior: contain;
}

.map-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.map-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  flex: 1;
}

.map-region-label {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 700;
}

.map-close {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 140ms ease;
  min-height: 44px;
}

.map-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.map-legend {
  display: flex;
  gap: 16px;
  font-size: 0.72rem;
  color: var(--muted);
}

.map-legend-item.current {
  color: #f2c84b;
}

.map-legend-item.visited {
  color: #93d977;
}

.map-grid {
  display: grid;
  gap: 3px;
  overflow: auto;
  max-height: 420px;
}

.map-cell {
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.map-cell.visited {
  background: rgba(147, 217, 119, 0.18);
  border-color: rgba(147, 217, 119, 0.35);
}

.map-cell.current {
  background: rgba(242, 200, 75, 0.28);
  border-color: rgba(242, 200, 75, 0.7);
  box-shadow: 0 0 10px rgba(242, 200, 75, 0.3);
}

.map-cell-label {
  font-size: 0.58rem;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  line-height: 1;
  padding: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-cell.current .map-cell-label {
  font-size: 1rem;
  color: var(--accent);
}

.map-hint {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}

/* ── Info Rail Toggle ──────────────────────────────────────── */

.info-rail-toggle {
  display: none;
}

/* ── Mobile toolbar (hidden on desktop) ───────────────────── */

.mobile-toolbar {
  display: none;
}

/* ── Virtual D-pad (hidden on desktop) ────────────────────── */

.dpad {
  display: none;
}

/* ══════════════════════════════════════════════════════════════
   TABLET  ≤ 900px
══════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  .resource-grid {
    grid-template-columns: repeat(4, minmax(42px, 1fr));
  }

  .left-rail {
    width: 190px;
  }

  .info-rail {
    width: 190px;
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE  ≤ 680px
   Layout:
     - Top strip stacks vertically (full width)
     - Tool panel collapses → replaced by #mobile-toolbar at bottom
     - Info-rail → slide-up drawer
     - Build panel → narrow bottom sheet above toolbar
     - D-pad shown bottom-left
══════════════════════════════════════════════════════════════ */

@media (max-width: 680px) {
  /* Top strip full-width, stacked */
  .top-strip {
    left: calc(8px + var(--safe-left));
    right: calc(8px + var(--safe-right));
    top: calc(8px + var(--safe-top));
    flex-direction: column;
    gap: 6px;
  }

  .resource-bar {
    width: 100%;
    min-width: 0;
  }

  .progress-panel {
    width: 100%;
    min-width: 0;
  }

  /* Compact resource grid: single scrollable row */
  .resource-grid {
    grid-template-columns: repeat(8, minmax(38px, 1fr));
    gap: 4px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .resource-pill {
    min-width: 38px;
  }

  /* Hide kbd hints on mobile – buttons are already obvious */
  .map-hint-button kbd {
    display: none;
  }
  .map-hint-button .btn-label {
    display: none;
  }
  .map-hint-button {
    padding: 8px 10px;
    font-size: 1rem;
    min-width: 44px;
    justify-content: center;
  }

  /* Reset button text shortening */
  .reset-button .btn-label {
    display: none;
  }
  .reset-button::after {
    content: "↺";
  }

  /* Hide the desktop tool panel */
  .tool-panel {
    display: none;
  }

  /* Mobile toolbar: horizontal pill bar pinned above bottom safe zone */
  .mobile-toolbar {
    display: flex;
    position: fixed;
    bottom: calc(var(--safe-bottom) + 8px);
    left: calc(var(--safe-left) + 8px);
    right: calc(var(--safe-right) + 8px);
    z-index: 25;
    gap: 6px;
    pointer-events: auto;
    padding: 6px 8px;
    border-radius: 16px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    box-shadow: 0 12px 28px var(--shadow);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow-x: auto;
    overscroll-behavior: contain;
  }

  /* Mobile toolbar tool buttons: compact icon+label */
  .mobile-toolbar .tool-button {
    flex: 1 0 52px;
    min-width: 52px;
    min-height: 52px;
    /* Override the desktop grid layout completely */
    display: flex !important;
    grid-template-columns: unset;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 10px;
    font-size: 0.65rem;
    text-align: center;
    width: auto;
  }

  .mobile-toolbar .tool-button span:first-child {
    font-size: 1.4rem;
    line-height: 1;
  }

  .mobile-toolbar .tool-button strong {
    font-size: 0.6rem;
    font-weight: 700;
  }

  .mobile-toolbar .tool-button em {
    font-size: 0.55rem;
  }

  /* Upgrade button inside mobile toolbar */
  .mobile-toolbar .upgrade-button {
    flex: 1 0 60px;
    min-height: 52px;
    border-radius: 10px;
    font-size: 0.65rem;
    padding: 6px 4px;
    grid-column: unset;
    white-space: nowrap;
  }

  /* Info rail: slide-up drawer */
  .info-rail {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    max-height: 55vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 20px 20px 0 0;
    padding: 12px 16px calc(16px + var(--safe-bottom));
    transform: translateY(100%);
    transition: transform 240ms ease;
    z-index: 30;
    /* keep the panel gradient */
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
    border: 1px solid var(--border);
    box-shadow: 0 -8px 28px var(--shadow);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .info-rail.open {
    display: grid;
    transform: translateY(0);
    transition: transform 240ms ease;
  }

  /* Toggle button for info rail */
  .info-rail-toggle {
    display: block;
    position: fixed;
    bottom: calc(var(--safe-bottom) + 72px); /* above mobile-toolbar */
    right: calc(var(--safe-right) + 14px);
    z-index: 31;
    background: rgba(13, 32, 31, 0.88);
    border: 1px solid rgba(214, 244, 221, 0.22);
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 8px 16px;
    min-height: 44px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: auto;
  }

  /* Build panel: bottom sheet sitting above mobile-toolbar */
  .build-panel {
    left: calc(8px + var(--safe-left)) !important;
    right: calc(8px + var(--safe-right));
    bottom: calc(var(--safe-bottom) + 76px); /* above toolbar */
    width: auto !important;
    transform: none !important;
    max-height: 36vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 14px 14px 8px 8px;
  }

  /* Build grid: 2-up on narrow screens */
  .build-grid {
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 6px;
  }

  /* Action bar: sit above mobile toolbar */
  .action-bar {
    bottom: calc(var(--safe-bottom) + 80px);
  }

  /* D-pad: bottom-left, above toolbar */
  .dpad {
    display: grid;
    grid-template-areas:
      ".    up   ."
      "left .    right"
      ".    down .";
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 4px;
    position: fixed;
    left: calc(var(--safe-left) + 16px);
    bottom: calc(var(--safe-bottom) + 76px);
    z-index: 26;
    pointer-events: auto;
  }

  .dpad-btn {
    background: rgba(13, 32, 31, 0.80);
    border: 1px solid rgba(214, 244, 221, 0.22);
    color: var(--text);
    font-size: 1.1rem;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 100%;
    height: 100%;
    transition: background 100ms ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .dpad-btn:active {
    background: rgba(242, 200, 75, 0.22);
    border-color: rgba(242, 200, 75, 0.55);
  }

  .dpad-up    { grid-area: up; }
  .dpad-left  { grid-area: left; }
  .dpad-right { grid-area: right; }
  .dpad-down  { grid-area: down; }
}

/* ══════════════════════════════════════════════════════════════
   SHORT SCREENS  ≤ 620px height
══════════════════════════════════════════════════════════════ */

@media (max-height: 620px) {
  .build-panel {
    max-height: 30vh;
    overflow-y: auto;
  }

  .info-rail {
    max-height: 45vh;
  }
}
