/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red: #e7040f;
  --blue: #005eec;
  --green: #00a96c;
  --gold: #ffb700;
  --bg: #eee;
  --card: #fff;
  --border: #888;
  --shadow: #ccc;
  --text: #111;
  --meta: #555;
  --heading-border: #000;
  --link-underline: #aaa;
  --mono: "SF Mono", "Menlo", "Consolas", monospace;
  --sans: "Helvetica Neue", "Arial", "Nimbus Sans", sans-serif;
}

[data-theme="dark"] {
  --red: #ff6b6b;
  --blue: #6eb5ff;
  --green: #5edba6;
  --gold: #ffd056;
  --bg: #1a1a1a;
  --card: #242424;
  --border: #555;
  --shadow: #111;
  --text: #ddd;
  --meta: #999;
  --heading-border: #666;
  --link-underline: #888;
}

html { font-size: 16px; }
html.theme-transition {
  transition: background-color .33s ease !important;
}
html.theme-transition .content-card,
html.theme-transition .essay-item,
html.theme-transition .essay-meta,
html.theme-transition .site-header__bar {
  transition: background-color .33s ease, border-color .33s ease, box-shadow .33s ease !important;
}

body {
  font-family: var(--sans);
  line-height: 1.6rem;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* === LAYOUT === */
.site-wrapper {
  max-width: 1007px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.content-card {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 2px 2px var(--shadow);
  padding: 2rem 2.5rem;
  position: relative;
}

/* === HEADER === */
.site-header {
  margin-bottom: 2rem;
}

.site-header__bar {
  height: 6px;
  background: repeating-linear-gradient(
    90deg,
    var(--red) 0, var(--red) 25%,
    var(--blue) 25%, var(--blue) 50%,
    var(--green) 50%, var(--green) 75%,
    var(--gold) 75%, var(--gold) 100%
  );
  margin-bottom: 0.75rem;
}

.site-header__inner {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 2px solid var(--heading-border);
  padding-bottom: 0.5rem;
}

.site-header__title {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}

.site-header__right {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.site-header__subtitle {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--meta);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Theme toggle */
.site-nav {
  display: flex;
  gap: 1rem;
  align-items: baseline;
}

.site-nav__link {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--meta);
  text-decoration: none;
}

.site-nav__link:hover { color: var(--red); }

.theme-toggle {
  background: none;
  border: 1px dotted var(--border);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.15em 0.4em;
  color: var(--meta);
}

.theme-toggle:hover { border-style: solid; }

.theme-toggle__dark  { display: none; }
[data-theme="dark"] .theme-toggle__light { display: none; }
[data-theme="dark"] .theme-toggle__dark  { display: inline; }

/* === FOOTER === */
.site-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--meta);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
}

/* === HATCHED PATTERN === */
.hatched {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(0,0,0,0.06) 3px,
    rgba(0,0,0,0.06) 6px
  );
}

/* === HOME GRID (two-column layout) === */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 1.5rem;
  align-items: start;
}

.sidebar-card {
  border: 1px solid var(--border);
  box-shadow: 2px 2px var(--shadow);
  background: var(--card);
  padding: 1rem 1.25rem;
  position: sticky;
  top: 1rem;
}

.sidebar-card__title {
  font-family: var(--mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  border-bottom: 1px solid var(--heading-border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
}

.sidebar-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-stats dt { color: var(--meta); }
.sidebar-stats dd { color: var(--text); font-weight: 600; }

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 0.15em;
}

.status-dot--on  {
  background: var(--green);
  animation: pulse-green 2s ease-in-out infinite;
}

@keyframes pulse-green {
  0%, 100% { background-color: #00a96c; }
  50% { background-color: #00d486; }
}

[data-theme="dark"] .status-dot--on {
  animation-name: pulse-green-dark;
}

@keyframes pulse-green-dark {
  0%, 100% { background-color: #5edba6; }
  50% { background-color: #8dffc8; }
}

.status-dot--off { background: var(--red); }

.age-unit {
  text-transform: lowercase;
}

@media (max-width: 800px) {
  .home-grid {
    grid-template-columns: 1fr;
  }

  .home-grid__sidebar {
    order: -1;
  }

  .sidebar-card {
    position: static;
  }
}

/* === PAGE INTRO === */
.page-intro {
  margin-bottom: 1.5rem;
  color: var(--meta);
  font-size: 0.95rem;
  line-height: 1.5;
}

.page-intro p { margin-bottom: 0.75rem; }

.page-intro a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.page-intro a:hover { text-decoration-color: var(--red); }

/* Currently reading (homepage) */
.currently-reading {
  margin-bottom: 1.5rem;
  color: var(--meta);
  font-size: 0.95rem;
  line-height: 1.5;
}

.currently-reading a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.currently-reading a:hover { text-decoration-color: var(--red); }

.currently-reading em,
.currently-reading__author {
  color: var(--text);
}

/* === SKU TAG / METADATA LABEL === */
.sku-tag {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border: 1px dotted var(--border);
  padding: 0.1em 0.4em 0em;
  display: inline-block;
}

.sku-tag--draft     { border-color: var(--gold); color: var(--gold); }
.sku-tag--finished  { border-color: var(--green); color: var(--green); }
.sku-tag--red       { border-color: var(--red); color: var(--red); }
.sku-tag--blue      { border-color: var(--blue); color: var(--blue); }

/* === ESSAY LIST (homepage) === */
.essay-list { list-style: none; }

.essay-item {
  border: 1px solid var(--border);
  box-shadow: 2px 2px var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--card);
}

.essay-item__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.essay-item__title {
  font-size: 1.25rem;
  font-weight: 700;
}

.essay-item__title a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.essay-item__title a:hover { border-bottom-color: var(--red); }

.essay-item__date {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--meta);
  letter-spacing: 0.05em;
}

.essay-item__abstract {
  font-size: 0.95rem;
  color: var(--meta);
  margin-top: 0.25rem;
}

.essay-item__footer {
  margin-top: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.essay-item__tags {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* === SINGLE ESSAY === */
.essay-body { min-width: 0; }

/* Metadata block */
.essay-meta {
  border: 1px solid var(--heading-border);
  box-shadow: 2px 2px var(--shadow);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  gap: 1.5rem;
}

.essay-meta__col {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  flex: 1;
  align-content: start;
  align-items: center;
}

.essay-meta dt { color: var(--meta); }
.essay-meta dd { color: var(--text); font-weight: 600; }

@media (max-width: 800px) {
  .essay-meta {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* Dropcap */
.essay-content > p:first-of-type::first-letter {
  float: left;
  font-size: 3rem;
  line-height: 2.6rem;
  font-weight: 700;
  margin-right: 0.1em;
  margin-top: 0.05em;
  color: var(--red);
}

/* Headings */
.essay-content h2 {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-variant: small-caps;
  border-bottom: 1px solid var(--heading-border);
  padding-bottom: 0.25rem;
  margin: 2rem 0 1rem;
}

.essay-content h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
}

.essay-content p {
  margin-bottom: 1rem;
}

.essay-content { counter-reset: blockquote; }
.essay-content blockquote { counter-increment: blockquote; }

.essay-content blockquote:nth-of-type(4n+1) { border-left-color: var(--red); }
.essay-content blockquote:nth-of-type(4n+2) { border-left-color: var(--blue); }
.essay-content blockquote:nth-of-type(4n+3) { border-left-color: var(--green); }
.essay-content blockquote:nth-of-type(4n)   { border-left-color: var(--gold); }

.essay-content blockquote {
  border-left: 3px solid;
  padding: 0.5rem 1rem;
  margin: 1.25rem 0;
  background: rgba(0,0,0,0.02);
  font-style: italic;
  color: var(--meta);
}

.essay-content ul, .essay-content ol {
  margin: 0.75rem 0 1rem 1.5rem;
}

.essay-content a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  text-underline-offset: 2px;
}

.essay-content a:hover { text-decoration-color: var(--red); }

.essay-content hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 2rem 0;
}

/* === TABLE OF CONTENTS (sidebar) === */
.toc {
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@media (min-width: 801px) {
  .essay-body {
    display: grid;
    grid-template-columns: 1fr 250px;
    gap: 1.5rem;
  }

  .essay-body > h1,
  .essay-body > .essay-meta {
    grid-column: 1 / -1;
  }

  .toc {
    grid-column: 2;
    grid-row: 3;
    align-self: start;
  }

  .essay-content {
    grid-column: 1;
    grid-row: 3;
  }
}

.toc__title {
  font-weight: 700;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--heading-border);
  padding-bottom: 0.25rem;
}

.toc > nav > ul {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--heading-border);
}

.toc nav ul {
  list-style: none;
  padding-left: 0;
  counter-reset: toc;
}

.toc nav ul ul {
  padding-left: 0.75rem;
}

.toc nav li {
  counter-increment: toc;
}

.toc nav li a {
  display: flex;
}

.toc nav li a::before {
  content: counters(toc, ".");
  font-size: 0.65rem;
  color: var(--border);
  margin-right: 0.35em;
  flex-shrink: 0;
}

.toc nav a {
  color: var(--meta);
  text-decoration: none;
  display: block;
  padding: 0.15em 0;
  border-bottom: none;
}

.toc nav a:hover { color: var(--red); }

/* === FOOTNOTES (bottom of page, default) === */
.footnotes {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  color: var(--meta);
}

.footnotes ol {
  padding-left: 1.25rem;
}

.footnotes li {
  margin-bottom: 0.5rem;
}

.footnotes li p { margin: 0; }

.essay-content a.footnote-ref { text-decoration: none; border-bottom: none; color: var(--meta); }
.essay-content a.footnote-ref:hover { color: var(--fn-color, var(--red)); }
.footnote-backref { text-decoration: none; border-bottom: none; color: var(--meta); margin-left: 0.25em; }
.footnote-backref:hover { color: var(--red); }

/* === SIDENOTES (JS-promoted footnotes on wide screens) === */
.essay-content { position: relative; }

.sidenote {
  position: absolute;
  right: -265px;
  width: 250px;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--meta);
  border-left: 2px solid var(--gold);
  padding-left: 0.5rem;
  z-index: 2;
}

.sidenote__label {
  font-weight: 700;
  color: var(--gold);
  margin-right: 0.2em;
}

/* Prevent TOC from blocking sidenote clicks */
.toc { z-index: 1; }

/* === READING PAGE === */
.reading-stats {
  display: flex;
  gap: 1px;
  margin-bottom: 2rem;
  border: 1px solid var(--heading-border);
  box-shadow: 2px 2px var(--shadow);
  overflow: hidden;
}

.reading-stat {
  flex: 1;
  text-align: center;
  padding: 0.75rem 0.5rem;
  background: var(--card);
}

.reading-stat + .reading-stat { border-left: 1px solid var(--heading-border); }

.reading-stat__num {
  display: block;
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.reading-stat__label {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--meta);
}

.reading-section-title {
  font-family: var(--mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 1px solid var(--heading-border);
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
}

/* Currently reading */
.reading-current { margin-bottom: 1.5rem; }

.reading-current__item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
}

.reading-current__title {
  font-weight: 700;
}

.reading-current__author {
  color: var(--meta);
}

.reading-current__progress {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--meta);
}

.reading-current__since {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--border);
}

/* Quote + book pairs */
.reading-pair {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed var(--border);
}

.reading-pair:last-child { border-bottom: none; padding-bottom: 0; }

.reading-pair__header {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.reading-pair__title {
  font-weight: 700;
  font-size: 0.95rem;
}

.reading-pair__author {
  font-size: 0.85rem;
  color: var(--meta);
}

.reading-pair__tags {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.reading-pair__rating {
  font-family: var(--sans);
  font-size: 0.9rem;
  line-height: 0;
  vertical-align: middle;
  position: relative;
  top: -0.15em;
  color: var(--text);
}

.reading-pair__rating--small {
  font-size: 0.85rem;
  top: 0;
}

.reading-pair__quote {
  border-left: 3px solid;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.02);
  font-style: italic;
  color: var(--meta);
  font-size: 0.9rem;
  line-height: 1.5;
}

.reading-pair:nth-of-type(4n+1) .reading-pair__quote { border-left-color: var(--red); }
.reading-pair:nth-of-type(4n+2) .reading-pair__quote { border-left-color: var(--blue); }
.reading-pair:nth-of-type(4n+3) .reading-pair__quote { border-left-color: var(--green); }
.reading-pair:nth-of-type(4n)   .reading-pair__quote { border-left-color: var(--gold); }

.reading-pair__quote p { margin-bottom: 0.5rem; }

.reading-pair__quote cite {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--border);
}

@media (max-width: 800px) {
  .reading-stats { flex-wrap: wrap; }
  .reading-stat { min-width: 30%; }
}

/* === RESPONSIVE === */
@media (max-width: 800px) {
  .essay-layout {
    grid-template-columns: 1fr;
  }

  .toc {
    position: static;
    float: none;
    width: 100%;
    margin-right: 0;
    border: 1px dashed var(--border);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
  }

  .content-card {
    padding: 1.25rem 1rem;
  }
}
