:root {
  --color-bg: #071302;
  --color-text: #faf8f3;
  --color-primary: #9BC285;
  --color-secondary: #5D784B;
  --color-accent: #617F98;
  --color-code-bg: #f4f4f4;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  line-height: 1.6;
  width: min(1200px, 88vw);
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem);
  background: var(--color-bg);
  color: var(--color-text);
}

main {
  text-align: left;
}

h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--color-primary);
  text-align: center;
}

h2 {
  color: var(--color-primary);
}

h3 {
  color: var(--color-secondary);
}

/* Offset scroll targets to account for sticky search bar */
h2[id], h3[id] {
  scroll-margin-top: 6.3rem;
}

code {
  background: var(--color-code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

a {
  color: var(--color-accent);
  font-family: inherit;
}

.text-and-figures {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin: 1rem 0;
}

.text-and-figures .text-block {
  flex: 1;
  min-width: 0;
}

.figure-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.figure-row figure {
  flex: 0 1 calc((100% - 4 * 0.5rem) / 5);
  margin: 0;
  min-width: 0;
}

.figure-with-text {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin: 1rem 0 1.5rem;
}

.figure-with-text figure {
  flex: 0 0 calc((100% - 4 * 0.5rem) / 5);
  margin: 0;
  min-width: 0;
}

.figure-with-text figure img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.figure-with-text figure figcaption {
  font-size: 0.9em;
  color: var(--color-primary);
  margin-top: 0.5rem;
  text-align: center;
}

.figure-with-text figure {
  cursor: pointer;
}

.figure-with-text .text-content {
  flex: 1;
  min-width: 0;
}

.figures-two-with-text {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin: 1rem 0 1.5rem;
}

.figures-two-with-text .figures-group {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 calc(2 * (100% - 4 * 0.5rem) / 5 + 0.5rem);
}

.figures-two-with-text figure {
  flex: 1;
  margin: 0;
  min-width: 0;
  cursor: pointer;
}

.figures-two-with-text figure img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.figures-two-with-text figure figcaption {
  font-size: 0.9em;
  color: var(--color-primary);
  margin-top: 0.5rem;
  text-align: center;
}

.figures-two-with-text .text-content {
  flex: 1;
  min-width: 0;
}

.figures-three-with-text {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin: 1rem 0 1.5rem;
}

.figures-three-with-text .figures-group {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 calc(3 * (100% - 4 * 0.5rem) / 5 + 1rem);
}

.figures-three-with-text figure {
  flex: 1;
  margin: 0;
  min-width: 0;
  cursor: pointer;
}

.figures-three-with-text figure img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.figures-three-with-text figure figcaption {
  font-size: 0.9em;
  color: var(--color-primary);
  margin-top: 0.5rem;
  text-align: center;
}

.figures-three-with-text .text-content {
  flex: 1;
  min-width: 0;
}

figure {
  margin-bottom: 1.5rem;
}

figure img {
  border-radius: 10px;
}

.figure-row img {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
}

.figure-row figcaption {
  font-size: 0.9em;
  color: var(--color-primary);
  margin-top: 0.5rem;
  text-align: center;
}

.figure-row figure {
  cursor: pointer;
}

/* Lightbox for enlarged figure */
.figure-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(7, 19, 2, 0.9);
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.figure-lightbox[aria-hidden="false"] {
  display: flex;
}

.figure-lightbox__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  font-size: 2rem;
  line-height: 1;
  color: var(--color-text);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.figure-lightbox__close:hover {
  background: var(--color-accent);
}

.figure-lightbox__content {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.figure-lightbox__img {
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 26px;
}

.figure-lightbox__caption {
  color: var(--color-primary);
  font-size: 1rem;
  margin: 0;
}

/* Page Search */
.search-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 1.5rem 0;
  padding: 1rem;
  background: rgba(7, 19, 2, 0.8);
  border: 1px solid var(--color-secondary);
  border-radius: 8px;
  position: sticky;
  top: 1rem;
  z-index: 100;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.search-input-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  padding: 0.6rem 1rem;
  padding-right: 5rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--color-secondary);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

#search-input:focus {
  border-color: var(--color-primary);
}

#search-input::placeholder {
  color: var(--color-secondary);
}

.search-count {
  position: absolute;
  right: 0.75rem;
  font-size: 0.85rem;
  color: var(--color-secondary);
  pointer-events: none;
}

.search-nav {
  display: flex;
  gap: 0.5rem;
}

.search-nav-btn {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-secondary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.search-nav-btn:hover:not(:disabled) {
  background: var(--color-primary);
}

.search-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.search-clear-btn {
  padding: 0 0.75rem;
  height: 2.25rem;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
  border: 1px solid var(--color-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.search-clear-btn:hover {
  background: var(--color-secondary);
  border-color: var(--color-primary);
}

/* Search highlight marks */
mark.search-highlight {
  background: rgba(155, 194, 133, 0.4);
  color: inherit;
  padding: 0.1em 0;
  border-radius: 2px;
}

mark.search-highlight.current {
  background: var(--color-primary);
  color: var(--color-bg);
}

@media (max-width: 768px) {
  .text-and-figures {
    flex-direction: column;
  }

  .figure-row {
    max-width: none;
  }

  .figure-with-text {
    flex-direction: column;
  }

  .figure-with-text figure {
    flex: 0 0 auto;
    max-width: 200px;
  }

  .figures-two-with-text {
    flex-direction: column;
  }

  .figures-two-with-text .figures-group {
    flex: 0 0 auto;
    max-width: 400px;
  }

  .figures-three-with-text {
    flex-direction: column;
  }

  .figures-three-with-text .figures-group {
    flex: 0 0 auto;
    max-width: 100%;
  }
}
