/* Elements, then a few generic components (rule AR6). */

:root {
  --text: #1b1f24;
  --muted: #5b6470;
  --background: #ffffff;
  --surface: #f2f4f7;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --alert: #a3201a;
  --border: #c9ced6;
  --outer: #dfe3e9;
  /* The closed menu's height: what stays on top of a phone's screen. */
  --nav-height: 3rem;
  color-scheme: light dark;
}

/* Dark: the device's setting, unless the reader chose a theme at the
   bottom of the page (data-theme on <html>). The two blocks hold the
   same colours: CSS cannot share them between a media query and a
   selector. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #e6e9ee;
    --muted: #a3acb8;
    --background: #14171b;
    --surface: #1f242a;
    --accent: #5aa2ec;
    --accent-text: #0b1420;
    --alert: #f08a84;
    --border: #3a414b;
    --outer: #0c0e11;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --text: #e6e9ee;
  --muted: #a3acb8;
  --background: #14171b;
  --surface: #1f242a;
  --accent: #5aa2ec;
  --accent-text: #0b1420;
  --alert: #f08a84;
  --border: #3a414b;
  --outer: #0c0e11;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
/* Wins over the display of label, p…: a hidden element stays hidden. */
[hidden] { display: none; }
/* Only for a touch screen: a mouse or a touchpad means a computer. */
@media (pointer: fine) { [data-phone-only] { display: none; } }

body {
  margin: 0;
  font: 1rem/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
}

main { max-width: 40rem; margin: 0 auto; padding: 0 1rem 3rem; }

h1 { font-size: 1.4rem; margin: 1rem 0; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }

a { color: var(--accent); }

/* Breadcrumbs: the page's parents, above its title. */
main > nav { margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
main > nav + h1 { margin-top: 0.3rem; }

/* The menu: one line, "☰ Menu", that opens the list of pages. It stays
   on top of the screen while the page scrolls, so it is always at hand. */
body > nav {
  position: sticky;
  top: 0;
  z-index: 2;
  max-height: 100vh;
  overflow-y: auto;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
body > nav summary {
  list-style: none;
  color: var(--text);
  font-weight: 600;
  line-height: var(--nav-height);
}
body > nav summary::-webkit-details-marker { display: none; }
body > nav a, body > nav form { display: block; margin: 0; padding: 0.45rem 0 0.45rem 0.75rem; }
/* The version, at the end of the menu. */
body > nav small { display: block; padding: 1rem 0 0.5rem 0.75rem; color: var(--muted); }
body > nav [aria-current="page"] {
  font-weight: 700;
  text-decoration: none;
  border-left: 0.25rem solid var(--accent);
  padding-left: 0.5rem;
}
/* A wide screen: the menu, kept open by menu.js, is a column beside the
   page, and the two are centred together; its "☰ Menu" line hides once
   open. A run's page with photos gets a wider column. */
@media (min-width: 64rem) {
  body:has(> nav) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 15rem minmax(0, 48rem) minmax(0, 1fr);
    align-items: start;
  }
  body:has(> nav):has(main [data-photos] img) {
    grid-template-columns: minmax(0, 1fr) 15rem minmax(0, 72rem) minmax(0, 1fr);
  }
  body > nav {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-height: 100vh;
    padding: 0.5rem 1rem;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  /* The page is a panel of its own, as the menu is, on the outer
     colour. */
  body:has(> nav) { background: var(--outer); }
  body:has(> nav) > main {
    grid-column: 3;
    width: 100%;
    max-width: none;
    min-height: 100vh;
    margin: 0;
    padding-left: 2rem;
    padding-right: 2rem;
    background: var(--background);
    border-right: 1px solid var(--border);
  }
  body > nav details[open] > summary { display: none; }
}

form { display: grid; gap: 0.8rem; margin: 1rem 0; }
/* A form of one field (data-inline), and a search form such as a date
   range: fields side by side, the button on the same row, wrapping on
   a narrow screen. */
form[data-inline], form[role="search"] {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: end;
}
form[data-inline] > label { flex: 1 1 14rem; }

label { display: grid; gap: 0.2rem; }

fieldset { border: 1px solid var(--border); border-radius: 0.4rem; display: grid; gap: 0.6rem; }
legend { color: var(--muted); }

input, select, textarea, button {
  font: inherit;
  color: inherit;
  min-height: 2.6rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--background);
}

input[type="checkbox"], input[type="radio"] { min-height: 0; }

/* As wide as its text, not the form: a form's title and fields come
   first, its button after. */
button {
  justify-self: start;
  padding-inline: 1.2rem;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.6; }
/* A button that must not look like the page's main action. */
button.secondary { background: none; color: var(--accent); }

details > summary { cursor: pointer; color: var(--muted); }
/* A section that opens (results, rests, games): framed like a fieldset,
   so a nested one is set in. */
main details {
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.4rem 0.8rem;
}
main details[open] > summary { margin-bottom: 0.6rem; }
main details > label, main details > details { margin-bottom: 0.6rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.35rem 0.3rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
td input { width: 100%; min-width: 4rem; }

img { max-width: 100%; height: auto; }
/* The run's photos stay at the top of the screen, under the menu, a
   third of it, while the fields scroll under them; a tap opens one in
   full. On a wide screen, the form has two columns: the photos on the
   left, as tall as the screen, and [data-fields] on the right. */
[data-fields] { display: grid; gap: 0.8rem; }
[data-photos] {
  position: sticky;
  top: calc(var(--nav-height) + 1px); /* under the menu and its border */
  z-index: 1;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.3rem 0;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
[data-photos]:not(:has(img)) { display: none; }
[data-photos] img { max-height: 33vh; width: auto; }
[data-photo-preview] { display: contents; }
@media (min-width: 64rem) {
  form:has(> [data-photos] img) { grid-template-columns: 1fr 1fr; align-items: start; }
  /* The photos share the screen's height, with no scroll bar of their
     own; the form is at least that tall, so they never cover what
     follows it. */
  form > [data-photos] {
    top: 0;
    flex-direction: column;
    height: calc(100vh - 1rem);
    overflow: visible;
    border-bottom: none;
  }
  [data-photos] a { display: contents; }
  form > [data-photos] img {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    width: 100%;
    object-fit: contain;
    object-position: left top;
  }
}

footer {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
}
footer form { display: flex; gap: 0.5rem; margin: 0; }
footer select, footer button { min-height: 0; padding: 0.2rem 0.5rem; }

[role="alert"] {
  color: var(--alert);
  border-left: 0.25rem solid var(--alert);
  padding-left: 0.6rem;
}

[role="status"] {
  border-left: 0.25rem solid var(--accent);
  padding-left: 0.6rem;
}

.table-scroll { overflow-x: auto; }
/* A row's buttons (a program's steps): small, side by side. */
[data-actions] { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
[data-actions] form { margin: 0; }
[data-actions] button { min-height: 2rem; min-width: 2rem; padding: 0 0.4rem; }
[data-actions] a { padding: 0 0.3rem; text-decoration: none; }
