/* The minimap index: a reader on a white page, an article that scrolls on the left and its minimap on the right, the
   whole article in miniature with the section names beside it and a lens for the part on screen. */
:root {
  --page: #ffffff;          /* the page */
  --paper: #fbfaf7;         /* the reader */
  --edge: #e8e4dc;          /* the reader's border */
  --ink: #1f1c18;           /* the article's text */
  --muted: #7a746b;         /* the section names, secondary text */
  --word: #cfc9be;          /* the words in the minimap */
  --heading: #3a352e;       /* the headings in the minimap */
  --accent: #d9542a;        /* the current section, the lens being dragged */
  --code: #f1eee8;          /* the code block */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px 16px;
}

/* ---------------------------------------------------------------- the reader */
.reader {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  width: min(920px, 100%);
  height: min(600px, calc(100svh - 48px));
  border: 1px solid var(--edge);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 30px 60px -36px rgba(60, 42, 20, 0.28), 0 8px 18px -12px rgba(60, 42, 20, 0.16);
  overflow: hidden;
}

/* the name of the section being read: only on a phone, where the section names have no room */
.reader__now {
  display: none;
}

/* ---------------------------------------------------------------- the article */
.article {
  position: relative;
  min-width: 0;
  height: 100%;
  padding: 44px 56px 64px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: 17.5px;
  line-height: 1.62;
  outline: none;
  border-right: 1px solid var(--edge);
}

.article::-webkit-scrollbar {
  display: none;
}

.article:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: 20px 0 0 20px;
}

.article h1 {
  margin: 0 0 10px;
  font-size: 33px;
  font-weight: 560;
  line-height: 1.12;
  letter-spacing: -0.018em;
  text-wrap: balance;
}

.article__by {
  margin: 0 0 26px;
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  font-size: 13px;
  color: var(--muted);
}

.article h2 {
  margin: 40px 0 10px;
  font-size: 23px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  transition: color 0.6s ease;
}

.article h2.is-arrived {
  color: var(--accent);
  transition: none;
}

.article p {
  margin: 0 0 14px;
}

.article blockquote {
  margin: 22px 0;
  padding: 2px 0 2px 20px;
  border-left: 2px solid var(--accent);
  font-size: 21px;
  font-style: italic;
  line-height: 1.38;
  color: #4a443b;
}

.article pre {
  margin: 18px 0;
  padding: 14px 18px;
  border-radius: 10px;
  background: var(--code);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
}

.article ul {
  margin: 0 0 16px;
  padding: 2px 0 2px 18px;
  border-left: 1px solid var(--edge);
  list-style: none;
}

.article li {
  margin: 0 0 6px;
}

/* ---------------------------------------------------------------- the minimap */
.map {
  position: relative;
  height: 100%;
  padding: 26px 0 26px 22px;
  user-select: none;
  -webkit-user-select: none;
}

.map__frame {
  position: absolute;
  inset: 26px auto 26px 22px;
  width: var(--map-w, 96px);
  touch-action: none;
  cursor: pointer;
}

.map__canvas {
  position: absolute;
  inset: 0 auto auto 0;
  display: block;
}

/* the lens: the part of the article on screen */
.map__lens {
  position: absolute;
  left: -6px;
  right: -6px;
  top: 0;
  height: var(--lens-h, 80px);
  border-radius: 6px;
  background: rgba(31, 28, 24, 0.055);
  box-shadow: inset 0 0 0 1px rgba(31, 28, 24, 0.16), 0 1px 2px rgba(31, 28, 24, 0.06);
  cursor: grab;
  outline: none;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  will-change: transform;
}

.map__lens::before,
.map__lens::after {
  /* two small grips on the lens's sides */
  content: '';
  position: absolute;
  top: 50%;
  width: 2px;
  height: min(16px, 40%);
  border-radius: 1px;
  background: rgba(31, 28, 24, 0.22);
  transform: translateY(-50%);
  transition: background-color 0.2s ease;
}

.map__lens::before {
  left: 2px;
}

.map__lens::after {
  right: 2px;
}

@media (hover: hover) {
  .map__frame:hover .map__lens {
    background: rgba(31, 28, 24, 0.075);
    box-shadow: inset 0 0 0 1px rgba(31, 28, 24, 0.26), 0 2px 6px rgba(31, 28, 24, 0.08);
  }
}

.map__lens:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 3px rgba(217, 84, 42, 0.18);
}

.map__lens.is-held {
  cursor: grabbing;
  background: rgba(217, 84, 42, 0.09);
  box-shadow: inset 0 0 0 1.5px var(--accent), 0 6px 16px -6px rgba(217, 84, 42, 0.45);
}

.map__lens.is-held::before,
.map__lens.is-held::after {
  background: var(--accent);
}

/* the zone the preview shows, outlined on the miniature while pointing */
.map__zone {
  position: absolute;
  left: -3px;
  right: -3px;
  top: 0;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(217, 84, 42, 0.55);
  background: rgba(217, 84, 42, 0.05);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.map__zone.is-on {
  opacity: 1;
}

/* the leaders from each heading in the miniature to its name */
.map__leads {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.map__leads path {
  fill: none;
  stroke: #ddd7cc;
  stroke-width: 1;
  transition: stroke 0.35s ease;
}

.map__leads path.is-on {
  stroke: var(--accent);
}

/* the section names, beside the miniature at the height of their heading */
.map__nav {
  position: absolute;
  inset: 26px 0 26px calc(22px + var(--map-w, 96px) + 10px);
}

.map__list {
  position: relative;
  height: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.map__item {
  position: absolute;
  left: 0;
  right: 10px;
  top: 0;
}

.map__link {
  display: block;
  width: 100%;
  padding: 4px 8px 4px 14px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 12.5px;
  font-weight: 450;
  line-height: 1.25;
  text-align: left;
  white-space: nowrap;
  color: var(--muted);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 0.35s ease, font-weight 0.35s ease, background-color 0.2s ease;
}

@media (hover: hover) {
  .map__link:hover {
    color: var(--ink);
    background: rgba(31, 28, 24, 0.045);
  }
}

.map__link:active {
  background: rgba(31, 28, 24, 0.08);
}

.map__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.map__link[aria-current='true'] {
  color: var(--accent);
  font-weight: 640;
}

/* ---------------------------------------------------------------- the preview */
.peek {
  position: absolute;
  top: 0;
  right: calc(292px + 10px);
  width: 300px;
  height: 196px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(31, 28, 24, 0.1), 0 24px 48px -18px rgba(40, 28, 12, 0.38), 0 6px 14px -8px rgba(40, 28, 12, 0.22);
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  will-change: transform, opacity;
}

.peek__canvas {
  display: block;
}

.peek__name {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-bottom: 1px solid var(--edge);
  background: #f6f3ee;
  font-size: 11.5px;
  font-weight: 620;
  color: var(--accent);
  white-space: nowrap;
}

.peek__name::before {
  /* a small magnifier drawn with a mask, so it takes the text colour */
  content: '';
  flex: none;
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='5' cy='5' r='3.6'/%3E%3Cpath d='M7.8 7.8L11 11'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round'%3E%3Ccircle cx='5' cy='5' r='3.6'/%3E%3Cpath d='M7.8 7.8L11 11'/%3E%3C/svg%3E") center / contain no-repeat;
}

.beam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.beam path {
  fill: rgba(217, 84, 42, 0.07);
  stroke: rgba(217, 84, 42, 0.28);
  stroke-width: 1;
}

/* ---------------------------------------------------------------- phone: the minimap becomes a strip */
@media (max-width: 720px) {
  .reader {
    grid-template-columns: minmax(0, 1fr) 46px;
    grid-template-rows: auto minmax(0, 1fr);
    height: min(680px, calc(100svh - 48px));
    border-radius: 18px;
  }

  .reader__now {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 12px 18px 11px;
    border-bottom: 1px solid var(--edge);
    font-size: 13px;
    overflow: hidden;
  }

  .reader__now-label {
    color: var(--muted);
  }

  .reader__now-name {
    display: inline-block;
    font-weight: 620;
    color: var(--accent);
    white-space: nowrap;
  }

  .article {
    padding: 22px 18px 48px 20px;
    font-size: 16.5px;
  }

  .article:focus-visible {
    border-radius: 0 0 0 18px;
  }

  .article h1 {
    font-size: 26px;
  }

  .article h2 {
    font-size: 20px;
    margin-top: 32px;
  }

  .article blockquote {
    font-size: 18px;
  }

  .article pre {
    font-size: 10.5px;
    padding: 12px;
  }

  .map {
    padding: 0;
  }

  .map__frame {
    inset: 12px auto 12px 9px;
  }

  .map__lens {
    left: -4px;
    right: -4px;
  }

  .map__nav,
  .map__leads {
    display: none;
  }

  .peek {
    right: 54px;
    width: min(230px, calc(100% - 80px));
    height: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .article h2,
  .map__link {
    transition: none;
  }
}
