/* ================================
   @font-face
   ================================ */

@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/EBGaramond-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/EBGaramond-Medium.woff2') format('woff2');
}

@font-face {
  font-family: 'EB Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/EBGaramond-Italic.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/JetBrainsMono-Bold.woff2') format('woff2');
}

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

:root {
  --bg: #0a0a0a;
  --fg: #e8e8e8;
  --fg-dim: #666;
  --accent: #fff;
  --font-title: 'JetBrains Mono', monospace;
  --font-body: 'EB Garamond', serif;
  --transition-duration: 400ms;
}

html {
  font-size: 18px;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  line-height: 1.7;
  min-height: 100vh;
  overflow: hidden;
}

/* ================================
   Main container
   ================================ */

#collection {
  position: relative;
  width: 100%;
  height: 100vh;
}

/* ================================
   Poem articles
   ================================ */

.poem {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem;
  padding-bottom: 5rem;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-duration) ease,
    visibility var(--transition-duration) ease;
  overflow-y: auto;
}

.poem.active {
  opacity: 1;
  visibility: visible;
  margin-bottom: 4rem;
}

.poem-content {
  max-width: 42rem;
  width: 100%;
  margin-block: auto;
}

/* ================================
   Title page
   ================================ */

.title-page {
  text-align: center;
}

.title-page h1 {
  font-family: var(--font-title);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-transform: uppercase;
  margin-bottom: 2rem;
}

.title-page .author {
  font-family: var(--font-title);
  font-size: 0.875rem;
  color: var(--fg-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ================================
   Poem titles
   ================================ */

h2 {
  font-family: var(--font-title);
  font-size: clamp(0.875rem, 2.5vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--fg-dim);
}

/* ================================
   Poem text
   ================================ */

.poem-text {
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 400;
}

.poem-text p {
  margin-bottom: 1.5em;
}

.poem-text p:last-child {
  margin-bottom: 0;
}

/* ================================
   Navigation
   ================================ */

#navigation {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 1.5rem;
  background: linear-gradient(to top, var(--bg) 50%, transparent);
  z-index: 100;
}

#navigation button {
  font-family: var(--font-title);
  font-size: 0.75rem;
  background: none;
  border: 1px solid var(--fg-dim);
  color: var(--fg);
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  transition:
    border-color 200ms ease,
    color 200ms ease;
}

#navigation button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#navigation button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

#progress {
  font-family: var(--font-title);
  font-size: 0.75rem;
  color: var(--fg-dim);
  letter-spacing: 0.1em;
  min-width: 5rem;
  text-align: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 1rem;
  white-space: nowrap;
  transition: color 200ms ease;
}

button#progress {
  width: auto;
}

/* ================================
   Scrollbar (för längre dikter)
   ================================ */

.poem::-webkit-scrollbar {
  width: 4px;
}

.poem::-webkit-scrollbar-track {
  background: transparent;
}

.poem::-webkit-scrollbar-thumb {
  background: var(--fg-dim);
}

/* ================================
   Selection
   ================================ */

::selection {
  background: var(--fg);
  color: var(--bg);
}

/* ================================
   Progress button
   ================================ */

#progress {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem 1rem;
  transition: color 200ms ease;
}

#progress:hover {
  color: var(--fg);
}

/* ================================
   Overlay / Innehållsförteckning
   ================================ */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-duration) ease,
    visibility var(--transition-duration) ease;
  overflow-y: auto;
}

.overlay[hidden] {
  display: block;
}

.overlay.open {
  opacity: 1;
  visibility: visible;
}

.overlay-content {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem;
  min-height: 100%;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--fg-dim);
}

.overlay-header h2 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

#toc-close {
  font-family: var(--font-title);
  font-size: 1.25rem;
  background: none;
  border: 1px solid var(--fg-dim);
  color: var(--fg);
  width: 3rem;
  height: 3rem;
  cursor: pointer;
  transition:
    border-color 200ms ease,
    color 200ms ease;
}

#toc-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#toc-list {
  list-style: none;
  counter-reset: toc;
}

#toc-list li {
  counter-increment: toc;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#toc-list li:first-child {
  counter-increment: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#toc-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 1.1rem;
  padding: 1rem 0;
  padding-left: 3rem;
  position: relative;
  cursor: pointer;
  transition: color 200ms ease;
}

#toc-list button::before {
  content: counter(toc, decimal-leading-zero);
  position: absolute;
  left: 0;
  font-family: var(--font-title);
  font-size: 0.75rem;
  color: var(--fg-dim);
}

#toc-list li:first-child button::before {
  content: "";
}

#toc-list li:first-child button {
  padding-left: 0;
  font-family: var(--font-title);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#toc-list button:hover {
  color: var(--accent);
}

#toc-list button.current {
  color: var(--accent);
}

#toc-list button.current::after {
  content: "←";
  margin-left: 0.5rem;
  font-family: var(--font-title);
}

@media screen and (max-width: 600px) {
  html {
    font-size: 16px;
  }

  .poem {
    padding: 1.5rem;
    padding-bottom: 6rem;
    align-items: flex-start;
    padding-top: 3rem;
  }

  .poem.active {
    margin-bottom: 8rem;
  }

  h2 {
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
  }

  #navigation {
    gap: 1rem;
  }

  #navigation button {
    height: 2.5rem;
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .poem {
    transition: none;
  }
}