/*
 * UI overlay shell — parlor + Match-3.
 * Theme tokens live in match3_theme.css
 */

.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: var(--ck-text, #5A3A2A);
  -webkit-user-select: none;
  user-select: none;
}

.ui-overlay.is-hidden {
  display: none !important;
}

/* Match-3: exclusive top / stage / bottom bands. Stage is the only board region. */
.ui-overlay.ui-overlay--match3 .ui-top {
  padding: 6px 10px 4px;
  min-height: 52px;
  grid-template-columns: minmax(0, 1fr) auto;
}
.ui-overlay.ui-overlay--match3 .ui-bottom {
  padding: 0;
  min-height: 0;
  gap: 0;
}
.ui-overlay.ui-overlay--match3 .ui-mid {
  padding: 0;
  grid-template-columns: 0 1fr 0;
  min-height: 0;
}
.ui-overlay.ui-overlay--match3 .ui-center-wrap {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.ui-overlay.ui-overlay--match3 .ui-center-stage {
  margin: 0;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  align-self: stretch;
}

.ui-overlay--match3 .ui-side,
.ui-overlay--match3 .ui-side-slot {
  display: none;
  background: none !important;
  opacity: 0;
  box-shadow: none;
}

.ui-overlay--match3 .ui-top-left,
.ui-overlay--match3 .ui-top-right {
  flex-wrap: nowrap;
  min-width: 0;
}

.ui-overlay--match3 .ui-top-left {
  flex: 1 1 auto;
}

.ui-overlay--match3 .ui-top-right {
  flex: 0 0 auto;
}

.ui-m3-stats,
.ui-m3-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ui-m3-stats {
  flex: 0 1 auto;
}

/* Slim candy pills: beat base .ui-stat { min-width: 64px } on all viewports */
.ui-overlay--match3 .ui-stat {
  flex: 0 1 auto;
  flex-shrink: 1;
  min-width: 0;
  max-width: 5.5rem;
  padding: 4px 10px;
  border-radius: 18px;
}

.ui-overlay--match3 .ui-stat span {
  font-size: 9px;
}

.ui-overlay--match3 .ui-stat strong {
  font-size: 14px;
}

.ui-m3-stats .ui-stat {
  flex: 0 1 auto;
  flex-shrink: 1;
  min-width: 0;
}

/* Keep ≥44px control hits (portrait + desktop) */
.ui-overlay--match3 .ui-m3-controls .ui-btn {
  min-width: 44px;
  min-height: 44px;
}

.ui-m3-controls {
  flex: 0 0 auto;
}

.ui-m3-controls .ui-btn {
  flex: 0 0 auto;
}

.ui-overlay.ui-overlay--match3.ui-hud-narrow .ui-bottom {
  padding: 4px 8px 6px;
  min-height: 52px;
  gap: 8px;
}

.ui-overlay.ui-overlay--match3.ui-hud-narrow .ui-bottom-left,
.ui-overlay.ui-overlay--match3.ui-hud-narrow .ui-bottom-center,
.ui-overlay.ui-overlay--match3.ui-hud-narrow .ui-bottom-right {
  min-height: 44px;
}

.ui-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 12px 6px;
  pointer-events: none;
}

.ui-top-left,
.ui-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  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-overlay--match3 .ui-mid {
    grid-template-columns: 0 1fr 0;
  }
}

.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: 18px;
  background: transparent;
  opacity: 0;
}

.ui-side-slot:empty { min-height: 16px; }
.ui-side-slot:not(:empty) {
  opacity: 1;
  background: var(--ck-panel, rgba(255, 246, 232, 0.94));
  border: 3px solid var(--ck-chocolate, #5A3A2A);
  pointer-events: auto;
}

.ui-center-stage {
  position: relative;
  z-index: 2;
  flex: 1;
  margin: 0;
  border-radius: 18px;
  border: 1px solid transparent;
  background: transparent;
  pointer-events: none;
  overflow: hidden;
  min-height: 80px;
}

.ui-center-label {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--ck-muted, #8B5E4A);
  font-size: 14px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 3;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.ui-center-label strong {
  display: block;
  color: var(--ck-frosting, #FF8FB7);
  font-size: 22px;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
  text-transform: none;
}

.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: 3px solid var(--ck-chocolate, #5A3A2A);
  background: linear-gradient(180deg, #FFFCF6 0%, #FFF6E8 55%, #F5E0C8 100%);
  color: var(--ck-chocolate, #5A3A2A);
  font-weight: 800;
  font-size: 15px;
  border-radius: 16px;
  padding: 10px 18px;
  min-height: 44px;
  min-width: 44px;
  box-shadow:
    0 4px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 3px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

.ui-btn:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.ui-btn-primary {
  min-width: 48px;
  background: linear-gradient(180deg, #B8FFD8 0%, #7DFFB3 55%, #5EE89A 100%);
  color: var(--ck-chocolate, #5A3A2A);
  border-color: var(--ck-chocolate, #5A3A2A);
  box-shadow:
    0 4px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 3px 0 rgba(255, 255, 255, 0.55);
}

.ui-btn-ghost {
  background: linear-gradient(180deg, #FFFCF6 0%, #FFF6E8 100%);
  border-color: var(--ck-chocolate, #5A3A2A);
  font-weight: 700;
  font-size: 14px;
}

.ui-btn-danger {
  background: linear-gradient(180deg, #FFB3C4 0%, #FF6B8A 55%, #F04E74 100%);
  color: var(--ck-chocolate, #5A3A2A);
  border-color: var(--ck-chocolate, #5A3A2A);
}

.ui-btn-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ui-stat {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  min-width: 64px;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 22px;
  background: linear-gradient(180deg, #FFFCF6 0%, #FFF6E8 55%, #FFE8D2 100%);
  border: 3px solid var(--ck-chocolate, #5A3A2A);
  box-shadow:
    0 3px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 2px 0 rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

.ui-stat span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ck-frosting, #FF8FB7);
  line-height: 1.1;
}

.ui-stat strong {
  font-size: 16px;
  font-weight: 800;
  color: var(--ck-chocolate, #5A3A2A);
  line-height: 1.2;
}

@media (max-width: 480px) and (orientation: portrait) {
  .ui-overlay.ui-overlay--match3 .ui-top {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 4px 6px;
    min-height: 48px;
  }
  .ui-overlay.ui-overlay--match3 .ui-top-left,
  .ui-overlay.ui-overlay--match3 .ui-top-right {
    flex-wrap: nowrap;
    min-height: 44px;
    gap: 4px;
  }
  .ui-overlay.ui-overlay--match3 .ui-m3-stats,
  .ui-overlay.ui-overlay--match3 .ui-m3-controls {
    flex-wrap: nowrap;
    gap: 4px;
  }
  .ui-overlay.ui-overlay--match3 .ui-stat {
    min-width: 0;
    min-height: 40px;
    padding: 3px 8px;
    flex-shrink: 1;
    border-radius: 16px;
  }
  .ui-overlay.ui-overlay--match3 .ui-stat span {
    font-size: 9px;
  }
  .ui-overlay.ui-overlay--match3 .ui-stat strong {
    font-size: 13px;
  }
}

.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: var(--ck-panel, rgba(255, 246, 232, 0.96));
  border: 3px solid var(--ck-chocolate, #5A3A2A);
  color: var(--ck-text, #5A3A2A);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 4px 0 var(--ck-chocolate, #5A3A2A), 0 10px 22px rgba(90, 58, 42, 0.18);
}

/* Overworld path map — 5 unlocked P0 boards */
.ui-overlay--overworld .ui-center-label.ow-map {
  pointer-events: auto;
  width: min(96%, 380px);
  top: 46%;
  max-height: min(58vh, 420px);
  overflow: visible;
}

.ow-path {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 6px;
  margin: 12px auto 8px;
  padding: 12px 4px 8px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: visible;
  /* Keep nodes above decorative track; never clip taps */
  touch-action: manipulation;
}

.ow-path-track {
  display: none; /* hidden when wrapped (narrow phones) */
  position: absolute;
  left: 18px;
  right: 18px;
  top: 50%;
  height: 10px;
  margin-top: -5px;
  border-radius: 999px;
  background: linear-gradient(90deg, #7DFFB3 0%, #FFE566 45%, #F5E0C8 100%);
  border: 3px solid var(--ck-chocolate, #5A3A2A);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55);
  z-index: 0;
  pointer-events: none;
}

.ow-node {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  border: 3px solid var(--ck-chocolate, #5A3A2A);
  background: linear-gradient(180deg, #FFFCF6 0%, #FFF6E8 55%, #F5E0C8 100%);
  box-shadow:
    0 4px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 3px 0 rgba(255, 255, 255, 0.7);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--ck-chocolate, #5A3A2A);
  font-weight: 800;
  line-height: 1.05;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

button.ow-node {
  appearance: none;
  cursor: pointer;
  font: inherit;
  padding: 0;
  margin: 0;
}

.ow-node--play {
  background: linear-gradient(180deg, #B8FFD8 0%, #7DFFB3 55%, #5EE89A 100%);
}

.ow-node--play:active {
  transform: translateY(2px);
  box-shadow:
    0 2px 0 var(--ck-chocolate, #5A3A2A),
    inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.ow-node-emoji {
  font-size: 18px;
  line-height: 1;
}

.ow-node-label {
  font-size: 9px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.ow-node--locked {
  opacity: 0.55;
  filter: grayscale(0.35);
  background: linear-gradient(180deg, #E8DFD4 0%, #D9CBBA 100%);
}

.ow-node-sil {
  font-size: 20px;
  line-height: 1;
  opacity: 0.75;
}

.ow-lock {
  font-size: 12px;
  line-height: 1;
}

.ow-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ck-muted, #8B5E4A);
  font-weight: 600;
}

/* Wide enough for a single-row path with track */
@media (min-width: 420px) {
  .ui-overlay--overworld .ui-center-label.ow-map {
    width: min(92%, 400px);
  }

  .ow-path {
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 8px;
    padding: 18px 10px 10px;
  }

  .ow-path-track {
    display: block;
  }

  .ow-node {
    width: 64px;
    height: 64px;
    border-radius: 22px;
  }

  .ow-node-emoji {
    font-size: 22px;
  }

  .ow-node-label {
    font-size: 11px;
    letter-spacing: 0.04em;
  }
}

/* Extra-narrow (≈375) — slightly tighter nodes, still tappable */
@media (max-width: 389px) {
  .ow-node {
    width: 52px;
    height: 52px;
    border-radius: 16px;
  }

  .ow-node-emoji {
    font-size: 16px;
  }

  .ow-node-label {
    font-size: 8px;
  }
}
