:root {
  color-scheme: light dark;
  --text: #1b1f23;
  --background: #ffffff;
  --muted: #4f5963;
  --control-border: #5c6670;
  --accent: #1a5fb4;
  --on-accent: #ffffff;
  --error: #b00020;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e8eaed;
    --background: #16181b;
    --muted: #b7bec6;
    --control-border: #9aa3ad;
    --accent: #8ab4f8;
    --on-accent: #10131a;
    --error: #ff9c9c;
  }
}
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1rem;
  font: 100%/1.5 system-ui, sans-serif;
  color: var(--text);
  background: var(--background);
  overflow-wrap: break-word;
}

main {
  max-width: 36rem;
  margin-inline: auto;
}

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

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Present for the browser, but not shown */
.visually-hidden {
  position: absolute;
  left: -999rem;
}

/* Off screen until a keyboard user reaches it */
.skip-link {
  position: absolute;
  left: -999rem;
}
.skip-link:focus {
  position: static;
}

.field {
  margin-block-end: 1.5rem;
}

label {
  display: block;
  font-weight: 600;
}

.hint {
  margin: 0 0 0.25rem;
  color: var(--muted);
}

/* A font size of at least 1rem stops iOS zooming in on focus */
input:not([type=checkbox], [type=radio]),
textarea,
select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem;
  font: inherit;
  color: inherit;
  background: var(--background);
  border: 2px solid var(--control-border);
  border-radius: 0.25rem;
}

textarea {
  resize: vertical;
}

/* Safari ignores the height of a native select, so draw our own arrow instead */
select {
  appearance: none;
  padding-inline-end: 2.5rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--text) 50%), linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-repeat: no-repeat;
  background-position: right 1.35rem center, right 1rem center;
  background-size: 0.35rem 0.35rem;
}

/* Background images are removed in forced colours, so use the native control there */
@media (forced-colors: active) {
  select {
    appearance: auto;
  }
}
.checkbox {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.75rem;
  align-items: center;
}
.checkbox .error {
  grid-column: 1/-1;
}
.checkbox input[type=checkbox] {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  accent-color: var(--accent);
}
.checkbox {
  /* The label is part of the target, so it is as tall as the other controls */
}
.checkbox label {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  font-weight: 400;
}

/* A group of radio buttons or checkboxes: the fieldset and legend name the question */
.radios,
.checkboxes {
  min-inline-size: 0;
  margin-inline: 0;
  padding: 0;
  border: 0;
}
.radios legend,
.checkboxes legend {
  padding: 0;
  font-weight: 600;
}
.radios label,
.checkboxes label {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-height: 2.75rem;
  font-weight: 400;
}
.radios input[type=radio],
.radios input[type=checkbox],
.checkboxes input[type=radio],
.checkboxes input[type=checkbox] {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  accent-color: var(--accent);
}

/* A repeating group of fields, such as one line of an order */
.line {
  min-inline-size: 0;
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 2px solid var(--control-border);
  border-radius: 0.25rem;
}
.line legend {
  padding-inline: 0.5rem;
  font-weight: 600;
}

button {
  min-height: 2.75rem;
  padding: 0.5rem 1.5rem;
  font: inherit;
  border: 2px solid var(--accent);
  border-radius: 0.25rem;
  cursor: pointer;
}

input[type=submit] {
  width: auto;
  padding-inline: 1.5rem;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
  cursor: pointer;
}

/* A button that changes the form rather than sending it */
button.secondary,
input[type=submit].secondary {
  font-weight: 600;
  color: var(--accent);
  background: var(--background);
  border-color: var(--accent);
}

.error-summary {
  padding: 1rem;
  margin-block-end: 1.5rem;
  border: 4px solid var(--error);
  border-radius: 0.25rem;
}
.error-summary h2 {
  margin-block-start: 0;
}
.error-summary a {
  color: var(--error);
}
.error-summary:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Errors are marked by a bar and by text, so colour is never the only signal */
.field:has([aria-invalid=true]) {
  padding-inline-start: 0.75rem;
  border-inline-start: 4px solid var(--error);
}

.error {
  margin: 0 0 0.25rem;
  padding: 0;
  list-style: none;
  font-weight: 600;
  color: var(--error);
}

[aria-invalid=true] {
  border-color: var(--error);
}

/* Only for the running demos: leave this file out of your own stylesheet */
.demo-note {
  max-width: 36rem;
  margin: 0 auto 1rem;
  padding: 0 1rem;
  color: var(--muted);
  border: 2px dashed var(--control-border);
  border-radius: 0.25rem;
}
