:root {
  --bg: #336666;
  --ink: #0b1c1c;
  --muted: #355858;
  --panel: #ffffff;
  --accent: #336666;
  --accent-2: #1f4c4c;
  --shadow: 0 16px 40px rgba(8, 32, 32, 0.18);
  --border: rgba(12, 44, 44, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: #f5fbfb;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  line-height: 1.5;
}

h1,
h2,
h3,
h4 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  letter-spacing: 0.02em;
  margin: 0 0 0.75rem;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--accent-2);
}

button {
  font: inherit;
}

.brainstem-app {
  background: var(--bg);
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 1.75rem;
  padding: 1rem 4vw 4vw;
  min-height: 100vh;
}

.atlas-nav {
  background: rgba(245, 251, 251, 0.1);
  border-radius: 24px;
  padding: 1.5rem;
  border: 1px solid rgba(245, 251, 251, 0.2);
  box-shadow: var(--shadow);
  position: sticky;
  top: 1rem;
  z-index: 100;
}

.atlas-nav.compact {
  padding: 1rem 1.25rem;
  max-height: 24vh;
  overflow: hidden;
}

.atlas-nav h2 {
  color: #f5fbfb;
}

.atlas-nav p {
  color: rgba(245, 251, 251, 0.8);
  margin: 0 0 1rem;
}

.section-groups {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(210px, 210px);
  gap: 1rem;
  overflow-x: auto;
  padding: .25rem;
}

.group-card {
  --thumb-height: 78px;
  --card-pad: 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border-radius: 18px;
  padding: var(--card-pad);
  border: 2px solid transparent;
  gap: 0.75rem;
  width: 160px;
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: stretch;
  height: calc(var(--thumb-height) + (var(--card-pad) * 2));
}

.group-card.active {
  border-color: var(--accent);
}

.group-thumb {
  width: 64px;
  height: var(--thumb-height);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: rgba(51, 102, 102, 0.08);
  display: grid;
  place-items: center;
  align-self: stretch;
}

.group-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.group-thumb img.is-fallback {
  display: none;
}

.group-thumb::after {
  content: "No image";
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(11, 28, 28, 0.5);
}

.group-thumb.has-image::after {
  content: "";
}

.group-links {
  display: grid;
  gap: 0.12rem;
  align-content: stretch;
  height: var(--thumb-height);
  grid-auto-rows: 1fr;
}

.section-link {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.1rem 0.3rem;
  text-align: left;
  cursor: pointer;
  border-radius: 10px;
  color: var(--muted);
  line-height: 1.1;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
}

.section-link strong {
  display: inline-block;
  margin-right: 0.35rem;
  color: var(--ink);
}

.section-link.active,
.section-link:hover {
  border-color: rgba(51, 102, 102, 0.4);
  background: rgba(51, 102, 102, 0.08);
  color: var(--ink);
}

.app-main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.viewer-title-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.viewer-title {
  font-size: 1.4rem;
}

.viewer-subtitle {
  color: rgba(245, 251, 251, 0.8);
  margin: 0;
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-buttons {
  display: flex;
  gap: 0.6rem;
}

.nav-buttons button {
  border-radius: 999px;
  padding: 0.45rem 1rem;
  border: 1px solid rgba(245, 251, 251, 0.4);
  background: rgba(245, 251, 251, 0.12);
  color: #f5fbfb;
  cursor: pointer;
}

.nav-buttons button:hover {
  background: rgba(245, 251, 251, 0.22);
}

.magnification {
  display: flex;
  gap: 0.5rem;
}

.magnification button {
  border-radius: 999px;
  padding: 0.45rem 1rem;
  border: 1px solid rgba(245, 251, 251, 0.4);
  background: rgba(245, 251, 251, 0.12);
  color: #f5fbfb;
  cursor: pointer;
}

.magnification button.active {
  background: #f5fbfb;
  color: var(--accent);
  border-color: #f5fbfb;
}

.viewer-frame {
  flex: 1;
  height: 815px;
  min-height: 815px;
  border-radius: 24px;
  overflow: auto;
  border: 2px solid rgba(245, 251, 251, 0.2);
  box-shadow: var(--shadow);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.viewer-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.brainstem-image,
.brainstem-controls,
.brainstem-article,
.brainstem-index {
  background: #f7f9f9;
  color: var(--ink);
  margin: 0;
}

.brainstem-image {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  padding: 1.5rem;
  overflow: auto;
}

.brainstem-image table {
  background: #fff;
  border-radius: 12px;
  border-collapse: collapse;
  box-shadow: var(--shadow);
}

.brainstem-image img {
  max-width: none;
  height: auto;
  display: block;
}

@media (max-width: 768px) {
  .viewer-frame {
    height: 55vh;
    min-height: 55vh;
    border-radius: 18px;
  }
}

.brainstem-controls {
  padding: 1.5rem;
}

.brainstem-article {
  padding: 3rem 6vw 4rem;
}

.brainstem-article .article-shell {
  max-width: 980px;
  margin: 0 auto;
  background: var(--panel);
  padding: 0.2rem;
  border-radius: 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brainstem-article img {
  max-width: 100%;
  height: auto;
}

.brainstem-article table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.brainstem-article td,
.brainstem-article th {
  border: 1px solid var(--border);
  padding: 0.7rem 0.9rem;
  text-align: left;
  vertical-align: top;
}

.brainstem-index {
  padding: 2rem 4vw;
}

.index-shell {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
}

.index-grid {
  display: grid;
  gap: 1.2rem;
}

.index-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: var(--panel);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 18px rgba(28, 36, 36, 0.08);
}

.index-item img {
  width: 64px;
  height: 78px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.app-shell {
  padding: 0 6vw 12vw;
}

.section-groups {
  grid-auto-columns: minmax(180px, 1fr);
}

.atlas-nav.compact {
  max-height: 26vh;
}

.brainstem-article .article-shell {
  padding: 2rem;
}
