.matrix {
    display: inline-block;
    vertical-align: middle;
    font-size: 18px;
    line-height: 1;
    white-space: nowrap;
    padding: 10px;
    position: relative;
    user-select: none;
}

.matrix:before,
.matrix:after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--matrix-bracket, #000000);
}

.matrix:before {
    left: 0;
}

.matrix:after {
    right: 0;
}

.matrix-row {
    display: flex;
    justify-content: flex-start;
}

.matrix-wrapper {
    display: inline-block;
    font-family: monospace;
    font-size: 14px;
    color-scheme: light dark;
    --matrix-text: #111827;
    --matrix-muted: #333333;
    --matrix-accent: #0066cc;
    --matrix-static: #666666;
    --matrix-bracket: rgba(0, 0, 0, 0.85);
}

.dark .matrix-wrapper,
.dark-theme .matrix-wrapper,
[data-theme="dark"] .matrix-wrapper {
    --matrix-text: #f3f4f6;
    --matrix-muted: #c7d2fe;
    --matrix-accent: #7dd3fc;
    --matrix-static: #e2e8f0;
    --matrix-bracket: rgba(148, 163, 184, 0.85);
}

.matrix-grid {
    display: flex;
    align-items: flex-start;
    color: inherit;
}

.matrix-column {
    display: flex;
    flex-direction: column;
    color: inherit;
}

.matrix-label-column {
    margin-right: 5px;
}

.matrix-data-wrapper {
    display: flex;
    position: relative;
    padding: 0 15px;
}

.matrix-data-wrapper::before,
.matrix-data-wrapper::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 100%;
    pointer-events: none;
}

.matrix-data-wrapper::before {
    left: 3px;
    border-left: 2px solid var(--matrix-bracket, black);
    border-top: 2px solid var(--matrix-bracket, black);
    border-bottom: 2px solid var(--matrix-bracket, black);
}

.matrix-data-wrapper::after {
    right: 3px;
    border-right: 2px solid var(--matrix-bracket, black);
    border-top: 2px solid var(--matrix-bracket, black);
    border-bottom: 2px solid var(--matrix-bracket, black);
}

.matrix-data-column {
    margin: 0;
}

.matrix-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2em;
    box-sizing: border-box;
    color: inherit;
}

.matrix-element {
    width: 3em;
    height: 1.5em;
    text-align: center;
    margin: 0.2em;
    cursor: ew-resize;
    color: var(--matrix-accent, #0066cc);
    display: flex;
    align-items: center;
    justify-content: center;
}

.matrix-element::selection {
    background-color: transparent;
}

.matrix-element-static {
    cursor: default;
    color: var(--matrix-static, #666666);
}

.matrix-row-label {
    width: auto;
    min-width: 5em;
    justify-content: flex-end;
    padding-right: 0.5em;
    font-weight: bold;
    color: var(--matrix-muted, #333333);
    white-space: nowrap;
}

.matrix-col-label {
    font-weight: bold;
    color: var(--matrix-muted, #333333);
    margin-bottom: 5px;
    width: 3.6em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.matrix-grid.flexible-columns .matrix-element {
    width: auto;
    min-width: 3em;
    padding: 0 0.5em;
}

.matrix-grid.flexible-columns .matrix-col-label {
    width: auto;
    min-width: 3.6em;
    padding: 0 0.5em;
}

.matrix-grid.flexible-columns .matrix-data-column {
    flex-shrink: 0;
}

.matrix-corner-cell {
    visibility: hidden;
    height: 2em;
    margin-bottom: 5px;
}

.matrix-grid:has(.matrix-col-label) .matrix-data-wrapper::before,
.matrix-grid:has(.matrix-col-label) .matrix-data-wrapper::after {
    top: calc(2em + 5px);
    height: calc(100% - 2em - 5px);
}

.matrix-grid:not(:has(.matrix-col-label)) .matrix-data-wrapper::before,
.matrix-grid:not(:has(.matrix-col-label)) .matrix-data-wrapper::after {
    top: 0;
    height: 100%;
}
