:root {
  --page-bg: #f4f1ea;
  --text: #1f2933;
  --muted: #52606d;
  --brand: #176d67;
  --brand-strong: #0e4f4b;
  --accent: #d97a28;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.12);
  --header-height: 4rem;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Crimson Text", Georgia, serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(217, 122, 40, 0.18), transparent 28rem),
    linear-gradient(180deg, #f7f2e8 0%, var(--page-bg) 28%, #efe7dc 100%);
}

a {
  color: var(--brand-strong);
}

a:hover {
  color: var(--accent);
}

.site-nav {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--header-height);
  padding: 0.7rem 1rem;
  background: rgba(23, 109, 103, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px rgba(14, 79, 75, 0.18);
}

.site-nav a,
.toc-toggle {
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  color: #f7f5ef;
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
  background: transparent;
  cursor: pointer;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.toc-toggle:hover,
.toc-toggle:focus-visible {
  outline: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.site-nav a.active,
.toc-toggle {
  color: #fff8ef;
  background: rgba(217, 122, 40, 0.9);
}

.toc-toggle {
  margin-left: auto;
  display: none;
  font-family: inherit;
}

.page-shell {
  width: min(100%, 104rem);
  margin: 0 auto;
  padding: 1.4rem 1rem 2rem;
}

.hero {
  margin-bottom: 1.25rem;
  padding: 1.75rem;
  border-radius: 1.6rem;
  background:
    linear-gradient(135deg, rgba(23, 109, 103, 0.96), rgba(14, 79, 75, 0.92)),
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent);
  color: #fff;
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 3.6vw, 3.6rem);
  line-height: 1.02;
}

.hero p {
  max-width: 56rem;
  margin: 0.85rem 0 0;
  font-size: clamp(1.08rem, 1.5vw, 1.28rem);
  line-height: 1.45;
  color: rgba(255, 250, 245, 0.88);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.15rem;
}

.hero-actions a {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  text-decoration: none;
}

.hero-actions a.primary {
  background: #f7b733;
  color: #173339;
}

.hero-actions a.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fffaf2;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(22rem, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.panel {
  padding: 1.35rem;
  border-radius: 1.35rem;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 1.6rem;
  color: #102a43;
}

.panel p,
.panel li {
  font-size: 1.08rem;
  line-height: 1.55;
}

.panel img {
  max-width: 100%;
  height: auto;
}

.figure-card {
  text-align: center;
}

.figure-card figcaption {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.98rem;
}

.book-shell {
  width: min(100%, 106rem);
  margin: 0 auto;
  padding: 1.4rem 1rem 2rem;
}

.book-layout {
  display: grid;
  grid-template-columns: minmax(14rem, 20rem) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.toc-panel,
.content-panel {
  border: 1px solid rgba(31, 41, 51, 0.08);
  border-radius: 1.35rem;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.toc-panel {
  position: sticky;
  top: calc(var(--header-height) + 1rem);
  max-height: calc(100vh - var(--header-height) - 2rem);
  overflow: auto;
  padding: 1rem 0.85rem;
}

.toc-panel h2 {
  margin: 0 0 0.75rem;
  padding: 0 0.35rem;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.toc-list a {
  display: block;
  border-radius: 0.8rem;
  padding: 0.45rem 0.65rem;
  text-decoration: none;
  line-height: 1.3;
  color: var(--text);
}

.toc-list a:hover,
.toc-list a:focus-visible,
.toc-list a.is-active {
  outline: none;
  background: rgba(23, 109, 103, 0.1);
  color: var(--brand-strong);
}

.toc-level-2 {
  margin-left: 0.8rem;
}

.toc-level-3,
.toc-level-4,
.toc-level-5,
.toc-level-6 {
  margin-left: 1.5rem;
  font-size: 0.94rem;
  color: var(--muted);
}

.content-panel {
  padding: clamp(1rem, 2vw, 2rem);
  overflow-x: auto;
  overflow-y: hidden;
}

.content-panel h1,
.content-panel h2,
.content-panel h3,
.content-panel h4,
.content-panel h5,
.content-panel h6 {
  scroll-margin-top: calc(var(--header-height) + 1.25rem);
}

.content-panel h1 {
  margin-top: 2.2rem;
  margin-bottom: 0.9rem;
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 1.08;
  color: #102a43;
}

.content-panel h1:first-child {
  margin-top: 0;
}

.content-panel h2 {
  margin-top: 1.9rem;
  margin-bottom: 0.65rem;
  font-size: clamp(1.5rem, 2.1vw, 1.95rem);
  color: #163c5a;
}

.content-panel h3,
.content-panel h4,
.content-panel h5,
.content-panel h6 {
  margin-top: 1.45rem;
  margin-bottom: 0.5rem;
  color: #1f4f73;
}

.heading-anchor {
  margin-left: 0.4rem;
  opacity: 0;
  text-decoration: none;
  color: var(--accent);
  transition: opacity 140ms ease;
}

.content-panel h1:hover .heading-anchor,
.content-panel h2:hover .heading-anchor,
.content-panel h3:hover .heading-anchor,
.content-panel h4:hover .heading-anchor,
.content-panel h5:hover .heading-anchor,
.content-panel h6:hover .heading-anchor {
  opacity: 1;
}

.content-panel img {
  max-width: 100%;
  height: auto;
}

.content-panel table {
  max-width: 100%;
  margin: 1rem auto;
}

.content-panel p,
.content-panel li,
.content-panel td,
.content-panel th {
  overflow-wrap: anywhere;
}

.content-panel p.MsoCaption {
  margin: 0.35rem auto 1.25rem !important;
  max-width: 44rem;
  padding: 0 0.75rem;
  text-align: center !important;
  font-size: 0.98rem !important;
  line-height: 1.45 !important;
  color: var(--muted);
}

.content-panel p.MsoQuote {
  margin: 1rem 0 1.15rem !important;
  padding: 0.9rem 1rem;
  border-left: 4px solid rgba(217, 122, 40, 0.72);
  background: #f8f3ea;
  border-radius: 0 0.9rem 0.9rem 0;
  line-height: 1.55 !important;
}

.content-panel p.MsoBibliography {
  margin: 0 0 0.8rem !important;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(23, 109, 103, 0.12);
  border-radius: 0.95rem;
  background: #fcfaf5;
  text-indent: 0 !important;
  line-height: 1.55 !important;
}

.viewer-shell {
  width: min(100%, 110rem);
  margin: 0 auto;
  padding: 1.4rem 1rem 2rem;
}

.viewer-card {
  border-radius: 1.35rem;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.viewer-stage {
  padding: 1rem;
}

.viewer-stage img {
  display: block;
  width: min(100%, 95vw);
  margin: 0 auto;
  height: auto;
}

.applet-frame {
  width: 100%;
  overflow: auto;
  border-bottom: 1px solid rgba(31, 41, 51, 0.08);
  background: #fff;
}

.book-footer,
.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.8rem;
  margin-top: 1rem;
  padding: 0 0.3rem;
  color: var(--muted);
}

.book-footer a,
.site-footer a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}

.book-footer img,
.site-footer img {
  height: 1.8rem;
  width: auto;
}

@media (max-width: 960px) {
  .book-layout,
  .grid-two {
    grid-template-columns: 1fr;
  }

  .toc-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .toc-panel {
    position: fixed;
    inset: var(--header-height) 0 auto 0;
    z-index: 20;
    max-height: calc(100vh - var(--header-height));
    border-radius: 0;
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }

  .toc-panel.is-open {
    transform: translateX(0);
  }
}
