/* 
  Reset
*/

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

/* Prevent font size inflation */
html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

/* Remove default margin in favour of better control in authored CSS */
body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd {
  margin-block-end: 0;
}

/* Remove list styles on ul, ol elements with a list role, which suggests default styling will be removed */
ul[role='list'],
ol[role='list'] {
  list-style: none;
}

/* Set core body defaults */
body {
  min-height: 100vh;
  line-height: 1.5;
}

/* Set shorter line heights on headings and interactive elements */
h1,
h2,
h3,
h4,
button,
input,
label {
  line-height: 1.1;
}

/* Balance text wrapping on headings */
h1,
h2,
h3,
h4 {
  text-wrap: balance;
}

/* A elements that don't have a class get default styles */
a:not([class]) {
  text-decoration-skip-ink: auto;
  color: currentColor;
}

/* Make images easier to work with */
img,
picture {
  max-width: 100%;
  display: block;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

/* Make sure textareas without a rows attribute are not tiny */
textarea:not([rows]) {
  min-height: 10em;
}

/* Anything that has been anchored to should have extra scroll margin */
:target {
  scroll-margin-block: 5ex;
}

/* 
  Variables
*/
:root {
  --border-radius: var(--s-1);
  --color-dark: #000000;
  --color-light: #ffffff;
  --font-base: serif;
  --font-heading: sans-serif;
  --font-special: cursive;
  --gutter: var(--s-0);
  --s--2: clamp(0.8681rem, 0.8448rem + 0.1486vw, 0.96rem);
  --s--1: clamp(1.0417rem, 1.0017rem + 0.2559vw, 1.2rem);
  --s-0: clamp(1.25rem, 1.1869rem + 0.404vw, 1.5rem);
  --s-1: clamp(1.5rem, 1.4053rem + 0.6061vw, 1.875rem);
  --s-2: clamp(1.8rem, 1.6627rem + 0.8788vw, 2.3438rem);
  --s-3: clamp(2.16rem, 1.9656rem + 1.2439vw, 2.9297rem);
  --s-4: clamp(2.592rem, 2.3218rem + 1.7295vw, 3.6621rem);
  --s-5: clamp(3.1104rem, 2.7399rem + 2.3713vw, 4.5776rem);
  --s-10: clamp(7.7397rem, 6.1664rem + 10.069vw, 13.9698rem);
  --tracking: -0.05ch;
  --color-mode: 'light';
  --background: var(--color-light);
  --text-color: var(--color-dark);
  --wrapper-max-width: 70rem;
}

/* 
  Global styles 

  Low-specificity, global styles that apply to the whole 
  project: https://cube.fyi/css.html
*/
body {
  color: var(--text-color);
  background: var(--background);
  font-size: var(--s-1);
  font-family: var(--font-base);
  line-height: 1.4;
  letter-spacing: var(--tracking);
}

/* Base typesetting */
h1,
h2,
h3 {
  line-height: 1;
  /* letter-spacing: var(--tracking); */
  letter-spacing: 0.02ch;
  font-family: var(--font-heading);
  font-weight: 400;
}

h1 {
  font-size: var(--s-4);
}

h2 {
  font-size: var(--s-3);
}

h3 {
  font-size: var(--s-2);
}

/* Set line lengths */
p,
li,
blockquote:not([class]) {
  max-width: 50ch;
}

h1,
h2,
h3 {
  max-width: 26ch;
}

/* More generic elements */
blockquote:not([class]) {
  font-family: var(--font-serif);
  font-size: var(--s-2);
}

/* Markdown blockquuote:not([class])s aren't ideal, so we're presuming the person quoted is the last p */
blockquote:not([class]) p:last-of-type {
  font-family: var(--font-base);
  font-size: var(--s-1);
  font-weight: normal;
}

svg {
  height: 2ex;
  width: auto;
  flex: none;
}

[role='list'] {
  padding: 0;
}

/* Base interactive elements */

a {
  color: currentcolor;
}

a:hover {
  text-decoration: none;
}

:focus {
  outline: 2px solid;
  outline-offset: 0.3ch;
}

:target {
  scroll-margin-top: 2ex;
}

main:focus {
  outline: none;
}

/* Base selection styles that invert whatever colours are rendered */
::selection {
  background: var(--text-color);
  color: var(--background);
}

/* compositions */
.box {
  --bg-color: var(--background, #fff);
  --color: var(--text-color, #000);
  padding: var(--s-1);
  border: var(--border-thin) solid;
  color: var(--color);
  background-color: var(--bg-color);
}

.box * {
  color: inherit;
}

.box.invert {
  color: var(--bg-color);
  background-color: var(--color);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s--2, 1rem);
  justify-content: flex-start;
  align-items: center;

  &[data-justify='flex-end'] {
    justify-content: flex-end;
  }

  &[data-justify='space-between'] {
    justify-content: space-between;
  }
}

.cover {
  display: flex;
  flex-direction: column;
  min-block-size: var(--space, 100vh);
  padding: 1rem;
}

.cover > * {
  margin-block: 1rem;
}

.cover > :first-child:not(h1) {
  margin-block-start: 0;
}

.cover > :last-child:not(h1) {
  margin-block-end: 0;
}

.cover > h1 {
  margin-block: auto;
}

.grid {
  display: grid;
  grid-gap: 1rem;
}

@supports (width: min(250px, 100%)) {
  .grid {
    grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
  }
}

.stack {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.stack > * {
  margin-block: 0;
}

.stack > * + * {
  margin-block-start: var(--space, 1.5rem);
}

/* utilities */
.center {
  box-sizing: content-box;
  margin-inline: auto;
  text-align: center;
  max-inline-size: var(--measure);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 
FLOW UTILITY
Like the Every Layout stack: https://every-layout.dev/layouts/stack/
Info about this implementation: https://piccalil.li/quick-tip/flow-utility/ 
*/
.flow > * + * {
  margin-top: var(--flow-space, 1em);
}

/**
 * WRAPPER
 * Sets a max width, adds a consistent gutter and horizontally
 * centers the contents
 * Info: https://piccalil.li/quick-tip/use-css-clamp-to-create-a-more-flexible-wrapper-utility/
 */
.wrapper {
  max-width: var(--wrapper-max-width, 85rem);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
  position: relative;
}

.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: auto;
  margin: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  white-space: nowrap;
}
