/* Tufte CSS */
@charset "UTF-8";

/* Import ET Book fonts */
@font-face {
  font-family: "et-book";
  src: url("/fonts/et-book-roman-line-figures.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "et-book";
  src: url("/fonts/et-book-display-italic-old-style-figures.woff2") format("woff2");
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "et-book";
  src: url("/fonts/et-book-bold-line-figures.woff2") format("woff2");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "et-book-roman-old-style";
  src: url("/fonts/et-book-roman-old-style-figures.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* Variables for theming */
:root {
  --background-color: #fffff8;
  --text-color: #111;
  --link-color: #111;
  --secondary-color: #777;
  --border-color: #ddd;
  --selection-bg-color: #b4d5fe;
  --selection-text-color: #111;
  --code-bg-color: #f8f8f8;
  --footnote-bg-color: rgba(238, 238, 238, 0.5);
  --sidebar-width: 12rem;
  --content-width: 32rem;
  --fullwidth: calc(var(--content-width) + var(--sidebar-width) + 4rem);
  --line-height: 1.6;
  --font-size: 15px;
  --side-note-number-font-family: et-book-roman-old-style;
}

/* Dark mode variables */
[data-theme="dark"] {
  --background-color: #1a1a1a;
  --text-color: #ddd;
  --link-color: #ddd;
  --secondary-color: #999;
  --border-color: #444;
  --selection-bg-color: #556;
  --selection-text-color: #eee;
  --code-bg-color: #2a2a2a;
  --footnote-bg-color: rgba(51, 51, 51, 0.5);
}

/* Basic elements */
html {
  font-size: var(--font-size);
  -webkit-text-size-adjust: 100%;
}

body {
  width: 87.5%;
  margin: 0 auto;
  padding: 0;
  color: var(--text-color);
  background-color: var(--background-color);
  font-family: et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  counter-reset: sidenote-counter;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: color 0.3s ease, background-color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 400;
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
  line-height: 1;
}

h1 {
  font-size: 3.2rem;
  margin-top: 4rem;
}

h2 {
  font-style: italic;
  font-size: 2.2rem;
}

h3 {
  font-style: italic;
  font-size: 1.7rem;
}

/* Links */
a:link,
a:visited {
  color: var(--link-color);
  text-decoration: none;
  background: linear-gradient(var(--background-color), var(--background-color)), 
              linear-gradient(var(--background-color), var(--background-color)), 
              linear-gradient(currentColor, currentColor);
  background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
  background-repeat: no-repeat, no-repeat, repeat-x;
  background-position: 0% 93%, 100% 93%, 0% 93%;
  text-shadow: 0.03em 0 var(--background-color), 
               -0.03em 0 var(--background-color), 
               0 0.03em var(--background-color), 
               0 -0.03em var(--background-color);
  transition: color 0.2s;
}

a:hover {
  color: var(--link-color);
  opacity: 0.7;
}

/* Selection styling */
::selection {
  background: var(--selection-bg-color);
  color: var(--selection-text-color);
  text-shadow: none;
}

/* Main layout */
.main-container {
  display: flex;
  margin-top: 2rem;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  padding: 2rem;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-title {
  font-size: 1.8rem;
  margin-bottom: 2rem;
  font-weight: normal;
  line-height: 1.2;
}

.sidebar-nav {
  list-style-type: none;
  padding: 0;
  margin-top: 2rem;
}

.sidebar-nav li {
  margin-bottom: 0.8rem;
}

.sidebar-nav a {
  font-size: 1.2rem;
}

.content-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  max-width: calc(100% - var(--sidebar-width));
}

.main-content {
  width: var(--content-width);
  padding: 2rem;
  max-width: 100%;
}

.footnotes-container {
  width: var(--sidebar-width);
  padding: 2rem 0;
}

/* Typography */
p, ol, ul {
  font-size: 1.4rem;
  line-height: var(--line-height);
  margin-top: 1.4rem;
  margin-bottom: 1.4rem;
  padding-right: 0;
  vertical-align: baseline;
  hyphens: auto;
}

blockquote {
  font-size: 1.4rem;
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 3px solid var(--secondary-color);
}

blockquote p {
  width: 100%;
}

/* Footnote styles */
.sidenote,
.marginnote {
  float: right;
  clear: right;
  margin-right: -60%;
  width: 50%;
  margin-top: 0;
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.3;
  vertical-align: baseline;
  position: relative;
  background-color: var(--footnote-bg-color);
  padding: 0.5rem;
  border-radius: 4px;
}

.sidenote-number {
  counter-increment: sidenote-counter;
}

.sidenote-number:after,
.sidenote:before {
  font-family: var(--side-note-number-font-family);
  position: relative;
  vertical-align: baseline;
}

.sidenote-number:after {
  content: counter(sidenote-counter);
  font-size: 0.9rem;
  top: -0.5rem;
  left: 0.1rem;
}

.sidenote:before {
  content: counter(sidenote-counter) " ";
  font-size: 1rem;
  top: -0.3rem;
}

/* Responsiveness styles */
.mobile-menu-button {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  padding: 0.5rem;
  background-color: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
}

.theme-toggle {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 1000;
  padding: 0.5rem;
  background-color: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  cursor: pointer;
  transition: background-color 0.3s;
  display: flex;
  justify-content: center;
  align-items: center;
}

.moon-icon,
.sun-icon {
  width: 1.2rem;
  height: 1.2rem;
  color: var(--text-color);
}

/* Dark mode toggling */
[data-theme="dark"] .moon-icon {
  display: none;
}

[data-theme="light"] .sun-icon {
  display: none;
}

/* Image styles */
figure {
  margin: 0;
  padding: 0;
  max-width: 100%;
}

figure.fullwidth {
  max-width: var(--fullwidth);
  margin-right: -50%;
}

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

figcaption {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-top: 0.5rem;
  color: var(--secondary-color);
}

/* Posts styling */
.post {
  margin-bottom: 3rem;
}

.post-title {
  margin-bottom: 0.5rem;
}

.post-meta {
  color: var(--secondary-color);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
}

/* Essay list styling */
.essays-list .post {
  margin-bottom: 1.5rem;
}

.essays-list .post-title {
  margin-bottom: 0.2rem;
}

.essays-list .post-thumbnail {
  float: right;
  width: 80px;
  height: 60px;
  object-fit: cover;
  margin-left: 1rem;
  border-radius: 3px;
}

/* Aside styling */
.asides-list .post {
  margin-bottom: 2rem;
}

.asides-list .post-content {
  font-size: 1.5rem;
}

/* Photo grid styling */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.photo-grid-item {
  border-radius: 4px;
  overflow: hidden;
  transition: transform 0.2s;
}

.photo-grid-item:hover {
  transform: scale(1.03);
}

.photo-grid-item img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

/* Archive styling */
.archive-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.archive-stat {
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  text-align: center;
}

.archive-stat-value {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.archive-stat-label {
  font-size: 1rem;
  color: var(--secondary-color);
}

.tag-cloud {
  margin: 2rem 0;
  text-align: center;
}

.tag-item {
  display: inline-block;
  margin: 0.3rem;
  padding: 0.2rem 0.5rem;
}

/* Posts by year/month */
.archive-year {
  margin: 2rem 0;
}

.archive-year-title {
  font-size: 1.8rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.archive-month {
  margin: 1rem 0;
}

.archive-month-title {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.archive-entry {
  display: flex;
  margin-bottom: 0.5rem;
}

.archive-date {
  width: 10rem;
  flex-shrink: 0;
}

/* Search styling */
.search-container {
  margin-bottom: 2rem;
}

.search-form {
  display: flex;
  margin-bottom: 1.5rem;
}

.search-input {
  flex: 1;
  padding: 0.7rem;
  font-size: 1.1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px 0 0 4px;
  background-color: var(--background-color);
  color: var(--text-color);
}

.search-button {
  padding: 0.7rem 1rem;
  background-color: var(--text-color);
  color: var(--background-color);
  border: 1px solid var(--text-color);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.search-results {
  margin-top: 1.5rem;
}

.search-result {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.search-result-title {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.search-result-snippet {
  margin-top: 0.5rem;
}

.search-result-highlight {
  background-color: rgba(180, 213, 254, 0.3);
  padding: 0.1rem;
}

/* Links page styling */
.link-item {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.link-title {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.link-description {
  margin-top: 0.5rem;
}

.link-screenshot {
  width: 100%;
  height: auto;
  border-radius: 4px;
  margin-top: 1rem;
  border: 1px solid var(--border-color);
  transition: transform 0.2s ease;
}

.link-screenshot:hover {
  transform: scale(1.02);
}

.link-tags {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.link-tag {
  font-size: 0.9rem;
  background-color: var(--code-bg-color);
  color: var(--text-color);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 2rem 0;
}

.pagination-previous,
.pagination-next {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.pagination-info {
  color: var(--secondary-color);
}

/* Mobile styles */
@media screen and (max-width: 1120px) {
  .content-wrapper {
    flex-direction: column;
    margin-left: var(--sidebar-width);
    max-width: calc(100% - var(--sidebar-width));
  }
  
  .main-content {
    width: 100%;
    max-width: 100%;
  }
  
  .footnotes-container {
    width: 100%;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
  }
  
  .sidenote,
  .marginnote {
    float: none;
    display: block;
    margin: 1rem 0;
    width: 100%;
    position: relative;
  }
  
  figure.fullwidth {
    margin-right: 0;
    max-width: 100%;
  }
}

@media screen and (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }
  
  body {
    width: 100%;
  }
  
  .main-container {
    flex-direction: column;
  }
  
  .mobile-menu-button {
    display: flex;
  }
  
  .sidebar {
    transform: translateX(-100%);
    z-index: 900;
    background-color: var(--background-color);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .content-wrapper {
    margin-left: 0;
    max-width: 100%;
  }
  
  .theme-toggle {
    top: 1rem;
    right: 1rem;
    left: auto;
    bottom: auto;
  }
  
  .archive-stats {
    grid-template-columns: 1fr;
  }
  
  .archive-entry {
    flex-direction: column;
  }
  
  .archive-date {
    width: 100%;
    margin-bottom: 0.3rem;
  }
  
  .search-form {
    flex-direction: column;
  }
  
  .search-input {
    border-radius: 4px;
    margin-bottom: 0.5rem;
  }
  
  .search-button {
    border-radius: 4px;
  }
}

/* Footer */
.footer {
  margin-top: 4rem;
  padding: 2rem 0;
  border-top: 1px solid var(--border-color);
  text-align: center;
  font-size: 1.1rem;
  color: var(--secondary-color);
}

/* Mobile footnote support */
@media screen and (max-width: 768px) {
  .sidenote-number {
    cursor: pointer;
    background-color: var(--footnote-bg-color);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
  }
  
  .footnote-popup {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--background-color);
    padding: 1rem;
    border-top: 2px solid var(--border-color);
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    font-size: 1.1rem;
    max-height: 50vh;
    overflow-y: auto;
  }
  
  .footnote-popup.active {
    display: block;
  }
  
  .footnote-popup-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
  }
}