/*
 * UI overlay shell — Overworld + Match-3.
 * Layers: background → Phaser → #ui-overlay
 */

.ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e8eefc;
  -webkit-user-select: none;
  user-select: none;
}

.ui-overlay.is-hidden {
  display: none !important;
}

/* Match-3: minimal chrome — no extra band padding */
.ui-overlay.ui-overlay--match3 .ui-top {
  padding: 4px 8px 2px;
  min-height: 40px;
}
.ui-overlay.ui-overlay--match3 .ui-bottom {
  padding: 2px 8px 6px;
  min-height: 8px;
}
.ui-overlay.ui-overlay--match3 .ui-mid {
  padding: 0;
}
.ui-overlay.ui-overlay--match3 .ui-center-stage {
  margin: 0 4px;
  border-radius: 12px;
  background: transparent;
  border-color: rgba(107, 122, 148, 0.2);
}

.ui-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 8px 12px 6px;
  pointer-events: none;
}

.ui-top-left,
.ui-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  pointer-events: none;
  flex-wrap: wrap;
}

.ui-top-left { justify-content: flex-start; }
.ui-top-right { justify-content: flex-end; }

.ui-mid {
  display: grid;
  grid-template-columns: 8px 1fr 8px;
  min-height: 0;
  pointer-events: none;
}

@media (min-width: 420px) {
  .ui-mid {
    grid-template-columns: 12px 1fr 12px;
  }
}

.ui-side {
  display: grid;
  grid-template-rows: 1fr 1fr;
  pointer-events: none;
}

.ui-side-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border-radius: 2px;
  background: linear-gradient(
    180deg,
    rgba(154, 171, 204, 0.2) 0%,
    rgba(154, 171, 204, 0.05) 50%,
    rgba(154, 171, 204, 0.2) 100%
  );
  opacity: 0.45;
}

.ui-side-slot:empty {
  min-height: 16px;
}

.ui-side-slot:not(:empty) {
  opacity: 1;
  background: rgba(18, 20, 28, 0.55);
  pointer-events: auto;
}

.ui-center-stage {
  position: relative;
  margin: 2px 4px;
  border-radius: 14px;
  border: 1px solid rgba(107, 122, 148, 0.35);
  background: rgba(12, 14, 22, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  pointer-events: none;
  overflow: hidden;
  min-height: 80px;
}

.ui-center-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #9aa3b5;
  font-size: 13px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 2;
}

.ui-center-label strong {
  display: block;
  color: #c8d0e8;
  font-size: 16px;
  margin-bottom: 4px;
}

/* Never show overworld copy while in match-3 mode */
.ui-overlay--match3 .ui-center-label {
  display: none !important;
}

.ui-bottom {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 8px 12px 12px;
  pointer-events: none;
}

.ui-overlay--match3 .ui-bottom-left,
.ui-overlay--match3 .ui-bottom-center,
.ui-overlay--match3 .ui-bottom-right {
  min-height: 0;
}

.ui-bottom-left,
.ui-bottom-center,
.ui-bottom-right {
  display: flex;
  align-items: center;
  min-height: 48px;
  pointer-events: none;
}

.ui-bottom-left { justify-content: flex-start; }
.ui-bottom-center { justify-content: center; }
.ui-bottom-right { justify-content: flex-end; }

.ui-overlay button,
.ui-overlay .ui-hit {
  pointer-events: auto;
}

.ui-btn {
  appearance: none;
  border: 1px solid rgba(154, 171, 204, 0.55);
  background: linear-gradient(180deg, #3a4560 0%, #2c3448 100%);
  color: #f0f4ff;
  font-weight: 700;
  font-size: 15px;
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  min-width: 44px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.ui-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.ui-btn-primary {
  min-width: 48px;
  background: linear-gradient(180deg, #4a6fa5 0%, #2f4d7a 100%);
  border-color: rgba(180, 205, 255, 0.65);
}

.ui-btn-ghost {
  background: rgba(20, 24, 36, 0.65);
  border-color: rgba(107, 122, 148, 0.55);
  font-weight: 600;
  font-size: 14px;
}

.ui-btn-icon {
  min-width: 44px;
  padding-left: 12px;
  padding-right: 12px;
}

.ui-stat {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  min-width: 52px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(26, 31, 46, 0.92);
  border: 1px solid rgba(107, 122, 148, 0.55);
  pointer-events: none;
}

.ui-stat span {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #9aa3b5;
  line-height: 1.1;
}

.ui-stat strong {
  font-size: 14px;
  font-weight: 700;
  color: #f0f4ff;
  line-height: 1.2;
}

.ui-toast-host {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 48px);
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 360px);
  pointer-events: none;
}

.ui-toast {
  background: rgba(18, 20, 28, 0.94);
  border: 1px solid rgba(107, 122, 148, 0.55);
  color: #e8eefc;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
