/* The app shell: the app bar (.topbar) with the brand, the four tabs, the theme toggle and the Parents link.
   Linked from index.html after styles.css. Everything is plain CSS on the static markup in index.html.

   From 720 px: one sticky row, brand | tabs | tools. The row always fits, at every text size up to 200 %, because its parts shrink
   to what is certain to fit: the tabs keep their labels from 720 px at the default text size and show them only while the bar is
   wide enough for four labels on ONE line (a container query in rem, so it follows the text size), icon-only below that (large
   text); the Parents link adds its word beside the gear where there is still room (its label is its name either way). Labels never wrap, so the sticky bar is never taller than a row (a long brand name may take two
   lines). Below 720 px: a compact header, the brand and tools on top and the four tabs as an equal-width icon-and-label row
   under them, not sticky so it never eats a small screen; there the labels hide when the bar is narrower than 18rem. The hidden
   labels stay the links' accessible names. The bar sits inside the page flow and is not a fixed bottom bar: a fixed bar would
   cover content, the plan page's sticky status line and the widget screenshots. Nothing in the bar animates or transitions: the
   widget browser tests assert that nothing on a widget's page does. Do not make <body> a container: that would stop its
   background from painting the whole window. */

.topbar {
  position: static; z-index: 5;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 24px -16px color-mix(in srgb, var(--accent) 60%, transparent);
  padding: 0.5rem 16px;
}

.topbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand tools" "nav nav";
  align-items: center; gap: 0.4rem 0.75rem;
  /* The bar's own width, in rem, is what the label queries below measure (its width does not depend on its content). */
  container: bar / inline-size;
}

.brand { grid-area: brand; display: inline-flex; align-items: center; gap: 0.55rem; min-width: 0; min-height: 44px; font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; color: var(--text); text-decoration: none; }
.brand-mark { flex: none; width: min(2rem, 40px); height: min(2rem, 40px); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 45%, transparent)); }
.brand-name { min-width: 0; overflow-wrap: anywhere; line-height: 1.1; }
.brand-accent { background: linear-gradient(90deg, var(--accent), var(--neon-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
@media (forced-colors: active) { .brand-accent { background: none; color: inherit; } }

/* The tabs. */
.app-nav { grid-area: nav; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }

.nav-tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 44px; min-height: 48px; padding: 0.3rem 0.15rem; border: 1px solid transparent; border-radius: 14px;
  color: var(--muted); text-decoration: none; text-align: center; font-size: 0.72rem; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere;
}
.nav-label { white-space: nowrap; overflow-wrap: normal; }
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab[aria-current="page"] {
  color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 16px -4px color-mix(in srgb, var(--accent) 55%, transparent);
}
.nav-icon { flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Too narrow for the words (a phone, or large text, where the nav is only a few rem wide): icons only. The labels stay in the
   page for screen readers. */
@container bar (width < 18rem) {
  .nav-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
}

.topbar-tools { grid-area: tools; display: flex; align-items: center; gap: 4px; }
.nav-parents { flex-direction: row; min-height: 44px; padding: 0 0.6rem; }
.nav-parents .nav-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.theme-toggle {
  position: relative; display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 14px -4px color-mix(in srgb, var(--accent) 60%, transparent); }
.theme-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle[aria-pressed="true"] .theme-icon--sun, .theme-toggle[aria-pressed="false"] .theme-icon--moon { display: none; }
.theme-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* The one-row bar. Three content-sized tracks, spaced tightly so the labels fit from 720 px at the default text size (and roomier
   again once the bar is 60rem wide, at the end of this block). */
@media (min-width: 720px) {
  .topbar { position: sticky; top: 0; }
  /* None can squeeze another (the brand wraps to two lines before anything overlaps). */
  .topbar-inner { grid-template-columns: auto auto auto; justify-content: space-between; grid-template-areas: "brand nav tools"; gap: 0.5rem; }
  .app-nav { grid-template-columns: repeat(4, auto); justify-content: center; gap: 2px; }
  .nav-tab { flex-direction: row; gap: 0.25rem; min-height: 44px; padding: 0.4rem 0.45rem; font-size: 0.92rem; }
  .topbar-tools { gap: 2px; }
  .nav-parents { padding: 0 0.5rem; }
  /* Measured in Docker (bar = brand + tabs + tools + gaps): with the four labels 681 px at a 16 px root (42.6rem before the padding was
     tightened, about 41.4rem after), less in rem at larger text (the px parts are icons), so a threshold of 42rem leaves a margin
     at every size up to where the 1100 px bar stops: 672 px at a 16 px root, so the labels show from a 720 px window. The Parents
     label adds about 60 px (722 px at 16 px, 45.1rem): it shows from 45.5rem, so only where the tabs' labels show too. Narrower
     than 42rem the tabs are icons, which only happens at large text. */
  @container bar (width >= 45.5rem) { .nav-parents .nav-label { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip-path: none; } }
  @container bar (width < 42rem) {
    .nav-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
    .nav-tab { padding: 0.4rem 0.7rem; }
  }
  /* Wide bars get the roomier spacing back. .topbar-inner is the container, so a container query cannot change its own gap: the extra
     0.5rem on each side of the nav (on top of its 0.5rem gap) makes the 1rem between brand, tabs and tools. Measured in Docker (see the
     comment in tests/ui-shell-browser.test.js): the roomy row with the four labels and the Parents word is 841 px at a 16 px root
     (52.6 rem, and less in rem at larger text, since the icons and the toggle are px), so a 60rem threshold leaves a margin of about
     7.4 rem (119 px); a 1100 px bar is 60rem only up to an 18.3 px root. The labels are never hidden here (their threshold is 42rem),
     so the larger tab padding of the narrow rule above does not apply. */
  @container bar (width >= 60rem) {
    .app-nav { margin-inline: 0.5rem; gap: 6px; }
    .nav-tab { gap: 0.45rem; padding: 0.4rem 0.9rem; }
    .topbar-tools { gap: 6px; }
    .nav-parents { padding: 0 0.9rem; }
  }
}

/* A focused element scrolled to the top edge must not end up under the sticky bar (a row: about 60 px at 16 px text, about 95 px at
   32 px, where the brand may take two lines). */
@media (min-width: 720px) { html { scroll-padding-top: calc(2rem + 48px); } }
