/* Layout of the shell: top bar, map, left panel, right sheet, runway strip,
   phone tab bar. Views style their own insides in their own css/<view>.css. */

:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  height: 100dvh;
  background: var(--ground);
  color: var(--text);
  font: 400 15px/1.45 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0 0 .4em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .7em; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-weight: 500; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
input[type="text"], input[type="search"], input[type="number"], select, textarea {
  min-height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); width: 100%;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Top bar ------------------------------------------------------------ */
#topbar {
  display: flex; align-items: center; gap: 16px; padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line); z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; min-height: 44px; }
#topnav { display: flex; gap: 2px; flex: 1; }
#topnav a, #tabbar a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px;
  color: var(--muted); text-decoration: none; border-radius: 8px;
}
#topnav a:hover, #tabbar a:hover { background: var(--accent-tint); color: var(--text); }
#topnav a[aria-current="page"], #tabbar a[aria-current="page"] { color: var(--accent); background: var(--accent-tint); font-weight: 600; }
#topnav a[hidden], #tabbar a[hidden] { display: none; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn { width: 44px; padding: 0; display: inline-grid; place-items: center; border-color: transparent; background: transparent; font-size: 1.4rem; }

/* The theme toggle shows the moon while light, the sun while dark. */
#theme-toggle .sun { display: none; }
#theme-toggle[aria-pressed="true"] .moon { display: none; }
#theme-toggle[aria-pressed="true"] .sun { display: inline; }

.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; }
.avatar-fallback { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu-pop {
  position: absolute; right: 0; top: 48px; min-width: 200px; padding: 10px; display: grid; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 40;
}
.user-menu-pop a { padding: 8px 4px; }
.gsi-slot { min-height: 32px; }

/* --- Main: the map always fills it ------------------------------------------- */
#app { position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--ground); }

#panel {
  position: absolute; z-index: 10; display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}
#panel-body { overflow: auto; padding: 14px; flex: 1; min-height: 0; }
.panel-handle { display: none; }

#sheet {
  position: absolute; z-index: 15; display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}
#sheet[hidden] { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h1 { margin: 0; font-size: 1.1rem; }
#sheet-body { overflow: auto; padding: 16px; flex: 1; min-height: 0; }

#runway {
  position: absolute; z-index: 9; background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
  height: var(--runway-h); display: flex; flex-direction: column;
}
#runway[data-collapsed="true"] { height: var(--runway-collapsed-h); }
#runway[data-collapsed="true"] #runway-body { display: none; }
.runway-toggle { min-height: 44px; border: 0; border-radius: 0; background: transparent; text-align: left; font-size: .85rem; color: var(--muted); padding: 0 12px; }
#runway-body { flex: 1; min-height: 0; }

#tabbar { display: none; }
#footer { padding: 3px 12px; font-size: .75rem; background: var(--surface); border-top: 1px solid var(--line); }
#footer a { color: var(--muted); }
#services[hidden] { display: none; }

/* --- Desktop ------------------------------------------------------------------- */
@media (min-width: 900px) {
  #panel { top: 12px; left: 12px; bottom: calc(var(--runway-h) + 24px); width: var(--panel-w); border-radius: var(--radius); }
  /* A folded runway gives its height back to the panel. */
  #app:has(#runway[data-collapsed="true"]) #panel { bottom: calc(var(--runway-collapsed-h) + 24px); }
  #sheet { top: 12px; right: 12px; bottom: 12px; width: min(66.666%, 920px); border-radius: var(--radius); }
  #runway { left: calc(var(--panel-w) + 24px); right: 12px; bottom: 12px; border-radius: var(--radius); }
  /* A sheet leaves the left third of the map live beside it; the panel
     stays mounted underneath so its search and scroll come back. */
  body[data-sheet="open"] #panel { display: none; }
  body[data-sheet="open"] #runway { left: 12px; right: calc(min(66.666%, 920px) + 24px); }
}

/* --- Phone: map fills the screen, everything else is a bottom sheet ------------------------- */
@media (max-width: 899px) {
  body { padding-bottom: var(--tabbar-total); }
  /* A field under 16px makes iOS zoom the page on focus and stay zoomed. A view
     that sizes its own fields smaller does so only from 900px up. */
  input, select, textarea { font-size: var(--fs-input); }
  #topnav { display: none; }
  /* No footer on a phone: its link is in Me and in the map's credits. */
  #footer { display: none; }
  #tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: var(--tabbar-total); padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  #tabbar a { flex: 1; justify-content: center; border-radius: 0; font-size: .8rem; }
  /* In landscape the notch is at the side: the sheets and the tab bar keep
     inside the safe area (env() is 0 everywhere else). */
  #panel {
    left: env(safe-area-inset-left, 0px); right: env(safe-area-inset-right, 0px); bottom: 0; border-radius: 16px 16px 0 0; transition: height .2s ease;
  }
  #panel[data-snap="peek"] { height: var(--sheet-peek); }
  #panel[data-snap="half"] { height: 50%; }
  #panel[data-snap="full"] { height: 100%; border-radius: 0; }
  /* A 44 px drag zone. The bar sits at its top, and the list starts where the
     zone ends (panel-body has no top padding here). Dragging the handle, a
     [data-grip] row or the list from its top moves the sheet (lib/panel.js);
     those elements take the touch themselves, so they do not scroll. */
  .panel-handle { display: grid; place-items: start center; width: 100%; min-height: 44px; padding: 10px 0 0; border: 0; border-radius: 16px 16px 0 0; background: transparent; touch-action: none; }
  .panel-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--handle); }
  #panel-body { padding-top: 0; overscroll-behavior: contain; }
  [data-grip] { touch-action: none; }
  #sheet { inset: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); border-radius: 0; }
  #runway { display: none; }
  body[data-sheet="open"] #panel { display: none; }
}

/* --- Small shared pieces ------------------------------------------------------------------- */
.stub { padding: 8px 2px; }
.stub-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.stub-list li { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.stub-list a { font-weight: 600; text-decoration: none; }

/* Above the tab bar and, on an event page, above the pinned row (--pinned-bar, set by lib-board/track-slot.js). */
#toasts { position: fixed; left: 50%; bottom: calc(var(--tabbar-total) + var(--pinned-bar, 0px) + 16px); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-size: .9rem; }
.toast-action { flex: none; min-height: 40px; padding: 0 14px; border: 1px solid currentColor; border-radius: 6px; background: transparent; color: inherit; font-weight: 600; }
.toast-action:hover { border-color: currentColor; background: color-mix(in srgb, currentColor 12%, transparent); }
.toast-error { background: var(--urgent); color: #fff; }

.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(92vw, 520px); }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; }
.dlg-title { margin: 0; font-size: 1.05rem; }
.dlg-x { width: 44px; border: 0; background: transparent; font-size: 1.4rem; }
.dlg-body { padding: 8px 16px 16px; }

/* Community is reached on purpose, not first: a plainer link after Me. */
#topnav a.nav-secondary { font-weight: 400; color: var(--muted); }
