/* Theorem environments */
.theorem, .lemma, .proposition, .corollary,
.definition, .proof, .remark, .observation, .example {
  margin: 1.5em 0;
  padding: 0.8em 1em 0.8em 1.2em;
  border-radius: 2px;
  line-height: 1.6;
}

/* Blue family: theorem, lemma, proposition, corollary */
.theorem, .lemma, .proposition, .corollary {
  border-left: 3px solid #2563eb;
  background: #f8fafc;
}

/* Green: definition */
.definition {
  border-left: 3px solid #16a34a;
  background: #f0fdf4;
}

/* Gray: remark, observation */
.remark, .observation {
  border-left: 3px solid #9ca3af;
  background: #f9fafb;
}

/* Orange: example */
.example {
  border-left: 3px solid #ea580c;
  background: #fff7ed;
}

/* Proof */
.proof {
  border-left: 3px solid #d1d5db;
  background: transparent;
}

/* Labels */
.theorem::before, .lemma::before, .proposition::before,
.corollary::before, .definition::before, .remark::before,
.observation::before, .example::before, .proof::before {
  font-weight: 700;
  font-size: 0.9em;
  display: block;
  margin-bottom: 0.3em;
}

/* Auto-numbering */
body { counter-reset: theorem definition; }

.theorem::before {
  counter-increment: theorem;
  content: "Theorem " counter(theorem) ".";
  color: #2563eb;
}
.theorem[text]::before {
  content: "Theorem " counter(theorem) " (" attr(text) ").";
}

.lemma::before {
  counter-increment: theorem;
  content: "Lemma " counter(theorem) ".";
  color: #2563eb;
}
.lemma[text]::before {
  content: "Lemma " counter(theorem) " (" attr(text) ").";
}

.proposition::before {
  counter-increment: theorem;
  content: "Proposition " counter(theorem) ".";
  color: #2563eb;
}

.corollary::before {
  counter-increment: theorem;
  content: "Corollary " counter(theorem) ".";
  color: #2563eb;
}

.definition::before {
  counter-increment: definition;
  content: "Definition " counter(definition) ".";
  color: #16a34a;
}
.definition[text]::before {
  content: "Definition " counter(definition) " (" attr(text) ").";
}

.remark::before {
  content: "Remark.";
  color: #6b7280;
}
.remark[text]::before {
  content: "Remark (" attr(text) ").";
}

.observation::before {
  content: "Observation.";
  color: #6b7280;
}

.example::before {
  content: "Example.";
  color: #ea580c;
}

.proof::before {
  content: "Proof.";
  color: #6b7280;
  font-style: italic;
}

.proof::after {
  content: "□";
  float: right;
  color: #6b7280;
}

/* Photo gallery - masonry style */
.photo-gallery {
  column-count: 3;
  column-gap: 12px;
  margin: 1.5em 0;
}

@media (max-width: 768px) {
  .photo-gallery {
    column-count: 2;
  }
}

@media (max-width: 480px) {
  .photo-gallery {
    column-count: 1;
  }
}

.photo-gallery .photo-item {
  break-inside: avoid;
  margin-bottom: 12px;
  border-radius: 4px;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.photo-gallery .photo-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.photo-gallery .photo-item img {
  width: 100%;
  display: block;
}

.photo-gallery .photo-caption {
  font-size: 0.8em;
  color: #6b7280;
  padding: 6px 8px;
  text-align: center;
}

/* Sticky sidebar navigation */
.sidebar {
  position: sticky;
  top: 2em;
  align-self: flex-start;
}

/* Sticky sidebar */
.masthead {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Narrower sidebar, wider content */
.masthead {
  width: 180px;
  padding: 20px 20px 20px 10px;
}

.main {
  margin-left: 180px;
  width: calc(100% - 180px);
  max-width: 780px;
}

/* Even narrower sidebar */
.masthead {
  width: 120px;
  padding: 20px 10px 20px 10px;
}

.masthead h1 {
  font-size: 28px;
}

.main {
  margin-left: 120px;
  width: calc(100% - 120px);
  max-width: 840px;
}

/* Final sidebar size */
.masthead {
  width: 160px;
  padding: 20px 15px 20px 10px;
}

.masthead h1 {
  font-size: 36px;
}

.main {
  margin-left: 160px;
  width: calc(100% - 160px);
  max-width: 820px;
}







/* Mobile: let theme's hamburger menu work, sidebar becomes top bar */
@media (max-width: 768px) {
  .masthead {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    float: none !important;
    padding: 15px !important;
    text-align: center !important;
  }
  
  .masthead h1 {
    font-size: 24px !important;
    text-align: center !important;
    margin-bottom: 5px !important;
  }
  
  .masthead .tagline {
    text-align: center !important;
    font-size: 0.85em !important;
  }
  
  .masthead .menu {
    direction: ltr !important;
    text-align: center !important;
    margin-right: 0 !important;
  }
  
  .main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-left: none !important;
    padding: 15px !important;
    min-height: auto !important;
  }
}

/* Back to top button */
#back-to-top {
  display: none;
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #333;
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  z-index: 999;
}

#back-to-top:hover {
  opacity: 1;
}

@media (max-width: 768px) {
  #back-to-top {
    bottom: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}

/* Dark mode toggle button */
#dark-toggle {
  position: fixed;
  bottom: 30px;
  right: 80px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #333;
  color: #fff;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  z-index: 999;
}

#dark-toggle:hover {
  opacity: 1;
}

@media (max-width: 768px) {
  #dark-toggle {
    bottom: 20px;
    right: 64px;
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* Dark mode colors */
[data-theme="dark"] {
  background-color: #1a1a2e !important;
  color: #e0e0e0 !important;
}

[data-theme="dark"] .masthead {
  background-color: #1a1a2e !important;
}

[data-theme="dark"] .main {
  background-color: #1a1a2e !important;
  border-left-color: #444 !important;
}

[data-theme="dark"] a {
  color: #7eb8da !important;
}

[data-theme="dark"] a:hover {
  color: #a8d8ea !important;
}

[data-theme="dark"] .masthead h1 a {
  color: #e0e0e0 !important;
}

[data-theme="dark"] .title h1 {
  color: #e0e0e0 !important;
}

[data-theme="dark"] code {
  background-color: #2d2d44 !important;
  color: #e0e0e0 !important;
}

[data-theme="dark"] pre {
  background-color: #2d2d44 !important;
}

[data-theme="dark"] blockquote {
  border-left-color: #555 !important;
  color: #bbb !important;
}

[data-theme="dark"] .photo-caption {
  color: #999 !important;
}

/* Dark mode theorem environments */
[data-theme="dark"] .theorem,
[data-theme="dark"] .lemma,
[data-theme="dark"] .proposition,
[data-theme="dark"] .corollary {
  background: #1e2a3a !important;
  border-left-color: #4a90d9 !important;
}

[data-theme="dark"] .definition {
  background: #1e3a2a !important;
  border-left-color: #4ad97a !important;
}

[data-theme="dark"] .remark,
[data-theme="dark"] .observation {
  background: #2a2a2a !important;
  border-left-color: #666 !important;
}

[data-theme="dark"] .proof {
  border-left-color: #555 !important;
}

[data-theme="dark"] #back-to-top,
[data-theme="dark"] #dark-toggle {
  background: #555;
}

/* Dark mode tables */
[data-theme="dark"] table {
  color: #e0e0e0 !important;
}

[data-theme="dark"] th, 
[data-theme="dark"] td {
  border-color: #444 !important;
}
