/* =============================================
   Calculus Textbook — Design System
   ============================================= */

/* --- CSS Variables --- */
:root {
  --c-text: #2C2C2C;
  --c-text-secondary: #555555;
  --c-text-light: #777777;
  --c-bg: #FDFDFD;
  --c-card: #FFFFFF;
  --c-border: #D8D8D8;
  --c-accent: #2B6CB0;
  --c-accent-light: #EBF4FF;
  --c-gold: #B7791F;
  --c-gold-light: #FEFCF0;
  --c-green: #276749;
  --c-green-light: #F0FFF4;
  --c-red: #9B2C2C;
  --c-red-light: #FFF5F5;
  --c-purple: #553C9A;
  --c-purple-light: #FAF5FF;
  --c-def-border: #2B6CB0;
  --c-thm-border: #276749;
  --c-proof-border: #777777;

  --font-serif: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-sans: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-math: 'KaTeX_Main', 'Times New Roman', serif;
  --max-width: 820px;
  --radius: 6px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.85;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--c-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Language Toggle --- */
.lang-en .zh,
.lang-zh .en {
  display: none !important;
}

/* --- Typography --- */
h1 {
  font-family: var(--font-serif);
  font-size: 36px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--c-text);
  margin-bottom: 8px;
}

h2 {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--c-text);
  margin: 48px 0 20px;
}

h3 {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--c-text);
  margin: 36px 0 16px;
}

h4 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--c-text);
  margin: 28px 0 12px;
}

p {
  margin-bottom: 16px;
}

strong {
  font-weight: 700;
}

em {
  font-style: italic;
}

/* --- Container --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* --- Navigation --- */
.calc-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(253, 253, 253, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.calc-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.calc-nav-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--c-text);
}

.calc-nav-title a {
  color: inherit;
  text-decoration: none;
}

.calc-nav-title a:hover {
  color: var(--c-accent);
  text-decoration: none;
}

.calc-nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
}

.calc-nav-links a {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text-secondary);
}

.calc-nav-links a:hover {
  color: var(--c-accent);
  text-decoration: none;
}

/* --- Book Header --- */
.book-header {
  padding: 48px 0 32px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 40px;
}

.book-header .part-label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.book-header h1 {
  margin-bottom: 12px;
}

.book-header .subtitle {
  font-size: 18px;
  color: var(--c-text-secondary);
  line-height: 1.6;
}

/* --- Book Cover --- */
.book-cover {
  text-align: center;
  padding: 80px 0 60px;
  margin-bottom: 40px;
  border-bottom: 2px solid var(--c-accent);
}

.book-cover h1 {
  font-size: 42px;
  margin-bottom: 16px;
  letter-spacing: 0.05em;
}

.book-cover .cover-subtitle {
  font-size: 18px;
  color: var(--c-text-secondary);
  line-height: 1.6;
  margin-bottom: 32px;
}

.book-cover .cover-author {
  font-size: 16px;
  color: var(--c-text);
  line-height: 1.8;
}

.book-cover .cover-author .author-name {
  font-weight: 700;
  font-size: 18px;
}

.book-cover .cover-author .author-affil {
  color: var(--c-text-secondary);
}

.book-cover .cover-sigma {
  font-size: 72px;
  color: var(--c-accent);
  opacity: 0.15;
  margin-bottom: 24px;
  font-family: var(--font-serif);
  font-style: italic;
  line-height: 1;
}

/* --- Section Nav (prev / next) --- */
.section-nav {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 40px 0;
  margin-top: 48px;
  border-top: 1px solid var(--c-border);
}

.section-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
  max-width: 45%;
}

.section-nav a:hover {
  border-color: var(--c-accent);
  background: var(--c-accent-light);
  text-decoration: none;
}

.section-nav .nav-label {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-nav .nav-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text);
}

.section-nav a.next {
  margin-left: auto;
  text-align: right;
}

/* --- Definition Box --- */
.definition {
  margin: 24px 0;
  padding: 20px 24px;
  border-left: 4px solid var(--c-def-border);
  background: var(--c-accent-light);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.definition .label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

/* --- Theorem Box --- */
.theorem {
  margin: 24px 0;
  padding: 20px 24px;
  border-left: 4px solid var(--c-thm-border);
  background: var(--c-green-light);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.theorem .label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

/* --- Proof --- */
.proof {
  margin: 16px 0 24px;
  padding: 16px 24px;
  border-left: 3px solid var(--c-proof-border);
  background: #FAFAFA;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.proof .label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.proof .qed {
  float: right;
  font-size: 16px;
  color: var(--c-text-light);
}

/* --- Aside / 旁白 Box --- */
.aside {
  margin: 24px 0;
  padding: 16px 20px;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius);
  background: var(--c-gold-light);
}

.aside .label {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.aside p {
  font-size: 15px;
  color: var(--c-text-secondary);
  margin-bottom: 8px;
}

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

/* --- Example --- */
.example {
  margin: 24px 0;
  padding: 20px 24px;
  border-left: 4px solid var(--c-gold);
  background: var(--c-gold-light);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.example .label {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-gold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

/* --- Exercises --- */
.exercises {
  margin: 48px 0;
  padding: 32px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: #FAFAFA;
}

.exercises h3 {
  margin-top: 0;
  color: var(--c-text);
}

.exercises .exercise-type {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 700;
  color: var(--c-purple);
  margin: 24px 0 12px;
}

.exercises ol {
  padding-left: 24px;
}

.exercises li {
  margin-bottom: 12px;
  line-height: 1.7;
}

.exercises li ol {
  margin-top: 8px;
  padding-left: 20px;
}

/* --- Display Math --- */
.math-display {
  display: block;
  text-align: center;
  margin: 20px 0;
  overflow-x: auto;
  padding: 4px 0;
}

/* --- Inline list (for book TOC) --- */
.toc-list {
  list-style: none;
  padding: 0;
}

.toc-list li {
  margin-bottom: 8px;
}

.toc-list a {
  font-size: 17px;
  color: var(--c-accent);
}

.toc-part {
  margin: 32px 0 16px;
  padding: 12px 16px;
  background: var(--c-accent-light);
  border-radius: var(--radius);
}

.toc-part h3 {
  margin: 0;
  font-size: 18px;
  color: var(--c-accent);
}

.toc-chapter {
  margin: 20px 0 8px;
  font-weight: 700;
  color: var(--c-text);
  font-size: 17px;
}

.toc-section {
  padding-left: 24px;
}

.toc-section a {
  font-size: 15px;
}

/* --- Table --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 15px;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}

th {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  color: var(--c-text-secondary);
  background: #F8F8F8;
}

/* --- Translator Table --- */
.translator-table {
  overflow-x: auto;
  margin: 24px 0;
}

.translator-table table {
  font-size: 14.5px;
}

.translator-table td:first-child {
  white-space: nowrap;
  font-weight: 500;
  color: var(--c-text-secondary);
  min-width: 160px;
}

.translator-table td:nth-child(2) {
  min-width: 180px;
}

.translator-table td:last-child {
  color: var(--c-text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.translator-table tbody tr:hover {
  background: var(--c-accent-light);
}

/* --- Itemize --- */
.itemize {
  margin: 12px 0;
  padding-left: 24px;
}

.itemize li {
  margin-bottom: 8px;
}

/* --- Main --- */
main {
  flex: 1;
  padding-bottom: 40px;
}

/* --- Footer --- */
.footer {
  margin-top: auto;
  border-top: 1px solid var(--c-border);
  padding: 20px 0;
  background: #FAFAFA;
  text-align: center;
}

.footer a {
  font-size: 13px;
  color: var(--c-text-light);
}

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

/* --- Responsive --- */
@media (max-width: 768px) {
  h1 { font-size: 28px; }
  h2 { font-size: 22px; }
  h3 { font-size: 19px; }
  body { font-size: 16px; }
  .container { padding: 0 16px; }
  .book-cover h1 { font-size: 30px; }
  .book-cover .cover-sigma { font-size: 48px; }
  .book-cover { padding: 48px 0 40px; }
  .definition, .theorem, .proof, .aside, .example {
    padding: 16px;
  }
  .section-nav a {
    max-width: 100%;
  }
  .section-nav {
    flex-direction: column;
  }
}
