:root {
  --bg: #fbfaf7;
  --paper: #fffdf8;
  --text: #1f1b16;
  --muted: #71695f;
  --line: #e4ded4;
  --accent: #7a4f22;
  --sidebar: #f4efe7;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background: #beb3a0;
  color: var(--text);
}

html {
  overflow-y: scroll;
}

.reader {
  min-height: calc(100vh - 52px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 1280px;
  height: 52px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  font-family: Inter, Arial, sans-serif;
  background: #fbfaf7;
  border-bottom: 1px solid var(--line);
  box-sizing: border-box;
}

.book-title {
  font-size: 14px;
  letter-spacing: 0.02em;
}

.search,
.top-links {
  color: var(--muted);
  font-size: 13px;
}

.top-links {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: Inter, Arial, sans-serif;
}

.top-links a {
  color: var(--muted);
  text-decoration: none;
}

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

.layout {
  width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 300px 980px;
  min-height: calc(100vh - 52px);
  background: #fbfaf7;
  box-shadow: 0 10px 35px rgba(0,0,0,.08);
}

.sidebar {
  position: sticky;
  top: 52px;
  align-self: start;
  height: calc(100vh - 52px);
  overflow-y: auto;
  padding: 28px;
  border-right: 1px solid var(--line);     
  box-sizing: border-box;
  background: var(--sidebar); 
}

.brand h1 {
  margin: 0;
  font-size: 25px;
  font-weight: 500;
}

.brand p {
  margin: 6px 0 34px;
  color: var(--muted);
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
}

.section-label,
.part {
  font-family: Inter, Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 24px 0 10px;
}

.contents a {
  display: block;
  text-decoration: none;
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
  padding: 7px 0 7px 12px;
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition:
    background-color 140ms ease,
    border-left-color 140ms ease,
    border-left-width 140ms ease,
    padding-left 140ms ease,
    color 140ms ease;
}

.contents a:hover {
  background: rgba(122, 79, 34, 0.055);
  border-left-color: rgba(122, 79, 34, 0.45);
  border-left-width: 4px;
  padding-left: 10px;
}

.contents a.sub {
  padding-left: 28px;
  color: #3b352e;
}

.contents a.sub:hover {
  padding-left: 26px;
}

.contents a.active {
  border-left-color: var(--accent);
  border-left-width: 4px;
  color: var(--accent);
  font-weight: 600;
  background: rgba(122, 79, 34, 0.075);
  padding-left: 10px;
}

.contents a.active.sub {
  padding-left: 26px;
}

.contents a.active:hover {
  background: rgba(122, 79, 34, 0.095);
}

.reader {
  padding: 64px 84px;
}

.chapter {
  max-width: 760px;
  margin: 0 auto;
  background: transparent;
}

.chapter-kicker {
  font-family: Inter, Arial, sans-serif;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 18px;
}

.chapter h1 {
  font-size: 26px;
  line-height: 1.25;
  margin: 0 0 20px;
  font-weight: 600;
}

.chapter h2 {
  font-size: 18px;
  margin: 32px 0 14px;
  font-weight: 600;
}

.chapter p {
  font-size: 18px;
  line-height: 1.75;
  margin: 0 0 18px;
}

.chapter .lead {
  font-size: 21px;
  line-height: 1.65;
  color: #332b22;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 36px 0;
}

@media (max-width:1300px){
  .topbar{
    width:100%;
  }
  .layout{
    width:100%;
    grid-template-columns:300px 1fr;
  }
}

@media (max-width:1100px){
  .topbar{
    width:100%;
    padding:0 18px;
  }
  .layout{
    width:100%;
    grid-template-columns:1fr;
  }
  .sidebar{
    display:none;
  }
  .reader{
    padding:36px 24px;
  }
  .chapter h1{
    font-size:40px;
  }
  .chapter p{
    font-size:17px;
  }
}

.chapter img {
  max-width: 92%;
  height: auto;
  display: block;
  margin: 28px auto;
  border: 0px solid var(--line);
}

.Figure_Convert_To_Matrix {
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 50px minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  height: auto;
  margin: 24px auto;
  border: 0;
  overflow: visible;
}

.Figure_Convert_To_Matrix > * {
  min-width: 0;
  max-width: 100%;
}

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

.Figure_Convert_To_Matrix .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}

@media (min-width: 1101px) {
  .Figure_Convert_To_Matrix .katex {
    font-size: 0.82em;
  }
}
.Table_Content {
  max-width: 100%;  
  display: grid;
  grid-template-columns: 1fr 33% 1fr; 
  align-items: left;
  gap: 24px;
  height: auto;
  margin: 28px auto;
  border: 0px solid var(--line);
  font-size: 0.85cm;
}
.Table_Content_1 {
  max-width: 100%;  
  display: grid;
  grid-template-columns: 1fr 50% 1fr; 
  text-align: center;
  align-items: center;
  gap: 24px;
  height: auto;
  margin: 28px auto;
  border: 0px solid var(--line);
  font-size: 0.85cm;
}
.math-small {
  font-size: 0.85em;
}
.math-medium {
  font-size: 1em;
}
.math-large {
  font-size: 1.15em;
}
.math-huge {
  font-size: 1.25em;
}
.sidebar-separator {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;  
}
.image-resize {
  max-width: 60%;
  height: auto;
}
/* Mobile contents menu */
.mobile-menu-button {
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--paper);
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
  font-size: 13px;
  cursor: pointer;
}

.mobile-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(31, 27, 22, 0.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.mobile-menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1600;
  width: min(86vw, 360px);
  height: 100vh;
  padding: 22px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 32px rgba(0, 0, 0, 0.16);
  overflow-y: auto;
  transform: translateX(-105%);
  transition: transform 220ms ease;
}

.mobile-menu.open {
  transform: translateX(0);
}

.mobile-menu-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.mobile-menu-header h2 {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  font-size: 18px;
  font-weight: 650;
}

.mobile-menu-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-family: Inter, Arial, sans-serif;
  font-size: 13px;
}

.mobile-menu-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

body.menu-open {
  overflow: hidden;
}

@media (max-width:1100px){
  .mobile-menu-button {
    display: inline-flex;
  }

  .search {
    display: none;
  }

  .book-title {
    max-width: calc(100vw - 170px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chapter h1{
    font-size:32px;
  }

  .Figure_Convert_To_Matrix {
    grid-template-columns: 1fr;
    gap: 16px;
    font-size: 0.55cm;
  }

  /* Comparison tables: keep columns on mobile and allow horizontal scroll. */
  .Table_Content,
  .Table_Content_1 {
    display: flex;
    align-items: stretch;
    gap: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    font-size: 0.48cm;
    padding-bottom: 8px;
  }

  .Table_Content > div,
  .Table_Content_1 > div {
    flex: 0 0 190px;
    padding: 0 14px;
    border-right: 1px solid var(--line);
  }

  .Table_Content > div:first-child,
  .Table_Content_1 > div:first-child {
    flex-basis: 150px;
    padding-left: 0;
  }

  .Table_Content > div:last-child,
  .Table_Content_1 > div:last-child {
    border-right: 0;
  }

  .chapter table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .image-resize {
    max-width: 92%;
  }
}

/* --------------------------------------------------
   Mobile reading refinements
   -------------------------------------------------- */

.chapter,
.chapter * {
  min-width: 0;
}

.chapter {
  overflow-wrap: break-word;
  word-break: normal;
}

.chapter table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
}

.chapter th,
.chapter td {
  overflow-wrap: break-word;
}

.chapter pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
}

.chapter code {
  overflow-wrap: break-word;
}

.chapter .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}

.chapter .katex {
  max-width: 100%;
}

.chapter img,
.chapter svg,
.chapter canvas,
.chapter video {
  max-width: 100%;
  height: auto;
}

@media (max-width: 1100px) {
  body {
    background: var(--bg);
  }

  .topbar {
    width: 100%;
    height: 52px;
    padding: 0 14px;
    gap: 10px;
  }

  .book-title {
    max-width: calc(100vw - 150px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  .search {
    display: none;
  }

  .mobile-menu-button {
    display: inline-flex;
    flex: 0 0 auto;
    padding: 7px 11px;
    font-size: 13px;
  }

  .layout {
    width: 100%;
    display: block;
    min-height: calc(100vh - 52px);
    box-shadow: none;
  }

  .sidebar {
    display: none;
  }

  .reader {
    width: 100%;
    min-width: 0;
    padding: 34px 20px 56px;
  }

  .chapter {
    width: 100%;
    max-width: 100%;
  }

  .chapter-kicker {
    font-size: 11px;
    margin-bottom: 14px;
  }

  .chapter h1 {
    font-size: 22px; /*clamp(28px, 8vw, 32px);*/
    line-height: 1.18;
    margin-bottom: 18px;
  }

  .chapter h2 {
    font-size: 18px;
    line-height: 1.28;
    margin-top: 30px;
  }

  .chapter p,
  .chapter li {
    font-size: 16px;
    line-height: 1.72;
  }

  .chapter .lead {
    font-size: 18px;
    line-height: 1.62;
  }

  .chapter img {
    max-width: 100%;
    margin: 24px auto;
  }

  .image-resize {
    max-width: 100%;
  }

  .Figure_Convert_To_Matrix {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    gap: 16px;
    font-size: clamp(16px, 5vw, 20px);
  }

  .Figure_Convert_To_Matrix > *,
  .Table_Content > *,
  .Table_Content_1 > * {
    max-width: 100%;
  }

  .Table_Content,
  .Table_Content_1 {
    overflow-x: auto;
  }

  .chapter table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .chapter blockquote {
    margin-left: 0;
    margin-right: 0;
    padding-left: 16px;
  }

  .chapter ul,
  .chapter ol {
    padding-left: 22px;
  }

  .mobile-menu {
    width: min(88vw, 360px);
    padding: 20px;
  }
}

@media (max-width: 420px) {
  .reader {
    padding-left: 16px;
    padding-right: 16px;
  }

  .book-title {
    max-width: calc(100vw - 135px);
    font-size: 12px;
  }

  .mobile-menu-button {
    padding: 7px 10px;
    font-size: 12px;
  }

  .chapter p,
  .chapter li {
    font-size: 16.5px;
  }
}


/* Contact page */
.contact-card {
  margin: 28px 0;
  padding: 24px 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.contact-card p:last-child {
  margin-bottom: 0;
}

.contact-list {
  display: grid;
  gap: 14px;
  margin: 24px 0;
}

.contact-item {
  padding: 18px 20px;
  background: rgba(255, 253, 248, 0.75);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.contact-item strong {
  display: block;
  margin-bottom: 6px;
  font-family: Inter, Arial, sans-serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.contact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  text-decoration: none;
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
}

.contact-button:hover {
  background: rgba(122, 79, 34, 0.075);
}

@media (max-width: 1100px) {
  .top-links {
    display: none;
  }

  .contact-card,
  .contact-item {
    padding: 18px 18px;
  }
}
.mobile-contact {
  margin-top: 6px;
  font-family: Inter, Arial, sans-serif;
  color: var(--accent);
  font-size: 14px;
}
.mobile-contact a {
  color: var(--accent);
  text-decoration: none;
}
.mobile-contact a:hover {
  color: var(--accent);
}
.chapter-nav {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 56px 0 10px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.chapter-nav a {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  color: var(--accent);
  text-decoration: none;
  font-family: Inter, Arial, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.chapter-nav span {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.35;
}

.chapter-nav-next {
  text-align: right;
}

@media (max-width: 1100px) {
  .chapter-nav {
    display: grid;
    padding-top: 20px;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 44px;
  }

  .chapter-nav a {
    padding: 16px 18px;
  }

  .chapter-nav-next {
    text-align: left;
  }
}

/* Mobile chapter intro spacer */
.mobile-chapter-intro {
  display: none;
}

@media (max-width: 1100px) {
  .mobile-chapter-intro {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 33vh;
    margin: -8px 0 28px;
    padding: 20px 0 26px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-chapter-intro-label {
    margin-bottom: 12px;
    font-family: Inter, Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
  }

  .mobile-chapter-intro p {
    margin: 0;
    font-size: 18px;
    line-height: 1.62;
    color: #332b22;
  }
}

