* {
  box-sizing: border-box;
}

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;

  --bg: #fbf5ee;
  --bg-elevated: #f4e9db;
  --fg: #241f1a;
  --fg-muted: #63605b;
  --fg-soft: #8c8880;
  --border: #dccbb0;
  --accent: #c04a0a;
  --accent-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16140f;
    --bg-elevated: #201d17;
    --fg: #efece5;
    --fg-muted: #b2ada2;
    --fg-soft: #8d887d;
    --border: #423c32;
    --accent: #ff9752;
    --accent-fg: #201200;
  }
}

:root[data-theme="dark"] {
  --bg: #16140f;
  --bg-elevated: #201d17;
  --fg: #efece5;
  --fg-muted: #b2ada2;
  --fg-soft: #8d887d;
  --border: #423c32;
  --accent: #ff9752;
  --accent-fg: #201200;
}

html {
  color: var(--fg);
  background: var(--bg);
  font-family: var(--font-sans);
  line-height: 1.48;
}

body {
  margin: 0;
  background: var(--bg);
}

a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.12em;
}

.site-nav,
.page {
  width: min(100% - 2.5rem, 920px);
  margin: 0 auto;
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding-top: 1.4rem;
  font-family: var(--font-sans);
}

.site-nav a {
  display: inline-block;
  margin-right: 1.1rem;
  color: var(--fg-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--fg-soft);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }

  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}

.page {
  padding: 6.2rem 0 5rem;
}

.home-title,
.page-title {
  margin: 0 0 3.4rem;
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
}

.lorenz-inline {
  display: inline-block;
  width: 56px;
  height: 32px;
  margin-left: 0.5rem;
  vertical-align: middle;
  opacity: 0.9;
}

.content {
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-weight: 400;
}

.content p,
.content ul,
.content ol {
  margin: 0 0 1.55rem;
}

.content li {
  margin-bottom: 0.45rem;
}

.portrait-wrap {
  float: right;
  width: 26vw;
  max-width: 210px;
  margin: 0.2rem 0 1rem 2rem;
}

.portrait {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: 50% 20%;
  border-radius: 6px;
}

.social-row {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.entry {
  margin-bottom: 2.1rem;
}

.entry h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-serif);
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1.3;
}

.lock-icon {
  width: 21px;
  height: 21px;
  margin-left: 0.3rem;
  vertical-align: -0.2em;
  color: var(--fg-muted);
}

.entry p {
  margin-bottom: 0.8rem;
}

.entry .links {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 0.8rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.9rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.back-to-top {
  position: fixed;
  right: 1.4rem;
  bottom: 1.4rem;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg-muted);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease, border-color 0.15s ease;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.back-to-top svg {
  width: 18px;
  height: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.42rem 0.95rem;
  margin: 0 0.6rem 0.6rem 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  list-style: none;
}

.btn::-webkit-details-marker {
  display: none;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tldr[open] .btn {
  border-color: var(--accent);
  color: var(--accent);
}

.tldr-panel {
  flex-basis: 100%;
  margin: 0.3rem 0 0.6rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-elevated);
  font-family: var(--font-serif);
  font-size: 1.05rem;
}

.meta {
  font-family: var(--font-sans);
  color: var(--fg-muted);
  font-size: 0.98rem;
}

.math {
  overflow-x: auto;
}

.table-wrap {
  overflow-x: auto;
  margin: 0 0 1.9rem;
  -webkit-overflow-scrolling: touch;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.93rem;
}

.content table caption {
  caption-side: top;
  padding: 0 0 0.65rem;
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: left;
}

.content table caption strong {
  color: var(--fg);
}

.content thead th {
  padding: 0.5rem 0.7rem;
  border-top: 2px solid var(--fg);
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  font-size: 0.79rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.content tbody td {
  padding: 0.46rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.content tbody tr:last-child td {
  border-bottom: 2px solid var(--fg);
}

.content th.num,
.content td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.content thead th.group {
  border-bottom: 1px solid var(--fg-soft);
  text-align: center;
}

.content thead th.sub {
  border-top: none;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.content thead th[rowspan] {
  vertical-align: bottom;
}

.content table sup {
  font-size: 0.7em;
  line-height: 0;
  vertical-align: super;
}

.oneline {
  margin: 0 0 1.4rem;
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--fg);
  font-size: 1.14rem;
  line-height: 1.45;
}

.oneline strong {
  font-weight: 700;
}

details.proof {
  margin: 0 0 1.7rem;
  padding: 0.85rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
}

details.proof > summary {
  cursor: pointer;
  list-style: none;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

details.proof > summary::-webkit-details-marker {
  display: none;
}

details.proof > summary::before {
  content: "▸\00a0";
}

details.proof[open] > summary::before {
  content: "▾\00a0";
}

details.proof[open] > summary {
  margin-bottom: 0.9rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

details.proof > *:last-child {
  margin-bottom: 0;
}

details.proof .math {
  font-size: 0.97rem;
}

.content td.win {
  color: var(--accent);
  font-weight: 700;
}

.content tbody tr:hover {
  background: var(--bg-elevated);
}

.unlock-box {
  margin: 0 0 1.75rem;
  padding: 1.3rem 1.5rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-elevated);
  font-size: 1.05rem;
}

.unlock-box p {
  margin: 0 0 1rem;
}

#unlock-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 0.6rem;
}

.unlock-input {
  flex: 1 1 220px;
  min-width: 0;
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 1rem;
}

.unlock-input:focus {
  outline: none;
  border-color: var(--accent);
}

#unlock-form .btn {
  margin: 0;
  border-color: var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
}

#unlock-form .btn:hover {
  background: var(--accent);
  color: var(--accent-fg);
}

.unlock-error {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
}

.eyebrow {
  margin: 0 0 0.9rem;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title.tight {
  margin-bottom: 1.3rem;
}

.byline {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0 0 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
}

.byline-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.byline-info {
  flex: 1 1 auto;
  min-width: 0;
}

.byline-name {
  margin: 0;
  color: var(--fg);
  font-size: 0.98rem;
  font-weight: 700;
}

.byline-name .authors {
  color: var(--fg);
}

.byline-sub {
  margin: 0.15rem 0 0;
  color: var(--fg-muted);
  font-size: 0.92rem;
}

.content .lead {
  font-size: 1.32rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--fg);
}

.content h2 {
  margin: 2.8rem 0 1rem;
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.25;
}

.content h3 {
  margin: 2rem 0 0.8rem;
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.3;
}

.content hr {
  margin: 2.8rem 0;
  border: none;
  border-top: 1px solid var(--border);
}

.callout {
  margin: 0 0 1.75rem;
  padding: 1.3rem 1.5rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-elevated);
  font-size: 1.05rem;
}

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

.callout-label {
  margin: 0 0 0.55rem;
  color: var(--fg-soft);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.content .note {
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: 0.98rem;
}

.share-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-family: var(--font-sans);
}

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg-muted);
  text-decoration: none;
}

.share-btn svg {
  width: 15px;
  height: 15px;
}

.share-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 720px) {
  .site-nav,
  .page {
    width: min(100% - 2rem, 920px);
  }

  .site-nav {
    padding-top: 1rem;
  }

  .site-nav a {
    margin-right: 0.75rem;
    margin-bottom: 0.35rem;
    font-size: 0.92rem;
  }

  .page {
    padding-top: 4.25rem;
    padding-bottom: 3rem;
  }

  .home-title,
  .page-title {
    margin-bottom: 1.8rem;
    font-size: 1.95rem;
  }

  .lorenz-inline {
    width: 44px;
    height: 26px;
  }

  .content {
    font-size: 1.06rem;
    line-height: 1.5;
  }

  .portrait-wrap {
    float: none;
    width: 42vw;
    max-width: 180px;
    margin: 0 0 1.5rem;
  }

  .byline {
    flex-wrap: wrap;
  }

  .share-row {
    margin-top: 0.6rem;
  }

  .callout,
  .unlock-box {
    padding: 1.05rem 1.1rem;
  }

  .tldr-panel {
    padding: 0.85rem 1rem;
  }

  #unlock-form {
    flex-direction: column;
    align-items: stretch;
  }

  #unlock-form .btn {
    justify-content: center;
  }

  .byline-avatar {
    width: 36px;
    height: 36px;
  }
}
