/* Teamz Lab games — full-screen modals (not clipped by canvas overflow). */

.tz-game-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--tz-game-modal-backdrop, rgba(0, 0, 0, 0.62));
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px));
  box-sizing: border-box;
}

.tz-game-modal.show {
  display: flex;
}

.tz-game-modal-panel {
  background: var(--tz-game-modal-panel-bg, var(--bg, #0f1419));
  border: 1px solid var(--tz-game-modal-panel-border, var(--border, #2d3a4d));
  border-radius: 16px;
  width: min(420px, 100%);
  max-width: 100%;
  margin: auto;
  padding: 20px 18px;
  text-align: center;
  box-sizing: border-box;
  flex-shrink: 0;
  color: var(--tz-game-modal-text, var(--text, #c8d4e8));
}

.tz-game-modal-panel h2,
.tz-game-modal-panel h3 {
  margin: 0 0 8px;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  font-weight: 800;
  color: var(--tz-game-modal-heading, var(--heading, #e8eef7));
}

.tz-game-modal-body {
  max-height: min(68dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 140px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  text-align: left;
}

.tz-game-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

/* Opt-in rewarded offer card (lose modal, hint, etc.) */
.tz-ad-offer {
  margin: 0 0 12px;
  padding: 14px 14px 12px;
  border-radius: 14px;
  text-align: left;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--tz-game-primary, var(--success, #01875f)) 14%, var(--surface, #fff)),
    var(--surface, #fff)
  );
  border: 1px solid color-mix(in srgb, var(--tz-game-primary, var(--success, #01875f)) 38%, var(--border, #e8ecf1));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--tz-game-primary, var(--success, #01875f)) 12%, transparent);
}

.tz-ad-offer[hidden] {
  display: none !important;
}

.tz-ad-offer__row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.tz-ad-offer__emoji {
  font-size: 1.65rem;
  line-height: 1;
  flex-shrink: 0;
}

.tz-ad-offer__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tz-ad-offer__text strong {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--tz-game-modal-heading, var(--heading, #1a1a2e));
}

.tz-ad-offer__text span {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--tz-game-modal-text-muted, var(--text-muted, #6b7280));
}

.tz-ad-offer__cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--tz-game-primary-on, #fff);
  background: linear-gradient(135deg, var(--tz-game-primary, var(--success, #01875f)), color-mix(in srgb, var(--tz-game-primary, var(--success, #01875f)) 75%, #000));
  box-shadow: 0 4px 12px color-mix(in srgb, var(--tz-game-primary, var(--success, #01875f)) 35%, transparent);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.tz-ad-offer__cta:hover:not(:disabled) {
  transform: translateY(-1px);
  opacity: 0.95;
}

.tz-ad-offer__cta:disabled {
  opacity: 0.65;
  cursor: wait;
}

.tz-ad-offer__cta-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-size: 0.7rem;
}

/* Reusable modal buttons (any game — include tz-game-theme.css for colors) */
.tz-game-modal-btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 14px;
  border: 1px solid var(--tz-game-btn-border, var(--border, #2d3a4d));
  border-radius: 12px;
  background: var(--tz-game-btn-bg, transparent);
  color: var(--tz-game-btn-color, var(--heading, #e8eef7));
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, opacity 0.15s;
}

.tz-game-modal-btn:hover {
  border-color: var(--tz-game-modal-heading, var(--heading, #e8eef7));
}

.tz-game-modal-btn--primary {
  background: var(--tz-game-btn-primary-bg, var(--success, #01875f));
  color: var(--tz-game-btn-primary-color, #ffffff);
  border-color: var(--tz-game-btn-primary-border, var(--success, #01875f));
}

.tz-game-modal-btn--primary:hover {
  opacity: 0.9;
}

.tz-game-modal-actions .tz-game-modal-btn {
  flex: none;
  min-width: 0;
  width: 100%;
}

/* Reusable level picker (optional — Arrow Escape still uses ae3d-* aliases) */
.tz-level-jump {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  flex-wrap: wrap;
}

.tz-level-jump label {
  font-size: 0.85rem;
  color: var(--tz-game-modal-text-muted, var(--text-muted, #8b9cb3));
  white-space: nowrap;
}

.tz-level-jump input {
  width: 5.5rem;
  padding: 8px 10px;
  border: 1px solid var(--tz-game-modal-panel-border, var(--border, #2d3a4d));
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--tz-game-modal-panel-bg, var(--surface, #0f1419));
  color: var(--tz-game-modal-heading, var(--heading, #e8eef7));
}

.tz-level-jump .tz-game-modal-btn {
  min-width: 0;
  padding: 8px 14px;
  width: auto;
}

.tz-level-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin: 10px 0 14px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}

.tz-tier-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 6px 0 2px;
  text-align: left;
  color: var(--tz-game-tier-label, var(--text-muted, #8b9cb3));
  background: var(--tz-game-modal-panel-bg, var(--surface, #0f1419));
}

.tz-tier-label:first-child {
  margin-top: 0;
}

.tz-level-btn {
  aspect-ratio: 1;
  border: 2px solid var(--tz-game-level-border, var(--border, #2d3a4d));
  border-radius: 8px;
  background: var(--tz-game-level-bg, var(--surface, #0f1419));
  color: var(--tz-game-level-color, var(--heading, #e8eef7));
  font-family: inherit;
  font-weight: 800;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.tz-level-btn[disabled] {
  opacity: 0.32;
  cursor: not-allowed;
}

.tz-level-btn:hover:not([disabled]) {
  border-color: var(--tz-game-modal-heading, var(--heading, #e8eef7));
}

.tz-level-btn.is-done {
  border-color: var(--tz-game-level-done-border, var(--success, #01875f));
  color: var(--tz-game-level-done-color, var(--success, #01875f));
}

.tz-level-btn.is-current {
  border-color: var(--tz-game-level-current-bg, var(--danger, #e53935));
  background: var(--tz-game-level-current-bg, var(--danger, #e53935));
  color: var(--tz-game-level-current-color, #ffffff);
}

@media (max-width: 600px) {
  .tz-level-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* App mode: upgrade in-canvas modals without tz-game-modal class (legacy) */
html.tz-app-mode .tz-game-surface .tz-game-modal,
html.tz-app-mode .tz-game-surface .ae3d-modal,
html.tz-app-mode .ae3d-modal:not(.tz-game-modal-ignore) {
  position: fixed !important;
  inset: 0 !important;
  z-index: 10000 !important;
  align-items: flex-start !important;
  justify-content: center !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(12px, env(safe-area-inset-left, 0px)) !important;
}

html.tz-app-mode .ae3d-modal .ae3d-panel,
html.tz-app-mode .tz-game-modal-panel {
  width: min(440px, 100%);
  max-height: none;
  margin: auto;
  overflow: visible;
}

html.tz-app-mode .ae3d-modal .ae3d-level-grid,
html.tz-app-mode .tz-game-modal-body .ae3d-level-grid,
html.tz-app-mode .tz-game-modal-body .tz-level-grid {
  max-height: min(58dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 180px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

html.tz-app-mode.tz-app-landscape .ae3d-modal .ae3d-level-grid,
html.tz-app-mode.tz-app-landscape .tz-game-modal-body .ae3d-level-grid,
html.tz-app-mode.tz-app-landscape .tz-game-modal-body .tz-level-grid {
  grid-template-columns: repeat(10, 1fr);
  max-height: min(52dvh, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 160px));
}

html.tz-app-mode .ae3d-tier-label,
html.tz-app-mode .tz-tier-label {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--tz-game-modal-panel-bg, var(--bg, #0f1419));
  padding-top: 4px;
  margin-top: 0;
}
