/* A folded walking map, two-colour offset: forest green and one red on white paper. */
@property --tm-p {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}
@property --tm-hold {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

.tm {
  --green: #07663f;
  --red: #ee3120;
  --band: 38px;
  --map: 312px;
  --fold: 560ms cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: #fff;
  color: var(--green);
  font-family: "Archivo Variable", sans-serif;
  font-stretch: 62%;
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
  text-transform: uppercase;
  -webkit-font-smoothing: antialiased;
}

/* one printed band: stage number, leg, distance, climb */
.tm-row {
  display: grid;
  grid-template-columns: 58px 1fr 92px 100px;
  align-items: center;
  height: var(--band);
  padding: 0 12px;
  box-sizing: border-box;
  white-space: nowrap;
}
.tm-no {
  font-size: 42px;
  font-weight: 800;
  line-height: var(--band);
  letter-spacing: -0.01em;
  transform: translateY(-1.5px);
}
.tm-leg {
  font-size: 20px;
  letter-spacing: 0.012em;
  line-height: var(--band);
}
.tm-leg i {
  display: inline-block;
  width: 13px;
  height: 2px;
  margin: 0 7px;
  background: currentColor;
  vertical-align: 6px;
}
.tm-km,
.tm-up {
  font-size: 21px;
  line-height: var(--band);
  text-align: right;
}
.tm-km small,
.tm-up small {
  margin-left: 3px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.tm-climb {
  width: 9px;
  height: 11px;
  margin-right: 5px;
  fill: currentColor;
}

.tm-total {
  background: var(--green);
  color: #fff;
}
.tm-total .tm-no {
  font-size: 30px;
  letter-spacing: 0;
  transform: none;
}

.tm-acc,
.tm-item {
  display: block;
}
.tm-head {
  margin: 0;
  font: inherit;
}
.tm-trigger {
  all: unset;
  position: relative;
  display: block;
  width: 100%;
  height: var(--band);
  box-shadow: inset 0 1px 0 var(--green);
  cursor: pointer;
}
.tm-item:first-child .tm-trigger {
  box-shadow: none;
}
/* the open stage is overprinted with a red band, type knocked out */
.tm-row-on {
  position: absolute;
  inset: 0;
  background: var(--red);
  color: #fff;
  clip-path: inset(0 100% 0 0);
  transform: translate(0.6px, -0.4px);
  transition: clip-path 440ms cubic-bezier(0.4, 0, 0.2, 1);
}
/* under the pointer a closed stage shows a red index tab; the band then runs out from it */
.tm-trigger:hover .tm-row-on {
  clip-path: inset(0 calc(100% - 6px) 0 0);
  transition-duration: 140ms;
}
.tm-trigger[data-open] .tm-row-on {
  clip-path: inset(0 0 0 0);
  transition-duration: 440ms;
}
.tm-trigger:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: -4px;
}

/* The sheet keeps its length: the leaf being opened sets its own height, and the leaf
   being folded away takes whatever is left, so the two always add up to one map. */
.tm-acc {
  display: flex;
  flex-direction: column;
  height: calc(5 * var(--band) + var(--map));
}
.tm-item {
  display: contents;
}
.tm-head {
  flex: none;
}
.tm-panel {
  --tm-p: 1;
  --tm-hold: 1;
  flex: none;
  height: calc(var(--map) * var(--tm-p));
  overflow: hidden;
  transition:
    --tm-p var(--fold),
    --tm-hold 700ms linear;
}
.tm-panel[data-starting-style] {
  --tm-p: 0;
}
.tm-panel[data-ending-style] {
  --tm-p: 0;
  --tm-hold: 0;
}
.tm-panel:not([data-open]) {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
}
/* the map is drawn to the leaf's height, so a half-open leaf is foreshortened */
.tm-fold {
  position: relative;
  height: 100%;
  box-shadow: inset 0 1px 0 var(--green);
}
/* The leaf is a concertina of four: a crisp crease at each fold and a flat step of tone
   between the faces turned up and the faces turned down. No gradients, no shadows. */
.tm-fold::after,
.tm-shade {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    var(--up) calc(25% - 0.5px),
    var(--crease) calc(25% - 0.5px),
    var(--crease) calc(25% + 0.5px),
    var(--down) calc(25% + 0.5px),
    var(--down) calc(50% - 0.5px),
    var(--crease) calc(50% - 0.5px),
    var(--crease) calc(50% + 0.5px),
    var(--up) calc(50% + 0.5px),
    var(--up) calc(75% - 0.5px),
    var(--crease) calc(75% - 0.5px),
    var(--crease) calc(75% + 0.5px),
    var(--down) calc(75% + 0.5px),
    var(--down) 100%
  );
  mix-blend-mode: multiply;
  pointer-events: none;
}
/* what stays in the paper once it is flat */
.tm-fold::after {
  --up: rgb(6 70 44 / 0);
  --down: rgb(6 70 44 / 0.04);
  --crease: rgb(6 70 44 / 0.22);
}
.tm-map {
  display: block;
  width: 540px;
  height: 100%;
}
/* while the leaf is bent: the tone steps and creases deepen with the angle of the fold */
.tm-shade {
  --up: rgb(6 70 44 / 0.03);
  --down: rgb(6 70 44 / 0.3);
  --crease: rgb(6 70 44 / 0.62);
  opacity: calc(1 - var(--tm-p) * var(--tm-p));
}

/* the two creases down the sheet: a crisp line, the middle third a flat step darker */
.tm-creases {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  background: linear-gradient(
    90deg,
    rgb(6 70 44 / 0) 179.5px,
    rgb(6 70 44 / 0.22) 179.5px,
    rgb(6 70 44 / 0.22) 180.5px,
    rgb(6 70 44 / 0.02) 180.5px,
    rgb(6 70 44 / 0.02) 359.5px,
    rgb(6 70 44 / 0.22) 359.5px,
    rgb(6 70 44 / 0.22) 360.5px,
    rgb(6 70 44 / 0) 360.5px
  );
}

/* map inks */
.tm-ink {
  fill: var(--green);
}
.tm-map path {
  fill: none;
}
.tm-map path.tm-ink {
  fill: var(--green);
}
.tm-grid {
  stroke: var(--green);
  stroke-width: 0.5;
  opacity: 0.3;
}
.tm-contour {
  stroke: var(--green);
  stroke-width: 0.5;
  opacity: 0.8;
}
.tm-index {
  stroke-width: 1.1;
  opacity: 1;
}
.tm-coast {
  stroke: var(--green);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.tm-river {
  stroke: var(--green);
  stroke-width: 1.2;
}
.tm-sea {
  stroke: var(--green);
  stroke-width: 0.6;
}
.tm-ring {
  fill: #fff;
  stroke: var(--green);
  stroke-width: 1.5;
}
.tm-red {
  mix-blend-mode: multiply;
  transform: translate(0.6px, -0.4px);
  fill: var(--red);
}
.tm-map path.tm-route {
  stroke: var(--red);
  stroke-width: 3.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.tm-map path.tm-route-other {
  stroke-width: 1.5;
}
.tm-map path.tm-tick {
  stroke: var(--red);
  stroke-width: 1.5;
}
.tm-map text {
  fill: var(--green);
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.tm-place {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.tm-spot {
  font-size: 13px;
  font-weight: 600;
}
.tm-bar text {
  font-size: 13px;
  font-weight: 600;
}
.tm-bar-box {
  fill: #fff;
  stroke: var(--green);
  stroke-width: 1;
}
.tm-map path.tm-bar-box {
  fill: #fff;
}
