/*
 * A tune's chord chart, drawn by public/scripts/chord-chart.js.
 *
 * Its own file because two stylesheets need it: the app's pages (the tune page,
 * the tune form's preview, a set's link), which load it after main.css when
 * they draw a chart (PAGE_STYLES in utils/views.js), and the stage view, which
 * has no main.css and loads it when its chords are on. The colours come from
 * whichever page it is on: main.css's tokens, or the stage view's own, and
 * either theme follows.
 */
/* A tune's chords as bars (public/scripts/chord-chart.js): a row to each line
   as it was typed, in as many columns as the chart's longest line (four at
   least, --chord-cols), so phrases line up under each other and a short row is
   plainly short, and the chords of a bar share it evenly, a beat mark taking a
   beat's room. Rows are spaced apart; a line too long for its row carries on
   under itself with no space, so it still reads as one line. Barlines are the
   quiet text colour, faded, in either theme. */
.chord-chart {
    --chord-text: var(--text-color, var(--fg));
    --chord-dim: var(--secondary-color, var(--fg-dim));
    --chord-label: var(--earth-text, var(--title));
    --chord-line: color-mix(in srgb, var(--chord-dim) 45%, transparent);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chord-chart-part {
    margin: 0.75rem 0 0;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--chord-label);
}

.chord-chart-part:first-child {
    margin-top: 0;
}

.chord-chart-note {
    margin: 0.25rem 0;
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--chord-dim);
}

.chord-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chord-bars {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(var(--chord-cols, 4), minmax(0, 1fr));
    border-left: 2px solid var(--chord-line);
}

.chord-bar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0.15rem;
    min-height: 2.75rem;
    padding: 0.35rem 0.6rem;
    border-right: 2px solid var(--chord-line);
}

/* The room left in a bar is shared evenly, so beats sit about evenly. Chords
   that do not fit side by side go onto a line of their own within the bar,
   whole; only a chord longer than the bar itself is ever broken. The space
   after a chord or a beat is its own padding rather than a gap, so a full
   bar of beats asks for no more room than it shows. */
.chord {
    flex: 1 1 auto;
    min-width: 0;
    padding-right: 0.3em;
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
    color: var(--chord-text);
}

.chord-beat,
.chord-simile {
    font-weight: 400;
    color: var(--chord-dim);
}

/* A bar's own time, before its chords: the crooked bar. */
.chord-bar-time {
    flex: none;
    align-self: flex-start;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--chord-label);
}

/* Repeat signs: a heavy barline, and the two dots as a colon. Borders, not an
   inset box-shadow: Chrome printing without background graphics (its default)
   drew the shadow as a thin box round the whole bar, like an empty text field.
   The heavy line at a repeat's start sits beside the thin barline before it,
   as on a printed page. */
.chord-bar-repeat-start {
    padding-left: 1.1rem;
    border-left: 4px solid var(--chord-line);
}

.chord-bar-repeat-end {
    padding-right: 1.1rem;
    border-right-width: 5px;
}

.chord-bar-repeat-start::before,
.chord-bar-repeat-end::after {
    content: ':';
    position: absolute;
    top: 50%;
    transform: translateY(-55%);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--chord-dim);
}

.chord-bar-repeat-start::before {
    left: 0.4rem;
}

.chord-bar-repeat-end::after {
    right: 0.4rem;
}

.chord-row-repeat {
    flex: none;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--chord-dim);
}

@media (max-width: 480px) {
    .chord-bars {
        grid-template-columns: repeat(var(--chord-cols-phone, var(--chord-cols, 4)), minmax(0, 1fr));
    }

    .chord-bar {
        padding-top: 0.3rem;
        padding-bottom: 0.3rem;
    }

    .chord-bar:not(.chord-bar-repeat-start) {
        padding-left: 0.4rem;
    }

    .chord-bar:not(.chord-bar-repeat-end) {
        padding-right: 0.4rem;
    }

    .chord {
        font-size: 1rem;
    }
}

/* A crowded bar (more than four chords and beats: a bar of 6/8 or 9/8 written
   out in beats) takes two columns on a phone, so its beats stay on one line
   and keep their order, and its line carries on under itself. A chart of plain
   bars keeps its lines whole on any phone, up to six bars. By the screen, not the chart: a container query on the chart sized
   it from nothing first, and left a tall blank under it on the stage view. */
@media (max-width: 40rem) {
    .chord-bar-busy {
        grid-column: span 2;
    }
}
