/*
 * Brain's own rules for the web pages, on top of Pico CSS (classless build, see
 * README.md). Pico styles the plain elements; this file sets Brain's colours and sizes
 * through custom properties and adds the few things Pico does not give: the page widths,
 * one heading size, the quiet and danger buttons, the Google button, the connections
 * table on a phone, and a focus ring that is always visible.
 *
 * Sizes are relative only (sign-in plan D-28): rem, em, ch, %, viewport units, min()
 * and clamp(). The hairline border is Pico's --pico-border-width, which is 0.0625rem.
 * Light and dark come from prefers-color-scheme, with the same names in both.
 */

/* Tokens: light, the default, then dark when the system asks for it. */
:root {
  --brain-bg: #f7f6f3;
  --brain-surface: #ffffff;
  --brain-text: #1b1c1f;
  --brain-muted: #55585f;
  --brain-border: #dddbd6;
  --brain-border-strong: #85888e;
  --brain-hover: #efeee9;
  --brain-accent: #0b5fa5;
  --brain-accent-hover: #084a82;
  --brain-accent-inverse: #ffffff;
  --brain-danger: #b42318;
  --brain-danger-hover: #8f1c13;
  --brain-danger-inverse: #ffffff;
  --brain-focus: #0b5fa5;
  --brain-code-bg: #efeee9;
  --brain-google-bg: #ffffff;
  --brain-google-border: #747775;
  --brain-google-text: #1f1f1f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brain-bg: #121316;
    --brain-surface: #1a1c20;
    --brain-text: #e8e8ea;
    --brain-muted: #a7aab1;
    --brain-border: #34373d;
    --brain-border-strong: #7c8088;
    --brain-hover: #25282d;
    --brain-accent: #7cbcf6;
    --brain-accent-hover: #a6d2fa;
    --brain-accent-inverse: #0b1a29;
    --brain-danger: #ff8f85;
    --brain-danger-hover: #ffb3ac;
    --brain-danger-inverse: #2b0b08;
    --brain-focus: #7cbcf6;
    --brain-code-bg: #23262b;
    --brain-google-bg: #131314;
    --brain-google-border: #8e918f;
    --brain-google-text: #e3e3e3;
  }
}

/*
 * Pico's variables, fed from the tokens. Pico sets them on :root:not([data-theme=dark])
 * and :root:not([data-theme]); :root:root has the same weight and comes later, so it wins.
 */
:root:root {
  --pico-font-size: clamp(100%, 0.875rem + 0.4vw, 112.5%);
  --pico-line-height: 1.5;
  --pico-border-radius: 0.375rem;
  --pico-background-color: var(--brain-bg);
  --pico-color: var(--brain-text);
  --pico-muted-color: var(--brain-muted);
  --pico-muted-border-color: var(--brain-border);
  --pico-primary: var(--brain-accent);
  --pico-primary-background: var(--brain-accent);
  --pico-primary-border: var(--brain-accent);
  --pico-primary-underline: var(--brain-accent);
  --pico-primary-hover: var(--brain-accent-hover);
  --pico-primary-hover-background: var(--brain-accent-hover);
  --pico-primary-hover-border: var(--brain-accent-hover);
  --pico-primary-hover-underline: var(--brain-accent-hover);
  --pico-primary-focus: var(--brain-focus);
  --pico-primary-inverse: var(--brain-accent-inverse);
  --pico-h1-color: var(--brain-text);
  --pico-h2-color: var(--brain-text);
  --pico-h3-color: var(--brain-text);
  --pico-card-background-color: var(--brain-surface);
  --pico-card-border-color: var(--brain-border);
  --pico-card-box-shadow: none;
  --pico-card-sectioning-background-color: var(--brain-surface);
  --pico-table-border-color: var(--brain-border);
  --pico-code-background-color: var(--brain-code-bg);
  --pico-code-color: var(--brain-text);
  --pico-form-element-background-color: var(--brain-surface);
  --pico-form-element-active-background-color: var(--brain-surface);
  --pico-form-element-border-color: var(--brain-border-strong);
  --pico-form-element-color: var(--brain-text);
  --pico-text-selection-color: color-mix(in srgb, var(--brain-accent) 30%, transparent);
}

/* Layout: one centred column, narrower for sign-in and consent (body.narrow). */
body > header,
body > main,
body > footer {
  width: min(var(--brain-width, 45rem), 100% - 2rem);
  max-width: none;
  padding-inline: 0;
}

body.narrow {
  --brain-width: 26rem;
}

body > main {
  padding-block: clamp(1.5rem, 5vh, 3.5rem);
}

body > header {
  padding-block: 1rem 0;
}

body > header nav {
  --pico-nav-element-spacing-horizontal: 0.5rem;
  flex-wrap: wrap;
  column-gap: 1rem;
}

body > header nav ul:first-child a {
  --pico-color: var(--brain-text);
  font-weight: 700;
  text-decoration: none;
}

body > header nav ul {
  flex-wrap: wrap;
  align-items: center;
}

body > header nav li {
  display: flex;
  align-items: center;
  white-space: nowrap;
}

body > header nav ul + ul {
  font-size: 0.875rem;
}

body > header nav form {
  margin: 0;
}

/* A button in a row of text (the header, a table row, the address) is small. */
:is(nav, td, .copy) :is(button, [type=submit]) {
  --pico-form-element-spacing-vertical: 0.25rem;
  --pico-form-element-spacing-horizontal: 0.875rem;
  margin: 0;
  font-size: 0.875rem;
}

body > footer {
  padding-block: 1rem 2rem;
  border-top: var(--pico-border-width) solid var(--brain-border);
  font-size: 0.875rem;
}

body > footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  margin: 0;
  padding: 0;
}

body > footer li {
  list-style: none;
  margin: 0;
}

/* Type: one heading size and two text sizes (body and small). */
h1,
h2,
h3 {
  --pico-font-size: 1.375rem;
  --pico-line-height: 1.25;
  --pico-typography-spacing-top: 2rem;
  overflow-wrap: anywhere;
}

small {
  font-size: 0.875rem;
  line-height: 1.45;
}

p > small {
  display: block;
}

a.google + p {
  margin-top: 1rem;
}

article > :last-child,
article > form > :last-child {
  margin-bottom: 0;
}

hgroup > p,
.muted {
  color: var(--brain-muted);
}

code,
pre {
  font-family: var(--pico-font-family-monospace);
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Cards: thin border, no shadow. */
article {
  border: var(--pico-border-width) solid var(--brain-border);
  box-shadow: none;
}

/* Facts: a definition list of short labels and values. */
dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.5rem 1.5rem;
  margin: 0 0 var(--pico-spacing);
}

dt {
  color: var(--brain-muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Buttons: primary is Pico's button; quiet and danger are ours. */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0;
}

.actions > button {
  flex: 1 1 auto;
  width: auto;
  margin: 0;
}

button.quiet,
[role=button].quiet {
  --pico-background-color: transparent;
  --pico-border-color: var(--brain-border-strong);
  --pico-color: var(--brain-text);
}

button.quiet:is(:hover, :active, :focus),
[role=button].quiet:is(:hover, :active, :focus) {
  --pico-background-color: var(--brain-hover);
  --pico-border-color: var(--brain-text);
  --pico-color: var(--brain-text);
}

button.danger {
  --pico-background-color: transparent;
  --pico-border-color: var(--brain-danger);
  --pico-color: var(--brain-danger);
}

button.danger:is(:hover, :active, :focus) {
  --pico-background-color: var(--brain-danger);
  --pico-border-color: var(--brain-danger);
  --pico-color: var(--brain-danger-inverse);
}

/* Focus: an opaque ring on everything that takes focus, whatever Pico draws. */
:is(a, button, input, select, textarea, summary, [role=button], [tabindex]):focus-visible {
  outline: 0.1875rem solid var(--brain-focus);
  outline-offset: 0.125rem;
  box-shadow: none;
}

/* The Google button, after Google's branding rules for "Continue with Google". */
a.google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: var(--pico-border-width) solid var(--brain-google-border);
  border-radius: 0.25rem;
  background: var(--brain-google-bg);
  color: var(--brain-google-text);
  font-family: Roboto, var(--pico-font-family-sans-serif);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

a.google:hover {
  background: color-mix(in srgb, var(--brain-google-text) 8%, var(--brain-google-bg));
}

a.google svg {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}

/* Consent: each choice is a bordered row; the chosen one carries the accent. */
fieldset > label:has([type=radio]) {
  display: block;
  width: auto;
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  border: var(--pico-border-width) solid var(--brain-border);
  border-radius: var(--pico-border-radius);
}

fieldset > label:has(:checked) {
  border-color: var(--brain-accent);
}

label > small {
  display: block;
  width: auto;
  margin: 0.25rem 0 0;
  padding-inline-start: 2em;
  color: var(--brain-muted);
}

/*
 * The address to paste and its copy button, on one row that wraps on a phone. The
 * address is text, not an input, so it wraps instead of being cut; one click selects it.
 */
.copy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: var(--pico-spacing);
}

.copy > code {
  flex: 1 1 16rem;
  padding: 0.625rem 0.875rem;
  overflow-wrap: anywhere;
  user-select: all;
}

.copy > button {
  flex: none;
  margin: 0;
}

/* Steps: numbered, with room between them; commands wrap instead of scrolling. */
ol > li {
  margin-bottom: 0.5rem;
}

ol pre {
  margin: 0.5rem 0;
}

pre > code {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
}

/* The connections table; on a narrow screen each row becomes a block of labelled lines. */
table {
  margin-bottom: var(--pico-spacing);
}

th {
  color: var(--brain-muted);
  font-weight: 400;
  font-size: 0.875rem;
}

td:last-child {
  text-align: end;
}

th:last-child {
  text-align: end;
}

td form {
  margin: 0;
}

/*
 * A tool's name and host come from whoever registered the tool: they wrap anywhere,
 * so a long one never widens the page. A date stays on one line.
 */
td:first-child {
  overflow-wrap: anywhere;
}

td time {
  white-space: nowrap;
}

@media (max-width: 40rem) {
  table,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    position: absolute;
    width: 0.0625rem;
    height: 0.0625rem;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  tr {
    padding: 0.75rem 0;
    border-bottom: var(--pico-border-width) solid var(--brain-border);
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 0;
    border: 0;
    background: transparent;
    text-align: end;
  }

  td::before {
    content: attr(data-label);
    color: var(--brain-muted);
    text-align: start;
  }

  td:first-child {
    flex-direction: column;
    gap: 0;
    font-weight: 700;
    text-align: start;
  }

  td:first-child > small {
    font-weight: 400;
  }

  td:last-child {
    justify-content: flex-start;
    padding-top: 0.5rem;
  }

  td:first-child::before,
  td:last-child::before {
    content: none;
  }
}
