/* ==========================================================================
   I-Ging Hexagramm-Matrix
   Erzeugt vom Generator tools/gen_iging_matrix.py — Struktur dort,
   hier nur das Aussehen.
   ========================================================================== */

#hexagramm-matrix {
    margin-top: 2.5rem;
}

/* Nur fuer Screenreader sichtbar (im Repo noch nicht vorhanden). */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#hexagramm-matrix h2 {
    margin-bottom: 0.5rem;
}

.mx-intro {
    max-width: 68ch;
    color: var(--text-dim, #b9b3c7);
    margin-bottom: 1.5rem;
}

/* --- Auswahl: unteres / oberes Trigramm ------------------------------- */

.mx-picker {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.25rem;
    /* Grid-Items haben min-width:auto und wachsen sonst auf die
       Content-Breite. Die Trigram-Reihe ist auf Mobil bewusst
       horizontal scrollbar (overflow-x:auto) — ohne min-width:0
       waechst sie auf 653px und die ganze Seite bekommt 313px
       horizontalen Ueberlauf. */
    min-width: 0;
}

.mx-picker-group {
    background: var(--color-bg-card);
    border: 1px solid rgba(212, 169, 68, 0.14);
    border-radius: 12px;
    padding: 0.85rem 1rem 1rem;
    min-width: 0;
}

.mx-picker-label {
    display: block;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold, #d4af6a);
    margin-bottom: 0.65rem;
}

.mx-picker-label em {
    font-style: normal;
    color: var(--text-dim, #b9b3c7);
    text-transform: none;
    letter-spacing: 0.02em;
}

.mx-trigram-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.mx-trigram {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 169, 68, 0.20);
    border-radius: 999px;
    padding: 0.4rem 0.8rem 0.4rem 0.6rem;
    color: var(--text, #ece8f4);
    font: inherit;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.mx-trigram:hover {
    background: rgba(212, 175, 106, 0.16);
    border-color: rgba(212, 175, 106, 0.55);
}

.mx-trigram:focus-visible {
    outline: 2px solid var(--gold, #d4af6a);
    outline-offset: 2px;
}

.mx-trigram[aria-pressed="true"] {
    background: rgba(212, 175, 106, 0.26);
    border-color: var(--gold, #d4af6a);
    box-shadow: 0 0 0 1px rgba(212, 175, 106, 0.35) inset;
}

.mx-trigram-glyph {
    font-size: 1.35rem;
    line-height: 1;
    color: var(--gold, #d4af6a);
}

.mx-trigram-name {
    white-space: nowrap;
}

/* --- Ergebnisfeld ------------------------------------------------------ */

.mx-result {
    min-height: 3.25rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    background: var(--color-bg-card);
    border: 1px solid rgba(212, 169, 68, 0.35);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
}

.mx-result-hint {
    color: var(--text-dim, #b9b3c7);
    font-size: 0.94rem;
}

.mx-result.is-active {
    background: var(--color-bg-card);
    border-color: var(--color-gold);
    box-shadow: 0 0 18px rgba(212, 169, 68, 0.28);
}

.mx-result-lines {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    padding: 2px 0;
}

.mx-result-nr {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gold, #d4af6a);
    line-height: 1;
}

.mx-result-name {
    font-size: 1.02rem;
    font-weight: 600;
}

.mx-result-link {
    margin-left: auto;
    color: var(--gold, #d4af6a);
    font-size: 0.92rem;
    white-space: nowrap;
}

/* --- Die Matrix -------------------------------------------------------- */

.mx-wrap {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Eigenes Panel: ohne opake Flaeche schimmert das Hintergrundbild
       durch die Matrix und macht die Zellen unlesbar. */
    background: var(--color-bg);
    border: 1px solid rgba(212, 169, 68, 0.14);
    border-radius: 12px;
    padding: 0.6rem;
}

/* --- Scroll-Hinweis (mobil) -------------------------------------------
   Ohne sichtbaren Hinweis scrollt niemand — der Bereich sieht voll aus.
   Die Kante rechts blendet aus, damit klar wird, dass noch etwas kommt. */
.mx-scroll-hint {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin: 0.6rem 0 0;
    padding: 0.45rem 0.7rem;
    background: rgba(212, 169, 68, 0.10);
    border: 1px solid rgba(212, 169, 68, 0.28);
    border-radius: 999px;
    color: var(--color-gold, #d4a944);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    text-align: center;
}

.mx-scroll-hint::before,
.mx-scroll-hint::after {
    content: '\2194';
    font-size: 1rem;
    line-height: 1;
}

/* Weiche Ausblendung an der rechten Kante, solange links nicht gescrollt. */
.mx-wrap::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
    float: right;
    width: 26px;
    height: 100%;
    margin-left: -26px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(13, 13, 26, 0.92));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mx-wrap.can-scroll-right::after {
    opacity: 1;
}

.mx-wrap.at-end::after {
    opacity: 0;
}

.mx-table {
    width: 100%;
    min-width: 640px;
    border-collapse: separate;
    border-spacing: 4px;
    table-layout: fixed;
}

.mx-corner {
    width: 8.5%;
}

.mx-head {
    background: var(--color-bg-card);
    border-radius: 8px;
    padding: 0.4rem 0.25rem;
    text-align: center;
    font-weight: 500;
}

.mx-head .mx-trigram-glyph {
    display: block;
    font-size: 1.2rem;
}

.mx-head .mx-trigram-name {
    display: block;
    font-size: 0.68rem;
    color: var(--text-dim, #b9b3c7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mx-head-lower {
    text-align: right;
    padding-right: 0.5rem;
}

.mx-head-lower .mx-trigram-glyph,
.mx-head-lower .mx-trigram-name {
    display: inline-block;
    vertical-align: middle;
}

.mx-cell {
    padding: 0;
    background: var(--color-bg-card);
    border: 1px solid rgba(212, 169, 68, 0.10);
    border-radius: 8px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.mx-cell-link {
    display: block;
    padding: 0.5rem 0.35rem;
    text-decoration: none;
    color: inherit;
}

.mx-cell-link:focus-visible {
    outline: 2px solid var(--gold, #d4af6a);
    outline-offset: -2px;
}

/* --- Linien-Glyphen (yang = durchgehend, yin = geteilt) ---------------- */

.mx-line {
    display: block;
    height: 4px;
    width: 100%;
    background: var(--text, #ece8f4);
    border-radius: 2px;
}

.mx-yin {
    display: flex;
    gap: 22%;
    background: transparent;
}

.mx-yin i {
    display: block;
    height: 4px;
    flex: 1;
    background: var(--text, #ece8f4);
    border-radius: 2px;
}

.mx-cell-lines {
    display: flex;
    flex-direction: column-reverse; /* Linie 1 (unten) steht unten */
    gap: 2px;
    margin-bottom: 0.35rem;
}

.mx-cell-nr {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--gold, #d4af6a);
}

.mx-cell-name {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim, #b9b3c7);
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.mx-cell:hover {
    background: var(--color-secondary);
    border-color: var(--color-gold);
}

/* --- Hervorhebung der gewählten Zelle --------------------------------- */

.mx-cell.is-match {
    background: var(--color-secondary);
    border-color: var(--color-gold);
    box-shadow: 0 0 14px rgba(212, 169, 68, 0.45);
}

.mx-cell.is-match .mx-cell-name {
    color: var(--text, #ece8f4);
}

/* Nur den Inakt dimmen. Die Zelle selbst bleibt deckend —
   opacity auf der Zelle wuerde auch ihren Hintergrund durchsichtig machen. */
.mx-cell.is-dimmed .mx-cell-link {
    opacity: 0.42;
}

.mx-cell.is-dimmed .mx-cell-link {
    pointer-events: none;
}

/* --- Legende ----------------------------------------------------------- */

.mx-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-dim, #b9b3c7);
}

.mx-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.mx-legend .mx-line {
    width: 34px;
    flex: none;
}

/* --- Mobil ------------------------------------------------------------- */

@media (max-width: 640px) {
    .mx-result {
        flex-wrap: wrap;
    }

    .mx-result-link {
        margin-left: 0;
        width: 100%;
    }

    .mx-trigram {
        padding: 0.35rem 0.65rem 0.35rem 0.5rem;
        font-size: 0.84rem;
    }

    .mx-trigram-glyph {
        font-size: 1.15rem;
    }

    /* Tabelle kompakter: weniger Zellhoehe, damit die Matrix auf
       dem Handy nicht ueber eine Seite hinauslaeuft. */
    .mx-table {
        min-width: 520px;
        border-spacing: 3px;
    }

    .mx-head {
        padding: 0.3rem 0.2rem;
    }

    .mx-head .mx-trigram-glyph {
        font-size: 1rem;
    }

    .mx-head .mx-trigram-name {
        display: none;
    }

    .mx-cell-link {
        padding: 0.35rem 0.25rem;
    }

    .mx-cell-lines {
        gap: 1px;
        margin-bottom: 0.25rem;
    }

    .mx-line {
        height: 3px;
    }

    .mx-yin i {
        height: 3px;
    }

    .mx-cell-nr {
        font-size: 0.75rem;
    }

    .mx-cell-name {
        font-size: 0.62rem;
        -webkit-line-clamp: 2;
    }

    /* Picker: eine scrollbare Reihe statt drei umgebrochene.
       Spart auf dem Handy deutlich hoehe. */
    .mx-trigram-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.35rem;
        scrollbar-width: thin;
        /* Ohne min-width:0 waechst die scrollbare Reihe auf ihre
           Content-Breite (653px) statt im Container zu scrollen. */
        min-width: 0;
        max-width: 100%;
    }

    .mx-trigram {
        flex: none;
    }

    /* Scroll-Hinweis nur mobil zeigen — auf Desktop ist die Matrix
       voll sichtbar und der Hinweis waere irrefuehrend. */
    .mx-scroll-hint {
        display: flex;
    }

    .mx-wrap {
        /* Sichtbare Scrollbar, damit der Bereich als scrollbar erkennbar ist */
        scrollbar-width: thin;
        scrollbar-color: rgba(212, 169, 68, 0.6) rgba(212, 169, 68, 0.12);
    }

    .mx-wrap::-webkit-scrollbar {
        height: 8px;
    }

    .mx-wrap::-webkit-scrollbar-track {
        background: rgba(212, 169, 68, 0.12);
        border-radius: 999px;
    }

    .mx-wrap::-webkit-scrollbar-thumb {
        background: rgba(212, 169, 68, 0.6);
        border-radius: 999px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mx-cell,
    .mx-trigram {
        transition: none;
    }
}
