@import "fonts.css";

/* Base style ------------------------------------------------------- */
body {
  font-family: ArgentumSansLight;
  font-size: 12pt;
  letter-spacing: 0.03em;
  margin: 0;
  counter-reset: sidenote-counter;
}

:root {
  --orange: #f70; /* Luminance of 50, exactly between #000 and #fff */
  --purple: #807; /* Luminance of 27, halfway between #f70 and #000 */
  --heaven: #7bf; /* Luminance of 73, halfway between #f70 and #fff */
  --column-margin: 40pt;
  --clamped-vw: min(1vw, 15pt); /* Limit maximum width of the page */
  --sidebar-width: calc(15 * var(--clamped-vw));
  --left-column-width: calc(24 * var(--clamped-vw));
  --right-column-width: calc(
    100 * var(--clamped-vw) - var(--left-column-width) - 5 *
      var(--column-margin) - 2 * var(--sidebar-width)
  );
  --total-content-width: calc(
    var(--left-column-width) + var(--column-margin) + var(--right-column-width)
  );
  --absolute-full-width: calc(
    100 * var(--clamped-vw) - 2 * var(--column-margin)
  );
  --heading-counter-margin: calc(
    -1 * var(--right-column-width) - var(--column-margin)
  ); /* Allows header to stick out from section */
  background-color: var(--bg-color);
}

/* Header ----------------------------------------------------------- */
header {
  display: flex;
  justify-content: center;
  background-color: black;
  font-family: ArgentumSansMedium;
  font-size: 25pt;
  color: white;
  position: sticky;
  top: 0;
  padding: 0;
  z-index: 10;
  border-bottom: 1pt solid white;
}

@media (max-height: 550pt) {
  header {
    /* Hide header when scrolling down on very small screens */
    position: static;
  }
}

header > div {
  display: flex;
  justify-content: space-between;
  width: var(--total-content-width);
  padding: 10pt var(--column-margin);
}

header .name {
  text-transform: uppercase;
}

header .name:before {
  content: "Felix ";
}

header .title {
  /* Center the title on wide screens. Value is eyeballed. */
  min-width: 18%;
  transition: all 0.5s;
}

header .menu {
  text-align: right;
}

header .name,
header .menu {
  /* Workaround for older iOS Safari, see https://stackoverflow.com/a/59348265/2533467 */
  flex: 1 1 auto;
}

/* Make #title fade out if space gets tight*/
@media (max-width: 500pt) {
  header .title {
    opacity: 0;
  }
}

/* Ensure the space .title occupied is used by .name and .menu
   This can't be done in the same @-rule as changing the opacity,
   otherwise the transition is never displayed. */
@media (max-width: 490pt) {
  header .title {
    display: none;
  }
}

/* Regular text ----------------------------------------------------- */
p,
ul,
ol,
h1,
h2,
h3,
h4 {
  color: var(--text-color);
}

h1,
h2,
h3,
h4 {
  line-height: 1.25em;
  margin: 1em var(--heading-counter-margin) 0.5em 0;
  font-family: ArgentumSansMedium;
  text-align: left;
}

h1 {
  font-size: 25pt;
}

ul,
ol,
.quote {
  text-align: left;
}

/* Unnumbered headings without a name are used to create new sections
   for images. We don't want those to take up space in the layout. */
h1.unnumbered,
h2.unnumbered,
h3.unnumbered,
h4.unnumbered {
  display: none;
}

/* Tiny splash of color */
a {
  color: var(--orange);
}

a:visited {
  color: var(--purple);
}

p.quote {
  font-family: ArgentumSansItalic;
  font-size: 17pt;
}

p.quote::first-letter {
  padding-left: 40pt;
}

/* Article and sections --------------------------------------------- */
body > div {
  display: flex;
  justify-content: center;
  padding: 0;
}

article {
  margin-top: 16pt;
  width: var(--total-content-width);
  padding: 0 calc(var(--sidebar-width) + var(--column-margin));
}

section:not(.figure-set) {
  text-align: justify;
  line-height: 1.75em;
  max-width: var(--left-column-width);
  margin: 4em 0;
}

section:not(.figure-set):first-of-type {
  margin-top: 2em;
}

section > p {
  margin: 1.5em 0;
}

section > p:first-of-type {
  margin-top: 0;
}

section > p:last-of-type {
  margin-bottom: 0;
}

section > p:not(.quote)::first-letter {
  padding-left: 20pt;
}

/* Sidenotes -------------------------------------------------------- */
/* Adapted from https://github.com/edwardtufte/tufte-css, MIT License */
.sidenote {
  float: left;
  clear: left;
  margin-left: calc(-1 * var(--sidebar-width) - var(--column-margin));
  width: var(--sidebar-width);
  text-align: left;
  position: relative;
}

.sidenote,
.sidenote:before {
  font-size: 0.9rem;
  line-height: 1.5em;
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number:after {
  content: "(" counter(sidenote-counter) ")";
  font-size: 1rem;
  left: 0.1rem;
}

.sidenote:before {
  content: "(" counter(sidenote-counter) ") ";
}

blockquote .sidenote {
  margin-right: -82%;
  min-width: 59%;
  text-align: left;
}

input.margin-toggle {
  display: none;
}

label.sidenote-number {
  display: inline;
}

label.margin-toggle:not(.sidenote-number) {
  display: none;
}

.sidenote > code {
  font-size: 1rem;
}

@media (max-width: 1300pt) {
  label.margin-toggle:not(.sidenote-number) {
    display: inline;
  }

  .sidenote {
    display: none;
  }

  .sidenote-number {
    color: var(--orange);
    text-decoration: underline;
  }

  .margin-toggle:checked + .sidenote {
    display: block;
    float: none;
    width: 95%;
    margin: 1rem;
  }
}

/* Images / Figures ------------------------------------------------- */
img {
  box-sizing: border-box;
  border: 2px solid black;
}

.figure-set {
  display: flex;
  clear: both;
  justify-content: left;
  flex-direction: row;
  align-items: baseline;
  color: var(--text-color);
  transform: translateY(0.4em); /* Align figures better with paragraphs */
}

.figure-set.full-width {
  width: calc(var(--absolute-full-width));
  margin: 20pt 0;
  margin-left: calc(-1 * var(--sidebar-width) - var(--column-margin));
}

.figure-set:not(.full-width) {
  float: right;
  max-width: var(--right-column-width);
  margin: 0 0 20pt var(--column-margin);
  margin-right: calc(-1 * var(--right-column-width) - var(--column-margin));
}

figure {
  font-size: 0.9rem;
  line-height: 1.5em;
  flex: 0 1 auto;
  margin: 0;
}

figure:not(:last-of-type) {
  margin-right: 10pt;
}

figure > img {
  height: auto;
  max-height: 400pt;
  max-width: 100%;
}

figcaption {
  font-family: ArgentumSansLightItalic;
  margin: 0.5em 0 0 0;
  text-align: left;
}

/* Headings & Sections on narrow screens ---------------------------- */
/* This should always be the last section so previously set properties
   are overwritten! */

@media (max-width: 1300pt) {
  :root {
    /* Narrow layout shouldn't fill the whole width on semi-big screens */
    --clamped-vw: min(1vw, 10pt);
    --sidebar-width: 0pt;
    --heading-counter-margin: 0;
    --total-content-width: calc(
      var(--left-column-width) + 3 * var(--column-margin) +
        var(--right-column-width)
    );
  }

  section > p {
    -webkit-hyphens: auto;
    hyphens: auto;
  }

  section:not(.figure-set) {
    max-width: unset;
  }

  .figure-set.full-width {
    width: unset;
    margin-left: 0;
  }

  .figure-set:not(.full-width) {
    margin-right: unset;
  }
}

@media (max-width: 540pt) {
  .figure-set:not(.full-width) {
    float: none;
    width: unset;
    max-width: unset;
    margin-left: unset;
  }
}

@media (max-width: 350pt) {
  :root {
    --column-margin: 10pt;
  }

  header .name:before {
    content: "";
  }
}
