.tr {
  --ground: #ff6a0d;
  --ink: #0a0a0a;
  --paper: #ffffff;
  --row: 42px;
  --gutter: 20px;
  --col: 40px;
  --step: 50px;
  --open: 260ms;
  --ease: cubic-bezier(0.3, 0, 0.15, 1);
  width: 540px;
  height: 540px;
  box-sizing: border-box;
  padding: 18px 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font-family: "Martian Mono Variable", monospace;
  font-stretch: 112.5%;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.04em;
  -webkit-font-smoothing: antialiased;
}

.tr *, .tr *::before, .tr *::after { box-sizing: border-box; }

.tr-tree, .tr-group { margin: 0; padding: 0; list-style: none; }
.tr-tree { outline: none; }
.tr-item { display: block; outline: none; }

/* one row: a fixed box that its contents never leave */
.tr-label {
  position: relative;
  display: block;
  height: var(--row);
  overflow: hidden;
  cursor: default;
  user-select: none;
}

.tr-row {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  padding-left: calc(var(--gutter) + (var(--tree-level) - 1) * var(--step));
  padding-right: 20px;
}

.tr-fold, .tr-tag {
  flex: none;
  width: var(--col);
  margin-right: calc(var(--step) - var(--col));
}

/* the chevron: two strokes, turning a quarter over the whole of the opening */
.tr-fold { display: grid; place-items: center; height: 24px; }
.tr-chev {
  width: 13px;
  height: 13px;
  border-right: 4px solid currentColor;
  border-bottom: 4px solid currentColor;
  rotate: -45deg;
  translate: -3px 0;
  transition: rotate var(--open) var(--ease), translate var(--open) var(--ease);
}
.tr-label[data-expanded] .tr-chev { rotate: 45deg; translate: 0 -3px; }

/* the file type, as a tag */
.tr-tag {
  height: 22px;
  background: var(--ink);
  color: var(--ground);
  font-size: 14px;
  font-weight: 800;
  font-stretch: 75%;
  letter-spacing: 0.03em;
  line-height: 22px;
  text-align: center;
}

.tr-name { flex: 1; white-space: nowrap; }
.tr-label[data-branch] .tr-name { font-weight: 760; }

/* source control: a letter reversed out of a chip, a dot on the folder that holds it */
.tr-chip {
  flex: none;
  width: 26px;
  height: 26px;
  background: var(--ink);
  color: var(--paper);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 26px;
  text-align: center;
}
.tr-dot { flex: none; width: 10px; height: 10px; margin-right: 8px; background: var(--ink); }

/* the open file: a white row */
.tr-label[data-selected] .tr-row:not(.tr-inv) { background: var(--paper); }
.tr-label[data-selected] .tr-row:not(.tr-inv) .tr-tag { color: var(--paper); }

/* the focus bar: the same row reversed, shown through a clip that travels in the direction of the move */
.tr-inv {
  position: absolute;
  inset: 0;
  background: var(--ink);
  color: var(--paper);
  clip-path: inset(0 0 100% 0);
}
.tr-inv .tr-tag { background: var(--ground); color: var(--ink); }
.tr-inv .tr-chip { background: var(--paper); color: var(--ink); }
.tr-inv .tr-dot { background: var(--paper); }

.tr-label[data-f="in"] .tr-inv { clip-path: inset(0); }
.tr[data-dir="down"] .tr-label[data-f="in"] .tr-inv { animation: tr-in-down 180ms cubic-bezier(0.3, 0, 0.2, 1); }
.tr[data-dir="down"] .tr-label[data-f="out"] .tr-inv { animation: tr-out-down 180ms cubic-bezier(0.3, 0, 0.2, 1) both; }
.tr[data-dir="up"] .tr-label[data-f="in"] .tr-inv { animation: tr-in-up 180ms cubic-bezier(0.3, 0, 0.2, 1); }
.tr[data-dir="up"] .tr-label[data-f="out"] .tr-inv { animation: tr-out-up 180ms cubic-bezier(0.3, 0, 0.2, 1) both; }

@keyframes tr-in-down { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
@keyframes tr-out-down { from { clip-path: inset(0); } to { clip-path: inset(100% 0 0 0); } }
@keyframes tr-in-up { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0); } }
@keyframes tr-out-up { from { clip-path: inset(0); } to { clip-path: inset(0 0 100% 0); } }

/* a branch's children. The group's height opens and pushes everything below it down; its hairline
   guide, under the branch's chevron, is drawn down with it. */
.tr-group {
  position: relative;
  height: var(--tree-group-height);
  overflow: hidden;
  transition: height var(--open) var(--ease);
}
.tr-group:is([data-starting-style], [data-ending-style]) { height: 0; }
.tr-group::before,
.tr-item[data-level="2"] > .tr-label .tr-row::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--gutter) + var(--col) / 2);
  width: 1px;
  background: var(--ink);
}
/* the guide carries on through the white row and the focus bar */
.tr-item[data-level="2"] > .tr-label .tr-inv::before { background: #8a8a8a; }

/* each child arrives inside its own row box, once the opening group has made room for it */
.tr-group .tr-row:not(.tr-inv) {
  transition: opacity 150ms linear, translate 190ms cubic-bezier(0.2, 0.7, 0.2, 1);
  transition-delay: calc(70ms + var(--i) * 55ms);
}
/* no transition into the starting position, only out of it */
.tr-group[data-starting-style] .tr-row:not(.tr-inv) { opacity: 0; translate: 0 -12px; transition: none; }
.tr-group[data-ending-style] .tr-row:not(.tr-inv) { opacity: 0; transition: opacity 90ms linear; }
