/* Colours: the system's own (CSS system colours). The page follows the light or dark theme of the operating system and
   its high-contrast modes, and the contrasts are the ones the system guarantees. No palette of our own. */
:root {
  color-scheme: light dark;
  --bg: Canvas;
  --text: CanvasText;
  --link: LinkText;
  --border: CanvasText;
  --surface: ButtonFace;
  --on-surface: ButtonText;
  --focus: Highlight;
  --target: 2.75rem; /* 44 px at the default font size: minimum size of a touch target */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.125rem;
  line-height: 1.5;
  /* The page fills the window, so that a zone pinned at the bottom is at the bottom of the window even on a short page. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

a {
  color: var(--link);
}

/* A visible focus on everything that can take it, never removed. */
:focus-visible,
h1:focus,
main:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

main:focus:not(:focus-visible) {
  outline: none;
}

/* The `hidden` attribute must win over the `display` of a component. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--text);
}

.skip-link:focus {
  top: 0.5rem;
}

/* One line: the button of the header (« ← Accueil », « ← Retour », none on the home page) and the title of the page. */
.site-header {
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.site-header .site-name[hidden] {
  display: none;
}

.site-title {
  flex: 1 1 0;
  min-width: 0;
}

/* The title of the page (its h1, or the name of the page when the h1 is the title of a programme in the page). */
.site-title h1,
.site-title-text {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* Buttons that navigate look like the rest of the page, not like system buttons. */
.site-name,
.nav-button {
  font: inherit;
  color: var(--text);
  cursor: pointer;
}

.site-name {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 0 0.25rem;
  border: 0;
  background: none;
  font-weight: 700;
}

.nav-button {
  min-height: var(--target);
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--on-surface);
}

.nav-button:hover {
  border-color: var(--text);
}

/* The message "a new version is available": above the header, with its single button. */
.update-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--on-surface);
}

.update-notice[hidden] {
  display: none;
}

.update-notice p {
  margin: 0;
}

.update-notice button {
  min-height: var(--target);
  padding: 0.5rem 1rem;
  font: inherit;
}

main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
}

/* A page with a zone pinned at the bottom: the zone is pushed to the bottom of the window (`margin-top: auto`). */
main:has(> .sticky-bottom) {
  display: flex;
  flex-direction: column;
}

h1 {
  margin: 0.5rem 0 1rem;
  font-size: 1.75rem;
  line-height: 1.25;
}

/* Home menu: one large row per entry. */
.menu {
  margin: 0;
  padding: 0;
  list-style: none;
}

.menu li + li {
  margin-top: 0.5rem;
}

.menu .nav-button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 3.5rem;
  font-weight: 600;
  text-align: left;
}

/* Areas pinned to the top or the bottom of the page while the content scrolls (sticky, never fixed). */
.sticky-top,
.sticky-bottom {
  position: sticky;
  z-index: 5;
  padding: 0.5rem 0;
  background: var(--bg);
}

.sticky-top {
  top: 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.sticky-bottom {
  bottom: 0;
  border-top: 1px solid var(--border);
}

/* The pinned areas must not hide the element that takes the focus while the page scrolls to it: 7.5rem (120 px) is more than
   the row at the top on two lines (110 px; decided on 2026-10-14, 6rem was too short). */
html {
  scroll-padding-block: 7.5rem;
}

/* "40 programmes restants" under the family button of "Sélection rapide". */
.sort-remaining {
  margin: 0 0 0.5rem;
}

.sort-remaining[hidden] {
  display: none;
}

/* A pinned row of controls, in two equal columns: at the top the two checkboxes (audiodescription on the left, short programmes
   on the right) and the family button on a second line across the two columns (`.control-wide`); at the bottom of
   "Programmes" the time slot and the day. Every text is on one line and cut with "…" when it does not fit. */
.control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.25rem 0.5rem;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.control-wide {
  grid-column: 1 / -1;
}

/* The row at the bottom of "Programmes" (time slot, day) is pushed to the bottom of the window, like the detail actions. */
.page-bottom {
  margin-top: auto;
}

.control input[type="checkbox"] {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
}

/* One line of text, as high as a touch target, cut with "…" (the full name stays in the accessible name). */
.control label {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  line-height: var(--target);
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* A checkbox label has a full text and a short one: the short one by default (and where container queries are unknown), the
   full one when the cell is wide enough. The cell is the container; its width follows the window, and the thresholds are in rem so
   that a larger text size brings the short text back sooner. */
.control-text {
  container-type: inline-size;
}

.label-full {
  display: none;
}

/* "Audiodescription" is long (about 136 px, plus the box and its margins): the full word from 11.5 rem of cell, so a half of
   a 360 px phone (10 rem) shows "AD"; "Prog. courts" is shorter. */
@container (min-width: 11.5rem) {
  .control-ad .label-full {
    display: inline;
  }

  .control-ad .label-short {
    display: none;
  }
}

@container (min-width: 7.5rem) {
  .control-short .label-full {
    display: inline;
  }

  .control-short .label-short {
    display: none;
  }
}

.control .choice-wrapper,
.control .choice-wrapper > button {
  width: 100%;
  margin: 0;
}

/* The buttons that open a choice menu, and the buttons of the selection: one line of text, cut with "…". */
.choice-button,
.detail-actions .nav-button {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Lists of programmes: one full-width button per line. */
.program-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.program-list li + li {
  margin-top: 0.5rem;
}

.program-list .nav-button {
  display: block;
  width: 100%;
  text-align: left;
}

/* Settings: sections, groups of checkboxes (one per bouquet), text and number fields. */
h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.35rem;
  line-height: 1.25;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.setting-row input[type="checkbox"] {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
}

.setting-row label {
  display: inline-flex;
  align-items: center;
  flex: 1;
  min-height: var(--target);
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.75rem 0;
}

.setting-field input {
  min-height: var(--target);
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

#short-threshold {
  max-width: 8rem;
}

/* Page of a programme. */
/* One paragraph per element; a short one is "Name : value" on a single line. */
.detail-fields > p {
  margin: 0.5rem 0;
}

.detail-label {
  font-weight: 700;
}

.detail-fields dt {
  margin-top: 1rem;
  font-weight: 700;
}

.detail-fields dd {
  margin: 0;
}

.detail-fields dd p {
  margin: 0.5rem 0 0;
}

.detail-fields {
  margin-bottom: 1.5rem;
}

/* The button of the selection: "Vu ou ignorer" at the bottom left, "Sélectionner" at the bottom right. */
.detail-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.5rem;
  margin-top: auto;
}

.action-left {
  grid-column: 1;
}

.action-right {
  grid-column: 2;
}

/* Choice buttons: a button named after the active choice, opening a modal dialog with the choices. */
.choice-wrapper {
  position: relative;
  display: inline-block;
  margin: 0.5rem 0;
}

.choice-list button {
  display: block;
  width: 100%;
  text-align: left;
}

.choice-dialog {
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 1rem;
  border: 2px solid var(--text);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--text);
}

.choice-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.choice-title {
  margin: 0 0 0.5rem;
  font-weight: 700;
}

.choice-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.choice-list .nav-button {
  border: 1px solid var(--border);
}

.choice-list li + li {
  margin-top: 0.5rem;
}

/* The slider of the trial page: a large target, the value in big letters, the hint under it. */
.choice-slider {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  min-height: 7rem;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--on-surface);
  touch-action: manipulation;
}

.choice-slider-value {
  font-size: 1.5rem;
  font-weight: bold;
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
