/* The shared rules reference — charts, tables and rule cards.
 *
 * Drawn by static/bb/js/reference/reference-table.js for whichever
 * universe supplies the data. Class names are bb-ref-* rather than the
 * .tool-panel / .tools-tab of The Old World's own Tools screen: those
 * live in static/tow/css/tow-shell.css and reusing them would make one
 * universe's screen depend on another universe's stylesheet, which is
 * exactly the shape Epic 18 is unpicking.
 *
 * Every rule here is written for the 390px phone first. The charts are
 * ten columns wide and will never fit one, so they scroll inside their
 * own box with the row header pinned — the page itself must not scroll
 * sideways.
 */

.bb-ref-screen {
    padding: var(--bb-space-4);
    padding-bottom: var(--bb-space-12);
}

/* ── Tabs ───────────────────────────────────────────────────────── */

.bb-ref-tabs {
    display: flex;
    gap: var(--bb-space-2);
    overflow-x: auto;
    scrollbar-width: none;
    margin-bottom: var(--bb-space-4);
    padding-bottom: var(--bb-space-1);
}

.bb-ref-tabs::-webkit-scrollbar { display: none; }

.bb-ref-tab {
    flex: 0 0 auto;
    min-height: var(--bb-touch-min);
    white-space: nowrap;
}

.bb-ref-panel { display: none; }
.bb-ref-panel.active { display: block; }

/* ── Cross-indexed charts ───────────────────────────────────────── */

/* Ten columns do not fit a phone and never will. The chart scrolls
 * inside this box; the page does not scroll with it. */
.bb-ref-matrix-wrap,
.bb-ref-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.bb-ref-matrix,
.bb-ref-table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-family: var(--bb-font-body);
    font-size: var(--bb-text-sm);
}

.bb-ref-matrix th,
.bb-ref-matrix td,
.bb-ref-table th,
.bb-ref-table td {
    border: 1px solid var(--bb-border);
    padding: var(--bb-space-2);
    text-align: center;
}

.bb-ref-table td { text-align: left; }

.bb-ref-col-head {
    background: var(--bb-bg-elevated);
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky;
    top: 0;
}

/* The row header stays put while the chart scrolls under the thumb.
 * Without this the reader loses which row they are on at column four,
 * which is where a to-wound lookup usually lands. */
.bb-ref-row-head {
    background: var(--bb-bg-elevated);
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-xs);
    position: sticky;
    left: 0;
    z-index: 1;
}

.bb-ref-corner {
    background: var(--bb-bg-surface);
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 5.5rem;
}

.bb-ref-corner-row,
.bb-ref-corner-col {
    display: block;
    font-size: 0.625rem;
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bb-text-muted);
}

/* The two axis names read as a fraction: rows over columns. */
.bb-ref-corner-row { text-align: left; }
.bb-ref-corner-col { text-align: right; }

.bb-ref-cell {
    color: var(--bb-text-primary);
    font-variant-numeric: tabular-nums;
    min-width: 2.5rem;
}

/* A chart of numbers is read a cell at a time; a chart of colours is read
   at a glance, and mid-turn a glance is all anyone has.

   ONE BAND PER NUMBER ON THE DIE. It was three — success, warning, danger
   — until 2026-08-28, which put 2+ and 3+ in the same green and 5+ and 6+
   in the same red, collapsing the two steps a player actually acts on.
   Asked for as a gradient, so it is one, and the colours live in
   bb-tokens.css beside every other colour rather than being spelled out
   here. They are deliberately NOT the --bb-accent-* set: those change per
   universe, and a 4+ is a 4+ in both games.

   Colour is a second channel here, never the only one — the roll itself is
   printed in every cell, so nothing is lost to a reader who cannot tell
   these five apart. Weight carries the same signal at the hard end for the
   same reason. */
.bb-ref-roll-2 { color: var(--bb-roll-2); }
.bb-ref-roll-3 { color: var(--bb-roll-3); }
.bb-ref-roll-4 { color: var(--bb-roll-4); }
.bb-ref-roll-5 { color: var(--bb-roll-5); font-weight: 600; }
.bb-ref-roll-6 { color: var(--bb-roll-6); font-weight: 600; }

/* "Cannot happen" should not read as "I forgot to fill this in". */
.bb-ref-cell-none {
    color: var(--bb-text-muted);
    background: var(--bb-bg-base);
}

.bb-ref-note {
    margin-top: var(--bb-space-3);
    color: var(--bb-text-muted);
    font-size: var(--bb-text-sm);
    line-height: 1.5;
}

/* ── Rule cards ─────────────────────────────────────────────────── */

.bb-ref-cards-wrap { display: block; }

.bb-ref-group { margin-bottom: var(--bb-space-6); }

.bb-ref-group-title {
    font-family: var(--bb-font-display);
    font-size: var(--bb-text-lg);
    color: var(--bb-text-primary);
    margin: 0 0 var(--bb-space-1);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bb-ref-group-subtitle {
    margin: 0 0 var(--bb-space-3);
    color: var(--bb-text-muted);
    font-size: var(--bb-text-sm);
}

.bb-ref-card-list {
    display: flex;
    flex-direction: column;
    gap: var(--bb-space-3);
}

.bb-ref-card {
    background: var(--bb-bg-surface);
    border: 1px solid var(--bb-border);
    border-left: 3px solid var(--bb-accent-primary);
    border-radius: var(--bb-radius-md);
    padding: var(--bb-space-3);
}

.bb-ref-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--bb-space-2);
    margin-bottom: var(--bb-space-2);
}

.bb-ref-card-name {
    margin: 0;
    font-family: var(--bb-font-display);
    font-size: var(--bb-text-base);
    color: var(--bb-text-primary);
}

/* Timing and cost sit beside the name, because that is what a player
 * scans for mid-turn and prose is where scanning goes to die. */
.bb-ref-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--bb-space-1) var(--bb-space-3);
    margin: 0;
}

.bb-ref-meta-label {
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bb-ref-meta-label::after { content: ' '; }

.bb-ref-meta-value {
    margin: 0;
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-xs);
}

.bb-ref-card-body {
    margin: 0;
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-sm);
    line-height: 1.55;
}

.bb-ref-card-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: var(--bb-space-1);
    list-style: none;
    margin: var(--bb-space-2) 0 0;
    padding: 0;
}

.bb-ref-keyword {
    background: var(--bb-bg-elevated);
    border-radius: var(--bb-radius-sm);
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
    letter-spacing: 0.04em;
    padding: 2px var(--bb-space-2);
    text-transform: uppercase;
}

/* ── Picker ─────────────────────────────────────────────────────── */

.bb-ref-picker { display: block; }

.bb-ref-picker-label {
    display: block;
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
    letter-spacing: 0.05em;
    margin-bottom: var(--bb-space-4);
    text-transform: uppercase;
}

.bb-ref-picker-select {
    display: block;
    margin-top: var(--bb-space-1);
    min-height: var(--bb-touch-min);
    width: 100%;
}

.bb-ref-picker-body { display: block; }

/* ── The stated absence ─────────────────────────────────────────── */

/* An empty reference that is unwritten and one that is broken look
 * identical to a player at a table, so this box always carries a
 * sentence saying which. It is styled like a card rather than like an
 * error: nothing has gone wrong. */
.bb-ref-empty {
    background: var(--bb-bg-surface);
    border: 1px dashed var(--bb-border);
    border-radius: var(--bb-radius-md);
    padding: var(--bb-space-6) var(--bb-space-4);
}

.bb-ref-empty-text {
    margin: 0;
    color: var(--bb-text-muted);
    font-size: var(--bb-text-sm);
    line-height: 1.55;
    text-align: center;
}

/* ── The index: a long list with a box to find one in ───────────── */

/* Ninety-five Special Rules is not a page anyone reads top to bottom.
 * It is a page somebody searches mid-turn, so the search box is the
 * first thing under the tab and the entries are collapsed to a name and
 * a line until one is opened. */

.bb-ref-index { display: block; }

.bb-ref-index-label {
    display: block;
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
    letter-spacing: 0.05em;
    margin-bottom: var(--bb-space-2);
    text-transform: uppercase;
}

.bb-ref-index-search {
    display: block;
    margin-top: var(--bb-space-1);
    min-height: var(--bb-touch-min);
    width: 100%;
}

.bb-ref-index-count {
    margin: 0 0 var(--bb-space-3);
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
}

.bb-ref-index-list {
    display: flex;
    flex-direction: column;
    gap: var(--bb-space-2);
}

.bb-ref-index-item {
    background: var(--bb-bg-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-md);
    overflow: hidden;
}

.bb-ref-index-item[hidden] { display: none; }

/* The whole row is the control, so it carries the tap target rather
 * than leaving a 20px marker to aim at. */
.bb-ref-index-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    list-style: none;
    min-height: var(--bb-touch-min);
    padding: var(--bb-space-3) var(--bb-space-4);
}

.bb-ref-index-name::-webkit-details-marker { display: none; }

.bb-ref-index-title {
    color: var(--bb-text-primary);
    font-family: var(--bb-font-display);
    font-size: var(--bb-text-base);
}

.bb-ref-index-summary {
    color: var(--bb-text-muted);
    font-size: var(--bb-text-xs);
    line-height: 1.45;
}

/* Open: the summary line is repeated in full inside the card, so hide
 * the truncated copy in the header rather than printing it twice. */
.bb-ref-index-item[open] .bb-ref-index-summary { display: none; }

.bb-ref-index-item[open] .bb-ref-index-name {
    border-bottom: 1px solid var(--bb-border);
}

.bb-ref-index-item > .bb-ref-card {
    background: none;
    border: 0;
    border-radius: 0;
}

.bb-ref-card-subhead {
    margin: var(--bb-space-3) 0 var(--bb-space-1);
    color: var(--bb-text-secondary);
    font-family: var(--bb-font-display);
    font-size: var(--bb-text-sm);
}

.bb-ref-card-list-block {
    margin: 0 0 var(--bb-space-2);
    padding-left: var(--bb-space-4);
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-sm);
    line-height: 1.55;
}

.bb-ref-card-list-block li { margin-bottom: var(--bb-space-1); }

/* A table's non-value cells, explained under it. 'A' in a Hits-on
 * column reads as a typo until something says it means the shot hits
 * automatically, so this sits with the table rather than on a tab of
 * its own that nobody looking at an 'A' would think to open. */
.bb-ref-legend {
    margin: var(--bb-space-3) 0 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--bb-space-2);
}

.bb-ref-legend-term {
    color: var(--bb-text-primary);
    font-family: var(--bb-font-display);
    font-size: var(--bb-text-sm);
}

.bb-ref-legend-meaning {
    color: var(--bb-text-muted);
    font-family: var(--bb-font-body);
    font-size: var(--bb-text-xs);
    margin-left: var(--bb-space-2);
}

.bb-ref-legend-rule {
    margin: 0;
    color: var(--bb-text-secondary);
    font-size: var(--bb-text-sm);
    line-height: 1.55;
}
