/* Small screens (phones, small landscape windows): the controls become a collapsible bottom sheet, the stats
   a collapsible top-right panel, the data sources move into the sheet (controlsContents.js) and the clock
   sits just above the sheet. The four desktop corners would otherwise overlap. */
@media (max-width: 700px), (max-height: 500px) {
  .panelToggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    background: none;
    border: none;
    color: var(--text-color);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
  }

  .panelToggle::after {
    content: "▾";
  }

  .panelToggle[aria-expanded="true"]::after {
    content: "▴";
  }

  .collapsed > .panelBody {
    display: none !important;
  }

  #topLeftOverlay {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 60vh;
    max-height: 60dvh;
    padding: 0 0 env(safe-area-inset-bottom);
    border-radius: 12px 12px 0 0;
    background-color: rgba(11, 11, 11, 0.9);
    z-index: 1001; /* above the clock and the toolbar when open */
  }

  /* the sheet opens upwards */
  #controlsToggle::after {
    content: "▴";
  }

  #controlsToggle[aria-expanded="true"]::after {
    content: "▾";
  }

  #topLeftOverlay .panelBody {
    overflow-y: auto;
    padding: 0 10px 10px;
  }

  #topLeftOverlay .overlayStyle {
    background: none;
  }

  #constellationDescriptionContainer.scrollable {
    max-height: none;
    overflow: visible;
  }

  #sourcesMobileSlot {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line-color);
  }

  #bottomLeftOverlay {
    display: none;
  }

  #topRightOverlay {
    top: 8px;
    right: 8px;
    padding: 0;
    max-width: min(320px, calc(100vw - 80px));
    max-height: 50vh;
    overflow-y: auto;
  }

  #topRightOverlay .panelBody {
    padding: 0 10px 10px;
  }

  #bottomRightOverlay {
    bottom: calc(52px + env(safe-area-inset-bottom));
    right: 8px;
    padding: 4px 8px;
    font-size: 11px;
    pointer-events: none;
  }

  #loadingOverlay {
    bottom: calc(110px + env(safe-area-inset-bottom));
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    min-height: 40px;
    flex-shrink: 0;
  }

  .radio-group label {
    min-height: 32px;
  }
}

/* Touch screens have no right-click, Ctrl or Shift: a toolbar gives the same actions (initialize_globe.js) */
@media (pointer: coarse), (max-width: 700px), (max-height: 500px) {
  #touchToolbar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 999;
    padding: 4px;
  }

  #touchToolbar button {
    min-width: 56px;
    min-height: 40px;
    padding: 0 8px;
    border: 1px solid var(--line-color);
    border-radius: 6px;
    background: none;
    color: var(--text-color);
    font: inherit;
    cursor: pointer;
  }

  #touchToolbar button[aria-pressed="true"] {
    border-color: var(--accent-color);
    color: var(--accent-color);
  }
}

/* Large touch screens (tablets) keep the desktop corners: move the toolbar below the top-left panel's reach */
@media (pointer: coarse) and (min-width: 701px) and (min-height: 501px) {
  #touchToolbar {
    top: auto;
    left: auto;
    right: 10px;
    bottom: 70px;
  }
}
