/* The measured viewport has one owner: page chrome, the content pane, or a modal. */
html.home-page-active, body.home-page-active,
html.fullscreen-content-active, body.fullscreen-content-active {
  height: 100%; overflow: hidden !important;
}
body.home-page-active #main-content {
  padding: 6px 3px 10px !important;
  overflow: hidden !important;
  overscroll-behavior: none;
}
body.home-page-active #main-content .home-mode-card {
  box-sizing: border-box;
  height: 100%; min-height: 0;
  margin: 0 !important; padding: 0 !important;
  background: transparent; box-shadow: none;
}
body.home-page-active #main-content .home-mode-grid {
  display: grid !important;
  grid-template-rows: minmax(44px, 1fr) minmax(44px, .76fr) minmax(44px, 1fr);
  height: 100%; min-height: 0; gap: 4px !important;
}
body.home-page-active #main-root .home-image-btn {
  height: 100% !important; min-height: 0; max-height: none;
}
body.home-page-active #top-profile { min-height: 0 !important; }
body.home-page-active #top-profile .top-avatar-frame {
  width: clamp(44px, 13dvh, 102px);
  height: clamp(44px, 13dvh, 102px);
}
body.home-page-active #top-profile .top-avatar-img {
  width: 84%; height: 84%;
}
@media (max-height: 540px) {
  body.home-page-active #top-profile { padding-top: calc(4px + var(--safe-top-final)); padding-bottom: 4px; }
  body.home-page-active #top-profile .top-avatar-frame { width: 38px; height: 38px; margin-bottom: 2px; }
}
/* Content already ends above navigation; only a small reading gap remains. */
#main-content.exam-sections-scroll-root {
  scroll-padding-bottom: 16px !important;
}
#main-content.exam-sections-scroll-root .exam-sections-bottom-spacer { height: 16px; }
body.fullscreen-content-active #main-content { box-sizing: border-box; overflow-y: auto; overflow-x: hidden; overscroll-behavior-y: contain; }
body.tournament-lock #top-profile,
body.tournament-lock #bottombar { display: none !important; }
html body.tournament-lock #main-content,
html.capacitor body.tournament-lock #main-content {
  box-sizing: border-box;
  margin-top: var(--safe-top-final, 0px) !important;
  height: calc(100dvh - var(--safe-top-final, 0px) - var(--safe-bottom-final, 0px)) !important;
  max-height: calc(100dvh - var(--safe-top-final, 0px) - var(--safe-bottom-final, 0px)) !important;
  padding-top: 8px !important; padding-bottom: 12px !important;
  overflow-y: auto !important; overflow-x: hidden !important;
  touch-action: pan-y; overscroll-behavior: contain;
}
body.tournament-lock #main-content .tournament-battle-shell { min-height: 0; padding-bottom: 12px; }
body.tournament-lock .tournament-wait-screen { padding-top: 0; }
body.tournament-search-center #main-content { justify-content: safe center !important; }
/* Explicit available height prevents a flex child's percentage max-height from
   including the backdrop's padding and clipping the bottom border/content. */
html #achievements-modal-bg.safe-modal-overlay,
html #titles-modal-bg.safe-modal-overlay {
  align-items: center !important;
  padding: calc(12px + var(--modal-safe-top)) calc(12px + var(--modal-safe-right)) calc(12px + var(--modal-safe-bottom)) calc(12px + var(--modal-safe-left)) !important;
}
html #achievements-modal-bg.safe-modal-overlay > #achievements-modal-window,
html #titles-modal-bg.safe-modal-overlay > #titles-modal-window {
  flex: 0 1 auto; min-height: 0 !important;
  max-height: calc(var(--modal-viewport-height, 100dvh) - var(--modal-safe-top) - var(--modal-safe-bottom) - 24px) !important;
  margin: 0 !important; padding-bottom: 24px !important;
  box-sizing: border-box !important;
  overflow-y: auto !important; overscroll-behavior: contain;
  scroll-padding-bottom: 24px;
}
