/* 540 frame, one printed page: a flood of green with the type reversed out and one pink.
   Columns: floor mark from x = 24, disclosure at 140, floor name at 162, department at 184, counter at 206,
   right edge 516. Rows: floor var(--row) (50 to 82), department 30, counter 24. */
.ds {
  --ink: #fbf3e4;
  --quiet: #fbf3e4b8;
  --pink: #ffb3ad;
  --green: #0a3d27;
  --rule: #fbf3e470;
  --t: 340ms;
  --ease: cubic-bezier(0.3, 0, 0.1, 1);
  position: relative;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: #0d5a31 url("./stock.jpg") center / 540px 540px;
  color: var(--ink);
  font-family: "Noto Serif Display Variable", serif;
  font-weight: 500;
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.ds * {
  box-sizing: border-box;
}

.ds-tree {
  position: absolute;
  top: 24px;
  left: 0;
  width: 540px;
  outline: 0;
}

/* the last rule closes the page */
.ds-tree::after {
  content: "";
  display: block;
  margin: 0 24px;
  border-top: 1px solid var(--rule);
}

.ds-item {
  outline: 0;
}

.ds-row {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: baseline;
  white-space: nowrap;
  cursor: pointer;
}

/* The chosen row is a strip of the pink with the type in the page's green. */
.ds-row::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 130px;
  right: 16px;
  background: transparent;
}

.ds-row[data-selected] {
  color: var(--green);
}

.ds-row[data-selected]::before {
  background: var(--pink);
}

.ds-item:focus-visible > .ds-row::before {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

@media (hover: hover) {
  .ds-row:not([data-selected]):hover .ds-name {
    color: var(--pink);
  }
}

/* Floors */
.ds-floor {
  height: var(--row);
  padding: 0 24px 0 140px;
  font-size: 36px;
  line-height: 50px;
  letter-spacing: -0.005em;
  transition: height var(--t) var(--ease);
}

.ds-floor::after {
  content: "";
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  border-top: 1px solid var(--rule);
}

.ds-floor::before {
  top: 5px;
  height: 42px;
}

/* The floor's mark hangs from the cap line of its name. Closed, it is as deep as the row allows; open, it
   is a drop cap that stands on the baseline of the second department. */
.ds-num {
  position: absolute;
  left: 24px;
  top: calc(13px - var(--cap-top) * 1em);
  --cap-top: 0.174;
  color: var(--pink);
  font-size: calc(var(--row) * 0.78);
  font-style: italic;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.02em;
  pointer-events: none;
  transition: font-size var(--t) var(--ease);
}

.ds-floor[data-expanded] .ds-num {
  font-size: calc((var(--row) + 40.6px) * 1.389);
}

/* Two letters take the narrow cut of the face, and stand on the first department instead. */
.ds-num[data-wide] {
  font-stretch: 62.5%;
  letter-spacing: 0;
}

.ds-floor[data-expanded] .ds-num[data-wide] {
  font-size: calc((var(--row) + 10.6px) * 1.389);
}

.ds-mark {
  flex: none;
  align-self: flex-start;
  width: 22px;
}

.ds-mark svg {
  display: block;
  width: 10px;
  height: 10px;
  fill: currentColor;
  transition: rotate 220ms var(--ease);
}

.ds-mark[data-expanded] svg {
  rotate: 90deg;
}

.ds-floor .ds-mark {
  margin-top: 21px;
}

.ds-where {
  margin-left: auto;
  font-size: 15px;
  font-style: italic;
  letter-spacing: 0.01em;
}

.ds-row:not([data-selected]) .ds-where {
  color: var(--quiet);
}

/* Departments and counters */
.ds-group {
  height: var(--tree-group-height);
  overflow: hidden;
  transition: height var(--t) var(--ease);
}

.ds-group:is([data-starting-style], [data-ending-style]) {
  height: 0;
}

.ds-dept {
  height: 30px;
  padding: 0 24px 0 162px;
  font-size: 22px;
  font-style: italic;
  line-height: 30px;
}

.ds-dept::before {
  top: 2px;
  height: 26px;
}

.ds-dept .ds-mark {
  margin-top: 11px;
}

.ds-dept .ds-mark svg {
  width: 8px;
  height: 8px;
}

.ds-dept:not(:has(.ds-mark)) {
  padding-left: 184px;
}

.ds-counter {
  height: 24px;
  padding: 0 24px 0 206px;
  font-size: 16px;
  font-stretch: 87.5%;
  line-height: 24px;
  letter-spacing: 0.01em;
}

.ds-counter::before {
  top: 1px;
  height: 22px;
}

.ds-counter .ds-where {
  font-size: 14.5px;
  font-stretch: 100%;
  letter-spacing: 0.01em;
}

/* Lines arrive one after another as their floor opens. */
.ds-group > .ds-item > .ds-row {
  animation: ds-in 360ms var(--ease) both;
  animation-delay: calc(var(--i) * 34ms + 70ms);
}

@keyframes ds-in {
  from {
    opacity: 0;
    translate: 0 -5px;
  }
}

.ds-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (prefers-reduced-motion: reduce) {
  .ds-floor,
  .ds-num,
  .ds-group,
  .ds-mark svg {
    transition: none;
  }

  .ds-group > .ds-item > .ds-row {
    animation: none;
  }
}
