/* Smaller screens: narrower desktops, then phones. */
/* Narrower desktops. */
#topbar { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
#topbar::-webkit-scrollbar { display: none; }
/* The "Turn" label is the first thing to go when the bar is short of room (it needs about 1360px).
   */
@media (max-width: 1380px) { .turn { display: none; } }
@media (max-width: 1200px) {
  #topbar { gap: 12px; }
  .yields { gap: 10px; }
  .yield { font-size: 13px; }
  .btn .lbl { display: none; }
  .btn { padding: 4px 7px; }
  .search { flex-basis: 180px; min-width: 130px; }
}
@media (max-width: 1000px) and (min-width: 701px) {
  .brand-text { display: none; }
  .lp-body { grid-template-columns: 1fr; }
  #topbar { gap: 10px; padding: 0 10px; }
  .yields { gap: 8px; }
  .yield { font-size: 12.5px; gap: 4px; }
  .search { flex: 0 1 150px; min-width: 112px; }
  /* With a panel open there is no room for the dock beside the minimap: hide the minimap, give the
     dock the width. */
  body.panel-open #minimap-wrap { display: none; }
  body.panel-open #lens-area { left: calc(12px + var(--dock-left, 0px)); }
}
/* The yields row gives way first when the bar is short of room (topbar.js marks it .clipped). */
@media (max-width: 1000px) {
  .yields { flex: 0 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .yields::-webkit-scrollbar { display: none; }
  .yields.clipped {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  }
}

/* Phones. */
@media (max-width: 700px) {
  #topbar {
    gap: 8px; padding: 0 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #topbar::-webkit-scrollbar { display: none; }
  .brand-text { display: none; }
  .spacer { display: none; }
  .search { flex: 0 0 100px; min-width: 100px; order: -1; margin-left: 4px; }
  .brand { order: -2; }
  .search-kbd { display: none; }
  #search-input { padding-right: 8px; }
  /* The yields scroll in their own strip so the four buttons always show, at a 36px tap size. */
  .yields { gap: 10px; flex: 1 1 0; }
  .tb-buttons { gap: 4px; }
  .tb-buttons .btn { min-width: 36px; min-height: 36px; justify-content: center; }
  /* Below about 330px even that does not fit and the whole bar scrolls. Fades at its ends
     (ui/topbar.js sets .more-l / .more-r): sticky pseudo-elements stay at the visible edges; the
     negative margins cancel their width and the 8px flex gap so they add no scroll width. */
  #topbar::before, #topbar::after {
    content: ""; position: sticky; flex: none; align-self: stretch; width: 30px; z-index: 1;
    pointer-events: none;
    opacity: 0; transition: opacity .15s;
  }
  #topbar::before {
    order: -3; left: 0; margin-right: -38px;
    background: linear-gradient(90deg, #1b2a3a 20%, rgba(27,42,58,0));
  }
  #topbar::after {
    order: 99; right: 0; margin-left: -38px;
    background: linear-gradient(270deg, #1b2a3a 20%, rgba(27,42,58,0));
  }
  #topbar.more-l::before, #topbar.more-r::after { opacity: 1; }

  #lens-area { left: 0; right: 0; bottom: 0; gap: 6px; align-items: stretch; z-index: 13; }
  body.panel-open #lens-area { right: 0; }
  .lens-dock {
    border-radius: 10px 10px 0 0; border-left: none; border-right: none; border-bottom: none;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .lens-quick { flex: 1; }
  .res-toggle span, .lens-more span:not(.caret) { display: none; }
  .map-layers-pop { margin: 0 8px; width: auto; align-self: stretch; }
  .ml-row { min-height: 42px; }
  .legend { width: auto; margin: 0 8px; }
  /* The details toggle folds the long description, caveat, source line and hint on phones; the
     scale (with its histogram and ticks) and the categories stay. */
  .lg-more { display: inline-grid; place-items: center; width: 28px; height: 28px; }
  #legend:not(.expanded) :is(.desc, .lg-note, .lg-meta, .lg-hint) { display: none; }
  .lens-picker { width: auto; margin: 0 8px; max-height: 60vh; }
  .lp-body { grid-template-columns: 1fr; }

  #minimap-wrap { display: none; bottom: 64px; left: 8px; }
  body.minimap-on #minimap-wrap { display: block; }
  .minimap-toggle {
    display: grid; place-items: center; position: fixed; left: 8px; bottom: 60px; z-index: 11;
    width: 38px; height: 38px; padding: 0;
    cursor: pointer; color: var(--gold-bright); border-radius: 50%;
  }
  body.minimap-on .minimap-toggle { bottom: auto; top: 50px; }
  body.panel-open .minimap-toggle, body.panel-open #minimap-wrap { display: none; }

  #city-panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 55vh; height: 55dvh; z-index: 25;
    border-radius: 14px 14px 0 0; border-left: none; border-right: none; border-bottom: none;
    padding-bottom: calc(12px + env(safe-area-inset-bottom)); transition: transform .18s ease-out;
    box-shadow: 0 -8px 30px rgba(0,0,0,.55);
  }
  #city-panel.dragging-sheet { transition: none; }
  .app-dock {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; height: 55vh;
    height: 55dvh; z-index: 24;
    border-radius: 14px 14px 0 0; border: 1px solid var(--line); border-bottom: none;
    border-left: none; border-right: none;
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -8px 30px rgba(0,0,0,.55);
  }
  .sheet-grip {
    display: block; position: sticky; top: 0; z-index: 2; height: 18px; margin-bottom: -18px;
    touch-action: none;
  }
  .sheet-grip::before {
    content: ""; position: absolute; left: 50%; top: 6px; width: 44px; height: 4px;
    margin-left: -22px; border-radius: 2px; background: rgba(201,164,92,.6);
  }
  .cp-head { padding-top: 18px; touch-action: none; }
  .cp-close { top: 14px; width: 32px; height: 32px; }
  .cp-name { font-size: 21px; }
  .yield-tile .val { font-size: 13px; }

  .modal-card {
    grid-template-columns: 1fr; grid-template-rows: auto 1fr; width: 100vw; height: 100%;
    height: 100dvh; border-radius: 0;
  }
  #pedia-nav {
    display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line);
    padding: 8px 44px 8px 0;
  }
  #pedia-nav .hd { display: none; }
  .modal-card .close { background: #1c2836; top: 7px; right: 8px; }
  #pedia-nav button { width: auto; white-space: nowrap; padding: 6px 12px; }
  #pedia-body { padding: 14px 16px; }
  .help-card { padding: 16px; }
  .toast { top: 50px; }

  .yield-report {
    left: 0 !important; right: 0; width: auto; max-width: none; z-index: 28;
    max-height: calc(100vh - var(--topbar-h) - 64px);
    max-height: calc(100dvh - var(--topbar-h) - 64px);
    border-radius: 0 0 12px 12px; border-left: none; border-right: none; border-top-width: 2px;
  }
  .yr-total > b { font-size: 30px; }
  .yr-row { padding: 7px 8px; }
}
