/* Topics view (views/topics-view.js): the grid of subjects by years and the treemap of shares.
   Colours follow design.md: one topic tone from --color-role-topic for non-language subjects, because hues
   mean the language of letters in every other figure; --color-primary only for the chosen subject
   and for what can be pressed. The cells lie on a canvas above the row options, which carry name,
   focus and pointer. */

#topics-view.active {
    min-height: 0;
}

/* The four shades of the grid, from the shared topic tone. Wider apart than the heatmap scale
   (--color-scale-*), whose upper two steps a first-time reader could not tell apart in the grid
   (a year of six letters read as "10 und mehr"); the top step leans
   towards ink, so the darkest shade stays apart from the one below it. */
#topics-view {
    --tp-step-1: color-mix(in srgb, var(--color-role-topic) 18%, var(--color-bg));
    --tp-step-2: color-mix(in srgb, var(--color-role-topic) 40%, var(--color-bg));
    --tp-step-3: color-mix(in srgb, var(--color-role-topic) 66%, var(--color-bg));
    --tp-step-4: color-mix(in srgb, var(--color-role-topic) 55%, var(--color-text));
}

.tp-variants {
    display: flex;
    gap: 2px;
}

.tp-btn {
    min-height: 28px;
    padding: var(--space-xs) var(--space-sm);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-light);
    font: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition-fast);
    transition-property: var(--transition-properties);
}

.tp-btn:hover {
    color: var(--color-primary-dark);
    background: var(--color-bg-light);
}

.tp-btn[aria-pressed="true"] {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-weight: 600;
}

/* The figure fills the space under the header; strip and table follow below it */
.tp-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 0 var(--space-xs);
}

/* The controls of the figure in one line at its top: search, order, key */
.tp-bar {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-lg);
    padding: var(--space-sm) var(--space-lg) var(--space-xs);
}

.tp-search {
    width: 13rem;
    max-width: 100%;
    min-height: 28px;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-border-control);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    font: inherit;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.tp-order {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
}

.tp-order__label {
    margin-right: var(--space-xs);
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
}

.tp-key {
    flex: 1 1 auto;
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
}

/* One line of key that wraps like text */
.tp-key__line {
    display: block;
    text-align: right;
}

.tp-key__swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: var(--space-xs);
    border-radius: 2px;
    vertical-align: -1px;
}

.tp-key__swatch--s1 { background: var(--tp-step-1); }
.tp-key__swatch--s2 { background: var(--tp-step-2); }
.tp-key__swatch--s3 { background: var(--tp-step-3); }
.tp-key__swatch--s4 { background: var(--tp-step-4); }

/* The mark of the year of the most letters, as the canvas draws it under the cell */
.tp-key__peak {
    display: inline-block;
    width: 12px;
    height: 3px;
    margin-left: var(--space-sm);
    background: var(--color-text);
    vertical-align: 1px;
}

/* The years: a tick for every year, a label at round years, the scale over the bar column */
.tp-axis {
    position: relative;
    flex: none;
    height: 22px;
    border-bottom: 1px solid var(--color-border-light);
}

.tp-axis__ticks {
    position: absolute;
    left: 0;
    top: 0;
}

.tp-axis__ticks path {
    stroke: var(--color-border-control);
    stroke-width: 1;
}

.tp-axis__year {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    font-size: var(--font-size-xs);
    line-height: 12px;
    color: var(--color-text-light);
    font-variant-numeric: tabular-nums;
    background: var(--color-bg);
    padding: 0 2px;
}

.tp-axis__bar {
    position: absolute;
    top: 0;
    font-size: var(--font-size-xs);
    line-height: 14px;
    color: var(--color-text-light);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.tp-figure {
    position: relative;
    flex: 1;
    min-height: 240px;
}

.tp-scroll {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tp-rows {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tp-row {
    display: flex;
    align-items: flex-end;
    height: var(--tp-pitch, 26px);
    padding: 0 0 4px var(--space-lg);
    font-size: var(--font-size-xs);
    line-height: 1.2;
    color: var(--color-text);
    cursor: pointer;
}

.tp-row__name {
    display: block;
    width: calc(var(--tp-name-width, 200px) - var(--space-lg));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tp-row:hover {
    background: var(--color-bg-light);
}

.tp-row:focus-visible {
    outline-offset: -3px;
}

/* The chosen row as the chosen rows of the lists: light rust and a rust stripe at the left edge */
.tp-row--chosen {
    background: var(--color-primary-light);
    border-left: 3px solid var(--color-primary);
    padding-left: calc(var(--space-lg) - 3px);
}

/* Narrow: the name stands on the upper part of the row, the cells below it */
.tp-rows--narrow .tp-row {
    align-items: flex-start;
    padding: 2px var(--space-sm) 0 12px;
}

.tp-rows--narrow .tp-row.tp-row--chosen {
    padding-left: 9px;
}

.tp-rows--narrow .tp-row__name {
    width: 100%;
}

.tp-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: var(--z-raised);
    pointer-events: none;
}

.tp-tooltip {
    position: absolute;
    z-index: var(--z-raised);
    max-width: 320px;
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-text);
    color: var(--color-bg-light);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    pointer-events: none;
}

.tp-empty {
    position: absolute;
    inset: var(--space-xl) var(--space-lg) auto;
    margin: 0;
    color: var(--color-text-light);
}

/* The chosen subject: a quiet strip under the figure, separated by a hairline */
.tp-choice {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-lg);
    padding: var(--space-sm) var(--space-lg);
    border-top: 1px solid var(--color-border-light);
    font-size: var(--font-size-sm);
}

.tp-choice__group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-sm);
    min-width: 0;
}

.tp-choice__label {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
}

.tp-mark {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    min-height: 24px;
    padding: 0 var(--space-xs);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    color: var(--color-text);
    cursor: pointer;
    flex-shrink: 0;
}

.tp-mark:hover {
    background: var(--color-bg-light);
    color: var(--color-primary-dark);
}

.tp-mark circle {
    fill: var(--color-role-topic);
}

.tp-mark[aria-pressed="true"] {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-weight: 600;
}

.tp-mark[aria-pressed="true"] circle {
    fill: var(--color-primary);
}

.tp-mark__name {
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tp-table {
    flex: none;
    padding: 0 var(--space-lg);
}

/* An open table takes at most a third of the view, the figure keeps the rest */
.tp-table .chart-table__scroll {
    max-height: 30vh;
}

/* Treemap: areas in the neutral data tone; the kind of subject is a group with its name, not a
   hue, because hues mean the language of letters in every other figure */
.tp-map {
    display: flex;
    flex-direction: column;
    position: relative;
    flex: 1;
    min-height: 240px;
    margin: var(--space-xs) var(--space-lg) 0;
}

.tp-map__areas {
    flex: 1;
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tp-area {
    position: absolute;
    overflow: hidden;
    padding: 0;
    box-shadow: inset 0 0 0 .5px var(--color-bg);
    /* --tp-hue: the colour of a subject named like a language (topics-view.js, rule 5) */
    background: color-mix(in srgb, var(--tp-hue, var(--color-role-topic)) 22%, var(--color-bg));
    font-size: var(--font-size-xs);
    line-height: 1.25;
    color: var(--color-text);
    cursor: pointer;
}

.tp-area:hover {
    background: color-mix(in srgb, var(--tp-hue, var(--color-role-topic)) 36%, var(--color-bg));
}

.tp-area:focus-visible {
    outline-offset: -3px;
}

.tp-area__name {
    margin: 2px var(--space-xs);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tp-area--chosen,
.tp-area--chosen:hover {
    background: var(--color-primary-light);
    border: 2px solid var(--color-primary);
    color: var(--color-primary-dark);
}

.tp-map__groups {
    display: flex;
    gap: var(--space-sm);
}

.tp-map__group {
    min-height: 28px;
    margin-bottom: var(--space-xs);
    padding: 0 var(--space-xs);
    border: 1px solid var(--color-border-control);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-link);
    font: inherit;
    font-size: var(--font-size-xs);
    cursor: pointer;
}

.tp-map__group[aria-pressed="true"] {
    text-decoration: underline;
    font-weight: bold;
}

.tp-map__note {
    flex: none;
    margin: 0;
    padding: var(--space-xs) var(--space-lg);
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
}

.tp-map__back {
    min-height: 24px;
    padding: 0 var(--space-xs);
    border: none;
    background: transparent;
    font: inherit;
    color: var(--color-link);
    cursor: pointer;
}

/* The course of the chosen subject below the map: its row of the grid, in the steps the grid
   gives the chosen row */
.tp-course {
    flex: 1 1 16rem;
    flex-wrap: nowrap;
}

.tp-course__cells {
    flex: 1;
    min-width: 8rem;
    height: 16px;
}

.tp-course__base { fill: var(--color-border-light); }
.tp-course__s1 { fill: var(--color-primary); fill-opacity: 0.3; }
.tp-course__s2 { fill: var(--color-primary); fill-opacity: 0.5; }
.tp-course__s3 { fill: var(--color-primary); fill-opacity: 0.75; }
.tp-course__s4 { fill: var(--color-primary); }

@media (max-width: 767px) {
    .tp-bar {
        padding-inline: 12px;
    }

    .tp-search {
        width: 100%;
    }

    /* The three orders fit one line without their label, which stays for screen readers */
    .tp-order__label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .tp-key__line {
        text-align: left;
    }

    /* The figure keeps a readable height; strip and table follow below it within the view */
    .tp-stage {
        overflow-y: auto;
    }

    .tp-figure,
    .tp-map {
        flex: 1 0 300px;
    }

    .tp-map {
        margin-inline: 12px;
    }

    .tp-choice {
        padding-inline: 12px;
        gap: var(--space-xs) var(--space-md);
    }

    .tp-mark__name {
        max-width: 11rem;
    }
}
