/* Gematria subproject — overlay on /styles.css + /css/gematria-site.css */

html,
body.page-gematria {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.page-gematria .gematria-main,
.page-gematria .hero.gematria-hero {
    background: transparent;
}

.page-gematria .gematria-main {
    max-width: 52rem;
    width: 100%;
    overflow-x: clip;
    box-sizing: border-box;
}

/* iOS / WebKit: reset native button styling (blue pills) */
.page-gematria button,
.page-gematria .btn {
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
    font: inherit;
    background-image: none;
    cursor: pointer;
}

.page-gematria button:disabled,
.page-gematria .btn:disabled,
.page-gematria .gematria-btn[disabled] {
    cursor: not-allowed;
}

.page-gematria button.is-loading,
.page-gematria .gematria-btn.is-loading {
    cursor: wait;
}

.page-gematria a.lang-link,
.page-gematria .gematria-systems-link,
.page-gematria a.btn {
    cursor: pointer;
}

.page-gematria .btn-primary {
    background-color: #c9a227;
    background-image: linear-gradient(135deg, #c9a227, #a67c0f);
    color: #1a1408;
    border: none;
    text-decoration: none;
}

.page-gematria .btn-primary:hover {
    filter: brightness(1.06);
}

.page-gematria .gematria-actions .btn-secondary,
.page-gematria #searchMatrix.btn-secondary,
.page-gematria #searchAbbrev.btn-secondary {
    background-color: rgba(201, 162, 39, 0.12);
    background-image: none;
    border: 1px solid rgba(201, 162, 39, 0.5);
    color: #c9a227;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

html[data-theme="light"] .page-gematria .gematria-actions .btn-secondary,
html[data-theme="light"] .page-gematria #searchMatrix.btn-secondary,
html[data-theme="light"] .page-gematria #searchAbbrev.btn-secondary {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.page-gematria .gematria-actions .btn-secondary:hover,
.page-gematria #searchMatrix.btn-secondary:hover,
.page-gematria #searchAbbrev.btn-secondary:hover {
    background-color: rgba(201, 162, 39, 0.22);
    border-color: rgba(201, 162, 39, 0.72);
}

@supports (background: color-mix(in srgb, #c9a227 12%, transparent)) {
    .page-gematria .gematria-actions .btn-secondary,
    .page-gematria #searchMatrix.btn-secondary,
    .page-gematria #searchAbbrev.btn-secondary {
        background: color-mix(in srgb, var(--gold) 12%, transparent);
    }

    .page-gematria .gematria-actions .btn-secondary:hover,
    .page-gematria #searchMatrix.btn-secondary:hover,
    .page-gematria #searchAbbrev.btn-secondary:hover {
        background: color-mix(in srgb, var(--gold) 22%, transparent);
    }
}

/* Form row — stack on mobile; never push input off-screen */
.page-gematria .gematria-form-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 100%;
    margin-bottom: 1rem;
}

.page-gematria .gematria-form-row .gematria-select,
.page-gematria .gematria-form-row .gematria-input {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

@media (min-width: 720px) {
    .page-gematria .gematria-form-row {
        flex-direction: row;
        align-items: stretch;
    }

    .page-gematria .gematria-form-row .gematria-select {
        flex: 0 1 46%;
        max-width: 46%;
    }

    .page-gematria .gematria-form-row .gematria-input {
        flex: 1 1 0;
        min-width: 0;
    }
}

/* Selects — visually distinct from text inputs */
.page-gematria .gematria-select,
.page-gematria .matrix-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    min-height: 2.75rem;
    min-width: 0;
    line-height: 1.25;
    padding-right: 2.5rem;
    border-width: 1.5px;
    border-style: solid;
    border-color: rgba(201, 162, 39, 0.38);
    font-weight: 600;
    background-color: var(--input-bg);
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23c9a227' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

html[data-theme="light"] .page-gematria .gematria-select,
html[data-theme="light"] .page-gematria .matrix-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23a67c0f' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.page-gematria .gematria-select:hover,
.page-gematria .matrix-select:hover {
    border-color: rgba(201, 162, 39, 0.55);
}

.page-gematria .gematria-select:focus,
.page-gematria .matrix-select:focus {
    outline: 2px solid rgba(201, 162, 39, 0.45);
    outline-offset: 1px;
}

.page-gematria .gematria-input {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    border-width: 1px;
    font-weight: 400;
}

html[data-theme="light"] .page-gematria .gematria-input {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.page-gematria .gematria-loader__tanakh {
    color: var(--gold);
}

.page-gematria .gematria-loader {
    min-height: 11rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.page-gematria .gematria-loader[hidden] {
    display: none !important;
}

.page-gematria .gematria-loader__text {
    margin: 0.35rem 0 0;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    animation: gem-loader-pulse 1.6s ease-in-out infinite;
}

@keyframes gem-loader-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

.matrix-open-loader {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(10, 9, 8, 0.68);
    backdrop-filter: blur(7px);
    opacity: 0;
    transition: opacity 0.18s ease;
}

.matrix-open-loader[hidden] {
    display: none !important;
}

.matrix-open-loader.is-visible {
    opacity: 1;
}

.matrix-open-loader__card {
    min-width: min(18rem, calc(100vw - 2.5rem));
    padding: 1.5rem 1.75rem 1.25rem;
    border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
    border-radius: 18px;
    background: color-mix(in srgb, var(--card-bg, #1a1a1f) 94%, transparent);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.46);
    text-align: center;
    transform: translateY(8px) scale(0.98);
    transition: transform 0.18s ease;
}

.matrix-open-loader.is-visible .matrix-open-loader__card {
    transform: translateY(0) scale(1);
}

body.matrix-open-loading {
    overflow: hidden;
    cursor: wait;
}

/* Flipping-book loader */
.page-gematria .gem-book {
    position: relative;
    width: 104px;
    height: 68px;
    margin: 0 auto 1.1rem;
    border: 3px solid color-mix(in srgb, var(--gold) 50%, transparent);
    border-radius: 2px 8px 8px 2px;
    background: linear-gradient(145deg, #5c4308 0%, var(--gold) 42%, #a67c0f 100%);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.page-gematria .gem-book__page {
    position: absolute;
    left: 50%;
    top: -3px;
    width: 52px;
    height: 68px;
    margin: 0 auto;
    border-top: 3px solid rgba(255, 252, 240, 0.9);
    border-bottom: 3px solid rgba(255, 252, 240, 0.9);
    border-right: 3px solid rgba(255, 252, 240, 0.9);
    border-radius: 0 5px 5px 0;
    background: linear-gradient(180deg, #fff9ee 0%, #f2e8d4 100%);
    color: #3d2f0a;
    font-family: "Frank Ruhl Libre", "Heebo", "Noto Sans Hebrew", serif;
    font-size: 0.62rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    direction: rtl;
    line-height: 1.15;
    transform-origin: 0% 50%;
    animation: gem-book-flip 2.1s infinite linear;
    animation-fill-mode: forwards;
    box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.18);
}

.page-gematria .gem-book__page--1 {
    z-index: 3;
    animation-delay: 0s;
}

.page-gematria .gem-book__page--2 {
    z-index: 2;
    animation-delay: 0.7s;
}

.page-gematria .gem-book__page--3 {
    z-index: 1;
    animation-delay: 1.4s;
}

@keyframes gem-book-flip {
    0% {
        transform: perspective(600px) rotateY(0deg);
        opacity: 1;
    }
    22% {
        background: linear-gradient(180deg, #fff3dc 0%, #e8dcc4 100%);
    }
    30% {
        transform: perspective(220px) rotateY(-92deg);
    }
    54.9% {
        opacity: 1;
    }
    55% {
        opacity: 0;
    }
    60% {
        transform: perspective(220px) rotateY(-180deg);
        opacity: 0;
    }
    100% {
        transform: perspective(220px) rotateY(-180deg);
        opacity: 0;
    }
}

.page-gematria .gematria-btn.is-loading {
    opacity: 0.55;
    pointer-events: none;
}

.page-gematria .gem-search-summary {
    margin: 1rem 0 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--card-border));
    background: color-mix(in srgb, var(--gold) 8%, var(--card-bg));
    color: var(--text);
    font-size: 0.98rem;
    line-height: 1.45;
    text-align: center;
}

.page-gematria .gem-search-summary b,
.page-gematria .gem-search-summary strong {
    color: var(--gold);
    font-weight: 700;
}

.page-gematria .gematria-search-result details {
    color: var(--card-text);
}

.page-gematria .gematria-search-result summary {
    cursor: pointer;
    color: var(--gold);
}

.page-gematria .gematria-search-result ul {
    color: var(--muted);
}

.gem-error {
    margin: 0.75rem 0 0;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid rgba(220, 80, 80, 0.45);
    background: color-mix(in srgb, #dc5050 12%, var(--card-bg));
    color: var(--text);
}

html[data-theme="light"] .gem-error {
    background: color-mix(in srgb, #c0392b 10%, var(--card-bg));
    border-color: rgba(192, 57, 43, 0.35);
}

.page-gematria .matrix-container {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
}

.page-gematria .matrix-title {
    color: var(--gold);
}

.page-gematria .table,
.page-gematria .table-condensed {
    width: 100%;
    border-collapse: collapse;
    background: var(--table-bg);
    border: 1px solid var(--table-border);
    border-radius: 8px;
    overflow: hidden;
    color: var(--card-text);
}

.page-gematria .table td,
.page-gematria .table-condensed td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--table-border);
}

.page-gematria .table tr.gem-summary-row td,
.page-gematria .table-condensed tr.gem-summary-row td {
    background: var(--panel-soft) !important;
    color: var(--text) !important;
}

.page-gematria .table tr[style*="background"] td,
.page-gematria .table-condensed tr[style*="background"] td {
    background: var(--panel-soft) !important;
    color: var(--text) !important;
}

#scrollTopBtn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    opacity: 0;
    pointer-events: none;
    width: 46px;
    height: 46px;
    -webkit-appearance: none;
    appearance: none;
    background-color: rgba(20, 18, 14, 0.88);
    background-image: none;
    color: #c9a227;
    border: 1px solid rgba(201, 162, 39, 0.4);
    border-radius: 50%;
    font-size: 1.2rem;
    line-height: 44px;
    text-align: center;
    cursor: pointer;
    z-index: 200;
    transition: opacity 0.3s ease, transform 0.2s ease;
    backdrop-filter: blur(8px);
}

#scrollTopBtn.show {
    opacity: 1;
    pointer-events: auto;
}

#scrollTopBtn:hover {
    transform: translateY(-2px);
}

.matrix-line .matrix {
    background: color-mix(in srgb, var(--gold) 35%, transparent);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

.matrix-line .matrix .letter {
    font-weight: 700;
    color: #e74c3c;
}

.matrix-letter-grid-wrap {
    position: relative;
}

.matrix-word-outline {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

.matrix-word-outline__path {
    fill: none;
    stroke: #e74c3c;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 0.35px color-mix(in srgb, var(--gold) 65%, transparent));
}

html[data-theme="light"] .matrix-word-outline__path {
    stroke: #c0392b;
}

.matrix-equal-outlines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

.matrix-equal-outlines__path {
    fill: none;
    stroke: #46ad68;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 0.45px color-mix(in srgb, #46ad68 70%, transparent));
}

.matrix-equal-outlines__path--alternate {
    stroke: #318fbd;
    filter: drop-shadow(0 0 0.45px color-mix(in srgb, #318fbd 72%, transparent));
}

html[data-theme="light"] .matrix-equal-outlines__path {
    stroke: #338b50;
}

html[data-theme="light"] .matrix-equal-outlines__path--alternate {
    stroke: #247ba5;
}

.matrix-letter-grid {
    display: grid;
    grid-template-columns: repeat(var(--matrix-cols, 3), minmax(0, 1fr));
    gap: 0.12rem 0.2rem;
    direction: rtl;
    width: 100%;
    font-family: 'Frank Ruhl Libre', 'Times New Roman', serif;
    font-size: clamp(0.82rem, 2.6vw, 1.05rem);
    line-height: 1.15;
}

.matrix-letter-grid--empty {
    padding: 0.5rem;
    text-align: center;
}

.matrix-grid-cell {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 1.35em;
    padding: 0.08rem 0.05rem;
    text-align: center;
    border-radius: 3px;
}

.matrix-grid-cell--letter {
    z-index: 2;
    font-weight: 700;
    color: #e74c3c;
}

.matrix-grid-cell--equal {
    background: color-mix(in srgb, #76c893 28%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, #76c893 42%, transparent);
    animation: matrix-equal-found 0.34s ease-out both;
}

html[data-theme="light"] .matrix-grid-cell--equal {
    background: color-mix(in srgb, #70bd86 24%, #fff);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, #4f9f68 32%, transparent);
}

.matrix-grid-cell--alternate,
.matrix-grid-cell--alternate-persistent {
    background: color-mix(in srgb, #67b9df 28%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, #67b9df 45%, transparent);
    animation: matrix-equal-found 0.34s ease-out both;
}

html[data-theme="light"] .matrix-grid-cell--alternate,
html[data-theme="light"] .matrix-grid-cell--alternate-persistent {
    background: color-mix(in srgb, #67b9df 24%, #fff);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, #318fbd 34%, transparent);
}

@keyframes matrix-equal-found {
    from { transform: scale(0.82); filter: brightness(1.28); }
    to { transform: scale(1); filter: brightness(1); }
}

html[data-theme="light"] .matrix-grid-cell--letter {
    color: #c0392b;
}

html[data-theme="light"] .matrix-line .matrix .letter {
    color: #c0392b;
}

.matrix-heading {
    cursor: pointer;
    background: color-mix(in srgb, var(--gold) 10%, var(--card-bg));
    padding: 0.4rem;
    border-radius: 6px;
    font-weight: 700;
    border: 1px solid var(--card-border);
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    color: var(--text);
}

.matrix-block {
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    background: color-mix(in srgb, var(--gold) 6%, var(--card-bg));
}

.matrix-block--clickable {
    cursor: pointer;
}

.matrix-block--clickable:hover {
    border-color: rgba(201, 162, 39, 0.45);
}

.matrix-line {
    font-size: 1.05rem;
    line-height: 1.5;
    direction: rtl;
    word-break: break-word;
    margin-top: 0.4rem;
}

.matrix-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    padding: 0.35rem 1.8rem 0.35rem 0.55rem;
    font-size: 0.8rem;
    color: var(--text);
    max-width: 110px;
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: right 0.45rem center;
    background-size: 0.85rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23c9a227' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

html[data-theme="light"] .matrix-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a67c0f' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.matrix-cell {
    max-width: 320px;
    vertical-align: top;
}

.matrix-actions {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.matrix-open-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.2;
    white-space: nowrap;
    width: auto;
    max-width: none;
}

.gematria-modal--matrix .gematria-modal__content {
    max-width: min(52rem, 96vw);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gematria-modal--matrix .gematria-modal__title {
    flex: 0 0 auto;
}

.gematria-modal--matrix .gematria-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.gematria-modal--matrix .gematria-modal__body.is-matrix-equals {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gematria-modal--matrix .gematria-modal__footer {
    flex: 0 0 auto;
    margin-top: 0.9rem;
}

.matrix-modal-layout {
    display: block;
}

.matrix-modal-layout::after {
    content: '';
    display: block;
    clear: both;
}

.matrix-modal-aside {
    float: inline-end;
    width: min(16rem, 48vw);
    min-width: 7rem;
    max-height: min(46vh, 20rem);
    resize: horizontal;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin-inline-start: 1rem;
    margin-block-end: 0.75rem;
    padding: 0.7rem;
    border-radius: 14px;
    border: 1px solid var(--card-border);
    background: linear-gradient(
        155deg,
        color-mix(in srgb, var(--gold) 14%, var(--card-bg)) 0%,
        var(--card-bg) 55%,
        color-mix(in srgb, var(--gold) 6%, var(--table-bg)) 100%
    );
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}

.matrix-modal-layout--equals {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    animation: matrix-equals-mode-open 0.28s ease-out both;
}

.matrix-modal-layout--equals::after {
    display: none;
}

.matrix-modal-layout--equals .matrix-modal-aside {
    flex: 0 0 auto;
    float: none;
    margin: 0 auto 0.75rem;
}

.matrix-modal-layout--equals .matrix-modal-verses {
    display: none !important;
}

.matrix-modal-layout--equals .matrix-modal-line {
    max-height: 100%;
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.matrix-modal-layout--equals .matrix-modal-line:hover,
.matrix-modal-layout--equals .matrix-modal-line:focus-visible {
    border-color: color-mix(in srgb, var(--gold) 58%, var(--card-border));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 10%, transparent);
    outline: none;
}

@keyframes matrix-equals-mode-open {
    from { opacity: 0.72; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.matrix-equals-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
    padding-bottom: 0.55rem;
}

.matrix-equals-results {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0.35rem 0 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent;
    animation: matrix-equals-tags-open 0.28s ease-out both;
}

.matrix-equals-results[hidden] {
    display: none !important;
}

.matrix-equals-tags {
    flex: 1 1 auto;
    min-height: 0;
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding: 0.05rem;
}

.matrix-equals-results__head {
    flex: 0 0 auto;
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    margin-bottom: 0.55rem;
}

.matrix-equals-results__meta {
    min-width: 0;
    flex: 1 1 auto;
}

.matrix-equals-results__title {
    flex: 0 0 auto;
    margin-bottom: 0.08rem;
    color: color-mix(in srgb, #70bd86 62%, var(--text));
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.08rem;
    font-weight: 700;
}

.matrix-equals-results__status {
    flex: 0 0 auto;
    min-height: 1.15rem;
    margin-bottom: 0;
    color: color-mix(in srgb, var(--gold) 68%, var(--text));
    font-size: 0.78rem;
    font-weight: 650;
}

.matrix-equals-sort {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    margin-bottom: 0;
}

.matrix-equals-sort[hidden] {
    display: none !important;
}

.matrix-equals-sort__btn {
    position: relative;
    width: 1.9rem;
    height: 1.9rem;
    flex: 0 0 1.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--gold) 28%, var(--card-border));
    border-radius: 7px;
    background: color-mix(in srgb, var(--gold) 5%, var(--card-bg));
    color: color-mix(in srgb, var(--text) 82%, var(--gold));
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.matrix-equals-sort__btn::before {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 0.55rem);
    inset-inline-end: 0;
    z-index: 30;
    max-width: min(13rem, 72vw);
    padding: 0.42rem 0.62rem;
    border: 1px solid color-mix(in srgb, var(--gold) 48%, transparent);
    border-radius: 8px;
    background: #28241d;
    color: #fff8e9;
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.28);
    font-family: "Cormorant Garamond", Georgia, serif;
    font-size: 0.78rem;
    font-weight: 650;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
    unicode-bidi: plaintext;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.matrix-equals-sort__btn::after {
    content: "";
    position: absolute;
    top: calc(100% + 0.2rem);
    left: 50%;
    z-index: 31;
    width: 0;
    height: 0;
    border-inline: 5px solid transparent;
    border-bottom: 5px solid #28241d;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%);
    transition: opacity 0.16s ease, visibility 0.16s ease;
}

.matrix-equals-sort__btn:hover::before,
.matrix-equals-sort__btn:focus::before,
.matrix-equals-sort__btn:hover::after,
.matrix-equals-sort__btn:focus::after {
    opacity: 1;
    visibility: visible;
}

.matrix-equals-sort__btn:hover::before,
.matrix-equals-sort__btn:focus::before {
    transform: translateY(0);
}

.matrix-equals-sort__btn:hover,
.matrix-equals-sort__btn:focus-visible {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, #70bd86 60%, var(--card-border));
    background: color-mix(in srgb, #70bd86 12%, var(--card-bg));
    outline: none;
}

.matrix-equals-sort__btn.is-active {
    border-color: color-mix(in srgb, #70bd86 76%, var(--card-border));
    background: color-mix(in srgb, #70bd86 20%, var(--card-bg));
    color: color-mix(in srgb, #70bd86 68%, var(--text));
}

.matrix-equals-sort__icon {
    width: 1.05rem;
    height: 1.05rem;
}

.matrix-equals-sort__alphabet {
    direction: rtl;
    font-family: "Frank Ruhl Libre", "Times New Roman", serif;
    font-size: 0.78rem;
    font-weight: 750;
    line-height: 1;
    letter-spacing: -0.04em;
}

.matrix-equals-sort__arrow {
    position: absolute;
    right: -0.25rem;
    bottom: -0.25rem;
    width: 0.9rem;
    height: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, #70bd86 84%, var(--card-bg));
    color: var(--card-bg);
    font-size: 0.64rem;
    font-weight: 800;
    line-height: 1;
    direction: ltr;
    box-shadow: 0 0 0 2px var(--card-bg);
}

.matrix-equals-sort__arrow:empty {
    display: none;
}

.matrix-equals-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.08rem;
    min-height: 1.7rem;
    padding: 0.1rem 0.2rem;
    border: 1px solid color-mix(in srgb, #70bd86 42%, var(--card-border));
    border-radius: 999px;
    background: color-mix(in srgb, #70bd86 9%, var(--card-bg));
    color: var(--text);
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
    margin: 0.16rem 0.12rem;
    transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.matrix-equals-tag:hover,
.matrix-equals-tag:focus-within {
    transform: translateY(-1px);
    border-color: color-mix(in srgb, #70bd86 72%, var(--card-border));
    background: color-mix(in srgb, #70bd86 18%, var(--card-bg));
    outline: none;
}

.matrix-equals-tag.is-active {
    border-color: color-mix(in srgb, #70bd86 86%, var(--card-border));
    background: color-mix(in srgb, #70bd86 28%, var(--card-bg));
    box-shadow: 0 0 0 2px color-mix(in srgb, #70bd86 14%, transparent);
}

.matrix-equals-tag--alternate {
    border-color: color-mix(in srgb, #67b9df 58%, var(--card-border));
    background: color-mix(in srgb, #67b9df 13%, var(--card-bg));
}

.matrix-equals-tag--alternate:hover,
.matrix-equals-tag--alternate:focus-within {
    border-color: color-mix(in srgb, #67b9df 78%, var(--card-border));
    background: color-mix(in srgb, #67b9df 21%, var(--card-bg));
}

.matrix-equals-tag--alternate.is-active {
    border-color: color-mix(in srgb, #67b9df 88%, var(--card-border));
    background: color-mix(in srgb, #67b9df 29%, var(--card-bg));
    box-shadow: 0 0 0 2px color-mix(in srgb, #67b9df 16%, transparent);
}

.matrix-equals-tag.is-outlined {
    border-color: color-mix(in srgb, #46ad68 88%, var(--card-border));
}

.matrix-equals-tag--alternate.is-outlined {
    border-color: color-mix(in srgb, #318fbd 88%, var(--card-border));
}

.matrix-equals-tag__main {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.1rem 0.2rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: inherit;
    cursor: pointer;
}

.matrix-equals-tag__main:focus-visible {
    outline: none;
}

.matrix-equals-tag__outline {
    position: relative;
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 1.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.matrix-equals-tag__outline-checkbox {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.matrix-equals-tag__outline-ui {
    width: 0.72rem;
    height: 0.72rem;
    position: relative;
    display: inline-block;
    border: 1px solid color-mix(in srgb, #46ad68 68%, var(--card-border));
    border-radius: 3px;
    background: color-mix(in srgb, #46ad68 5%, var(--card-bg));
    transition: background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.matrix-equals-tag__outline-checkbox:focus-visible + .matrix-equals-tag__outline-ui {
    box-shadow: 0 0 0 2px color-mix(in srgb, #46ad68 28%, transparent);
}

.matrix-equals-tag__outline-checkbox:checked + .matrix-equals-tag__outline-ui {
    border-color: #46ad68;
    background: #46ad68;
}

.matrix-equals-tag--alternate .matrix-equals-tag__outline-checkbox:checked + .matrix-equals-tag__outline-ui {
    border-color: #318fbd;
    background: #318fbd;
}

.matrix-equals-tag__outline-checkbox:checked + .matrix-equals-tag__outline-ui::after {
    content: "";
    position: absolute;
    left: 0.22rem;
    top: 0.04rem;
    width: 0.2rem;
    height: 0.4rem;
    border-right: 1.5px solid #fff;
    border-bottom: 1.5px solid #fff;
    transform: rotate(45deg);
}

.matrix-equals-tag__word {
    font-family: 'Frank Ruhl Libre', serif;
    font-weight: 700;
    white-space: nowrap;
}

.matrix-equals-tag__translation {
    min-width: 0;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.9em;
    font-weight: 600;
    color: color-mix(in srgb, var(--gold) 68%, var(--text));
}

.matrix-equals-tag__count {
    min-width: 1.1rem;
    padding: 0.11rem 0.28rem;
    border-radius: 999px;
    background: color-mix(in srgb, #70bd86 24%, transparent);
    font-family: inherit;
    font-size: 0.68rem;
    text-align: center;
}

.matrix-equals-tag__skip {
    min-width: 1.35rem;
    max-width: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.1rem 0.28rem;
    border-radius: 999px;
    background: color-mix(in srgb, #70bd86 20%, transparent);
    font-family: inherit;
    font-size: 0.66rem;
    font-weight: 700;
    direction: ltr;
    text-align: center;
}

.matrix-equals-tag--alternate .matrix-equals-tag__skip,
.matrix-equals-tag--alternate .matrix-equals-tag__count {
    background: color-mix(in srgb, #67b9df 24%, transparent);
}

@keyframes matrix-equals-tags-open {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 620px) {
    #matrixModal.gematria-modal--matrix {
        padding: 0.25rem;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals {
        box-sizing: border-box;
        height: calc(100vh - 0.5rem);
        height: calc(100dvh - 0.5rem);
        max-height: calc(100vh - 0.5rem);
        max-height: calc(100dvh - 0.5rem);
        padding: 0.65rem 0.85rem;
        border-radius: 12px;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .gematria-modal__title {
        margin-bottom: 0.35rem;
        padding-inline-end: 1.35rem;
        font-size: 0.9rem;
        line-height: 1.2;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header {
        gap: 0.18rem;
        padding-bottom: 0.25rem;
        margin-bottom: 0;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header__word {
        font-size: 1.05rem;
        line-height: 1.15;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header__source {
        flex-direction: row;
        align-items: baseline;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.15rem 0.45rem;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header__he {
        font-size: 0.9rem;
        line-height: 1.15;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header__loc {
        font-size: 0.78rem;
        line-height: 1.15;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-modal-header__step {
        padding-top: 0.08rem;
        font-size: 0.74rem;
        line-height: 1.15;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .gematria-modal__close {
        top: 0.35rem;
        inset-inline-end: 0.45rem;
    }

    .matrix-modal-layout--equals .matrix-modal-aside {
        margin-bottom: 0.35rem;
    }

    .matrix-modal-layout--equals .matrix-equals-toolbar {
        display: flex;
        gap: 0.3rem;
        padding-bottom: 0.35rem;
    }

    .matrix-modal-layout--equals .matrix-find-equals-btn {
        min-height: 1.8rem;
        padding: 0.3rem 0.38rem;
        font-size: 0.66rem;
    }

    .matrix-modal-layout--equals .matrix-equals-results {
        padding-top: 0.15rem;
    }

    .matrix-modal-layout--equals .matrix-equals-results__head {
        gap: 0.45rem;
        margin-bottom: 0.32rem;
    }

    .matrix-modal-layout--equals .matrix-equals-results__title {
        font-size: 0.92rem;
        line-height: 1.05;
    }

    .matrix-modal-layout--equals .matrix-equals-results__status {
        min-height: 0;
        font-size: 0.68rem;
        line-height: 1.1;
    }

    .matrix-modal-layout--equals .matrix-equals-sort {
        gap: 0.34rem;
    }

    .matrix-modal-layout--equals .matrix-equals-sort__btn {
        width: 1.75rem;
        height: 1.75rem;
        flex-basis: 1.75rem;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .gematria-modal__footer {
        margin-top: 0.35rem;
    }

    .gematria-modal--matrix .gematria-modal__content.is-matrix-equals .matrix-share-bar {
        margin-top: 0;
        padding-top: 0.4rem;
    }
}

.matrix-find-equals-btn {
    width: auto;
    flex: 1 1 0;
    min-height: 2.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.42rem 0.65rem;
    border: 1px solid color-mix(in srgb, #70bd86 48%, var(--card-border));
    border-radius: 10px;
    background: color-mix(in srgb, #70bd86 10%, var(--card-bg));
    color: color-mix(in srgb, #8bd8a1 78%, var(--text));
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.matrix-find-equals-btn svg {
    width: 1rem;
    height: 1rem;
    flex: 0 0 auto;
}

.matrix-find-equals-btn:hover,
.matrix-find-equals-btn:focus-visible {
    transform: translateY(-1px);
    background: color-mix(in srgb, #70bd86 18%, var(--card-bg));
    border-color: color-mix(in srgb, #70bd86 68%, var(--card-border));
    box-shadow: 0 4px 12px rgba(40, 110, 63, 0.14);
    outline: none;
}

.matrix-find-equals-btn.is-loading {
    cursor: wait;
    opacity: 0.84;
}

.matrix-find-equals-btn.is-loading svg {
    animation: matrix-equals-spin 0.9s linear infinite;
}

.matrix-find-equals-btn.has-results {
    background: color-mix(in srgb, #70bd86 22%, var(--card-bg));
    border-color: color-mix(in srgb, #70bd86 72%, var(--card-border));
}

.matrix-find-all-btn {
    border-color: color-mix(in srgb, #67b9df 55%, var(--card-border));
    background: color-mix(in srgb, #67b9df 12%, var(--card-bg));
    color: color-mix(in srgb, #7dc9eb 82%, var(--text));
}

.matrix-find-all-btn:hover,
.matrix-find-all-btn:focus-visible,
.matrix-find-all-btn.has-results {
    border-color: color-mix(in srgb, #67b9df 76%, var(--card-border));
    background: color-mix(in srgb, #67b9df 22%, var(--card-bg));
}

@keyframes matrix-equals-spin {
    to { transform: rotate(360deg); }
}

html[data-theme="light"] .matrix-modal-aside {
    box-shadow: 0 4px 14px rgba(80, 60, 30, 0.1);
}

.matrix-square-grid {
    display: grid;
    grid-template-columns: repeat(var(--matrix-cols, 3), minmax(0, 1fr));
    gap: 0.4rem;
}

.matrix-square-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--card-border));
    background: color-mix(in srgb, var(--gold) 20%, var(--table-bg));
}

.matrix-square-cell--empty {
    opacity: 0.25;
    border-style: dashed;
}

.matrix-square-letter {
    font-family: 'Frank Ruhl Libre', 'Times New Roman', serif;
    font-size: clamp(1.15rem, 4.2vw, 1.5rem);
    font-weight: 700;
    line-height: 1;
    color: #e74c3c;
}

html[data-theme="light"] .matrix-square-letter {
    color: #c0392b;
}

.matrix-modal-verses {
    direction: rtl;
    text-align: right;
    line-height: 1.65;
    font-size: 1.02rem;
}

.matrix-modal-verses .verse-translation {
    direction: ltr;
    text-align: left;
}

.gematria-modal__title {
    font-weight: 700;
    color: var(--gold);
    margin: 0 0 1rem;
    padding-inline-end: 1.5rem;
    text-align: center;
    font-size: 1.05rem;
    line-height: 1.4;
}

.matrix-modal-header {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--card-bg, #1a1a1f);
    padding-bottom: 0.45rem;
    border-bottom: 1px solid color-mix(in srgb, var(--gold) 18%, transparent);
    margin-bottom: 0.6rem;
}

.matrix-modal-header__source {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.matrix-modal-header__word {
    font-family: 'Frank Ruhl Libre', serif;
    font-size: 1.28rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text);
}

.matrix-modal-header__word-meaning {
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.92em;
    font-weight: 600;
    color: color-mix(in srgb, var(--gold) 76%, var(--text));
}

.matrix-modal-header__he {
    direction: rtl;
    font-size: 1.08rem;
    line-height: 1.35;
}

.matrix-modal-header__loc {
    direction: ltr;
    font-size: 0.92rem;
    font-weight: 500;
    color: color-mix(in srgb, var(--gold) 72%, var(--text));
    line-height: 1.35;
}

.matrix-modal-header__step {
    direction: ltr;
    font-size: 0.88rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--gold) 55%, var(--text));
    line-height: 1.3;
    padding-top: 0.15rem;
    border-top: 1px solid color-mix(in srgb, var(--gold) 22%, transparent);
}

.gematria-modal__footer {
    margin-top: 1.1rem;
    text-align: center;
}

.gematria-modal__footer:empty {
    display: none;
}

.matrix-share-bar {
    margin-top: 0.25rem;
    padding-top: 0.85rem;
    border-top: 1px solid color-mix(in srgb, var(--gold) 22%, transparent);
    text-align: center;
}

.matrix-share-bar__title {
    font-size: 0.82rem;
    font-weight: 700;
    color: color-mix(in srgb, var(--gold) 70%, var(--text));
    margin-bottom: 0.55rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.matrix-share-bar__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    justify-content: center;
    align-items: center;
}

.matrix-share-bar__primary {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.65rem;
}

.matrix-share-bar__primary .matrix-share-btn {
    width: 2.65rem;
    height: 2.65rem;
}

.matrix-share-btn--toggle {
    color: color-mix(in srgb, var(--gold) 88%, var(--text));
}

.matrix-share-btn--toggle .matrix-share-btn__icon {
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.matrix-share-bar.is-open .matrix-share-btn--toggle {
    background: color-mix(in srgb, var(--gold) 22%, var(--card-bg));
    border-color: color-mix(in srgb, var(--gold) 68%, var(--card-border));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 10%, transparent);
}

.matrix-share-bar.is-open .matrix-share-btn--toggle .matrix-share-btn__icon {
    transform: rotate(-16deg) scale(1.08);
}

.matrix-share-bar__networks {
    display: grid;
    grid-template-rows: 0fr;
    max-width: 42rem;
    margin: 0 auto;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition:
        grid-template-rows 0.34s cubic-bezier(0.2, 0.8, 0.2, 1),
        opacity 0.22s ease,
        transform 0.28s ease,
        visibility 0s linear 0.34s;
}

.matrix-share-bar__network-list {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.45rem;
}

.matrix-share-bar__networks .matrix-share-btn {
    opacity: 0;
    transform: translateY(10px) scale(0.72);
    transition:
        opacity 0.18s ease,
        transform 0.24s cubic-bezier(0.2, 0.9, 0.25, 1.2);
}

.matrix-share-bar.is-open .matrix-share-bar__networks {
    grid-template-rows: 1fr;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition-delay: 0s;
}

.matrix-share-bar.is-open .matrix-share-bar__network-list {
    overflow: visible;
    padding-top: 0.75rem;
}

.matrix-share-bar.is-open .matrix-share-bar__networks .matrix-share-btn {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition-delay: var(--share-delay, 55ms);
}

.matrix-share-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--card-border));
    background: color-mix(in srgb, var(--gold) 8%, var(--card-bg));
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

.matrix-share-bar.is-disabled {
    opacity: 0.48;
}

.matrix-share-bar.is-disabled .matrix-share-btn {
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    box-shadow: none;
}

.matrix-share-btn__icon {
    width: 1.1rem;
    height: 1.1rem;
    display: block;
    flex-shrink: 0;
}

.matrix-share-btn[data-tooltip]::before,
.matrix-share-btn[data-tooltip]::after {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
    z-index: 5;
}

.matrix-share-btn[data-tooltip]::before {
    content: '';
    bottom: calc(100% + 2px);
    border: 6px solid transparent;
    border-top-color: color-mix(in srgb, #1a1510 92%, var(--gold) 8%);
    transform: translateX(-50%) translateY(4px);
}

.matrix-share-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    bottom: calc(100% + 13px);
    padding: 0.32rem 0.55rem;
    border-radius: 8px;
    background: color-mix(in srgb, #1a1510 92%, var(--gold) 8%);
    color: #f5ecd8;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
    transform: translateX(-50%) translateY(6px);
}

.matrix-share-btn:hover::before,
.matrix-share-btn:hover::after,
.matrix-share-btn:focus-visible::before,
.matrix-share-btn:focus-visible::after {
    opacity: 1;
}

.matrix-share-btn:hover::before,
.matrix-share-btn:focus-visible::before {
    transform: translateX(-50%) translateY(0);
}

.matrix-share-btn:hover::after,
.matrix-share-btn:focus-visible::after {
    transform: translateX(-50%) translateY(0);
}

html[data-theme="light"] .matrix-share-btn[data-tooltip]::before {
    border-top-color: color-mix(in srgb, #2c2418 94%, var(--gold) 6%);
}

html[data-theme="light"] .matrix-share-btn[data-tooltip]::after {
    background: color-mix(in srgb, #2c2418 94%, var(--gold) 6%);
    color: #fff8ea;
    box-shadow: 0 4px 12px rgba(60, 45, 20, 0.22);
}

.matrix-share-btn:hover,
.matrix-share-btn:focus-visible {
    background: color-mix(in srgb, var(--gold) 18%, var(--card-bg));
    border-color: color-mix(in srgb, var(--gold) 55%, var(--card-border));
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    outline: none;
}

.matrix-share-btn--copy {
    font-family: inherit;
}

.matrix-share-btn--telegram { color: #229ed9; border-color: color-mix(in srgb, #229ed9 45%, var(--card-border)); }
.matrix-share-btn--whatsapp { color: #25d366; border-color: color-mix(in srgb, #25d366 45%, var(--card-border)); }
.matrix-share-btn--facebook { color: #1877f2; border-color: color-mix(in srgb, #1877f2 45%, var(--card-border)); }
.matrix-share-btn--vk { color: #4c75a3; border-color: color-mix(in srgb, #4c75a3 45%, var(--card-border)); }
.matrix-share-btn--ok { color: #ee8208; border-color: color-mix(in srgb, #ee8208 45%, var(--card-border)); }
.matrix-share-btn--twitter { color: var(--text); border-color: color-mix(in srgb, #111 25%, var(--card-border)); }
.matrix-share-btn--instagram { color: #e4405f; border-color: color-mix(in srgb, #e4405f 45%, var(--card-border)); }
.matrix-share-btn--linkedin { color: #0a66c2; border-color: color-mix(in srgb, #0a66c2 45%, var(--card-border)); }
.matrix-share-btn--threads { color: var(--text); border-color: color-mix(in srgb, #111 25%, var(--card-border)); }
.matrix-share-btn--pinterest { color: #bd081c; border-color: color-mix(in srgb, #bd081c 45%, var(--card-border)); }
.matrix-share-btn--reddit { color: #ff4500; border-color: color-mix(in srgb, #ff4500 45%, var(--card-border)); }
.matrix-share-btn--viber { color: #7360f2; border-color: color-mix(in srgb, #7360f2 45%, var(--card-border)); }
.matrix-share-btn--messenger { color: #0084ff; border-color: color-mix(in srgb, #0084ff 45%, var(--card-border)); }
.matrix-share-btn--truthsocial { color: #5448ee; border-color: color-mix(in srgb, #5448ee 45%, var(--card-border)); }
.matrix-share-btn--email { color: color-mix(in srgb, var(--gold) 80%, var(--text)); }
.matrix-share-btn--copy { color: color-mix(in srgb, var(--gold) 75%, var(--text)); }

.matrix-modal-line {
    font-size: clamp(0.82rem, 2.6vw, 1.05rem);
    line-height: 1.15;
    direction: rtl;
    word-break: break-word;
    padding: 0.55rem 0.45rem;
    border-radius: 10px;
    background: var(--panel-soft, rgba(201, 162, 39, 0.06));
    border: 1px solid var(--card-border);
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.matrix-modal-verse {
    direction: rtl;
    text-align: right;
    line-height: 1.65;
    font-size: 1.05rem;
}

.verse-pair + .verse-pair {
    margin-top: 1rem;
}

.verse-he {
    direction: rtl;
    text-align: right;
    line-height: 1.55;
}

.verse-translation {
    direction: ltr;
    text-align: left;
    margin-top: 0.35rem;
    color: var(--text-muted, #5c5348);
    line-height: 1.5;
    font-size: 0.95rem;
}

.verse-he--context {
    margin-top: 0.35rem;
    font-size: 0.92rem;
    color: var(--text-muted, #5c5348);
}

.result-loc-list {
    margin: 0.5rem 0 0 1rem;
    padding: 0;
    list-style: none;
}

.result-loc-list li + li {
    margin-top: 0.5rem;
}

.gematria-app .matrix-table--results tbody tr.result-row--clickable {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.gematria-app .matrix-table--results tbody tr.result-row--clickable:hover td {
    background: color-mix(in srgb, var(--gold) 10%, transparent);
}

.gematria-app .matrix-table--steps tbody tr.matrix-step-row {
    cursor: pointer;
}

.gematria-app .matrix-table--steps tbody tr.matrix-step-row:hover td,
.gematria-app .matrix-table--steps tbody tr.matrix-step-row--open td {
    background: color-mix(in srgb, var(--gold) 8%, transparent);
}

.gematria-app .matrix-table--steps th:first-child,
.gematria-app .matrix-table--steps td:first-child {
    width: 4rem;
    text-align: center;
}

.gematria-app .matrix-table--steps .matrix-expand-th,
.gematria-app .matrix-table--steps .matrix-expand-cell,
.gematria-app .matrix-table--steps th:nth-child(2),
.gematria-app .matrix-table--steps td:nth-child(2) {
    display: table-cell !important;
    width: auto !important;
    text-align: start;
}

.matrix-expand-control {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.matrix-count-label {
    flex: 1 1 auto;
    font-size: 0.88rem;
    font-weight: 650;
    color: color-mix(in srgb, var(--gold) 68%, var(--text));
    white-space: nowrap;
}

.matrix-expand-arrow {
    display: inline-block;
    flex: 0 0 auto;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
    background: color-mix(in srgb, var(--gold) 10%, transparent);
    position: relative;
    vertical-align: middle;
    transition: transform 0.2s ease, background 0.2s ease;
}

.matrix-expand-arrow::before {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 0.5rem;
    height: 0.5rem;
    border-inline-end: 2px solid var(--gold);
    border-bottom: 2px solid var(--gold);
    transform: rotate(45deg) translate(-0.08rem, -0.08rem);
}

.matrix-step-row--open .matrix-expand-arrow {
    transform: rotate(180deg);
    background: color-mix(in srgb, var(--gold) 22%, transparent);
}

.gematria-app .matrix-table--steps tbody tr.matrix-sources-row > td {
    padding: 0;
    border-bottom: 1px solid var(--card-border);
}

.matrix-sources {
    background: color-mix(in srgb, var(--gold) 6%, var(--card-bg));
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.18);
    padding: 0.7rem 0.9rem;
    animation: matrixSourcesIn 0.22s ease;
}

html[data-theme="light"] .matrix-sources {
    box-shadow: inset 0 2px 8px rgba(120, 90, 20, 0.12);
}

@keyframes matrixSourcesIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.matrix-sources-loading {
    min-height: 3.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    color: color-mix(in srgb, var(--gold) 76%, var(--text));
    font-size: 0.85rem;
    font-weight: 650;
    padding: 0.55rem 0.2rem;
}

.matrix-sources-loading__spinner {
    position: relative;
    width: 1.55rem;
    height: 1.55rem;
    flex: 0 0 1.55rem;
    border: 2px solid color-mix(in srgb, var(--gold) 22%, transparent);
    border-top-color: var(--gold);
    border-radius: 50%;
    box-shadow: 0 0 12px color-mix(in srgb, var(--gold) 18%, transparent);
    animation: matrixSourcesSpin 0.72s linear infinite;
}

.matrix-sources-loading__spinner::after {
    content: "";
    position: absolute;
    inset: 0.28rem;
    border-radius: 50%;
    background: color-mix(in srgb, var(--gold) 74%, transparent);
    animation: matrixSourcesCore 0.9s ease-in-out infinite;
}

.matrix-sources-loading__text {
    animation: gem-loader-pulse 1.25s ease-in-out infinite;
}

.matrix-step-row--loading .matrix-expand-arrow {
    animation: matrixSourcesArrowPulse 0.85s ease-in-out infinite;
}

@keyframes matrixSourcesSpin {
    to { transform: rotate(360deg); }
}

@keyframes matrixSourcesCore {
    0%, 100% { opacity: 0.35; transform: scale(0.72); }
    50% { opacity: 0.9; transform: scale(1); }
}

@keyframes matrixSourcesArrowPulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--gold) 32%, transparent); }
    50% { box-shadow: 0 0 0 5px transparent; }
}

.matrix-source-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.45rem;
}

.matrix-source-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.5rem 0.7rem;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: color-mix(in srgb, var(--gold) 4%, var(--card-bg));
}

.matrix-source-item--clickable {
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.matrix-source-item--clickable:hover,
.matrix-source-item--clickable:focus-visible {
    background: color-mix(in srgb, var(--gold) 14%, var(--card-bg));
    border-color: color-mix(in srgb, var(--gold) 55%, transparent);
    transform: translateY(-1px);
    outline: none;
}

.matrix-source-num {
    flex: 0 0 auto;
    min-width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--gold);
    border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent);
    background: color-mix(in srgb, var(--gold) 10%, transparent);
}

.matrix-source-ref {
    flex: 1 1 auto;
}

.matrix-source-go {
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    border-inline-end: 2px solid var(--gold);
    border-bottom: 2px solid var(--gold);
    transform: rotate(-45deg);
    opacity: 0.75;
}

.matrix-source-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    margin-top: 0.65rem;
    padding-top: 0.6rem;
    border-top: 1px solid color-mix(in srgb, var(--gold) 22%, transparent);
}

.matrix-source-page-btn {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--gold) 42%, var(--card-border));
    border-radius: 50%;
    background: color-mix(in srgb, var(--gold) 9%, var(--card-bg));
    color: var(--gold);
    font: inherit;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.matrix-source-page-btn:hover:not(:disabled),
.matrix-source-page-btn:focus-visible:not(:disabled) {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--gold) 18%, var(--card-bg));
    border-color: color-mix(in srgb, var(--gold) 66%, var(--card-border));
    outline: none;
}

.matrix-source-page-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.matrix-source-page-status {
    min-width: 4.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: color-mix(in srgb, var(--gold) 64%, var(--text));
    text-align: center;
}

[dir="rtl"] .matrix-source-go {
    transform: rotate(135deg);
}

.gem-phrase-mark {
    background: #e8c547;
    color: #0a0a0c;
    font-weight: 700;
    padding: 0.08em 0.22em;
    border-radius: 0.28em;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    box-shadow: 0 0 0 1px color-mix(in srgb, #e8c547 70%, #0a0a0c);
}

html[data-theme="light"] .gem-phrase-mark {
    background: color-mix(in srgb, var(--gold) 55%, #fff3cc);
    color: #1c1914;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--gold) 40%, transparent);
}

.result-modal-phrase {
    padding: 1rem 0.9rem;
    border-radius: 12px;
    background: #1a1f27;
    border: 1px solid var(--card-border);
}

html[data-theme="light"] .result-modal-phrase {
    background: #faf0dc;
}

.result-modal-phrase .verse-he {
    font-size: clamp(1.1rem, 4vw, 1.35rem);
    line-height: 1.65;
}

.result-modal-sources {
    margin-top: 1.1rem;
}

.result-modal-sources-title {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--gold);
    margin-bottom: 0.45rem;
}

.result-modal-source-line {
    padding: 0.7rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: color-mix(in srgb, var(--gold) 5%, var(--card-bg));
}

.result-modal-source-line + .result-modal-source-line {
    margin-top: 0.5rem;
}

.result-modal-source-line--clickable {
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.result-modal-source-line--clickable:hover {
    border-color: color-mix(in srgb, var(--gold) 55%, var(--card-border));
    background: color-mix(in srgb, var(--gold) 12%, var(--card-bg));
}

.result-modal-source-line--active {
    border-color: color-mix(in srgb, var(--gold) 65%, var(--card-border));
    background: color-mix(in srgb, var(--gold) 16%, var(--card-bg));
    box-shadow: inset 3px 0 0 var(--gold);
}

.result-loc-list li.result-loc-item {
    cursor: pointer;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.result-loc-list li.result-loc-item:hover {
    background: color-mix(in srgb, var(--gold) 12%, var(--table-bg));
    border-color: color-mix(in srgb, var(--gold) 35%, var(--table-border));
}

.verse-translation--phrase {
    margin-top: 0.5rem;
}

.gematria-app .matrix-table .verse-he,
.gematria-app .matrix-table .verse-translation {
    max-width: 100%;
}

@media (max-width: 520px) {
    .gematria-app .matrix-table--steps th:first-child,
    .gematria-app .matrix-table--steps td:first-child {
        width: 3.5rem;
    }

    .gematria-app .matrix-table--steps .matrix-expand-th,
    .gematria-app .matrix-table--steps .matrix-expand-cell {
        width: auto !important;
    }

    .matrix-sources {
        padding: 0.55rem 0.6rem;
    }

    .matrix-count-label {
        font-size: 0.82rem;
    }
}

.fade-in {
    animation: gem-fade-in 0.5s ease-in-out;
}

@keyframes gem-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.gem-about h1,
.gem-about h2,
.gem-about h3 {
    font-family: "Cormorant Garamond", Georgia, serif;
    color: var(--gold);
}

.gem-about h1 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    text-align: center;
    margin-top: 0;
}

.gem-about h2 {
    font-size: 1.35rem;
    margin-top: 2rem;
}

.gem-about h3 {
    font-size: 1.1rem;
    margin-top: 1.5rem;
}

.gem-about p,
.gem-about li {
    line-height: 1.65;
}

.gem-about-notice {
    margin: 1.25rem 0 1.75rem;
    padding: 1rem 1.15rem;
    border-radius: 10px;
    border: 1px solid var(--gold, #c9a227);
    background: var(--panel-soft, rgba(201, 162, 39, 0.08));
    line-height: 1.6;
}

.gem-about table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0 1.5rem;
    font-size: 0.84rem;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
}

.gem-about td {
    border: 1px solid var(--card-border);
    padding: 0.4rem 0.8rem;
    text-align: center;
}

.gem-about-footer {
    margin-top: 28px;
    text-align: center;
}

.gematria-systems-help {
    font-size: 0.65em;
    vertical-align: super;
}

/* Matrix verse popup — local fallback if /css/gematria-site.css is slow */
.gematria-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0, 0, 0, 0.65);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.gematria-modal.show {
    display: flex;
}

.gematria-modal__content {
    position: relative;
    max-width: 36rem;
    width: 100%;
    max-height: 80vh;
    overflow: auto;
    padding: 1.25rem 1.5rem;
    border-radius: 14px;
    background: var(--card-bg, #1a1a1f);
    border: 1px solid var(--card-border, rgba(201, 162, 39, 0.35));
    color: var(--text, #f0ebe3);
}

.gematria-modal__close {
    position: absolute;
    top: 0.5rem;
    right: 0.65rem;
    border: none;
    background: transparent;
    color: var(--muted, #a89f8f);
    font-size: 1.1rem;
    cursor: pointer;
}

.gematria-modal__body {
    direction: rtl;
    text-align: right;
    font-family: "Heebo", "Rubik", "Noto Sans Hebrew", serif;
    line-height: 1.6;
}
