.mtt {
  --mtt-bg: #f6f8fa;
  --mtt-panel: #fff;
  --mtt-ink: #101820;
  --mtt-muted: #596673;
  --mtt-line: #cdd5dc;
  --mtt-cyan: #00d9ff;
  --mtt-steel: #6b7b88;
  --mtt-dark: #202932;

  display: grid;
  grid-template-columns: minmax(250px, 0.85fr) minmax(320px, 1.35fr);
  gap: 14px;
  color: var(--mtt-ink);
  background: var(--mtt-bg);
  border: 1px solid var(--mtt-line);
  border-radius: 8px;
  padding: 14px;
}

.theme-dark .mtt {
  --mtt-bg: #11161b;
  --mtt-panel: #171f27;
  --mtt-ink: #eff6fb;
  --mtt-muted: #a6b3be;
  --mtt-line: #30404d;
  --mtt-steel: #9cabb6;
  --mtt-dark: #d8e1e8;
}

.mtt-panel,
.mtt-reference {
  background: var(--mtt-panel);
  border: 1px solid var(--mtt-line);
  border-radius: 6px;
  padding: 14px;
}

.mtt-controls {
  display: grid;
  gap: 14px;
}

.mtt-fieldset > span,
.mtt-material > span,
.mtt-numeric-grid span,
.mtt-result-main span,
.mtt-result-sub span {
  display: block;
  color: var(--mtt-muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.mtt-thread-buttons,
.mtt-segments {
  display: grid;
  gap: 6px;
}

.mtt-thread-buttons {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mtt-segments {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mtt button,
.mtt select,
.mtt input {
  border: 1px solid var(--mtt-line);
  border-radius: 5px;
  color: var(--mtt-ink);
  background: var(--mtt-panel);
  font: inherit;
}

.mtt button {
  min-height: 38px;
  cursor: pointer;
  font-weight: 800;
}

.mtt button.active {
  border-color: var(--mtt-cyan);
  box-shadow: inset 0 -3px 0 var(--mtt-cyan);
}

.mtt-numeric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mtt-numeric-grid label,
.mtt-material {
  display: block;
}

.mtt-numeric-grid input,
.mtt-material select {
  width: 100%;
  height: 42px;
  padding: 0 10px;
}

.mtt-numeric-grid b {
  color: var(--mtt-muted);
  font-size: 0.78rem;
}

.mtt-warning {
  border-left: 4px solid #ffb020;
  color: var(--mtt-ink);
  background: color-mix(in srgb, #ffb020 16%, transparent);
  margin: 0;
  padding: 10px;
  font-size: 0.88rem;
}

.mtt-visual {
  min-height: 320px;
}

.mtt-visual svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 260px;
}

.mtt-grid-bg {
  fill: url("#mtt-grid");
}

#mtt-grid path {
  fill: none;
  stroke: var(--mtt-line);
  stroke-width: 0.7;
}

.mtt-axis {
  stroke: var(--mtt-line);
  stroke-dasharray: 6 8;
}

.mtt-female,
.mtt-male {
  fill: none;
  stroke-width: 8;
  stroke-linejoin: bevel;
}

.mtt-female {
  stroke: var(--mtt-steel);
}

.mtt-male {
  stroke: var(--mtt-dark);
}

.mtt-clearance {
  fill: color-mix(in srgb, var(--mtt-cyan) 38%, transparent);
  stroke: var(--mtt-cyan);
  stroke-width: 2;
}

.mtt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--mtt-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.mtt-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mtt-legend i {
  width: 18px;
  height: 4px;
  display: inline-block;
}

.mtt-legend .female { background: var(--mtt-steel); }
.mtt-legend .male { background: var(--mtt-dark); }
.mtt-legend .clearance { background: var(--mtt-cyan); }

.mtt-results {
  display: grid;
  grid-column: 1;
  grid-row: 2;
  gap: 12px;
}

.mtt-result-main {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mtt-result-main div {
  border: 1px solid var(--mtt-line);
  border-radius: 5px;
  padding: 12px;
}

.mtt-result-main strong {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: clamp(1.7rem, 5vw, 2.7rem);
  line-height: 1;
}

.mtt-result-main small {
  color: var(--mtt-muted);
  font-size: 0.88rem;
}

.mtt-result-sub {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mtt-result-sub div {
  background: var(--mtt-bg);
  border-radius: 5px;
  padding: 10px;
}

.mtt-result-sub b::after {
  content: " mm";
}

.mtt code {
  display: block;
  overflow-wrap: anywhere;
  border: 1px solid var(--mtt-line);
  border-radius: 5px;
  background: var(--mtt-bg);
  padding: 10px;
}

#mtt-copy {
  background: var(--mtt-cyan);
  border-color: var(--mtt-cyan);
  color: #001014;
}

.mtt-reference {
  grid-column: 2;
  grid-row: 2;
}

.mtt-reference h2 {
  font-size: 1rem;
  margin: 0 0 10px;
}

.mtt-reference table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.mtt-reference th,
.mtt-reference td {
  border-top: 1px solid var(--mtt-line);
  padding: 7px 9px;
  text-align: left;
}

@media (max-width: 780px) {
  .mtt {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .mtt-thread-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mtt-segments,
  .mtt-result-main,
  .mtt-result-sub {
    grid-template-columns: 1fr;
  }

  .mtt-results,
  .mtt-reference {
    grid-column: auto;
    grid-row: auto;
  }
}
