/* The heat map (slice 8.1): a fixed five-step scale, cold to hot (HeatScale). Step 1 is
   the "used" tint. Text stays readable on every step; the state is also written out,
   so colour is never the only signal. The colours are the --btm-heat-* tokens in
   app.css, defined once for the table here and the body illustration below. */
.heat-step-0 { background: var(--btm-heat-0); color: var(--btm-heat-ink-0); }
.heat-step-1 { background: var(--btm-heat-1); color: var(--btm-heat-ink-1); }
.heat-step-2 { background: var(--btm-heat-2); color: var(--btm-heat-ink-2); }
.heat-step-3 { background: var(--btm-heat-3); color: var(--btm-heat-ink-3); }
.heat-step-4 { background: var(--btm-heat-4); color: var(--btm-heat-ink-4); }

/* The muscle page's one painted line, "Now" and its state (slice 8.1). */
.heat-now {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin: 0;
    border-radius: 4px;
}

/* The heat map as a dense table (slice 11.8, Look and Feel "As built: tables"): the
   base's table style, laid out as the per-muscle volume table is (a group row with its
   name in a row header, its muscles indented under it), with the heat step as each
   row's paint. The step's background and ink fill the row's cells in place of the zebra
   shading and the group row's surface grey, so the rule is on the cells, where those
   are. A fresh row is on the cold step, as the key says, not left unpainted. */
table.heat tr.heat-step-0 > * { background: var(--btm-heat-0); color: var(--btm-heat-ink-0); }
table.heat tr.heat-step-1 > * { background: var(--btm-heat-1); color: var(--btm-heat-ink-1); }
table.heat tr.heat-step-2 > * { background: var(--btm-heat-2); color: var(--btm-heat-ink-2); }
table.heat tr.heat-step-3 > * { background: var(--btm-heat-3); color: var(--btm-heat-ink-3); }
table.heat tr.heat-step-4 > * { background: var(--btm-heat-4); color: var(--btm-heat-ink-4); }

/* Every row carries a link, so every row is the 32 px a row with a control is (slice
   11.4), the muscle's name a link in the row's own ink (the accent would not read on
   the hot steps), underlined, its tap area reaching the touch height into the rows
   either side the way the set rows' Edit and Delete do. */
table.heat th, table.heat td {
    height: 2rem;
    padding-top: 0;
    padding-bottom: 0;
}

table.heat td.muscle a {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    color: inherit;
}

table.heat td.muscle a::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: calc((2rem - var(--btm-touch)) / 2);
    bottom: calc((2rem - var(--btm-touch)) / 2);
}

.heat-key {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    list-style: none;
    padding: 0;
}

.heat-key li {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* The body illustration (slice 8.2): front and back side by side, each region filled
   on the same steps. Regions the map leaves neutral keep the artwork's greys. */
/* --body-view is how wide each 2D view may get: 240px on the heat map's own pages, less
   where the body is drawn compact (below). The 3D body's room is worked out from it. */
.body-map {
    --body-view: 240px;
    margin: 1rem 0;
}

.body-map-views {
    position: relative;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

/* The 3D body (slice 20.6): a 3D body has an empty box laid over the two views, which
   body-3d.js fills with a canvas once the model is drawn. The canvas takes the views'
   place and size, so nothing on the page moves, and the views are hidden, not
   removed: if the canvas goes, they are the body again. An empty box lets taps through
   to the 2D regions under it. */
.body-3d {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* A 3D body's box is taller than the 2D views (slice 20.10). The one camera frames the
   tallest body with its elbows overhead (the scene script's "aim"), so a lean body
   standing is 74% of its picture's height; in a box only as tall as the 2D views it was
   plainly smaller than they are. BodyIllustration marks the box when it asks for a 3D
   body, so the room is there from the server's markup and nothing moves when the canvas
   arrives; until it does, and where it never does (no WebGL, a failed load), the 2D
   views stand in the middle of the box.
   The room is padding above and below, 0.35 of a view's width each: a view is 1.937
   times as tall as it is wide, so the box is 1.36 times the views' height and a lean
   body stands as tall as the 2D ones do. A percentage of padding is of the box's width,
   and a view is half of that until it reaches --body-view, hence the two terms. The box
   then stays wider than 0.727 of its height, the shape below which the camera would
   back off for the body's reach and the figure would shrink again. */
.body-map-tall,
:root[data-show-3d] .body-map-switch {
    padding-block: min(17.5%, calc(var(--body-view) * 0.35));
}

/* The switch to the 3D body on the heat map pages (slice 20.14): a labelled checkbox
   above the body, the same room whichever way it is set. The views under it take the
   taller room only while the choice is on: the root's data-show-3d, set by the
   script in App.razor's head before the first paint and kept by body-3d.js. */
.body-3d-switch {
    margin: 0 0 0.5rem;
    text-align: center;
}

/* The body is turned by dragging it sideways (slice 20.7). pan-y leaves a vertical swipe
   over it to the browser, which scrolls the page, and hands a sideways one to the
   script; pinch-zoom is left alone too. */
.body-3d canvas {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    touch-action: pan-y pinch-zoom;
    user-select: none;
    -webkit-user-select: none;
}

.body-map-views:has(.body-3d canvas) > svg {
    visibility: hidden;
}

.body-map svg {
    width: 50%;
    max-width: var(--body-view);
    height: auto;
}

.body-map path {
    pointer-events: none;
}

.body-map a path {
    pointer-events: auto;
    cursor: pointer;
}

/* The artwork's neutral greys are its own fill attributes; these put them on tokens so
   the body reads on dark too (slice 11.6). The underlayer is the silhouette the muscles
   sit on, so it shows as the outline and the gaps between regions; the parts the map
   leaves uncoloured (hands, feet, face, neck, shins) and the detail lines are the rest.
   A mapped region keeps the attribute under its class, so the step rules come after. */
.body-map path[fill="#E0E0E0"] { fill: var(--btm-body-outline); }
.body-map path[fill="#BDBDBD"], .body-map path[fill="#BDBDBD "] { fill: var(--btm-body-part); }
.body-map path[stroke="black"] { stroke: var(--btm-body-line); }

.body-map path.heat-step-0 { fill: var(--btm-heat-0); }
.body-map path.heat-step-1 { fill: var(--btm-heat-1); }
.body-map path.heat-step-2 { fill: var(--btm-heat-2); }
.body-map path.heat-step-3 { fill: var(--btm-heat-3); }
.body-map path.heat-step-4 { fill: var(--btm-heat-4); }

.body-map figcaption {
    font-size: 0.8rem;
    text-align: center;
}

/* The info icon under a body (slice 20.5): a touch-size link to the credits page, drawn
   as a small ringed "i". It stands in for the credit line the body used to carry. */
.body-credits {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--btm-touch);
    min-height: var(--btm-touch);
    color: var(--btm-muted);
    text-decoration: none;
}

.body-credits span {
    box-sizing: border-box;
    width: 1.25rem;
    height: 1.25rem;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    font-weight: 600;
    line-height: calc(1.25rem - 2px);
}

/* Inline on the workout page and the gym screen (slice 12.5): the body, the colour key
   under it and the muscles the workout used, in the table's own rules above. On the gym
   screen the picture sits behind the Muscles button under the exercise list, a quiet
   row like the list's, and the body is drawn a little smaller than on its own page. */
section.gym p.muscles {
    margin: 0;
    padding: var(--btm-space-1) 0;
    border-bottom: 1px solid var(--btm-border);
}

section.gym p.muscles button {
    width: 100%;
    margin: 0;
    text-align: left;
}

section.gym section.muscles {
    padding-bottom: var(--btm-space-3);
    border-bottom: 1px solid var(--btm-border);
}

section.muscles .body-map {
    --body-view: 180px;
    margin-top: var(--btm-space-3);
}

/* What an exercise hits, on its page (slice 12.7): the body under the muscle list at
   the gym screen's compact size, so the two views sit side by side on a phone, and the
   two-swatch key under it. */
.exercise-muscles .body-map {
    --body-view: 180px;
    margin-top: var(--btm-space-3);
}

/* A routine day's body (slice 14.2): the exercise page's compact size, beside the day's
   exercises at the desk and under them on a phone. */
.routine-muscles .body-map {
    --body-view: 180px;
    margin: var(--btm-space-3) 0 0;
}

.routine-muscles .body-map svg {
    width: 180px;
    max-width: 50%;
}

.routine-muscles .heat-key {
    justify-content: center;
}

/* Add an exercise's By muscle view (slice 13.1, Product/Heat Map Workout.md): By name and
   By muscle as the page's own row of links, buttons here since they switch a view in
   place; the body at the inline size, so both views sit side by side on a phone; the
   flat table of every muscle, its name a button that lists the muscle's exercises, in
   the row's ink as the heat map's links are, not indented since there are no group
   rows, so the three columns fit a phone, with Last trained kept on one line; and
   the small square beside each of an exercise's other muscles, painted on its step. */
section.picker nav.links button {
    min-height: var(--btm-touch);
    padding: 0;
    border: 0;
    background: none;
    color: var(--btm-accent);
    font-weight: normal;
    text-decoration: underline;
}

section.picker nav.links button[aria-current=true] {
    color: var(--btm-text);
    font-weight: 600;
    text-decoration: none;
}

section.picker .body-map {
    --body-view: 180px;
}

table.picker-heat td.muscle {
    padding-left: var(--btm-space-2);
}

table.picker-heat td.muscle button {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-weight: normal;
    text-align: left;
    text-decoration: underline;
}

section.picker nav.links button:hover, table.picker-heat td.muscle button:hover {
    background: none;
}

table.picker-heat .last {
    white-space: nowrap;
}

.swatch {
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    margin-left: 0.25em;
    border: 1px solid var(--btm-border);
    border-radius: 2px;
    vertical-align: baseline;
}

/* Home's summary (slice 21.4, Product/One Home Screen.md): the week's volume chart, the
   body, and the folded muscle table, under the gym screen's start. The gym screen's open
   workout is a section.gym with no .start, rendered before the summary, and hides it in
   place: in a workout Home is the gym screen and nothing else. */
section.gym:not(.start) ~ .home-summary {
    display: none;
}

/* The folded table: a row per muscle group, painted on its heat step as the heat table's
   rows are, opening to its muscles. The rows are grids of the same three columns so the
   numbers line up without a table, which could not hold a row that opens. In the table
   face, with tabular figures. A group's row is the touch height, being a control. */
.muscle-summary {
    font-family: var(--btm-font-table);
    font-size: var(--btm-text-table);
    font-variant-numeric: tabular-nums;
    max-width: 40rem;
    margin: 0 0 var(--btm-space-3);
}

.muscle-summary-head,
.muscle-summary summary,
.muscle-summary li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 5.5rem 6.5rem;
    align-items: center;
    border-bottom: 1px solid var(--btm-border);
}

/* The base draws a <details> as a bordered box with its summary inset (app.css); here
   the groups are rows of one table, edge to edge with no gap between them. */
.muscle-summary details {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
}

.muscle-summary summary,
.muscle-summary details[open] summary {
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--btm-border);
}

.muscle-summary-head {
    border-bottom-width: 2px;
    font-weight: 600;
}

.muscle-summary-head > *,
.muscle-summary summary > *,
.muscle-summary li > * {
    padding: var(--btm-space-1) var(--btm-space-2);
}

.muscle-summary .num {
    text-align: right;
    white-space: nowrap;
}

.muscle-summary summary {
    min-height: var(--btm-touch);
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}

.muscle-summary summary::-webkit-details-marker {
    display: none;
}

/* The mark that a row opens: a chevron in the row's own ink, turned down when open. */
.muscle-summary summary .name::before {
    content: "";
    display: inline-block;
    width: 0.4rem;
    height: 0.4rem;
    margin: 0 0.6rem 0.1rem 0.1rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
}

.muscle-summary details[open] > summary .name::before {
    transform: rotate(45deg);
}

.muscle-summary ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.muscle-summary li {
    min-height: 2rem;
    margin: 0;
}

.muscle-summary li .name {
    padding-left: 1.75rem;
    color: inherit;
}
