/* ============================================================================
   widgets/bio.css  --  the interactive figures on the lecture and notes pages
   (sequence alignment, BWT, motif finding, ...). One stylesheet for all of them.

   Loaded by the _metadata.yml of each section that has these widgets
   (lectures/1, notes/2/1).

   Structure
     1. .bio-widget    the figure itself: color roles, mono text, tables
     2. .bio-controls  the row of inputs above a figure
     3. Page options   switches set per page with `body-classes:` in the
                       page's front matter (nothing here needs editing to
                       change one page)

   Page options
     bio-outlined   outlined buttons and text inputs in .bio-controls
                    (the lecture look; without it the controls take the
                    site-wide Observable skin from base/site.css)
     bio-mono-lg    larger, wider-spaced .bio-mono text   (L1.3)
     bio-mono-xl    largest .bio-mono text                (L1.6)

   All colors derive from --bs-body-color, which Quarto sets per theme and
   updates on a light/dark toggle, so the widgets stay legible in both.
   ==========================================================================*/


/* ------------------------------------------------------------- 1. Widget */

.bio-widget {
    --bio-neutral: var(--bs-body-color, #1f2937);
    /* 70%, not 60%: at 60% the muted gray lands at 4.06:1 against a white body
       background, which fails WCAG AA for normal-size text. 70% gives 5.53:1 in
       light mode and 8.80:1 in dark. */
    --bio-muted: color-mix(in srgb, var(--bs-body-color, #1f2937) 70%, transparent);

    /* Column colors are consistent across widgets:
         c1  substitution / mismatch        c2  insertion
         c3  deletion / gap / current cell  c4  main highlight */
    --bio-c1: color-mix(in srgb, #ea580c 68%, var(--bs-body-color, #1f2937));
    --bio-c2: color-mix(in srgb, #059669 68%, var(--bs-body-color, #1f2937));
    --bio-c3: color-mix(in srgb, #dc2626 68%, var(--bs-body-color, #1f2937));
    --bio-c4: color-mix(in srgb, #2563eb 68%, var(--bs-body-color, #1f2937));
    margin-block: 1rem;
}

/* Center the visual outputs within their container; text panels stay left-aligned. */
.bio-widget svg,
.bio-widget canvas {
    display: block;
    margin-inline: auto;
    max-width: 100%;
}

/* ---- monospace text: sequences, one row per line ---- */
.bio-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: var(--bio-mono-size, 1.05rem);
    letter-spacing: var(--bio-mono-tracking, 0.12em);
    white-space: pre;
    overflow-x: auto;
    color: var(--bio-neutral);
}

.bio-mono2 {
    letter-spacing: 0.16em;
    font-size: 1.05rem;
}

/* ---- alignment rows as a grid: one fixed-width column per alignment column,
   so the three rows line up by structure, not by font metrics ---- */
.bio-aln {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(3, auto);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.15rem;
    line-height: 1.4;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    margin-inline: auto;
}

.bio-aln>span {
    text-align: center;
}

.bio-grid {
    margin-inline: auto;
}

/* ---- BWT tables: one row per rotation ---- */
.bio-table {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    width: max-content;
    max-width: 100%;
}

.bio-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 1px 4px;
    white-space: pre;
    border-radius: 3px;
}

.bio-idx {
    color: var(--bio-muted);
    font-size: 0.72rem;
    width: 1.3rem;
    text-align: right;
}

.bio-cap {
    font-size: 0.8rem;
    color: var(--bio-muted);
    margin-bottom: 0.3rem;
}

.bio-note {
    color: var(--bio-muted);
    font-size: 0.9rem;
}

.bio-flex {
    display: flex;
    gap: 1.6rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.bio-sortmark {
    align-self: center;
    color: var(--bio-muted);
    font-size: 1.4rem;
    padding: 0 0.2rem;
}

/* ---- numeric matrices ---- */
.bio-mat {
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: ui-monospace, monospace;
}

.bio-mat td,
.bio-mat th {
    /* larger figures need a little more room between matrix cells */
    padding: 5px 10px;
    text-align: right;
}

.bio-mat th {
    color: var(--bio-muted);
    font-weight: 500;
    font-size: 0.78rem;
}

/* ---- a checkbox whose label wraps: keep the box pinned to line 1 ---- */
.bio-toggle-wide {
    --input-width: 100%;
}

.bio-toggle-wide label {
    max-width: none !important;
    white-space: normal !important;
    align-items: flex-start !important;
}


/* ---------------------------------------------------------- 2. Controls */

.bio-controls {
    margin-bottom: 1rem;
}

/* enough room for a short phrase, so "Generate again" and "Reveal path"
   do not wrap onto a second line */
.bio-controls label {
    min-width: 8ch;
}


/* ------------------------------------------------------ 3. Page options
   :where() keeps these at the specificity of a plain class selector, so they
   compete with the site-wide Observable skin exactly as a page-local
   <style> block used to. */

:where(.bio-outlined) .bio-controls button {
    color: var(--bs-body-color);
    background: color-mix(in srgb, var(--bs-body-color) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--bs-body-color) 35%, transparent);
    border-radius: 6px;
    padding: 0.25rem 0.7rem;
    cursor: pointer;
}

:where(.bio-outlined) .bio-controls button:hover {
    background: color-mix(in srgb, var(--bs-body-color) 18%, transparent);
}

:where(.bio-outlined) .bio-controls input,
:where(.bio-outlined) .bio-controls select,
:where(.bio-outlined) .bio-controls label {
    color: var(--bs-body-color);
}

:where(.bio-outlined) .bio-controls input[type="text"] {
    background: color-mix(in srgb, var(--bs-body-color) 6%, transparent);
    border: 1px solid color-mix(in srgb, var(--bs-body-color) 30%, transparent);
    border-radius: 5px;
    padding: 0.2rem 0.45rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.08em;
}

.bio-mono-lg {
    --bio-mono-size: 1.15rem;
    --bio-mono-tracking: 0.18em;
}

.bio-mono-xl {
    --bio-mono-size: 1.2rem;
    --bio-mono-tracking: 0.22em;
}
