/* Bàn tương tác (xem docs/javascripts/btt/btt.js). */

/* Khối "!!! btt": một kiểu admonition riêng, viền tím, biểu tượng hai thanh trượt. */
:root {
  --btt-color: #7c4dff;
  --btt-color-soft: rgba(124, 77, 255, 0.1);
  --md-admonition-icon--btt: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8 13c-1.86 0-3.41 1.28-3.86 3H2v2h2.14c.45 1.72 2 3 3.86 3s3.41-1.28 3.86-3H22v-2H11.86c-.45-1.72-2-3-3.86-3m0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2M19.86 6c-.45-1.72-2-3-3.86-3s-3.41 1.28-3.86 3H2v2h10.14c.45 1.72 2 3 3.86 3s3.41-1.28 3.86-3H22V6h-2.14M16 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2"/></svg>');
}

/* Cỡ chữ theo các khối ghi chú khác (xem extra.css). */
.md-typeset .admonition.btt,
.md-typeset details.btt {
  border-color: var(--btt-color);
}

.md-typeset .btt > .admonition-title,
.md-typeset .btt > summary {
  background-color: var(--btt-color-soft);
}

.md-typeset .btt > .admonition-title::before,
.md-typeset .btt > summary::before {
  background-color: var(--btt-color);
  -webkit-mask-image: var(--md-admonition-icon--btt);
  mask-image: var(--md-admonition-icon--btt);
}

/* Bàn và các điều khiển. */
.md-typeset .btt-app {
  margin: 1em 0 0.8em;
}

.md-typeset .btt-body {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.md-typeset .btt-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.4rem;
}

.md-typeset .btt-split {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 0.9rem;
  align-items: start;
}

.md-typeset .btt-cell {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
}

/* Hai bảng vẽ ngang hàng nhau (chẳng hạn thang thường và thang logarit): chia đều hai cột */
.md-typeset .btt-split.btt-deu {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

@media screen and (max-width: 44.9375em) {
  .md-typeset .btt-split,
  .md-typeset .btt-split.btt-deu {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Nhãn dài thì thanh và con số tự xuống dòng dưới nhãn, thay vì bị đẩy ra ngoài khung. */
.md-typeset .btt-slider {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.6rem;
  min-width: 0;
}

.md-typeset .btt-row > .btt-slider {
  flex: 1 1 15rem;
}

.md-typeset .btt-lab {
  white-space: nowrap;
}

.md-typeset .btt-slider .btt-lab {
  white-space: normal;
}

/* Màn hình hẹp: nhãn thanh trượt luôn nằm riêng một dòng, thanh và con số ở dòng dưới. */
@media screen and (max-width: 44.9375em) {
  .md-typeset .btt-slider .btt-lab {
    flex: 1 0 100%;
  }
}

.md-typeset .btt-slider input[type="range"] {
  flex: 1 1 8rem;
  min-width: 5rem;
  height: 1.6rem;
  margin: 0;
  accent-color: var(--btt-color);
  cursor: pointer;
}

.md-typeset .btt-val {
  min-width: 3.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.md-typeset .btt-btn {
  font: inherit;
  line-height: 1.4;
  color: var(--md-typeset-color);
  background: transparent;
  border: 1px solid var(--md-default-fg-color--lighter);
  border-radius: 0.2rem;
  padding: 0.25em 0.75em;
  cursor: pointer;
}

.md-typeset .btt-btn:hover {
  border-color: var(--btt-color);
}

.md-typeset .btt-btn:disabled {
  opacity: 0.4;
  cursor: default;
  border-color: var(--md-default-fg-color--lighter);
}

.md-typeset .btt-btn[aria-pressed="true"] {
  background: var(--btt-color);
  border-color: var(--btt-color);
  color: #ffffff;
}

.md-typeset .btt-btn.btt-primary {
  border: 2px solid var(--btt-color);
  font-weight: 700;
}

.md-typeset .btt-app button:focus-visible,
.md-typeset .btt-app input:focus-visible {
  outline: 2px solid var(--btt-color);
  outline-offset: 2px;
}

.md-typeset .btt-choice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.md-typeset .btt-choice .btt-lab {
  margin-right: 0.3rem;
}

.md-typeset .btt-toggle,
.md-typeset .btt-number {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.md-typeset .btt-toggle input {
  accent-color: var(--btt-color);
}

.md-typeset .btt-number input {
  font: inherit;
  width: 6.5em;
  padding: 0.15em 0.4em;
  color: var(--md-typeset-color);
  background: transparent;
  border: 1px solid var(--md-default-fg-color--lighter);
  border-radius: 0.2rem;
}

.md-typeset .btt-out {
  min-height: 1.5em;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Ô kết quả chưa có gì thì không chiếm chỗ. */
.md-typeset .btt-out:empty {
  display: none;
}

.md-typeset .btt-tex-cho {
  font-family: var(--md-code-font-family);
  opacity: 0.6;
}

/* Bảng vẽ: luôn nền trắng, như các hình SVG của sách ở chế độ tối. */
.md-typeset .btt-board {
  position: relative;
  width: 100%;
  margin: 0 auto;
  background: #ffffff;
  color: #0b0b0b;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 0.3rem;
  overflow: hidden;
}

.md-typeset .btt-board svg {
  display: block;
  width: 100%;
  height: auto;
  -webkit-user-select: none;
  user-select: none;
}

.md-typeset .btt-board svg.btt-clickable {
  cursor: pointer;
}

.md-typeset .btt-over {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.md-typeset .btt-lbl {
  position: absolute;
  white-space: nowrap;
  line-height: 1.25;
  font-size: 0.8rem;
  color: #0b0b0b;
}

@media screen and (max-width: 44.9375em) {
  .md-typeset .btt-lbl {
    font-size: 0.75rem;
  }
}

.md-typeset .btt-lbl-bg {
  background: rgba(255, 255, 255, 0.82);
  border-radius: 0.15rem;
  padding: 0 0.15rem;
}

.md-typeset .btt-handle {
  cursor: grab;
  touch-action: none;
  outline: none;
}

.md-typeset .btt-handle.btt-dragging {
  cursor: grabbing;
}

.md-typeset .btt-handle:focus-visible .btt-handle-dot {
  stroke: var(--btt-color);
  stroke-width: 3;
}

/* Bảng số trong bàn. */
.md-typeset .btt-table-wrap {
  overflow-x: auto;
}

.md-typeset table.btt-table {
  border-collapse: collapse;
  font-size: 1em;
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.md-typeset table.btt-table th,
.md-typeset table.btt-table td {
  padding: 0.25em 0.6em;
  border: 1px solid var(--md-default-fg-color--lightest);
  text-align: center;
}

/* Màn hình hẹp: bảng nhỏ hơn chữ quanh nó một chút và ô hẹp hơn, để ít phải cuộn ngang. */
@media screen and (max-width: 44.9375em) {
  .md-typeset table.btt-table {
    font-size: 0.9em;
  }

  .md-typeset table.btt-table th,
  .md-typeset table.btt-table td {
    padding: 0.2em 0.35em;
  }
}

.md-typeset table.btt-table th {
  font-weight: 700;
  background: var(--md-default-fg-color--lightest);
}

.md-typeset table.btt-table tr.btt-hl td {
  background: var(--btt-color-soft);
  font-weight: 700;
}

/* Tô ô theo màu chuỗi của bảng vẽ (xanh, cam), kèm chữ đậm để không chỉ dựa vào màu. */
.md-typeset table.btt-table td.btt-xanh {
  background: rgba(42, 120, 214, 0.16);
}

.md-typeset table.btt-table td.btt-cam {
  background: rgba(235, 104, 52, 0.2);
  font-weight: 700;
}

/* Chú thích: chữ nhỏ hơn một chút và nhạt hơn chữ chính, nhưng vẫn đủ đậm để đọc. */
.md-typeset .btt-chu-thich {
  font-size: 0.94em;
  color: var(--md-default-fg-color);
  opacity: 0.8;
}

.md-typeset .btt-bar {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.md-typeset .btt-reset {
  font-size: 0.9em;
}

.md-typeset .btt-err {
  color: #e34948;
}
