/* The storage defragmenter: a phone's storage as a grid of blocks, alone on a white page, with its words above, the
   legend under it and the pill at the foot. The grid is painted by script.js on the canvas with the colours below. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #151517;           /* the words */
  --muted: #7d7a74;         /* the quiet words */
  --system: #1d1d21;        /* system blocks */
  --apps: #4f56e8;          /* app blocks */
  --photos: #ff7442;        /* photo blocks */
  --docs: #c9c2b4;          /* file blocks */
  --cache: #dedad2;         /* the cache, hatched, that gets cleared */
  --cache-ink: #a29d93;     /* the cache's hatching and its word */
  --free: #ecebe7;          /* the outline of a free block */
  --head: #151517;          /* the frame that marks the block being placed */
  --error: #e5362b;         /* a block that could not be moved */
  --ok: #1f9e5a;            /* optimized */
  --button: #151517;        /* the pill */
  --button-ink: #ffffff;    /* its words */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap, no zoom */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Martian Mono Variable', ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 40px 16px;
}

/* ---------------------------------------------------------------- the panel */
.df {
  display: grid;
  width: min(380px, 100%);
}

.df__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 1px;
}

.df__words {
  min-width: 0;
}

.df__title,
.df__meta {
  margin: 0;
  white-space: nowrap;
}

.df__title {
  font-size: 17px;
  font-weight: 560;
  font-variation-settings: 'wdth' 87.5;
  line-height: 24px;
  letter-spacing: -0.03em;
}

.df__meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 400;
  font-variation-settings: 'wdth' 87.5;
  line-height: 16px;
  letter-spacing: -0.01em;
}

/* the words change by rising out of a window */
.df__swap {
  display: inline-block;
}

.df[data-mode='stuck'] .df__title {
  color: var(--error);
}

.df[data-mode='done'] .df__title {
  color: var(--ok);
}

/* the percentage, and the tick that takes its place at the end */
.df__figure {
  position: relative;
  flex: none;
  display: grid;
  place-items: center end;
  min-width: 64px;
  height: 30px;
  margin: 0;
}

.df__pct {
  grid-area: 1 / 1;
  font-size: 24px;
  font-weight: 380;
  font-variation-settings: 'wdth' 75;
  line-height: 30px;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}

.df[data-mode='stuck'] .df__pct {
  color: var(--error);
}

.df__tick {
  grid-area: 1 / 1;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
}

/* ---------------------------------------------------------------- the grid */
.df__grid {
  position: relative;
  margin-top: 16px;
}

/* the canvas reaches a little past the grid on every side, so a lifted block and its shadow are never cut */
.df__canvas {
  display: block;
  width: calc(100% + 24px);
  margin: -12px;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the legend */
.df__legend {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0 1px;
  font-size: 10.5px;
  font-variation-settings: 'wdth' 75;
  line-height: 15px;
  letter-spacing: -0.01em;
}

.df__kind {
  color: color-mix(in srgb, var(--kind) 78%, #000000);
  font-weight: 520;
  white-space: nowrap;
}

.df__kind b {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.df__kind {
  justify-self: start;
}

.df__kind > span {
  text-decoration: line-through transparent 1px;
  transition: text-decoration-color 0.4s ease;
}

/* the cache, once cleared, is struck through */
.df__kind--cache.is-cleared > span {
  text-decoration-color: var(--cache-ink);
}

/* ---------------------------------------------------------------- the foot */
.df__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.df__status {
  min-width: 0;
  overflow: hidden;
  padding: 3px 1px;
  margin: -3px 0;
  color: var(--muted);
  font-size: 11px;
  font-variation-settings: 'wdth' 87.5;
  line-height: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.df[data-mode='stuck'] .df__status {
  color: var(--error);
}

/* the pill: its fill swells from the middle with a small give and the words widen on the wdth axis */
.pill {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  min-width: 112px;
  height: 44px;
  padding: 0 20px;
  overflow: hidden;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.25s ease;
}

.pill__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--button);
  transform: scale(1);
  transition: transform 0.55s cubic-bezier(0.3, 1.5, 0.5, 1), opacity 0.2s ease;
}

.pill__label {
  position: relative;
  display: inline-block;
  color: var(--button-ink);
  font-weight: 520;
  font-variation-settings: 'wdth' 87.5;
  letter-spacing: -0.02em;
  white-space: nowrap;
  transition: font-variation-settings 0.5s cubic-bezier(0.3, 1.5, 0.5, 1), color 0.25s ease;
}

/* while it works the pill is quiet: only its ring, the fill gone */
.pill.is-quiet .pill__fill {
  transform: scale(0.86, 0.4);
  opacity: 0;
}

.pill.is-quiet .pill__label {
  color: var(--ink);
}

@media (hover: hover) {
  .pill:hover .pill__label {
    font-variation-settings: 'wdth' 112.5;
  }

  .pill.is-quiet:hover .pill__fill {
    transform: scale(1);
    opacity: 1;
  }

  .pill.is-quiet:hover .pill__label {
    color: var(--button-ink);
  }
}

/* a finger, and the preview's pretend press, get the same as the mouse while they press */
.pill:active .pill__label,
.pill.is-pressed .pill__label {
  font-variation-settings: 'wdth' 112.5;
}

.pill.is-quiet:active .pill__fill,
.pill.is-quiet.is-pressed .pill__fill {
  transform: scale(1);
  opacity: 1;
}

.pill.is-quiet:active .pill__label,
.pill.is-quiet.is-pressed .pill__label {
  color: var(--button-ink);
}

.pill:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .pill__fill {
    transition: opacity 0.25s ease;
  }

  .pill.is-quiet .pill__fill {
    transform: none;
  }

  .pill__label {
    transition: color 0.25s ease;
  }
}
