/* Base: reset, type, page shell. Components live in components.css, screens in screens.css. */
*, *::before, *::after { box-sizing: border-box; }

/* `hidden` always wins over a component's display, so toggled fields really disappear. */
[hidden] { display: none !important; }

/* A phone's browser flashes a grey box over anything tapped; every control has its own pressed state instead
   (components.css, "Pressed"). */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
/* No double-tap zoom on controls, so a tap answers at once (pinch zoom stays on). */
:is(a, button, input, select, textarea, label, summary, [role="button"]) { touch-action: manipulation; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.4;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 800; line-height: 1; letter-spacing: 0.005em; }
h1 { font-size: var(--h1); }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
p { margin: 0; }
a { color: var(--ink); }
/* Hover styles only where there is a pointer to hover with: on a touch screen a tap would leave them stuck on. */
@media (hover: hover) and (pointer: fine) { a:hover { color: var(--signal); } }
button, input, select, textarea { font: inherit; color: inherit; }
/* Never under 16px, so iOS Safari doesn't zoom in on focus (pinch zoom stays on). */
input, select, textarea { font-size: max(16px, 1em); }
button { cursor: pointer; }
ul { margin: 0; padding: 0; list-style: none; }
svg { display: block; }

.display { font-family: var(--font-display); font-weight: 800; line-height: 1; }
.muted { color: var(--muted); }
.small { font-size: 15px; line-height: 1.45; }
.tiny { font-size: 14px; line-height: 1.4; }
.green { color: var(--green-deep); }
.warn { color: var(--warn); }
.eyebrow { font-size: 13px; font-weight: 700; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
/* Numbers that change use fixed-width figures, so columns line up and a new value doesn't nudge its neighbours. */
:is(.history-row .w, .history-row .d, .tile .value, .crew-points, .crew-rank, .loop-mark-number, .week-change, .calc-number, .admin-tile b) { font-variant-numeric: tabular-nums; }
/* Keyboard users jump past the navigation: off screen until it takes focus. */
.skip-link { position: absolute; left: -9999px; z-index: 3; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--ink); color: var(--paper); font-weight: 700; }
.skip-link:focus-visible { left: 16px; top: 16px; }
.nowrap { white-space: nowrap; }

/* Page shell: one phone-width column, centred on larger screens until the desktop layout lands. */
.screen {
  max-width: var(--screen);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.screen-public { padding: var(--top-inset) var(--gutter) var(--space-6); gap: var(--space-4); }
.screen-app { padding-bottom: 0; }
body:has(.tabs) .screen-app { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.screen-setup { padding: var(--top-inset) var(--gutter) var(--space-6); gap: var(--space-4); }

/* Turbo's bar on a slow visit: the orange, thin, under the status bar in the installed app (not its default blue). */
.turbo-progress-bar { height: 3px; background: var(--signal); }
@media (display-mode: standalone) { .turbo-progress-bar { top: env(safe-area-inset-top); } }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
/* Separate blocks that belong together. */
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
/* A title and the line under it. */
.stack-xs { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-5); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.grow { flex: 1; }
.push-bottom { margin-top: auto; }

.header-sky {
  background: var(--sky);
  border-bottom: 1px solid var(--line);
  padding: var(--top-inset) var(--gutter) var(--header-pad);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.header-plain {
  padding: var(--top-inset) var(--gutter) var(--header-pad);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}
/* A back header: a slim back chevron (no circle, a 44px tap area) and the title beside it, so the title gets nearly the
   full width. 28px on a phone, 38px from ~530px; long names break evenly and never overflow. */
.header-back {
  padding: var(--top-inset) var(--gutter) var(--header-pad);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: var(--space-0-5);
}
.row:has(> .back) { gap: var(--space-0-5); align-items: flex-start; }
/* Lined up with the title's first line, not the middle of the title and its subline: the chevron's middle sits just under
   the middle of the capitals (0.53 of the title's size from its top), at every title size, so it reads centred beside a
   mostly lower-case word. The 44px tap area is centred on it. */
:is(.header-back, .row:has(> .back)) { --title-size: clamp(28px, 7.2vw, var(--h1)); }
:is(.header-back, .row:has(> .back)) > .back { margin: calc(var(--title-size) * 0.53 - var(--tap) / 2) 0 0 -14px; border: 0; background: none; }
:is(.header-back, .row:has(> .back)) > .back svg { width: 22px; height: 22px; }
:is(.header-back, .row:has(> .back)) h1 { font-size: var(--title-size); text-wrap: balance; overflow-wrap: anywhere; }
.body { padding: var(--space-4) var(--gutter) var(--space-3); display: flex; flex-direction: column; gap: var(--space-4); }
/* Groups on a page: a label and its cards, set apart from the next label and its cards. */
.sections { display: flex; flex-direction: column; gap: var(--section-gap); }

.wordmark { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: 22px; letter-spacing: -0.01em; text-decoration: none; }
.wordmark svg { width: 30px; height: 30px; }

/* From 900px up: a top bar instead of bottom tabs, a wider column, no status-bar inset.
   From 1200px, Today spreads into three columns: the morning, the route, progress (BDesktop). */
@media (min-width: 900px) {
  :root { --screen: 640px; }
  body:has(.tabs) .screen-app { padding-bottom: var(--space-7); }
  .screen-public, .screen-setup { padding-top: var(--space-7); }
  /* The rule under a title spans the content, not the content plus the gutters. */
  .header-plain, .header-back { margin-inline: var(--gutter); padding-inline: 0; }
}

.today-side { display: none; }
@media (min-width: 1200px) {
  .screen:has(.today-layout) { --screen: 1340px; }
  /* Progress on the left, the morning in the centre, the route on the right. */
  .today-layout { display: grid; grid-template-columns: minmax(340px, 1fr) minmax(380px, 1.1fr) minmax(380px, 1.1fr); gap: var(--space-5); align-items: start; padding: 0 var(--gutter); }
  /* One side panel (a first morning has the route but no chart yet; a steady loop has the chart but no route):
     two columns, 1100px. No side panel: the morning alone, 640px. */
  .today-layout:has(.today-side):not(:has(.today-progress)), .today-layout:has(.today-side):not(:has(.today-route)) { grid-template-columns: minmax(380px, 1fr) minmax(380px, 1fr); max-width: 1100px; margin: 0 auto; }
  .today-layout:not(:has(.today-side)) { grid-template-columns: minmax(380px, 1fr); max-width: 640px; margin: 0 auto; }
  .today-layout .today-main .today-header { border-radius: var(--radius); border-bottom: 0; margin: var(--space-4) var(--gutter) 0; }
  .today-side { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-4); }
  .today-side > turbo-frame { display: flex; flex-direction: column; gap: var(--space-3); }
  .today-route .route-map-wrap svg { width: 100%; height: auto; }
}

/* From 1200px, Progress and Route use the width: the chart beside the weekly table, the map beside its details. */
@media (min-width: 1200px) {
  .screen:has(.progress-body), .screen:has(.route-wide) { --screen: 1180px; }
  .progress-body { display: grid; grid-template-columns: 1.4fr 1fr; gap: var(--space-5); align-items: start; }
  .progress-body > .tiles { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); }
  /* One row of four: every tile after the first gets its divider on the left, none on top. */
  .progress-body > .tiles-grid .tile:nth-child(3) { border-left: 1px solid var(--line-soft); }
  .progress-body > .tiles-grid .tile:nth-child(n+3) { border-top: 0; }
  .route-wide { display: grid; grid-template-columns: minmax(380px, 1fr) 1fr; grid-template-rows: auto 1fr; gap: 0 var(--space-6); padding: var(--space-4) var(--gutter) 0; }
  .route-wide .route-map-wrap { grid-column: 1; grid-row: 1 / span 2; align-self: start; border-radius: var(--radius); overflow: hidden; } /* hugs the map, so all four corners show */
  .route-wide .route-header, .route-wide .body { grid-column: 2; }
}
