/* Base: reset, typography, utilities and the app frame (header, bottom nav, footer). Mobile first. */
* { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
/* Safety net: whatever overflows, the page never becomes wider than the screen. `clip` (unlike `hidden`) does not turn the
   element into a scroll container, so position: sticky and the fixed bottom bar keep working. */
html, body { max-width: 100%; overflow-x: clip; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: var(--leading);
  /* Room for the fixed bottom navigation so the last card is never covered. */
  padding-bottom: calc(var(--tap) + var(--sp-4) + env(safe-area-inset-bottom, 0px));
}

h1 { font-size: var(--text-2xl); line-height: var(--leading-tight); margin: 0 0 var(--sp-4); }
h2 { font-size: var(--text-xl); line-height: var(--leading-tight); margin: 0 0 var(--sp-3); }
h3 { font-size: var(--text-base); margin: 0; }
p { margin: 0 0 var(--sp-2); }
a { color: var(--link); }
a:hover { color: var(--link-hover); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus, h1:focus { outline: none; } /* focus moves here on navigation; a ring on a heading is noise */

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

.skip-link {
  position: absolute; left: var(--sp-2); top: -4rem; z-index: 1000;
  background: var(--ink); color: var(--page); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--sp-2); }

/* Header: stays on one line at 360px because the navigation moved to the bottom bar. */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-4);
  background: var(--header-bg); color: var(--header-ink); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: var(--z-header);
}
.app-header a { color: var(--header-ink); text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; min-height: var(--tap); white-space: nowrap; }
/* The official logo (an app-icon square): rounded to match its own corners, never stretched. */
.brand-logo { width: 36px; height: 36px; border-radius: 9px; display: block; flex: none; }
.brand-name { font-weight: 800; letter-spacing: -.01em; }
.brand-name b { color: var(--emerald-400); font-weight: 800; }
.header-action {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: var(--tap); min-width: var(--tap); padding: 0 var(--sp-3);
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--header-ink); font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer;
}
.header-action:hover { background: rgba(255, 255, 255, .12); }

.container { max-width: var(--container); margin: 0 auto; padding: var(--sp-5) var(--sp-4) var(--sp-6); }

/* Bottom navigation: replaces the cramped top menu and keeps 4 destinations reachable with the thumb. */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: var(--z-nav);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: var(--shadow-lg);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tap); padding: var(--sp-1) 0;
  color: var(--muted); text-decoration: none; font-size: var(--text-xs); font-weight: 600;
}
.bottom-nav a[aria-current="page"] { color: var(--primary); }

.app-footer {
  max-width: var(--container); margin: 0 auto;
  padding: var(--sp-3) var(--sp-4) var(--sp-5);
  color: var(--muted); font-size: var(--text-xs);
}
.app-footer p { margin: var(--sp-1) 0; }

/* On phones the top navigation is hidden: the bottom bar owns it. These two rules must stay in this order, the media
   query AFTER the base rule, otherwise the desktop loses its navigation entirely. */
.app-header nav { display: none; }

@media (min-width: 48rem) {
  h1 { font-size: var(--text-3xl); }
  .bottom-nav { display: none; }
  body { padding-bottom: 0; }
  .app-header nav { display: flex; gap: var(--sp-1); }
  .app-header nav a {
    display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--sp-3);
    border-radius: var(--radius-sm); font-weight: 600;
  }
  .app-header nav a[aria-current="page"] { background: rgba(255, 255, 255, .18); }
  .app-header nav a:hover { background: rgba(255, 255, 255, .16); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}