.board-treemap {
    --map-header: 22px;
    position: relative;
    width: 100%;
    height: clamp(340px, 34vw, 460px);
    isolation: isolate;
}

.board-map-group,
.board-map-stock {
    position: absolute;
    left: var(--map-x);
    top: var(--map-y);
    width: calc(var(--map-w) - 3px);
    height: calc(var(--map-h) - 3px);
    min-width: 0;
    box-sizing: border-box;
}

.board-map-group {
    border: 1px solid #34434c;
    border-radius: 6px;
    background: #172229;
    transition: border-color .16s ease;
}

.board-map-group.filter-selected {
    border-color: #8fc8f7;
    box-shadow: 0 0 0 1px #8fc8f752;
    z-index: 1;
}

.board-map-group.filter-other:not(:hover) .board-map-stock:not([aria-pressed="true"]) {
    filter: saturate(.5) brightness(.8);
}

.board-map-sector,
.board-map-stock {
    border: 0;
    padding: 0;
    color: #f3f7fb;
    appearance: none;
    text-align: left;
    cursor: pointer;
}

.board-map-sector {
    display: flex;
    width: 100%;
    height: var(--map-header);
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 0 6px;
    border-radius: 5px 5px 0 0;
    background: #19262e;
    color: #d7e2ea;
    font-size: 11.5px;
    line-height: 1.15;
}

.board-map-sector span,
.board-map-stock span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.board-map-sector small {
    flex: none;
    color: #b1c3cf;
    font-size: 10px;
    white-space: nowrap;
}

.board-map-sector:hover,
.board-map-sector[aria-pressed="true"] {
    background: #294252;
    color: white;
}

.board-map-members {
    position: absolute;
    inset: calc(var(--map-header) + 1px) 1px 0 1px;
}

.board-map-stock {
    --heat: #42505a;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    width: calc(var(--map-w) - 2px);
    height: calc(var(--map-h) - 2px);
    overflow: hidden;
    padding: 2px 4px;
    border: 1px solid #f3f7fb24;
    border-radius: 3px;
    background: #263640;
    background: color-mix(in srgb, var(--heat) var(--heat-level), #223039);
    line-height: 1.05;
}

.board-map-stock.tone-rise { --heat: #b44740; }
.board-map-stock.tone-fall { --heat: #1d876c; }
.board-map-stock.tone-unknown {
    background: repeating-linear-gradient(135deg, #293640, #293640 5px, #25323b 5px, #25323b 10px);
}

.board-map-stock span {
    display: block;
    width: 100%;
    font-size: clamp(10px, .85vw, 13px);
    font-weight: 600;
}

.board-map-stock b {
    font-family: var(--mono, monospace);
    font-variant-numeric: tabular-nums;
    font-size: clamp(10px, 1vw, 15px);
    white-space: nowrap;
}

.board-map-stock[aria-pressed="true"] {
    box-shadow: inset 0 0 0 2px #e8f4ff;
    z-index: 2;
}

.board-map-stock:hover {
    z-index: 3;
    border-color: #e9f4ff;
    filter: brightness(1.2);
}

.board-map-group:focus-within { z-index: 4; }
.board-map-sector:focus-visible,
.board-map-stock:focus-visible {
    outline: 2px solid #f1db8a;
    outline-offset: -2px;
    z-index: 4;
}

.board-map-stock[data-flash="up"] { animation: board-map-rising .8s ease-out; }
.board-map-stock[data-flash="down"] { animation: board-map-falling .8s ease-out; }
@keyframes board-map-rising {
    from { box-shadow: inset 0 0 0 2px #ffc0ad, inset 0 0 25px #ffc0ad80; }
}
@keyframes board-map-falling {
    from { box-shadow: inset 0 0 0 2px #92f1cf, inset 0 0 25px #92f1cf80; }
}

.board-map-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 13px;
    padding-top: 7px;
    color: #aebfce;
    font-size: 11px;
    line-height: 1.35;
}

.board-map-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.board-map-legend i {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: #667987;
}

.board-map-legend .legend-rise i { background: #ca6155; }
.board-map-legend .legend-fall i { background: #34a383; }
.board-map-empty { padding: 45px 15px; text-align: center; color: #adbdc9; }

@media (max-width: 600px) {
    .board-treemap {
        display: grid;
        height: auto;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 5px;
        align-items: start;
        max-height: 420px;
        overflow: auto;
    }

    .board-map-group,
    .board-map-stock,
    .board-map-members {
        position: relative;
        inset: auto;
        width: auto;
        height: auto;
    }

    .board-map-members {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(65px, 100%), 1fr));
        gap: 2px;
        padding: 2px;
    }

    .board-map-stock { min-height: 41px; }
}

@media (prefers-reduced-motion: reduce) {
    .board-map-group { transition: none; }
    .board-map-stock[data-flash] { animation: none; }
}
