/* The frame and the top bar: how the app meets the edges of the screen.

   Loaded LAST. Every rule about the app's outer size, the notch and home
   bar, and the top bar lives here and nowhere else -- the bar used to be
   restyled by ten breakpoints in two files, each patching the one before.

   1. The frame fills the screen at its real, current height (dvh), so a
      phone's browser bars sliding in and out never hide the bottom.
   2. Any space the device reserves at an edge -- a home bar, a notch -- is
      reached into by the piece beside it, in ITS OWN background, so the extra
      space is always the colour of whatever is next to it, and only exists
      where the device has one. (Since 2026-11-03 the page does not opt into
      drawing under the status bar -- no viewport-fit=cover, an opaque status
      bar -- so iOS keeps it below the clock itself; these rules cover what
      is left, and any device that still reports an inset.)
   3. The top bar is fluid: its height and buttons scale smoothly with the
      screen (clamp), and as the screen narrows it gives things up in a fixed
      order -- the words on the stats, then the button labels, then the
      wordmark for the badge, then the kid's name, then the streak, then the
      points. Buttons never go below 40px. */

/* ------------------------------------------------------------ 1. frame */

#app {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--app-bg);
}
@supports (height: 100dvh) { #app { height: 100dvh; } }

/* ------------------------------------------------------------ 2. edges */

/* A background paints under its own border, so a transparent border as wide
   as the inset IS the element reaching into the inset in its own colour,
   with its content kept clear of it. Every screen is a child of #app. */
#app > * {
  border: 0 solid transparent;
  border-left-width: env(safe-area-inset-left);
  border-right-width: env(safe-area-inset-right);
}
#app > :first-child { border-top-width: env(safe-area-inset-top); }
#app > :last-child  { border-bottom-width: env(safe-area-inset-bottom); }

/* Parent mode and the app admin are one block holding a dark bar and a light
   page: the bar takes the top, the page the bottom. */
#app > .parent { border-width: 0; }
.parent > * {
  border: 0 solid transparent;
  border-left-width: env(safe-area-inset-left);
  border-right-width: env(safe-area-inset-right);
}
.parent > .parent-bar { border-top-width: env(safe-area-inset-top); }
.parent > :last-child { border-bottom-width: env(safe-area-inset-bottom); }
.parent-bar { height: auto; min-height: calc(64px + env(safe-area-inset-top)); }
@media (max-width: 560px), (max-height: 500px) {
  .parent-bar { min-height: calc(52px + env(safe-area-inset-top)); }
}

/* Things that float over the page keep clear of the notch and home bar too. */
.toast { bottom: calc(30px + env(safe-area-inset-bottom)); }
.rv { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* ---------------------------------------------------------- 3. top bar */

.header {
  /* The bar's height, and from it the buttons'. 52px on a phone, about 66px
     on an iPad held sideways, 76px on a desktop; 48px on a short screen. */
  --bar: clamp(52px, calc(38px + 2.4vw), 76px);
  --hit: clamp(40px, calc(var(--bar) - 20px), 48px);
  flex: none;
  height: calc(var(--bar) + env(safe-area-inset-top));
  display: flex; align-items: center;
  gap: clamp(4px, .7vw, 10px);
  padding: 0 clamp(8px, 1.6vw, 22px);
  background: var(--dark); color: #fff;
}
@media (max-height: 500px) { .header { --bar: 48px; } }

/* The logo -- the way home. The wordmark where there is room for it, the
   neon badge (the home-screen icon) where there is not. */
.header-home { flex: none; display: flex; align-items: center; min-height: var(--hit); padding: 0; }
.header .wordmark { width: clamp(170px, 19vw, 300px); }
.header .monogram { display: none; height: var(--hit); width: var(--hit); flex: none; }
.header .monogram img { display: block; width: 100%; height: 100%; border-radius: 22%; }
.header-spacer { flex: 1 1 0; min-width: 0; }

/* Calendar, Training, Drills, Locker -- and the kid, which is a pill too. */
.pill {
  position: relative; flex: 0 1 auto;
  height: var(--hit); min-width: var(--hit); padding: 0 clamp(10px, 1.1vw, 16px);
  border-radius: 999px; background: rgba(255,255,255,.1); color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 600; white-space: nowrap;
}
.pill.active { background: #fff; color: #141414; }
.pill.on { background: var(--accent); color: var(--ink); }

/* Streak and points: read-only, so no pill shape and no pressed state. */
.hdr-stats { display: flex; align-items: center; gap: clamp(8px, 1vw, 14px); flex: none; padding: 0 4px; }
.hdr-stat { display: inline-flex; align-items: center; gap: 5px; color: #fff; cursor: default; user-select: none; }
.hdr-stat-num { font-size: 19px; font-weight: 700; }
.hdr-stat-sub { font-size: 13px; opacity: .7; }

/* The kid: their number on a dot, their name, the menu arrow. The dot is
   sized here, from the bar -- not inline from the script, which CSS cannot
   shrink. */
.kid-menu-wrap { position: relative; flex: none; }
.kid-chip {
  --dot: calc(var(--hit) - 4px);
  height: calc(var(--hit) + 4px); padding: 0 12px 0 4px; gap: 8px; flex: none;
}
.kid-chip .jersey-dot { width: var(--dot); height: var(--dot); font-size: calc(var(--dot) * .46); }
.kid-chip-initial { display: none; }

/* As the screen narrows, in this order. */
@media (max-width: 1100px) {
  .hdr-stat-sub { display: none; }
}
@media (max-width: 900px) {
  .header .pill-label { display: none; }
  .header .pill:not(.kid-chip) { padding: 0; width: var(--hit); flex: 0 1 var(--hit); min-width: 38px; }
}
@media (max-width: 720px) {
  .header .wordmark { display: none; }
  .header .monogram { display: block; }
}
@media (max-width: 520px) {
  /* The dot has the number; the name moves into the menu it opens. */
  .kid-chip-name { display: none; }
  .kid-chip { padding: 0 6px 0 4px; gap: 2px; }
  .kid-menu-name {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 14px 10px; margin-bottom: 4px;
    border-bottom: 2px solid var(--hairline);
    font-size: 20px; font-weight: 800; color: var(--ink-900);
  }
  .hdr-stat:first-child { display: none; }
}
@media (max-width: 400px) {
  /* Points too: they are on the kid's card on the start screen and in the
     Locker. */
  .hdr-stats { display: none; }
}

/* The home-screen app on an iPhone or iPad: iOS softens the top edge of the
   app just below the clock, and it reached about a third of the way into
   the top bar, blurring its buttons (2026-11-04). The top piece reaches
   20px higher in its own colour, so the blur lands on empty bar instead.
   -webkit-touch-callout is iOS-only, so Android and desktops are untouched. */
@media (display-mode: standalone) {
  @supports (-webkit-touch-callout: none) {
    #app > :first-child, .parent > .parent-bar {
      border-top-width: calc(env(safe-area-inset-top) + 20px);
    }
    .header { height: calc(var(--bar) + env(safe-area-inset-top) + 20px); }
    .parent-bar { min-height: calc(64px + env(safe-area-inset-top) + 20px); }
  }
}
@media (display-mode: standalone) and ((max-width: 560px) or (max-height: 500px)) {
  @supports (-webkit-touch-callout: none) {
    .parent-bar { min-height: calc(52px + env(safe-area-inset-top) + 20px); }
  }
}
