/*
 * Classless element styles (site/DESIGN.md).
 *
 * Element selectors only, no utility classes; variations are attributes. Colours always go
 * through tokens.css: no hex or rgb literals here.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The root is 13px, so rem sizes stay small and exact for the chrome; reading text is set in em
   from body's 1.15rem (about 15px). */
html {
  font-family: var(--font-sans);
  font-size: 81.25%;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
  accent-color: var(--accent);
  caret-color: var(--accent);
  scrollbar-color: var(--line-3) transparent;
}

body {
  margin: 0;
  background: var(--bg-0);
  color: var(--text-1);
  font-size: 1rem;
  font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--accent-soft);
  color: var(--text-1);
}

main {
  display: block;
  padding: calc(var(--space) * 2) var(--space);
}

hgroup > * + * {
  margin-top: 0;
}

hgroup p {
  color: var(--text-2);
  margin: 0;
}

nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space);
  align-items: center;
  margin-top: var(--space);
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

section {
  margin-bottom: calc(var(--space) * 2);
}

article {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: var(--space);
  margin: 0 0 var(--space);
  box-shadow: var(--shadow-card);
}

figure {
  margin: 0 0 var(--space);
}

figcaption {
  color: var(--text-2);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

cite {
  color: var(--text-2);
  font-style: italic;
}

sub,
sup {
  font-size: 0.75em;
}

del {
  text-decoration: line-through;
  color: var(--danger);
}

ins {
  text-decoration: underline;
  color: var(--tip);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: calc(var(--space) * 1.5) 0 var(--space);
  line-height: 1.2;
  color: var(--text-1);
  text-wrap: balance;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1.3rem;
}

h3 {
  font-size: 1.2rem;
}

h4 {
  font-size: 1.1rem;
}

h5,
h6 {
  font-size: 1rem;
}

p {
  margin: 0 0 var(--space);
  text-wrap: pretty;
}

small {
  color: var(--text-2);
  font-size: 0.875rem;
}

strong,
b {
  font-weight: 600;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--text-1);
}

/* One focus ring for every control: 2px of the link colour, set off from the control's own
   border, so it reads on either theme. */
:is(a, button, summary, input, select, textarea):focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

ul,
ol {
  margin: 0 0 var(--space);
  padding-left: calc(var(--space) * 1.5);
}

li + li {
  margin-top: 0.25rem;
}

dl {
  margin: 0 0 var(--space);
}

dt {
  font-weight: 600;
}

dd {
  margin: 0 0 0.5rem;
  color: var(--text-2);
}

blockquote {
  margin: var(--space) 0;
  padding: 0.5rem var(--space);
  border-left: 1px solid var(--line-3);
  color: var(--text-2);
}

code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-3);
  padding: 0.1em 0.35em;
  border-radius: calc(var(--radius) / 2);
  border: 1px solid var(--line-1);
}

pre {
  font-family: var(--font-mono);
  background: var(--bg-3);
  color: var(--text-1);
  padding: var(--space);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0 0 var(--space);
}

pre code {
  background: transparent;
  padding: 0;
  border: 0;
  font-size: 1em;
}

hr {
  border: 0;
  border-top: 1px solid var(--line-2);
  margin: calc(var(--space) * 1.5) 0;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 var(--space);
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line-1);
  text-align: left;
}

th {
  background: var(--bg-3);
  font-weight: 600;
}

caption {
  caption-side: bottom;
  color: var(--text-2);
  padding-top: 0.5rem;
  text-align: left;
}

form {
  margin: 0 0 var(--space);
}

label {
  display: block;
  margin-top: var(--space);
  margin-bottom: 0.375rem;
  color: var(--text-1);
  font-weight: 500;
}

input,
textarea,
select {
  font: inherit;
  color: var(--text-1);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 0.3rem 0.5rem;
  width: 100%;
  max-width: 100%;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-3);
  opacity: 1;
}

:is(input, textarea, select, button):disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button,
a[data-variant-button] {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--accent-button);
  color: var(--on-accent-button);
  /* Transparent rather than none, so a filled button is the same height as an outlined one. */
  border: 1px solid transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  width: auto;
  margin: 0;
  box-shadow: var(--shadow-button);
}

a[data-variant-button],
a[data-variant-button]:hover {
  text-decoration: none;
}

/* An outlined secondary button. */
:is(button, a[data-variant-button])[data-variant="quiet"] {
  background: transparent;
  color: var(--text-1);
  border: 1px solid var(--line-3);
  box-shadow: none;
}

/* Finger-sized targets on touch screens. */
@media (pointer: coarse) {
  button,
  a[data-variant-button],
  select {
    min-height: 44px;
  }
}

/* A button that reads as a link (the docs' "Copy page"). */
button[data-as="link"] {
  display: inline;
  min-height: 0;
  padding: 0;
  background: none;
  color: var(--link);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-size: inherit;
  font-weight: inherit;

  &:hover:not(:disabled) {
    color: var(--text-1);
    filter: none;
  }
}

button:hover:not(:disabled),
a[data-variant-button]:hover {
  filter: brightness(1.08);
}

button:active:not(:disabled),
a[data-variant-button]:active {
  filter: brightness(0.95);
}

/* An outlined button has no fill for the brightness filter to act on: it takes a faint wash of
   the text colour instead, which reads on either theme. */
:is(button, a[data-variant-button])[data-variant="quiet"]:hover:not(:disabled) {
  background: color-mix(in srgb, var(--text-1) 7%, transparent);
  border-color: var(--text-4);
  filter: none;
}

details {
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 0.5rem var(--space);
  margin: 0 0 var(--space);
  background: var(--bg-2);
}

summary {
  cursor: pointer;
  font-weight: 600;
}

dialog {
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--text-1);
  padding: var(--space);
  max-width: var(--measure);
  box-shadow: var(--shadow-dropdown);
}

dialog::backdrop {
  background: var(--overlay);
}

mark {
  background: color-mix(in srgb, var(--workroom-yellow) 35%, transparent);
  color: var(--text-1);
  padding: 0 0.2em;
  border-radius: calc(var(--radius) / 2);
}

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}
