.bg-key-detector {
  --key-ink: #22303a;
  --key-muted: #6d7980;
  --key-line: #e3ded3;
  --key-paper: #fff;
  --key-blue: #dceef7;
  --key-blue-deep: #3f7897;
  --key-yellow: #ffdc27;
  --key-tonic: #2f7d6e;
  --key-subdominant: #c08a2d;
  --key-dominant: #c0492f;
  width: 100%;
  margin: 32px auto;
  color: var(--key-ink);
  font-size: 15px;
  line-height: 1.6;
}

.bg-key-detector *,
.bg-key-detector *::before,
.bg-key-detector *::after {
  box-sizing: border-box;
}

.bg-key-detector button {
  color: inherit;
  font: inherit;
}

.bg-key-detector-panel {
  margin-bottom: 18px;
  padding: 20px;
  border: 1px solid var(--key-line);
  border-radius: 8px;
  background: var(--key-paper);
}

.bg-key-detector-panel h3 {
  margin: 0;
  color: var(--key-ink);
  font-size: 16px;
  letter-spacing: 0;
}

.bg-key-detector-heading {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.bg-key-detector-clear {
  padding: 5px 12px;
  border: 1px solid var(--key-line);
  border-radius: 999px;
  background: #fff;
  color: var(--key-muted);
  font-size: 12px;
  cursor: pointer;
}

.bg-key-detector-clear:hover {
  border-color: var(--key-ink);
  color: var(--key-ink);
}

.bg-key-detector-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  margin-top: 12px;
}

.bg-key-detector-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid var(--key-tonic);
  border-radius: 6px;
  background: rgba(47, 125, 110, 0.06);
  color: var(--key-ink);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.bg-key-detector-chip i {
  color: var(--key-dominant);
  font-style: normal;
}

.bg-key-detector-placeholder,
.bg-key-detector-verdict {
  color: var(--key-muted);
  font-size: 13px;
}

.bg-key-detector-accidental {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--key-line);
  border-radius: 999px;
}

.bg-key-detector-accidental button {
  min-width: 48px;
  padding: 5px 14px;
  border: 0;
  background: #fff;
  color: var(--key-muted);
  cursor: pointer;
}

.bg-key-detector-accidental button + button {
  border-left: 1px solid var(--key-line);
}

.bg-key-detector-accidental button.is-active {
  background: var(--key-ink);
  color: #fff;
  font-weight: 800;
}

.bg-key-detector-palette {
  margin-top: 10px;
}

.bg-key-detector-note {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-left: 4px solid var(--key-blue-deep);
  border-radius: 0 6px 6px 0;
  background: var(--key-blue);
  color: var(--key-ink);
  font-size: 13px;
  line-height: 1.7;
}

.bg-key-detector-note p {
  margin: 0;
}

.bg-key-detector-note p + p {
  margin-top: 8px;
}

.bg-key-detector-root {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--key-line);
}

.bg-key-detector-root:last-child {
  border-bottom: 0;
}

.bg-key-detector-root-label {
  flex: 0 0 40px;
  font-size: 15px;
  font-weight: 800;
}

.bg-key-detector-quality-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bg-key-detector-quality {
  padding: 6px 9px;
  border: 1px solid var(--key-line);
  border-radius: 5px;
  background: #fff;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.bg-key-detector-quality:hover {
  border-color: var(--key-blue-deep);
  background: var(--key-blue);
}

.bg-key-detector-quality.is-selected,
.bg-key-detector-quality.is-selected:hover {
  border-color: #a8adb0;
  background: #d9dcde;
  color: #555d61;
  font-weight: 800;
}

.bg-key-detector-results[hidden] {
  display: none;
}

.bg-key-detector-verdict {
  margin: 8px 0 14px;
}

.bg-key-detector-key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 64px;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
  padding: 11px 12px;
  border: 1px solid var(--key-line);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}

.bg-key-detector-key-row.is-selected {
  border-color: var(--key-tonic);
  background: rgba(47, 125, 110, 0.05);
}

.bg-key-detector-key-name {
  font-size: 16px;
  font-weight: 800;
}

.bg-key-detector-key-name small,
.bg-key-detector-key-name .is-missing {
  margin-left: 6px;
  color: var(--key-muted);
  font-size: 12px;
  font-weight: 400;
}

.bg-key-detector-key-name .is-missing {
  color: var(--key-dominant);
}

.bg-key-detector-bar {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: #ece7dc;
}

.bg-key-detector-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--key-tonic);
}

.bg-key-detector-fit {
  color: var(--key-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.bg-key-detector-hint {
  margin-top: 8px;
  padding: 10px 13px;
  border: 1px solid #f0e2c0;
  border-radius: 6px;
  background: #fbf3e0;
  color: #8f6722;
  font-size: 13px;
}

.bg-key-detector-diatonic-title {
  margin-top: 24px !important;
}

.bg-key-detector-diatonic-title span {
  color: var(--key-muted);
  font-weight: 400;
}

.bg-key-detector-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.bg-key-detector-toggle button {
  padding: 6px 12px;
  border: 1px solid var(--key-line);
  border-radius: 999px;
  background: #fff;
  color: var(--key-muted);
  font-size: 12px;
  cursor: pointer;
}

.bg-key-detector-toggle button.is-active {
  border-color: var(--key-ink);
  color: var(--key-ink);
  font-weight: 700;
}

.bg-key-detector-diatonic {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.bg-key-detector-degree {
  min-width: 0;
  padding: 9px 6px;
  border: 1px solid var(--key-line);
  border-radius: 6px;
  background: #fff;
  text-align: center;
}

.bg-key-detector-degree-name {
  font-size: 11px;
  font-weight: 800;
}

.bg-key-detector-triad {
  margin-top: 3px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 14px;
  font-weight: 800;
}

.bg-key-detector-seventh {
  margin-top: 2px;
  color: var(--key-muted);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
}

.bg-key-detector-degree.is-tonic {
  border-color: rgba(47, 125, 110, 0.4);
  background: rgba(47, 125, 110, 0.06);
}

.bg-key-detector-degree.is-subdominant {
  border-color: rgba(192, 138, 45, 0.4);
  background: rgba(192, 138, 45, 0.06);
}

.bg-key-detector-degree.is-dominant {
  border-color: rgba(192, 73, 47, 0.4);
  background: rgba(192, 73, 47, 0.06);
}

.bg-key-detector-degree.is-tonic .bg-key-detector-degree-name {
  color: var(--key-tonic);
}

.bg-key-detector-degree.is-subdominant .bg-key-detector-degree-name {
  color: var(--key-subdominant);
}

.bg-key-detector-degree.is-dominant .bg-key-detector-degree-name {
  color: var(--key-dominant);
}

.bg-key-detector-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
  color: var(--key-muted);
  font-size: 12px;
}

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

.bg-key-detector-legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.bg-key-detector-legend .is-tonic {
  background: var(--key-tonic);
}

.bg-key-detector-legend .is-subdominant {
  background: var(--key-subdominant);
}

.bg-key-detector-legend .is-dominant {
  background: var(--key-dominant);
}

.bg-key-detector-dock {
  display: none;
}

@media (max-width: 680px) {
  .bg-key-detector {
    margin: 24px auto;
    padding-bottom: 98px;
  }

  .bg-key-detector-panel {
    padding: 16px;
  }

  .bg-key-detector-root {
    align-items: flex-start;
  }

  .bg-key-detector-quality-buttons {
    flex: 1;
  }

  .bg-key-detector-quality {
    min-width: 54px;
  }

  .bg-key-detector-key-row {
    grid-template-columns: minmax(0, 1fr) 48px;
  }

  .bg-key-detector-key-name {
    font-size: 14px;
  }

  .bg-key-detector-bar {
    display: none;
  }

  .bg-key-detector-diatonic {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bg-key-detector-dock {
    position: fixed;
    z-index: 999;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 1px;
    overflow: hidden;
    border: 1px solid var(--key-blue-deep);
    border-radius: 8px;
    background: var(--key-blue-deep);
    box-shadow: 0 10px 28px rgba(34, 48, 58, 0.24);
  }

  .bg-key-detector-dock button {
    display: grid;
    min-width: 0;
    min-height: 68px;
    gap: 2px;
    align-content: center;
    padding: 9px 12px;
    border: 0;
    background: #fff;
    text-align: left;
    cursor: pointer;
  }

  .bg-key-detector-dock span {
    color: var(--key-blue-deep);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0;
  }

  .bg-key-detector-dock strong {
    display: block;
    overflow: hidden;
    color: var(--key-ink);
    font-size: 13px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
