/* tech2 base — reset, shell layout, safe areas, scroll behavior. */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* The shell is position:fixed and #view owns all scrolling, so the document itself
   * must never scroll — otherwise iOS scrolls the page *and* the view, which reads as
   * the chrome drifting. Also the backstop against one unshrinkable flex child dragging
   * the fixed chrome sideways. */
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  overflow: hidden;
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Stop iOS rubber-banding the whole document behind the shell. */
  overscroll-behavior-y: none;
  /* Kill the 300ms tap flash without killing selection. */
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, h5, h6, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, video { display: block; max-width: 100%; }
img { background: var(--surface-alt); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

a { color: var(--accent-text); text-decoration: none; }

/* Visible focus for keyboard users only — pointer taps stay clean. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

/* ---------- App shell ----------
   Fixed header + fixed tab bar + one scrolling region between them.
   The scroll region — not the document — is what moves, so the chrome
   never drifts on iOS and scroll position is trivially restorable. */

/* Pinned to the visual viewport rather than sized with 100dvh.
 *
 * `height: 100dvh` left a gap below the tab bar in the installed PWA: dvh resolves
 * against the *layout* viewport, which on iOS standalone doesn't always agree with the
 * physical screen, so the shell ended up a few pixels short and body background showed
 * through under the bar. `position: fixed; inset: 0` is measured against the visual
 * viewport, so the bottom edge is the bottom edge. */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#header {
  flex: none;
  z-index: var(--z-header);
  padding-top: var(--sat);
  background: var(--bg-header);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-md);
}

.header-row {
  height: var(--header-h);
  display: grid;
  grid-template-columns: var(--tap-min) 1fr auto;
  align-items: center;
  gap: var(--s-2);
  padding-inline: max(var(--s-2), var(--sal)) max(var(--s-2), var(--sar));
}

/* With no back button there is no leading cell at all — reserving one would push the
 * title into an 8px column and wrap it to one character per line. */
.header-row.no-lead {
  grid-template-columns: 1fr auto;
  padding-left: max(var(--s-4), var(--sal));
}

.header-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.header-title strong {
  font-size: var(--text-lg);
  font-weight: var(--weight-semi);
  line-height: var(--leading-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-title small {
  font-size: var(--text-xs);
  opacity: 0.72;
  line-height: var(--leading-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  color: var(--text-on-brand);
  transition: background var(--dur-fast) var(--ease-out);
}
.header-btn:active { background: rgb(255 255 255 / 16%); }
.header-btn svg { width: 22px; height: 22px; }

.header-actions { display: flex; align-items: center; }

/* Slot for a segmented control or search bar pinned under the title row. */
#header-extra:empty { display: none; }

#view {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  padding-inline: max(0px, var(--sal)) max(0px, var(--sar));
}
@media (prefers-reduced-motion: reduce) {
  #view { scroll-behavior: auto; }
}

/* Every view pads its own bottom so the tab bar never covers content. */
.view-pad { padding-bottom: var(--s-8); }

#tabbar {
  flex: none;
  z-index: var(--z-tabbar);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-up);
  padding-bottom: var(--sab);
  padding-inline: max(0px, var(--sal)) max(0px, var(--sar));
}
#tabbar[hidden] { display: none; }

.tab {
  flex: 1;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--s-1) var(--s-1);
  color: var(--text-faint);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  position: relative;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab svg { width: 23px; height: 23px; }
.tab[aria-current="page"] { color: var(--accent-text); }
.tab:active { opacity: 0.6; }

.tab-badge {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: 4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: var(--white);
  font-size: 10px;
  font-weight: var(--weight-bold);
  line-height: 17px;
  text-align: center;
}

/* ---------- View transitions ----------
   Push feels forward, back feels backward. Falls back to a plain swap
   in browsers without the API and is disabled under reduced-motion. */

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: var(--dur-base);
    animation-timing-function: var(--ease-out);
  }

  html[data-nav="push"]::view-transition-old(root) {
    animation-name: slide-out-left;
  }
  html[data-nav="push"]::view-transition-new(root) {
    animation-name: slide-in-right;
  }
  html[data-nav="pop"]::view-transition-old(root) {
    animation-name: slide-out-right;
  }
  html[data-nav="pop"]::view-transition-new(root) {
    animation-name: slide-in-left;
  }
}

@keyframes slide-in-right {
  from { transform: translateX(22%); opacity: 0.4; }
  to   { transform: translateX(0);   opacity: 1; }
}
@keyframes slide-out-left {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(-14%); opacity: 0.4; }
}
@keyframes slide-in-left {
  from { transform: translateX(-14%); opacity: 0.4; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slide-out-right {
  from { transform: translateX(0);   opacity: 1; }
  to   { transform: translateX(22%); opacity: 0.4; }
}
