:root {
  --body-width: 1152px;
  --text-width: 896px;
  color-scheme: light;
  --bg-body: white;
  --bg-block: #f9f9f9;
  --border-color: #ddd;
  --box-shadow: 5px 5px 5px #eee;
  --color-fg: #1a1a1a;
  /* Light Theme DNA */
  --dna-primary: #94a3b8;
  --dna-secondary: #b45309;
  --base-pair: #cbd5e1;
  /* Where the header bottom rule starts (clears abs-positioned logo) */
  --nav-logo-rule-inset: clamp(4rem, 11vw, 9rem);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg-body: white;
  --bg-block: #f9f9f9;
  --border-color: #ddd;
  --box-shadow: 5px 5px 5px #eee;
  --color-fg: #1a1a1a;
  /* Light Theme DNA */
  --dna-primary: #94a3b8;
  --dna-secondary: #b45309;
  --base-pair: #cbd5e1;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-body: #242320;
  --bg-block: #2f2c28;
  --border-color: #5f5a55;
  --box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  --color-fg: #eceae7;
  /* Dark Theme DNA */
  --dna-primary: #5dccb0;
  --dna-secondary: #d8a878;
  --base-pair: #545b56;
}
* {
  box-sizing: border-box;
}
body {
  max-width: var(--body-width);
  min-height: calc(100vh - 3em);
  background-color: var(--bg-body);
  color: var(--color-fg);
  margin: auto;
  padding: 1em;
  line-height: 1.5;
  position: relative;
  display: flex;
  flex-direction: column;
  counter-reset: pageNumber;
  text-align: justify;
}

/* header and footer areas */
.nav-top, .single .meta-line, .nav-bottom, .post-nav {
  display: flex;
  justify-content: space-between;
}
.home + footer > .nav-bottom {
  display: block;
}
.nav-top {
  margin-bottom: 1em;
  border-bottom: 1px solid;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  text-align: left;
}
.nav-end {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 0.5rem 1rem;
  margin-left: auto;
}
.logo {
  font-weight: bold;
  margin-top: .1rem;
  img {
    display: none;
    max-height: 10rem;
    position: absolute;
    top: 0.5em;
  }
}
.menu {
  text-transform: uppercase;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  span {
    display: inline-block;
    margin: .5rem 0 0 .5em;
  }
  .active {
    border-bottom: 5px solid;
    margin-bottom: -5px;
  }
  .optional {
    display: none;
  }
}
/* Theme: compact icon button (narrow padding vs text links — see custom.css nav-top) */
.menu .theme-appearance-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin: 0.5rem 0 0 0.5em;
  vertical-align: baseline;
}
.theme-appearance-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: inherit;
  line-height: 1;
  color: var(--color-fg);
  background: transparent;
  cursor: pointer;
  box-sizing: border-box;
  transition:
    background-color 0.22s ease,
    border-color 0.22s ease;
}
.theme-appearance-btn:hover {
  background: transparent;
  border-color: transparent;
}
/* Mouse/touch: no ring (focus suppressed via mousedown on pointer). Keyboard: visible ring only. */
.theme-appearance-btn:focus {
  outline: none;
}
.theme-appearance-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--color-fg) 38%, var(--border-color));
  outline-offset: 3px;
}
.theme-appearance-svg {
  display: block;
  flex-shrink: 0;
}
/* Horizontal helix: two base-pair layers (different x / geometry); crossfade with data-theme */
.theme-helix-rungs {
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}
.theme-helix-rungs--light {
  opacity: 1;
}
.theme-helix-rungs--dark {
  opacity: 0;
}
html[data-theme="dark"] .theme-helix-rungs--light {
  opacity: 0;
}
html[data-theme="dark"] .theme-helix-rungs--dark {
  opacity: 1;
}
.theme-helix-rung {
  stroke-width: 1.55;
  stroke-linecap: round;
}
.theme-helix-rungs--light .theme-helix-rung:nth-child(1) {
  stroke: color-mix(in srgb, currentColor 68%, var(--border-color));
}
.theme-helix-rungs--light .theme-helix-rung:nth-child(2) {
  stroke: color-mix(in srgb, currentColor 55%, var(--border-color));
}
.theme-helix-rungs--light .theme-helix-rung:nth-child(3) {
  stroke: color-mix(in srgb, currentColor 62%, var(--border-color));
}
.theme-helix-rungs--light .theme-helix-rung:nth-child(4) {
  stroke: color-mix(in srgb, currentColor 50%, var(--border-color));
}
.theme-helix-rungs--dark .theme-helix-rung:nth-child(1) {
  stroke: color-mix(in srgb, currentColor 58%, var(--border-color));
}
.theme-helix-rungs--dark .theme-helix-rung:nth-child(2) {
  stroke: color-mix(in srgb, currentColor 68%, var(--border-color));
}
.theme-helix-rungs--dark .theme-helix-rung:nth-child(3) {
  stroke: color-mix(in srgb, currentColor 52%, var(--border-color));
}
.theme-helix-rungs--dark .theme-helix-rung:nth-child(4) {
  stroke: color-mix(in srgb, currentColor 62%, var(--border-color));
}
@media (prefers-reduced-motion: reduce) {
  .theme-helix-rungs {
    transition-duration: 0.01ms;
  }
}
@media (min-width: 768px) {
  .menu .theme-appearance-wrap {
    margin-left: 1em;
  }
}
footer {
  text-align: center;
  margin-top: 2rem;
}
.menu-bottom a + a::before {
  content: " · ";
}

pre,
pre code {
  text-align: left;
}
/* code */
pre code {
  display: block;
  padding: 1em;
  overflow-x: auto;
  &:not([class]) {
    background: none;
  }
}
pre code {
  border: 1px solid var(--border-color);
}
img[src$="#border"] {
  border: 1px solid var(--border-color);
  box-shadow: var(--box-shadow);
}
code {
  hyphens: none;
}
pre code, pre code:hover {
  white-space: pre-wrap;
  word-break: break-all;
}

/* misc elements */
.main, .home {
  hyphens: auto;
  flex-grow: 1;
}
a {
  text-decoration: none;
  border-bottom: 1px dashed;
  color: initial;
}
@media (hover: hover) and (pointer: fine) {
  :not(.logo) > a:hover {
    position: relative;
    inset: 1px 0 0 1px;
  }
}
nav a, footer a, .archive a, sup a {
  border-bottom: none;
}
.anchor {
  &:not(:hover > *) { display: none; }
  & > a::before { content: "#"; }
}
.single .main {
  h2 {
    border-bottom: 1px solid var(--border-color);
  }
  h3 {
    font-variant: small-caps;
    text-align: center;
  }
}
li {
  margin: 4px 0;
}
hr {
  border-style: dashed;
  color: var(--border-color);
}
img, iframe, video {
  max-width: 100%;
}
#TableOfContents {
  text-align: left;
  background-color: var(--bg-block);
  padding: .5em;
  & > ul {
    margin: 0 auto;
    & > li > ul li {
      margin-right: 2em;
    }
  }
}
blockquote, .toc-list, .toc-list ul {
  border-left: 2px solid var(--border-color);
  padding-left: 1em;
}
.single blockquote {
  background: var(--bg-block);
  border-left-width: 5px;
  padding: 3px 1em 3px;
}
.post-nav {
  margin-top: 1rem;
  span {
    width: calc(50% - 1em);
    & + span {
      text-align: right;
    }
  }
}
table {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 1em 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  thead th {
    border-bottom: 1px solid var(--border-color);
  }
  th, td {
    padding: 5px;
  }
  thead, tfoot, tr:nth-child(even), code {
    background: var(--bg-block);
  }
}

/* metadata */
.toc-line {
  display: flex;
  align-items: flex-end;
}
.dots {
  border-bottom: 2px dotted var(--border-color);
  margin: 0 .5em .5em;
  min-width: 10rem;
  flex-grow: 1;
}
.page-num {
  counter-increment: pageNumber;
  &::before {
    content: counter(pageNumber);
  }
}
.toc-list, .toc-list ul {
  list-style: none;
  margin-left: 1em;
}
.toc-line, .subtitle, .meta-line {
  font-weight: normal;
}
.author + .date::before {
  content: " / ";
}
h1.title, .toc-line > a {
  font-style: italic;
}
h1.title {
  margin-top: 1em;
}
h1.title::before {
  content: "";
  font-style: normal;
  font-weight: normal;
  font-size: 6em;
  color: var(--border-color);
  opacity: .5;
  position: absolute;
  inset: -.15em 0;
  z-index: -1;
}
.small, .term, .footnotes, li li {
  font-size: .9em;
}
.footnotes > hr {
  max-width: 20em;
  margin-left: 0;
}
.terms, #TableOfContents > ul > li > ul {
  display: flex;
  flex-wrap: wrap;
}
.terms li, .term {
  margin-left: 2em;
}
.term-cat + .term-tag::before {
  content: " · ";
}

@media (min-width: 768px) {
  body {
    padding: 3.5em 2em;
  }
  .main {
    margin: auto;
    width: var(--text-width);
  }
  /* pre & table stay in the main text column; use .fullwidth to break out to near viewport width */
  .fullwidth {
    width: calc(min(100vw, var(--body-width)) - 4rem);
    margin-left: calc(50% + 2rem - min(100vw, var(--body-width)) / 2);
  }
  .crop-h, .crop-v, .crop-c {
    position: absolute;
    z-index: -1;
  }
  .crop-h {
    inset: 2em 0;
    border-top: 1px solid;
    border-bottom: 1px solid;
  }
  .crop-v {
    inset: 0 2em;
    border-left: 1px solid;
    border-right: 1px solid;
  }
  .crop-c {
    inset: 1em;
    border: 1.5em solid var(--bg-body);
  }
  .menu {
    margin-left: 2em;
  }
  .menu span {
    margin-left: 1em;
  }
  h1.title::before {
    font-size: 6em;
    inset: 0;
  }
  .nav-top {
    border-bottom: none;
    background-image: linear-gradient(
      to right,
      transparent 0 var(--nav-logo-rule-inset),
      var(--border-color) var(--nav-logo-rule-inset) 100%
    );
    background-size: 100% 1px;
    background-position: left bottom;
    background-repeat: no-repeat;
  }
  .logo img, .menu .optional {
    display: inline-block;
  }
  .twocolumn {
    columns: 2;
  }
}

@media only screen and (min-width: 992px) {
  body {
    min-height: calc(100vh - 5em);
    margin: 2em auto;
  }
  .home {
    padding: 0 1.5em;
  }
  h1.title {
    margin-top: 2em;
    &::before {
      font-size: 9em;
      inset: -.1em 0;
    }
  }
  pre code {
    white-space: pre;
  }
}

/* --- DNA Flip Mechanism --- */
.dna-container {
    width: 70px;
    height: 20px;
    position: relative;
    cursor: pointer;
    perspective: 1000px;
}

.dna-helix {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    /* Slight Y tilt keeps segments near rotateX(90deg/270deg) from lying exactly
       edge-on to the viewport (otherwise the third pair from each end vanishes). */
    transform: rotateY(8deg);
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

html[data-theme="dark"] .dna-helix {
    transform: rotateY(8deg) rotateX(180deg);
}

.segment {
    position: absolute;
    top: 50%;
    width: 2px;
    height: 16px;
    background: var(--base-pair);
    left: var(--pos);
    transform: translateY(-50%) rotateX(var(--rot));
    transform-style: preserve-3d;
    opacity: 0.8;
}

.segment::before, .segment::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    left: -1px;
    transition: background 0.6s ease, box-shadow 0.6s ease;
}

.segment::before {
    top: -2px;
    background: var(--dna-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.segment::after {
    bottom: -2px;
    background: var(--dna-secondary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

html[data-theme="dark"] .segment::before,
html[data-theme="dark"] .segment::after {
    box-shadow: 0 0 4px var(--dna-primary);
}

