/* Responsive and interactive styles for every page. Loaded after style/style.css. */

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

pre {
  max-width: 100%;
  overflow-x: auto;
}

/* Code blocks with a copy button */
.code-block {
  position: relative;
}

.copy-code {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 4px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
  color: #333;
  font: 12px/1 sans-serif;
  cursor: pointer;
  opacity: 0.8;
}

.copy-code:hover,
.copy-code:focus-visible {
  opacity: 1;
}

/* Heading anchors */
.anchor {
  margin-left: 0.35em;
  color: #999;
  font-size: 0.7em;
  text-decoration: none;
  opacity: 0;
}

h2:hover .anchor,
h3:hover .anchor,
h4:hover .anchor,
.anchor:focus-visible {
  opacity: 1;
}

/* Table of contents on long lessons */
.toc {
  margin: 1em 0;
  padding: 0.5em 1em;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  background: #fafafa;
  font-size: 14px;
}

.toc summary {
  font-weight: bold;
  cursor: pointer;
}

.toc ol {
  margin: 0.3em 0;
  padding-left: 1.4em;
}

/* Site search, top right */
.site-search {
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  font: 14px/1.3 sans-serif;
}

.site-search input {
  width: 220px;
  padding: 5px 8px;
  border: 1px solid #aaa;
  border-radius: 4px;
  background: #fff;
}

.site-search input:focus {
  outline: 2px solid #4a90d9;
}

.site-search-results {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: min(420px, 90vw);
  max-height: 60vh;
  overflow: auto;
  margin: 4px 0 0;
  padding: 4px 0;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  list-style: none;
}

.site-search-results li {
  padding: 6px 10px;
}

.site-search-results a {
  color: #1a57a8;
}

.site-search-results[hidden],
.to-top[hidden] {
  display: none;
}

/* Interactive visualizations (js/viz.js) */
.viz {
  margin: 16px 0;
  padding: 12px;
  border: 1px solid #ccd6e0;
  border-radius: 8px;
  background: #f7f9fc;
}

.viz-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.viz-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 13px;
  color: #445;
}

.viz-input {
  padding: 6px 8px;
  border: 1px solid #aab;
  border-radius: 4px;
  background: #fff;
  font: inherit;
  max-width: 100%;
}

.viz-form input.viz-input {
  width: 18em;
  font-family: Consolas, monospace;
  font-size: 16px;
}

.viz-button {
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid #4a90d9;
  border-radius: 4px;
  background: #fff;
  color: #1d5fa8;
  font: inherit;
  cursor: pointer;
}

.viz-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.viz-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.viz-counter {
  margin-left: auto;
  font-size: 13px;
  color: #556;
}

.viz-stage {
  min-height: 60px;
  overflow-x: auto;
}

.viz-caption {
  min-height: 3em;
  margin: 8px 0 0;
}

.viz-note {
  margin: 6px 0;
  font-size: 13px;
  color: #556;
}

.viz-error {
  color: #b00020;
}

.viz-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.viz-row-label {
  flex: none;
  width: 110px;
  font-size: 13px;
  color: #445;
  text-align: right;
}

.viz-cells {
  display: flex;
  gap: 4px;
}

.viz-cell {
  min-width: 3.4em;
  padding: 4px 6px;
  border: 1px solid #b8c4d2;
  border-radius: 3px;
  background: #fff;
  font-family: Consolas, monospace;
  text-align: center;
}

.viz-cell-active {
  border-color: #e0a800;
  background: #fff3c4;
}

.viz-cell-hit {
  border-color: #d33;
  background: #ffd1d1;
}

.viz-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 180px;
  padding: 18px 0 0;
  border-bottom: 2px solid #889;
}

.viz-bar {
  position: relative;
  flex: 1;
  max-width: 48px;
  border-radius: 3px 3px 0 0;
  background: #9bb8d8;
}

.viz-bar-pair {
  background: #f0a030;
}

.viz-bar-done {
  background: #5cb85c;
}

.viz-bar-value {
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  font-size: 13px;
  text-align: center;
}

.viz-search {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.viz-search-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.viz-search-cell {
  min-width: 2.8em;
  padding: 6px 4px;
  border: 1px solid #b8c4d2;
  border-radius: 3px;
  background: #fff;
  font-family: Consolas, monospace;
  text-align: center;
}

.viz-search-range {
  background: #e8f1fb;
}

.viz-search-mid {
  border-color: #e0a800;
  background: #fff3c4;
}

.viz-search-found {
  border-color: #3a3;
  background: #c8f0c8;
}

.viz-search-pointer {
  min-height: 1em;
  font-size: 12px;
  color: #556;
}

.viz-graph {
  display: block;
  width: 100%;
  max-width: 360px;
  height: auto;
  margin: 0 auto;
}

.viz-graph text {
  fill: #223;
  font-family: Consolas, monospace;
  font-size: 14px;
}

.viz-edge {
  stroke: #98a;
  stroke-width: 2;
}

.viz-edge-hit {
  stroke: #d33;
  stroke-width: 3;
}

.viz-node {
  fill: #fff;
  stroke: #556;
  stroke-width: 2;
}

.viz-node-seen {
  fill: #dde9f7;
}

.viz-node-current {
  fill: #ffd36b;
}

@media (max-width: 600px) {
  .viz-row-label {
    width: 80px;
    font-size: 12px;
  }
}

.viz-formula {
  margin: 6px 0;
  font-family: Consolas, monospace;
  font-size: 15px;
  overflow-x: auto;
}

.viz-formula sup {
  font-size: 11px;
}

.viz-plane {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 8px 0 4px;
}

.viz-plane text {
  fill: #223;
  font-size: 11px;
}

.viz-axis {
  stroke: #889;
  stroke-width: 1;
}

.viz-circle {
  fill: none;
  stroke: #aab;
  stroke-dasharray: 4 3;
}

.viz-vector {
  stroke: #7a9cc6;
  stroke-width: 1.5;
}

.viz-vector-active {
  stroke: #e0a800;
  stroke-width: 2.5;
}

.viz-point {
  fill: #1d5fa8;
}

.viz-point-active {
  fill: #e0a800;
}

.viz-twiddle {
  stroke: #c33;
  stroke-width: 2;
}

.viz-match {
  stroke: #2a9d4b;
  stroke-width: 4;
}

.viz-color-0 {
  fill: #cfe3f7;
}

.viz-color-1 {
  fill: #fbd9b5;
}

/* Segment tree picture (js/viz.js, mountSegtree) */
.viz-seg {
  display: block;
  height: auto;
  margin: 8px 0;
}

.viz-seg-edge {
  stroke: #98a;
  stroke-width: 1.5;
}

.viz-seg-edge-used {
  stroke: #2a9d4b;
  stroke-width: 3;
}

.viz-seg-node {
  fill: #fff;
  stroke: #556;
  stroke-width: 1.5;
}

.viz-seg-done {
  fill: #eef5fc;
}

.viz-seg-pad {
  fill: #eee;
  stroke: #999;
  stroke-dasharray: 4 3;
}

.viz-seg-taken {
  fill: #c8f0c8;
  stroke: #2a9d4b;
  stroke-width: 2.5;
}

.viz-seg-changed {
  fill: #ffd1d1;
  stroke: #c0392b;
  stroke-width: 2.5;
}

.viz-seg-current {
  fill: #ffd36b;
  stroke: #b07400;
  stroke-width: 2.5;
}

.viz-seg-small {
  font-family: Consolas, monospace;
  font-size: 11px;
  fill: #556;
}

.viz-seg-value {
  font-family: Consolas, monospace;
  font-size: 15px;
  font-weight: bold;
  fill: #223;
}

.viz-seg-pointer {
  font-family: Consolas, monospace;
  font-size: 13px;
  font-weight: bold;
  fill: #1d5fa8;
}

/* The picture is 624 px wide. Up to 721 px of viewport it scrolls sideways inside its stage, and this line says so. */
.viz-seg-hint {
  display: none;
  margin: 4px 0 0;
  font-size: 13px;
  color: #556;
}

@media (max-width: 721px) {
  .viz-seg-hint {
    display: block;
  }
}

/* Navigation: the trail, the neighbouring lessons and the algorithms of a page (js/site.js) */
.site-trail {
  margin-top: 32px; /* below the .tags bar, which is absolutely positioned in the top right corner */
  margin-bottom: 8px;
  font-size: 14px;
  color: #556;
}

.site-trail a {
  color: #1d5fa8;
}

.page-algorithms {
  margin: 16px 0;
  padding: 10px 14px;
  border: 1px solid #ccd6e0;
  border-radius: 8px;
  background: #f7f9fc;
}

.page-algorithms summary {
  font-weight: bold;
  cursor: pointer;
}

.page-algorithms ul {
  margin: 8px 0;
  padding-left: 20px;
}

.complexity {
  font-family: Consolas, monospace;
  font-size: 13px;
  color: #556;
}

/* Complexity classes with examples and a log-scale meter (s1/alg.html) */
.complexity-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin: 12px 0 20px;
}

.complexity-table th:nth-child(1),
.complexity-table td:nth-child(1) {
  width: 24%;
}

.complexity-table th:nth-child(2),
.complexity-table td:nth-child(2) {
  width: 30%;
}

.complexity-table th,
.complexity-table td {
  padding: 6px 6px;
  border-bottom: 1px solid #dde3ea;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.complexity-table meter {
  display: block;
  width: 100%;
  max-width: 9em;
  height: 0.9em;
  margin-bottom: 2px;
}

.complexity-table meter::-webkit-meter-bar {
  background: #eef3f8;
  border: 1px solid #aab;
}

.complexity-table meter::-webkit-meter-optimum-value,
.complexity-table meter::-webkit-meter-suboptimum-value,
.complexity-table meter::-webkit-meter-even-less-good-value {
  background: #4a90d9;
}

.complexity-table meter::-moz-meter-bar {
  background: #4a90d9;
}

.site-pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin: 32px 0 16px;
}

.site-pager a {
  max-width: 48%;
}

.catalog li {
  margin-bottom: 10px;
}

/* A long display formula scrolls inside its own block instead of widening the page on a phone */
mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.2em 0;
}

/* Back to top */
.to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #4a90d9;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

@media (max-width: 600px) {
  .site-search input {
    width: 150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
