:root {
  --main: #282a36;
  --main-alt: #44475a;
  --white: #f8f8f2;
  --blue: #6272a4;
  --green: #50fa7b;
  --pink: #ff79c6;
  --purple: #bd93f9;

  --gap: clamp(1.5rem, 5vw, 4.5rem);
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  margin: 0;
  font-family: "Fira Code", monospace;
  background-color: var(--main);
}

/* The header, arrows, page count and search share the same look */
header h1,
.arrow-btn,
#pages,
#search input,
#search button {
  font-weight: bold;
  color: var(--white);
  background-color: var(--main-alt);
  opacity: 0.85;
}

header {
  text-align: center;
}

header h1 {
  display: inline-block;
  margin: 0;
  padding: 0.5rem 1.5rem;
  border-radius: 0 0 1rem 1rem;
}

main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin: 1rem 4.5rem 0;
  padding: 0 var(--gap) 5rem;
  border: 1px solid var(--blue);
  border-bottom: none;
  border-radius: 3rem 3rem 0 0;
}

/* Auto margins split the spare height evenly above the id, below it, and below the devices */
#user-id {
  margin-block: auto;
  font-size: 2rem;
  color: var(--white);
  text-align: center;
  font-weight: bold;
}

#devices {
  display: grid;
  flex: none;
  /* --columns is set in devices.js: half of MAX_DEVICES */
  grid-template-columns: repeat(var(--columns), minmax(0, 20dvh));
  /* fixed rows so a short last page lines up */
  grid-template-rows: repeat(2, minmax(0, 20dvh));
  justify-content: center;
  gap: var(--gap);
  margin: 1rem 0 auto; /* 1rem to match main's top margin, so the id sits halfway */
}

.device {
  display: grid;
  place-content: center;
  aspect-ratio: 1;
  padding: 1rem;
  border-radius: 50%;
  background-color: var(--purple);
  cursor: pointer;
}

.device:hover {
  background-color: var(--pink);
}

.device p {
  margin: 0.25rem 0;
  font-weight: bold;
  color: var(--white);
}

#arrows {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none; /* clicks pass through to the devices */
}

.arrow-btn {
  height: 50%;
  padding: 0 0.5rem;
  font-family: inherit;
  font-size: 2rem;
  line-height: 1;
  border: none;
  cursor: pointer;
  pointer-events: auto;
}

.arrow-btn:first-child {
  border-radius: 0 1rem 1rem 0;
}

.arrow-btn:last-child {
  border-radius: 1rem 0 0 1rem;
}

#pages {
  align-self: flex-end;
  padding: 0.5rem 1.5rem;
  border-radius: 1rem 1rem 0 0;
}

/* Search: the input and button join into one rounded bar */
#search {
  display: flex;
  justify-content: center;
}

#search input,
#search button {
  padding: 0.5rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  border: none;
}

#search input {
  width: 20ch;
  min-width: 0; /* lets it shrink on narrow phones */
  border-radius: 1rem 0 0 1rem;
  outline: none; /* no focus ring when clicked; the text cursor shows it's active */
}

#search input::placeholder {
  color: var(--white);
  opacity: 0.5;
}

#search button {
  border-radius: 0 1rem 1rem 0;
  cursor: pointer;
}

/* Mouse only, so a tap on a phone doesn't leave it green */
@media (hover: hover) {
  .arrow-btn:hover,
  #search button:hover {
    color: var(--green);
  }
}

@media (max-width: 768px) {
  :root {
    --gap: 1.5rem;
  }

  /* Grow with the content so the header can stick */
  body {
    height: auto;
    min-height: 100dvh;
  }

  header {
    position: sticky;
    top: 0;
  }

  main {
    margin-inline: var(--gap);
    padding: 0 0 5rem;
    border: none;
  }

  #devices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    /* 2 columns here, so --columns (half a page) is the number of rows */
    grid-template-rows: repeat(var(--columns), 3rem);
  }

  /* All words on one line */
  .device {
    display: flex;
    align-items: center;
    gap: 1ch;
    aspect-ratio: auto;
    padding: 0 0.5rem;
    border-radius: 1rem;
  }

  .device p {
    font-size: 0.75rem;
  }

  /* Centred between the last row and the arrows: the 1rem on top matches
     the 1rem of main's 5rem bottom padding left above the 4rem-tall arrows */
  #search {
    margin: 1rem 0 auto;
  }

  /* Arrows centred in each side, page count in between */
  #arrows {
    inset: auto 0 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    justify-items: center;
    align-items: end;
  }

  #arrows .arrow-btn {
    height: auto;
    padding: 1rem 3rem;
    border-radius: 1rem 1rem 0 0;
    transform-origin: bottom;
    transition: transform 0.1s;
  }

  #arrows .arrow-btn:active {
    color: var(--green);
    transform: scale(0.9);
  }
}
