/* RundtNorge on the website only (server/index.js adds this file; the desktop app never loads it).
   1. Small fixes for any browser window.  2. The phone layout: a bottom tab bar instead of the left rail,
   and drawers, details and menus as sheets from the bottom, with the map kept visible above them. */

/* ---------- any browser ---------- */
#titlebar, body.fullscreen #titlebar { padding-right: 18px; } /* no window buttons to leave room for */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
#map { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.rb-more, .more-sheet { display: none; }

/* share: in the rail, and next to × in every details card */
.share-btn { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; margin-right: 2px; display: grid; place-items: center; }
.share-btn svg { width: 17px; height: 17px; }
.share-btn:hover { color: var(--accent); }

/* the "where am I" button (a map control above the zoom buttons) and the dot that marks you */
.maplibregl-ctrl button.here-btn { display: grid; place-items: center; }
.here-btn svg { width: 18px; height: 18px; stroke: var(--text); stroke-width: 2; }
.here-btn.busy svg { animation: blink 1s infinite; }
.here-dot { width: 18px; height: 18px; border-radius: 50%; background: #2f8cff; border: 3px solid #fff; box-shadow: 0 0 0 7px rgba(47, 140, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.4); }

@media (hover: none) {
  .tooltip { display: none !important; } /* no hovering on a touch screen */
}
/* a touch screen: no mouse and keyboard help, no "Esc" hints */
@media (hover: none) and (pointer: coarse) {
  .desk-only, .tc-esc { display: none; }
  .tc-tap { display: inline; }
}

/* ---------- phones (and phones held sideways) ---------- */
@media (max-width: 760px), (pointer: coarse) and (max-height: 520px) {
  :root { --head: 52px; --nav: calc(58px + env(safe-area-inset-bottom)); }
  html, body { font-size: 14px; }

  /* title bar: logo, search, language, clock */
  #titlebar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; padding: 0 8px; }
  .wordmark, .search kbd, .hc-state { display: none; }
  .hright { gap: 8px; }
  #clock { font-size: 14px; }
  .hlang button { padding: 4px 7px; }
  .search input { font-size: 16px; height: 38px; padding-right: 10px; } /* 16 px: iPhones zoom in on smaller text fields */
  .search-results { position: fixed; top: calc(var(--head) + 4px); left: 8px; right: 8px; max-height: 64vh; }
  .sr { padding: 10px 8px; }
  .jump button { padding: 7px 14px; font-size: 14px; }

  /* the map fills what is between the title bar and the tab bar */
  #map { inset: var(--head) 0 var(--nav) 0; }
  body.bare #map, body.touring #map { inset: var(--head) 0 0 0; } /* the tab bar is hidden then: the map goes to the bottom */
  #map .maplibregl-ctrl-bottom-right { bottom: 50px; right: 2px; } /* above the live line and the replay pill */
  .maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out { display: none !important; } /* pinch to zoom */
  .maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }

  /* the left rail becomes a tab bar at the bottom: Layers, Now, Mine, Cameras, More */
  .rail {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; height: var(--nav); flex-direction: row; justify-content: space-around;
    gap: 0; padding: 2px 4px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--line);
  }
  .rb { flex: 1; width: auto; max-width: 96px; height: 54px; }
  .rb span { font-size: 11px; }
  .rb.on::before { left: 28%; right: 28%; top: -2px; bottom: auto; width: auto; height: 3px; }
  .rail-sep, .rail-fill, #btnShare, #btnCams, #btnOffshore, #btnTour, #btnSettings, #btnHelp, #btnFull { display: none; }
  .share-btn svg { width: 21px; height: 21px; }
  .share-btn { padding: 4px 8px; }
  .rb-more { display: flex; }
  body.bare .rail, body.touring .rail { transform: translateY(100%); }

  /* "More": the rest of the rail, as a small sheet above the tab bar */
  .more-sheet {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 6px; position: fixed; left: 8px; right: 8px; bottom: calc(var(--nav) + 8px); z-index: 46;
    padding: 8px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 -8px 28px var(--shadow); animation: rise 0.15s ease-out;
  }
  .more-sheet[hidden] { display: none !important; }
  .more-sheet button {
    display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 11px 4px; border: 1px solid var(--line); border-radius: 5px;
    background: var(--raise); color: var(--text); font: 500 12px var(--font);
  }
  .more-sheet svg { width: 21px; height: 21px; }

  /* drawers (Layers, Now, Mine) slide up from the bottom */
  .drawer {
    top: auto; left: 0; right: 0; bottom: var(--nav); width: auto; max-height: min(74vh, calc(100% - var(--head) - var(--nav) - 40px));
    border-right: 0; border-top: 1px solid var(--line); border-radius: 10px 10px 0 0; box-shadow: 0 -10px 28px var(--shadow); animation: sheet 0.18s ease-out;
  }
  .drawer::before, .card::before { content: ""; display: block; width: 34px; height: 3px; border-radius: 2px; background: var(--raise2); margin: 7px auto 0; flex: none; }
  .drawer-head { padding: 8px 14px 10px 16px; }
  .drawer-body { min-height: 0; padding: 8px 12px 16px 14px; }
  @keyframes sheet { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

  /* the details card is a sheet too, leaving the top of the map free for what it describes */
  .card, .card.wide {
    left: 0; right: 0; top: auto !important; bottom: var(--nav); width: auto; max-height: 56vh; padding: 0 14px 14px;
    border-radius: 10px 10px 0 0; box-shadow: 0 -10px 28px var(--shadow); animation: sheet 0.18s ease-out; z-index: 23;
  }
  .card::before { margin: 7px auto 8px; }
  .facts { gap: 8px 12px; }
  .board { max-height: none; }
  .brow { grid-template-columns: 48px auto minmax(0, 1fr) 30px 70px; gap: 6px; padding: 8px 4px; }
  ol.stops li { padding: 7px 4px; }

  /* the line that sums up what is live, and the replay bar, sit just above the tab bar */
  .ticker, body.drawer-open .ticker { left: 8px; bottom: calc(var(--nav) + 8px); height: 36px; max-width: calc(100vw - 16px); overflow: hidden; font-size: 12px; padding: 0 11px 0 10px; }
  .tl-btn span { display: none; } /* the replay button: just its icon */
  .tl-btn { padding: 0 8px; }
  .maplibregl-ctrl-scale { display: none; }
  #tickerText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; gap: 5px; }
  /* on a phone the counts get small icons instead of words, so the line fits beside the replay bar */
  .ticker .ti { display: inline-block; }
  .ticker .tw { display: none; }
  body.bottom-tight .ticker { bottom: calc(var(--nav) + 8px + 36px + 6px); }
  body.drawer-open .ticker, body.tl-open .ticker, body.replaying .ticker { opacity: 0; pointer-events: none; }
  .timeline { left: auto; right: 8px; bottom: calc(var(--nav) + 8px); transform: none; height: 36px; }
  body.drawer-open .timeline { opacity: 0; pointer-events: none; }
  body.tl-open .timeline, body.replaying .timeline { left: 8px; right: 8px; height: auto; flex-wrap: wrap; padding: 4px; }
  .tl-body { width: auto !important; min-width: 0; flex: 1; gap: 6px; }
  .time-label { min-width: 0; font-size: 11px; }
  .speeds button { padding: 2px 5px; }
  .tl-arch span { display: none; }
  .tl-arch { padding: 0 6px; }
  .archive-pop { left: 8px !important; right: 8px; bottom: calc(var(--nav) + 92px); transform: none; width: auto; max-height: 55vh; overflow-y: auto; }

  /* the map's right-click menu (here: press and hold) is a sheet above the tab bar */
  .ctxmenu { left: 8px !important; right: 8px; top: auto !important; bottom: calc(var(--nav) + 8px); min-width: 0; padding: 8px; border-radius: 8px; }
  .ctxmenu button { padding: 12px 12px; font-size: 15px; }
  .cm-save input { font-size: 16px; padding: 8px 10px; }

  /* dialogs (Settings, Help) take most of the screen */
  .dialog { left: 50%; top: calc(var(--head) + 8px); transform: translateX(-50%); width: calc(100vw - 16px); max-height: calc(100% - var(--head) - var(--nav) - 16px); padding: 16px; border-radius: 8px; animation: none; }
  .help-cols { grid-template-columns: 1fr; gap: 0; }
  .themes { grid-template-columns: 1fr 1fr; }
  .set-row { flex-wrap: wrap; }

  /* camera wall and offshore: full width, two cameras across */
  .gallery { inset: var(--head) 0 var(--nav) 0; }
  .gal-head { flex-wrap: wrap; gap: 8px 12px; padding: 12px 12px 10px; }
  .gal-head h2 { font-size: 17px; }
  .gal-head .card-close { order: 2; margin-left: auto; }
  .offshore .gal-head .cbtn { order: 3; margin-left: 0; }
  .gal-modes { order: 3; width: 100%; overflow-x: auto; }
  .gal-head .muted { order: 4; margin-left: 0; white-space: normal; }
  /* one camera per row on a phone (two on a wider one), big enough to see, with its place under it */
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; padding: 0 12px 16px; }
  .gal-grid figcaption { padding: 9px 12px 10px; }
  .gal-grid figcaption b { font-size: 15px; }
  .gal-grid figcaption span { font-size: 13px; }
  .off-body { padding: 0 10px 12px; }
  .off-kpis { grid-template-columns: 1fr 1fr; }
  .off-grid { grid-template-columns: 1fr; }
  .pwr-zones { grid-template-columns: 1fr; }
  .power .gal-head .pwr-mva { order: 3; margin-left: 0; }

  /* tour: smaller captions, the camera image in a corner */
  .tour-caption { left: 14px; right: 14px; bottom: 20px; }
  .tc-title { font-size: 26px; }
  .tc-sub { font-size: 14px; }
  .tour-cam { top: calc(var(--head) + 10px); bottom: auto; right: 10px; width: 46vw; border-radius: 12px; }

  /* small things */
  .toasts { left: 50%; top: calc(var(--head) + 10px); width: max-content; max-width: calc(100vw - 24px); }
  .foot-right { top: calc(var(--head) + 5px); bottom: auto; right: 6px; padding: 2px 7px; font-size: 11px; }
  .attribution { padding: 0; background: transparent; font-size: inherit; }
  .sources { top: calc(var(--head) + 26px); bottom: auto; right: 8px; width: calc(100vw - 16px); }
  body.drawer-open .foot-right { opacity: 0; pointer-events: none; }

  /* fingers need bigger targets */
  .cbtn { padding: 9px 13px; font-size: 13.5px; }
  button.mini { padding: 7px 12px; font-size: 13px; }
  .row { padding: 9px 6px; }
  .list-item { padding: 9px 4px; }
  .seg button { padding: 7px 8px; }
  .star { font-size: 24px; padding: 2px 6px; }
  .card-close { font-size: 28px; padding: 2px 6px; }
  .lr-more { width: 34px; height: 30px; }
  .lrow { padding: 8px 5px; }
  .lg-head { padding: 11px 10px 11px 9px; }

  /* the first-start chooser: the whole width, one group per row */
  .welcome { padding: 16px 14px 14px; max-height: calc(100% - var(--head) - 16px); bottom: auto; }
  .wl-groups { grid-template-columns: 1fr; gap: 8px; margin-top: 12px; }
  .wl-chip { padding: 6px 11px 6px 8px; font-size: 12.5px; }
  .wl-foot { position: sticky; bottom: -14px; margin: 14px -14px -14px; padding: 12px 14px; background: var(--surface); border-top: 1px solid var(--line); }
  .wl-foot .cbtn { flex: 1; padding: 11px 12px; }

  /* the tour: the button to end it, top left (the camera picture is top right) */
  .tour-exit { top: calc(var(--head) + 10px); left: 10px; right: auto; opacity: 1; padding: 10px 16px 10px 13px; font-size: 14px; }

  /* settings: a row with a choice of several puts the choice under its text */
  .set-row:has(.seg) > div:first-child { flex-basis: 100%; }
}
