/* Brand green sampled from the "First" letters in logo.webp: rgb(59, 176, 45). Pico reads
   data-theme on <html>: without it the operating system decides, "light" and "dark" force a
   theme. That makes three cases and only two palettes, so the dark one is written twice.
   Every selector here is anchored on :root, because Pico paints its own blue through
   ``:root:not([data-theme=dark])``, which keeps matching once data-theme is "light"; a bare
   ``[data-theme="light"]`` loses to it on specificity and the palette falls back to blue. */
:root:not([data-theme]),
:root[data-theme="light"] {
  --pico-text-selection-color: rgba(59, 176, 45, 0.25);
  --pico-primary: #297b1f;
  --pico-primary-background: #3bb02d;
  --pico-primary-underline: rgba(41, 123, 31, 0.5);
  --pico-primary-hover: #1f6118;
  --pico-primary-hover-background: #329625;
  --pico-primary-focus: rgba(59, 176, 45, 0.5);
  --pico-primary-inverse: #1e2d31;
}

/* The green is lifted towards #63d453 on dark backgrounds, where the ink-dark #297b1f would
   not carry enough contrast; buttons keep the brand green with near-black labels. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --pico-text-selection-color: rgba(99, 212, 83, 0.1875);
    --pico-primary: #63d453;
    --pico-primary-background: #34a027;
    --pico-primary-underline: rgba(99, 212, 83, 0.5);
    --pico-primary-hover: #8ce47f;
    --pico-primary-hover-background: #3bb02d;
    --pico-primary-focus: rgba(99, 212, 83, 0.375);
    --pico-primary-inverse: #08150a;
  }
}

:root[data-theme="dark"] {
  --pico-text-selection-color: rgba(99, 212, 83, 0.1875);
  --pico-primary: #63d453;
  --pico-primary-background: #34a027;
  --pico-primary-underline: rgba(99, 212, 83, 0.5);
  --pico-primary-hover: #8ce47f;
  --pico-primary-hover-background: #3bb02d;
  --pico-primary-focus: rgba(99, 212, 83, 0.375);
  --pico-primary-inverse: #08150a;
}

.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand img {
  height: 3.5rem;
  width: auto;
  max-width: 100%;
}

/* "Padel" is near-black in the logo and all but disappears on a dark background. Inverting
   lifts it to a light grey; the hue rotation puts the colours the inversion flipped back
   where they were, and the brightness undoes the dimming it costs the green, which lands on
   #2bb021, a shade off the brand's #3bb02d. The image is transparent, so nothing boxes it. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .brand img {
    filter: invert(1) hue-rotate(180deg) brightness(1.2);
  }
}

:root[data-theme="dark"] .brand img {
  filter: invert(1) hue-rotate(180deg) brightness(1.2);
}

header.container {
  padding-block: 0.75rem 0.25rem;
}

header nav {
  flex-wrap: wrap;
  row-gap: 0.25rem;
}

header nav li [role="button"] {
  width: auto;
  white-space: nowrap;
}

/* "Log out" is a real submit button wrapped in a form, so it arrives with Pico's bottom
   margin and the form puts it on a text line. Either one drops it below the centre of the
   links beside it: the nav row centres the margin box, and a strut leaves room for
   descenders under an inline-block. Flex removes the line, and the margin has to be
   cleared through [type], because Pico sets it from [type=submit] -- an attribute
   selector, which outranks any number of element names. */
header nav li form {
  display: flex;
  margin: 0;
}

header nav li form [type="submit"] {
  margin: 0;
}

/* Site-wide links on one side, the settings for this browser on the other, so the footer
   reads as two groups rather than one run-on list. They stack when the row runs out. */
.site-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

.site-settings {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
}

/* Hidden until theme.js reveals it: without JavaScript the button has nothing to toggle. */
.theme-toggle {
  display: none;
  align-items: center;
  width: auto;
  /* Same reason as the nav button above: the row centres the margin box, and Pico's
     bottom margin would push the icon above the links it sits next to. */
  margin: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--pico-muted-color);
}

.js-theme .theme-toggle {
  display: inline-flex;
}

.theme-toggle svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
}

.theme-toggle:is(:hover, :active, :focus) {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--pico-primary);
}

.theme-toggle:focus-visible {
  outline: var(--pico-outline-width) solid var(--pico-primary-focus);
  border-radius: var(--pico-border-radius);
}

/* The language switcher is a form, not links, because picking a language has to be
   recorded (see base.html); it should read as quietly as the footer links beside it.
   Pico gives a bare <form> a bottom margin, which would misalign the whole row. */
.language-switch {
  display: inline-flex;
  gap: 0.5rem;
  margin: 0;
}

.language-switch button {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--pico-muted-color);
  font: inherit;
  white-space: nowrap;
}

.language-switch button:is(:hover, :active, :focus) {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--pico-primary);
}

.language-switch button:focus-visible {
  outline: var(--pico-outline-width) solid var(--pico-primary-focus);
  border-radius: var(--pico-border-radius);
}

@media (max-width: 40rem) {
  .brand img {
    height: 2.25rem;
  }

  header nav {
    flex-direction: column;
    align-items: stretch;
  }

  header nav > ul:last-child {
    width: 100%;
    justify-content: flex-start;
    margin-top: -0.5rem;
  }
}

footer.container {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--pico-muted-border-color);
}

form,
form label {
  max-width: 100%;
  min-width: 0;
}

/* Waitlist box on the start page (pre-launch). */
.waitlist {
  border-left: 0.25rem solid var(--pico-primary-background);
}

.waitlist h2 {
  margin-bottom: 0.5rem;
}

.waitlist__form {
  margin-bottom: 0;
}

.waitlist__form fieldset[role="group"] {
  margin-bottom: 0.5rem;
}

.waitlist__form fieldset[role="group"] button {
  white-space: nowrap;
}

.waitlist__form .errorlist,
.waitlist__form .errorlist li {
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
  color: var(--pico-del-color);
}

/* Buttons of a form inside a dialog; Pico only styles a footer that is a direct child. */
.modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--pico-spacing) * 0.5);
  justify-content: flex-end;
}

.modal__actions :is(button, [role="button"]) {
  width: auto;
  margin-bottom: 0;
}

.password-field {
  display: block;
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.password-field input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin-bottom: 0;
  padding-inline-end: 2.75rem;
}

.password-field__toggle {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  box-sizing: border-box;
  width: 2.75rem;
  height: 100%;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--pico-muted-color);
  cursor: pointer;
}

.password-field input::-ms-reveal,
.password-field input::-webkit-credentials-auto-fill-button {
  display: none;
}

.password-field__toggle svg {
  display: block;
  margin: auto;
  width: 1.25rem;
  height: 1.25rem;
}

.password-field__toggle:hover,
.password-field__toggle:active,
.password-field__toggle:focus {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--pico-primary);
}

.password-field__toggle:focus-visible {
  outline: var(--pico-outline-width) solid var(--pico-primary-focus);
  outline-offset: -0.35rem;
  border-radius: var(--pico-border-radius);
}
