/* App shell - three SIZE CLASSES (structure, owned by the UX layer; visual polish by the UI layer):
     compact  < 760px         bottom tab dock, single column
     medium   760 - 1023px    bottom tab dock, 2-col court grid (iPad portrait)
     expanded >= 1024px       labelled floating rail + live panel (iPad landscape, desktop)
   js/ui.js sizeClass() mirrors these numbers and sets <html data-size>. */

:root {
  --rail-w: 96px;
  --topbar-h: 64px;
  --cmd-h: 88px;
  --tab-h: 68px;
  --panel-w: 380px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --toast-bottom: 110px;
}

#app {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  background: var(--bg);
}

.shell-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

/* Page edges: every screen's content, the command bar and the tab dock share the top bar's
   side gutters (16 / 24 / 32px by size class), so a screen's left edge lines up with its title
   and its right edge with the top bar's last button. No screen caps its own width. */
/* Main scroll region: the only thing that scrolls (top bar, command bar and dock stay put). */
.content-scroll {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden; /* decorations that bleed off the edge (Welcome ball, court lines) must not scroll sideways */
  box-sizing: border-box;
  padding: 8px 16px 24px;
  scroll-padding: 16px;
}

.content-inner { margin: 0 auto; }

/* ---------- Top bar ---------- */
.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--topbar-h);
  padding: 8px 16px;
  box-sizing: border-box;
}
.top-bar[hidden] { display: none; }
.top-bar__title-block { min-width: 0; }
.top-bar__actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ---------- Command bar (Back | round dots | Next) ---------- */
.command-bar {
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 0 16px 10px;
}
.command-bar[hidden] { display: none; }
.command-bar__inner {
  display: grid;
  /* R2-06: Back / Next never shrink below their content; the dots track gets the rest (main.js
     swaps the dots for the round picker when they overflow it). */
  grid-template-columns: minmax(max-content, 1fr) minmax(0, auto) minmax(max-content, 1fr);
  align-items: center;
  gap: 8px;
}

/* ---------- Rail (Expanded only) ---------- */
.rail {
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  width: var(--rail-w);
  box-sizing: border-box;
  margin: 12px 0 12px 12px;
  padding: var(--space-4) var(--space-2);
  border-radius: var(--radius-4); /* R4-08 */
}

/* ---------- Tab dock (Compact + Medium) ---------- */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  min-height: var(--tab-h);
  margin: 0 16px calc(10px + var(--safe-bottom));
  padding: 6px;
  box-sizing: border-box;
}
.tab-bar .tab-item { flex: 1; min-height: 52px; justify-content: center; }

/* ---------- Round screen: courts + live panel ---------- */
.round-layout { display: flex; flex-direction: column; gap: 12px; }
/* Below Expanded the panel dissolves so its children join .round-layout's flex column;
   the timer dock becomes an inline strip above the courts. Phone timer placement (b): it is
   not sticky - it scrolls away with the page, and the top-bar round mini pill stands in for
   it while it is out of view (main.js observeRoundDock, chrome.css). main.js also keeps the
   courts still when the dock changes height off-screen, so native anchoring is switched off
   here to avoid a double correction. */
.live-panel { display: contents; }
.live-panel .timer-dock { order: -1; }
@media (max-width: 1023px) { .content-scroll[data-screen="round"] { overflow-anchor: none; } }
.live-panel .panel-section { order: 1; }

@media (min-width: 760px) {
  :root { --topbar-h: 72px; --cmd-h: 96px; --toast-bottom: 200px; }
  .content-scroll { padding: 8px 24px 24px; }
  .top-bar { padding: 8px 24px; }
  .command-bar { padding: 0 24px 12px; }
  .tab-bar { margin-left: 24px; margin-right: 24px; }
}

@media (min-width: 1024px) {
  :root { --toast-bottom: 120px; }
  .rail { display: flex; }
  .tab-bar { display: none; }
  .content-scroll { padding: 8px 32px 28px; }
  .top-bar { padding: 8px 32px; }
  .command-bar { padding: 0 32px 16px; }

  .round-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--panel-w);
    gap: 24px;
    align-items: start;
  }
  .live-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 0;
    /* Taller than the viewport? The panel scrolls on its own (timer stays reachable). */
    max-height: calc(100dvh - var(--topbar-h) - var(--cmd-h) - var(--banner-h, 0px) - 44px);
    overflow-y: auto;
    padding: 2px;
    margin: -2px;
    /* R1-02: a thin visible scrollbar plus a fade at the bottom edge while more is below. */
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
    overscroll-behavior: contain;
  }
  .live-panel::-webkit-scrollbar { width: 4px; }
  .live-panel::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 2px; }
  .live-panel[data-more="true"] {
    -webkit-mask-image: linear-gradient(#000 calc(100% - 40px), transparent);
    mask-image: linear-gradient(#000 calc(100% - 40px), transparent);
  }
  .live-panel > * { flex-shrink: 0; }
  .live-panel .timer-dock { order: 0; position: static; }
  .live-panel .panel-section { order: 0; }
}

/* R1-02: short Expanded viewports (iPad landscape 820/768 tall) - tighter timer card and a
   top-3 leaderboard so Up next is visible without scrolling. */
@media (min-width: 1024px) and (max-height: 899px) {
  .live-panel { gap: 12px; }
}
