/* The file tree on a leash: a light grey panel on a white page, manila folders, white paper for the file chosen and
   cutting-mat green for the branch that holds the file you carry. */
:root {
  --page: #ffffff;          /* the page */
  --panel: #f5f5f2;         /* the panel */
  --edge: #e3e3de;          /* the panel's edge */
  --ink: #1c1f1d;           /* the names */
  --muted: #646a66;         /* the extensions and the quiet words */
  --guide: #cdd2ce;         /* the branch lines */
  --hover: #ebebe7;         /* a row under the mouse */
  --press: #e3e3de;         /* a row pressed */
  --chip: #ffffff;          /* the file chosen, and the file carried */
  --accent: #2b7657;        /* the branch that holds the file you carry, and the folder that will take it */
  --folder: #e6c682;        /* the folders */
  --folder-back: #d0a95a;   /* the back of the folders */
  --paper: #ffffff;         /* the files */
  --paper-line: #8b918d;    /* the files' outline and drawing */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Host Grotesk Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* the panel hangs from the top: it grows and shrinks downwards as the folders open and close, and never jumps */
.stage {
  min-height: 100svh;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: max(32px, 13vh) 16px 32px;
}

.explorer {
  --row: 30px;
  --indent: 16px;
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(304px, 100%);
  max-height: 560px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 1px 1px rgba(28, 31, 29, 0.04), 0 16px 32px -18px rgba(28, 31, 29, 0.24);
  overflow: hidden;
}

/* fingers get rows of 44 pixels */
@media (pointer: coarse) {
  .explorer {
    --row: 44px;
    --indent: 18px;
    width: min(336px, 100%);
  }
}

.explorer__head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 8px 0 16px;
}

/* a hairline under the title once the list has scrolled under it */
.explorer__head {
  position: relative;
  z-index: 1;
  box-shadow: 0 1px 0 transparent;
  transition: box-shadow 0.2s;
}

.explorer.is-scrolled .explorer__head {
  box-shadow: 0 1px 0 var(--edge);
}

.explorer__title {
  margin: 0;
  font-size: 15px;
  font-weight: 640;
  letter-spacing: -0.01em;
}

.explorer__tool {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.12s ease-out, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.explorer__tool svg,
.explorer__undo svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .explorer__tool:hover:not(:disabled) {
    background: var(--hover);
    color: var(--ink);
  }
}

.explorer__tool:active:not(:disabled) {
  transform: scale(0.92);
}

.explorer__tool:disabled {
  opacity: 0.4;
  cursor: default;
}

@media (pointer: coarse) {
  .explorer__tool {
    width: 44px;
    height: 44px;
  }
}

/* ---------------------------------------------------------------- the tree */
.explorer__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 6px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--guide) transparent;
}

.canvas {
  position: relative;
}

.lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.lines__guides {
  fill: none;
  stroke: var(--guide);
  stroke-width: 1.25;
  stroke-linecap: round;
}

.lines__wire {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* the space a file leaves behind while it is carried */
.lines__hole {
  fill: none;
  stroke: var(--guide);
  stroke-width: 1.25;
  stroke-dasharray: 3 3;
}

/* the folder that will take the file carried */
.lines__band {
  fill: color-mix(in srgb, var(--accent) 8%, transparent);
  stroke: color-mix(in srgb, var(--accent) 34%, transparent);
  stroke-width: 1;
  opacity: 0;
}

.tree {
  position: absolute;
  inset: 0;
  outline: none;
}

.row {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  height: var(--row);
  padding: 0 8px 0 calc(8px + (var(--level, 1) - 1) * var(--indent));
  font-size: 14px;
  font-weight: 450;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
  will-change: transform;
}

.row--file {
  cursor: grab;
}

.row--file::before {
  left: calc(22px + (var(--level, 1) - 1) * var(--indent));
}

/* the row's own ground: a white sheet when it is the one chosen or the one carried. It starts where the row's
   twig ends, so the branch holds it */
.row::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: 1px;
  bottom: 1px;
  left: calc(10px + (var(--level, 1) - 1) * var(--indent));
  right: 2px;
  border-radius: 8px;
  background: transparent;
  transition: background-color 0.15s, box-shadow 0.2s, left 0.22s cubic-bezier(0.23, 1, 0.32, 1), right 0.22s cubic-bezier(0.23, 1, 0.32, 1);
}

@media (hover: hover) {
  .row:hover::before {
    background: var(--hover);
  }
}

.row[aria-selected='true']::before {
  background: var(--chip);
  box-shadow: 0 0 0 1px rgba(28, 31, 29, 0.06), 0 1px 2px rgba(28, 31, 29, 0.08);
}

.row[aria-selected='true'] .row__name {
  font-weight: 600;
}

/* pressed */
.row:not([aria-selected='true']):not(.is-lifted):active::before {
  background: var(--press);
}

/* held down by a finger, before it comes away */
.row.is-pressing::before {
  background: var(--hover);
  transition: background-color 0.3s;
}

/* carried: the sheet closes round the name and casts a shadow */
.row.is-lifted {
  z-index: 5;
  cursor: grabbing;
}

.row.is-lifted:not(.is-wide)::before {
  right: var(--lift-right, 2px);
}

.row.is-lifted::before {
  transition: box-shadow 0.2s, left 0.22s cubic-bezier(0.23, 1, 0.32, 1), right 0.22s cubic-bezier(0.23, 1, 0.32, 1);
  background: var(--chip);
  box-shadow: 0 0 0 1px rgba(28, 31, 29, 0.07), 0 12px 24px -10px rgba(28, 31, 29, 0.38), 0 2px 4px rgba(28, 31, 29, 0.06);
}

/* the folder under the file carried */
.row.is-target .row__name {
  color: var(--accent);
}

/* cut with the keys, waiting for a folder */
.row.is-cut .row__icon,
.row.is-cut .row__name {
  opacity: 0.45;
}

.row:focus-visible::after {
  content: '';
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: calc(10px + (var(--level, 1) - 1) * var(--indent));
  right: 2px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--accent);
  pointer-events: none;
}

html[data-using='pointer'] .row:focus-visible::after {
  content: none;
}

.row--file:focus-visible::after {
  left: calc(22px + (var(--level, 1) - 1) * var(--indent));
}

.row__chev {
  flex: none;
  width: 16px;
  height: 16px;
  margin-right: 4px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

span.row__chev {
  display: block;
}

.row__icon {
  flex: none;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  overflow: visible;
}

.row__folder-back {
  fill: var(--folder-back);
}

.row__folder {
  fill: var(--folder);
}

.row__file {
  fill: var(--paper);
  stroke: var(--paper-line);
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.row__mark {
  fill: none;
  stroke: var(--paper-line);
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.row__mark--fill {
  fill: var(--paper-line);
  stroke: none;
}

.row__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}

.row__ext {
  color: var(--muted);
}

.row--empty {
  color: var(--muted);
  cursor: default;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the line at the bottom after a move */
.explorer__foot {
  flex: none;
  height: 0;
  overflow: hidden;
  visibility: hidden;
}

.explorer__foot-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 44px;
  margin: 0 8px;
  padding: 0 0 0 8px;
  border-top: 1px solid var(--edge);
}

.explorer__note {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.explorer__note b {
  color: var(--ink);
  font-weight: 600;
}

.explorer__undo {
  flex: none;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: 600 13px 'Host Grotesk Variable', system-ui, sans-serif;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.12s ease-out;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .explorer__undo:hover {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }
}

.explorer__undo:active {
  transform: scale(0.95);
}

@media (pointer: coarse) {
  .explorer__undo {
    height: 44px;
  }
}

.explorer__tool:focus-visible,
.explorer__undo:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

html[data-using='pointer'] .explorer__tool:focus-visible,
html[data-using='pointer'] .explorer__undo:focus-visible {
  outline: none;
}

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